summaryrefslogtreecommitdiff
path: root/src/pipe.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-07 21:12:57 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-07 21:12:57 +0000
commit858f01dedbb681c8e62c9dae4d7c3174991844bf (patch)
treeefe86d519ff4965373b1a2fe1f59b30e14d73d7e /src/pipe.c
parent44404eb5063bd5f040c7a4d8605aa3d43e3a968a (diff)
-podpora teleportov
-podpora rur git-svn-id: http://opensvn.csie.org/tuxanci_ng@9 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/pipe.c')
-rw-r--r--src/pipe.c174
1 files changed, 174 insertions, 0 deletions
diff --git a/src/pipe.c b/src/pipe.c
new file mode 100644
index 0000000..c82cb65
--- /dev/null
+++ b/src/pipe.c
@@ -0,0 +1,174 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "pipe.h"
+#include "layer.h"
+#include "screen_world.h"
+#include "shot.h"
+
+pipe_t* newPipe(int x, int y, int w, int h, int layer, int id, int id_out, int position, SDL_Surface *img)
+{
+ pipe_t *new;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(pipe_t) );
+ assert( new != NULL );
+
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->layer = layer;
+ new->id = id;
+ new->id_out = id_out;
+ new->position = position;
+ new->img = img;
+
+ return new;
+}
+
+void drawPipe(pipe_t *p)
+{
+ assert( p != NULL );
+
+ addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer);
+}
+
+void drawListPipe(list_t *listPipe)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+ drawPipe(thisPipe);
+ }
+}
+
+pipe_t* isConflictWithListPipe(list_t *listPipe, int x, int y, int w, int h)
+{
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ thisPipe = (pipe_t *)listPipe->list[i];
+ assert( thisPipe != NULL );
+
+ if( conflictSpace(x, y, w, h,
+ thisPipe->x, thisPipe->y, thisPipe->w, thisPipe->h) )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static int negPosition(int n)
+{
+ switch( n )
+ {
+ case TUX_UP :
+ return TUX_DOWN;
+
+ case TUX_LEFT :
+ return TUX_RIGHT;
+
+ case TUX_RIGHT :
+ return TUX_LEFT;
+
+ case TUX_DOWN :
+ return TUX_UP;
+
+ default :
+ assert( ! "premenna n ma zlu hodnotu !" );
+ break;
+ }
+}
+
+static pipe_t* getPipeId(list_t *listPipe, int id)
+{
+ int i;
+
+ for( i = 0 ; i < listPipe->count ; i++ )
+ {
+ pipe_t *thisPipe;
+
+ thisPipe = (pipe_t *) listPipe->list[i];
+
+ if( thisPipe->id == id )
+ {
+ return thisPipe;
+ }
+ }
+
+ return NULL;
+}
+
+static void moveShotFromPipe(shot_t *shot, pipe_t *pipe, list_t *listPipe)
+{
+ pipe_t *distPipe;
+
+ distPipe = getPipeId(listPipe, pipe->id_out);
+
+ if( distPipe == NULL )
+ {
+ fprintf(stderr, "Pipe %d ID not found\n", pipe->id);
+ return;
+ }
+
+ moveShot(shot, distPipe->position, pipe->x, pipe->y,
+ distPipe->x, distPipe->y, distPipe->w, distPipe->h);
+}
+
+void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot)
+{
+ shot_t *thisShot;
+ pipe_t *thisPipe;
+ int i;
+
+ assert( listPipe != NULL );
+ assert( listShot != NULL );
+
+ for( i = 0 ; i < listShot->count ; i++ )
+ {
+ thisShot = (shot_t *)listShot->list[i];
+ assert( thisShot != NULL );
+
+ if( ( thisPipe = isConflictWithListPipe(listPipe, thisShot->x, thisShot->y,
+ thisShot->w, thisShot->h) ) != NULL )
+ {
+ if( thisShot->author->bonus == BONUS_GHOST &&
+ thisShot->author->bonus_time > 0 )
+ {
+ continue;
+ }
+
+ if( negPosition( thisShot->position ) == thisPipe->position )
+ {
+ moveShotFromPipe(thisShot, thisPipe, listPipe);
+ }
+ else
+ {
+ delListItem(listShot, i, destroyShot);
+ i--;
+ }
+ }
+ }
+}
+
+void destroyPipe(pipe_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}
+