From 858f01dedbb681c8e62c9dae4d7c3174991844bf Mon Sep 17 00:00:00 2001 From: oroborus Date: Fri, 7 Mar 2008 21:12:57 +0000 Subject: -podpora teleportov -podpora rur git-svn-id: http://opensvn.csie.org/tuxanci_ng@9 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/pipe.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 src/pipe.c (limited to 'src/pipe.c') 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 +#include + +#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); +} + -- cgit v1.2.3