/* ** BETATRON high level library for platform and action arcade games. ** Copyright (C) 1997 Liouros Thanasis, liouros@hotmail.com ** ** OBJECTS.CC: This file is part of the BETATRON library and can be used ** and/or distributed only under the terms of the GNU Library ** General Public License. See doc/readme.1st for details. */ #include "world.h" #include "plvga.h" //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // returns TRUE if the 2 boxes have common place (collide) #define MACROiscmplace(x1,y1,x2,y2, X1,Y1,X2,Y2) \ ( ((long)(X1)-(long)(x2))*((long)(X2)-(long)(x1)) <= 0L && \ ((long)(Y1)-(long)(y2))*((long)(Y2)-(long)(y1)) <= 0L \ ) void TOworld::callactionfunctions() { unsigned short x2,y2; int i; objdeleted=0; for (i=0;(ideadbit) { if ( worldlist->activebit || (worldlist->visbit!=VIS_INVISIBLE) ) worldlist->callnext(); else if ( worldlist->rangeactivebit) { x2=x+Xres-1; y2=y+Yres-1; if (MACROiscmplace(x,y,x2,y2, worldlist->rx1, worldlist->ry1, worldlist->rx2,worldlist->ry2)) worldlist->callnext(); } } // ean mia action function svisei to antikeimeno me delete // tote to pedio Pnext den exei noima // frontizei i removeobj kai removelistobj na mas dosoun // stin worldlist to epomeno stoixeio tis listas if (!objdeleted) worldlist=worldlist->Pnext2; else objdeleted=0; } // worldlist for } worldlist=0; }; //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- short TOworld::addobj(unsigned char listno,TOobject *obj,unsigned char priority) { TOobject *plist; if ( (listno >= LISTSNO) || (priority>=PRIORITIESNO)) return ERR_OUTOFRANGE; // ektos orion to listno plist = objs[listno]; // o deiktis sto antikeimeno *obj eisagete kai sti 2 listes diplis kateuthinsis // enimerose prota ti lista ton sprites // exoume dipli lista if (plist) plist->Pprev = obj; obj->Pnext = plist; objs[listno] = obj; obj->Pprev = NULL; // enimerose tora tin lista proteraiotiton ektiposis plist = priorities[priority]; if (plist) plist->Pprev2 = obj; obj->Pnext2 = plist; priorities[priority] = obj; obj->Pprev2 = NULL; obj->setpriority(priority); // arithmos listas proteraiotitas obj->type=listno; // arithmos listas antikeimenon // objsno[listno]++; // auksise ton metriti antikeimenon stin antistoixi lista obj->owner=this; // these ton patera return ERR_NOERR; }; //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // afairei to antikeimeno me id id0 apo ti lista ip arithmon listno // an ta kataferei epistrefei ena deikti sto antikeimeno diaforetika // epistrefei NULL. Prosoxi den apodesmeuetai tixon mnimi pou katalamvanei // to antikeimeno. Xrisimopoihste to deikti pou epistrefetai gia na // apodesmeusetai ti mnimi. Episis afairei to antikeimeno apo ti lista // proteraiotitas pou tou exei antistoixithei TOobject *TOworld::removelistobj(unsigned char listno,unsigned short id0) { TOobject *plist,*ptmp; if (listno >=LISTSNO) return NULL; // ektos orion to listno for ( plist = objs[listno];plist;plist=plist->Pnext) { if (plist->id == id0 ) // vrikame to id { // afairese to stoixeio apo ti lista antikeimenon prota if ( plist->Pprev == NULL ) // proto stoixeio tis listas { ptmp=plist->Pnext; objs[listno]=ptmp; if (ptmp) ptmp->Pprev = NULL; } else { plist->Pprev->Pnext = plist -> Pnext; if (plist->Pnext) plist->Pnext->Pprev = plist->Pprev; }; // afairese to kai apo ti lista proteraiotitas tou // elegkse prota an exoume klithei apo tin callactionfunctions // kai to antikeimeno plist einai to trexon stin call... if (plist==worldlist) { worldlist=plist->Pnext2; objdeleted=1;} if ( plist->Pprev2 == NULL ) // proto stoixeio tis listas { ptmp=plist->Pnext2; priorities[plist->getpriority()]=ptmp; if (ptmp) ptmp->Pprev2 = NULL; } else { plist->Pprev2->Pnext2 = plist -> Pnext2; if (plist->Pnext2) plist->Pnext2->Pprev2 = plist->Pprev2; }; // objsno[listno]--; // meion o 1 o metritis stoixeion tis listas listno return plist; // epestrepse to stoixeio pou afaireses } } return NULL; // to stoixeio den brethike sti lista }; //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // psaxnei na vrei ena antikeimeno me id id0 se oles tis listes gia na to afairesei // an to petixei epistrefei ena deikti sto antikeimeno ,diaforetika epistrefei NULL TOobject *TOworld::removeobjid(unsigned short id0) { TOobject *res; for (int i=0;itype; TOobject *ptmp; if (!obj) return ERR_NULLOBJ; if (listno>=LISTSNO) return ERR_OUTOFRANGE; // afairese to stoixeio apo ti lista antikeimenon prota if ( obj->Pprev == NULL ) // proto stoixeio tis listas { ptmp=obj->Pnext; objs[listno]=ptmp; if (ptmp) ptmp->Pprev = NULL; } else { obj->Pprev->Pnext = obj -> Pnext; if (obj->Pnext) obj->Pnext->Pprev = obj->Pprev; }; // afairese to kai apo ti lista proteraiotitas tou if (obj==worldlist) { worldlist=obj->Pnext2; objdeleted=1;} if ( obj->Pprev2 == NULL ) // proto stoixeio tis listas { ptmp=obj->Pnext2; priorities[obj->getpriority()]=ptmp; if (ptmp) ptmp->Pprev2 = NULL; } else { obj->Pprev2->Pnext2 = obj -> Pnext2; if (obj->Pnext2) obj->Pnext2->Pprev2 = obj->Pprev2; }; return ERR_NOERR; } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- TOobject *TOworld::getlistobjpointer(unsigned char listno,unsigned short id0) { TOobject *plist; if (listno >=LISTSNO) return NULL; // ektos orion to listno for ( plist = objs[listno];plist;plist=plist->Pnext) if (plist->id == id0 ) // vrikame to id return plist; // epestrepse to proto stoixeio me id=id0 pou vrikes return NULL; // den vrikes tipota epestrepse NULL } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- TOobject *TOworld::getobjpointer(unsigned short id0) { TOobject *plist; for (int i=0;iPnext) if (plist->id == id0 ) // vrikame to id return plist; // epestrepse to proto stoixeio me id=id0 pou vrikes return NULL; //den vrethike tipota }