diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/Makefile | 10 | ||||
| -rw-r--r-- | src/arena.c | 4 | ||||
| -rw-r--r-- | src/arenaFile.c | 59 | ||||
| -rw-r--r-- | src/pipe.c | 174 | ||||
| -rw-r--r-- | src/screen_world.c | 15 | ||||
| -rw-r--r-- | src/shot.c | 112 | ||||
| -rw-r--r-- | src/teleport.c | 197 | ||||
| -rw-r--r-- | src/tux.c | 31 | ||||
| -rw-r--r-- | src/zal_pipe.c | 256 |
9 files changed, 851 insertions, 7 deletions
diff --git a/src/Makefile b/src/Makefile index 2d5921b..2aafa95 100755 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ CC = gcc #CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall -CFLAGS = -O2 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall +CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer @@ -11,8 +11,7 @@ FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o buffer.o dynamicInt.o arena.o arenaFile.o textFile.o sound.o audio.o music.o gun.o \ item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \ widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \ - widget_buttonimage.o screen_credits.o - + widget_buttonimage.o screen_credits.o teleport.o pipe.o tuxanci-ng: $(FILES) $(CC) $(CFLAGS) $(LIBS) -o tuxanci-ng $(FILES) @@ -134,6 +133,11 @@ widget_check.o: widget_check.c ../include/widget_check.h widget_image.o: widget_image.c ../include/widget_image.h $(CC) $(CFLAGS) -o widget_image.o -c widget_image.c +teleport.o: teleport.c ../include/teleport.h + $(CC) $(CFLAGS) -o teleport.o -c teleport.c + +pipe.o: pipe.c ../include/pipe.h + $(CC) $(CFLAGS) -o pipe.o -c pipe.c clean: rm -rf *.o *.c~ *.h~ tuxanci-ng diff --git a/src/arena.c b/src/arena.c index 320a697..6ce2712 100644 --- a/src/arena.c +++ b/src/arena.c @@ -22,6 +22,8 @@ arena_t* newArena() new->listShot = newList(); new->listWall = newList(); new->listItem = newList(); + new->listTeleport = newList(); + new->listPipe = newList(); return new; } @@ -32,6 +34,8 @@ void destroyArena(arena_t *p) destroyListItem(p->listShot, destroyShot); destroyListItem(p->listWall, destroyWall); destroyListItem(p->listItem, destroyItem); + destroyListItem(p->listTeleport, destroyItem); + destroyListItem(p->listPipe, destroyItem); free(p); } diff --git a/src/arenaFile.c b/src/arenaFile.c index e1cc5b4..64e59a4 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -12,6 +12,8 @@ #include "tux.h" #include "shot.h" #include "wall.h" +#include "pipe.h" +#include "teleport.h" #include "item.h" #include "director.h" #include "path.h" @@ -140,6 +142,61 @@ static void cmd_wall(arena_t *arena, char *line) addList(arena->listWall, new); } +static void cmd_teleport(arena_t *arena, char *line) +{ + char str_x[STR_NUM_SIZE]; + char str_y[STR_NUM_SIZE]; + char str_w[STR_NUM_SIZE]; + char str_h[STR_NUM_SIZE]; + char str_layer[STR_NUM_SIZE]; + char str_image[STR_SIZE]; + teleport_t *new; + + if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "image", str_image, STR_SIZE) != 0 )return; + + new = newTeleport(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_layer), getImage(IMAGE_GROUP_USER, str_image) ); + + addList(arena->listTeleport, new); +} + +static void cmd_pipe(arena_t *arena, char *line) +{ + char str_x[STR_NUM_SIZE]; + char str_y[STR_NUM_SIZE]; + char str_w[STR_NUM_SIZE]; + char str_h[STR_NUM_SIZE]; + char str_id[STR_NUM_SIZE]; + char str_id_out[STR_NUM_SIZE]; + char str_position[STR_NUM_SIZE]; + char str_layer[STR_NUM_SIZE]; + char str_image[STR_SIZE]; + pipe_t *new; + + if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "id", str_id, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "position", str_position, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return; + if( setValue(line, "image", str_image, STR_SIZE) != 0 )return; + + new = newPipe(atoi(str_x), atoi(str_y), + atoi(str_w), atoi(str_h), + atoi(str_layer), atoi(str_id), atoi(str_id_out), atoi(str_position), + getImage(IMAGE_GROUP_USER, str_image) ); + + addList(arena->listPipe, new); +} + int getArenaCount() { return listArenaFile->count; @@ -225,6 +282,8 @@ arena_t* getArena(int id) if( strncmp(line, "background", 10) == 0 )cmd_background(arena, line); if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); if( strncmp(line, "wall", 4) == 0 )cmd_wall(arena, line); + if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(arena, line); + if( strncmp(line, "pipe", 4) == 0 )cmd_pipe(arena, line); } return arena; 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); +} + diff --git a/src/screen_world.c b/src/screen_world.c index b7895e6..439cefa 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -19,6 +19,8 @@ #include "sound.h" #include "tux.h" #include "wall.h" +#include "teleport.h" +#include "pipe.h" #include "item.h" #include "shot.h" #include "gun.h" @@ -178,6 +180,8 @@ void drawWorld() drawListTux(arena->listTux); drawListWall(arena->listWall); + drawListTeleport(arena->listTeleport); + drawListPipe(arena->listPipe); drawListShot(arena->listShot); drawListItem(arena->listItem); @@ -206,6 +210,8 @@ int isFreeSpace(int x, int y, int w, int h) if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0; if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0; if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0; + if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0; + if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0; return 1; } @@ -356,11 +362,16 @@ void eventWorld() return; } - eventConflictShotWithTux(arena->listTux, arena->listShot); + eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport); + eventConflictTuxWithShot(arena->listTux, arena->listShot); + eventConflictShotWithWall(arena->listWall, arena->listShot); + eventConflictShotWithTeleport(arena->listTeleport, arena->listShot); + eventConflictShotWithPipe(arena->listPipe, arena->listShot); + eventConflictShotWithItem(arena->listItem, arena->listShot); + eventMoveListShot(arena->listShot); eventListItem(arena->listItem); - eventConflictShotWithItem(arena->listItem, arena->listShot); eventListTux(arena->listTux); eventTimer(); @@ -48,6 +48,7 @@ shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author) new->py = py; new->gun = gun; new->author = author; + new->position = author->position; new->isCanKillAuthor = FALSE; switch( gun ) @@ -152,6 +153,117 @@ void eventMoveListShot(list_t *listShot) } } +static int myAbs(int n) +{ + return ( n > 0 ? n : -n ); +} + +static int getSppedShot(shot_t *shot) +{ + return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); +} + +static void eventOnlyLasser(shot_t *shot) +{ + switch( shot->position ) + { + case TUX_RIGHT : + case TUX_LEFT : + shot->w = GUN_LASSER_HORIZONTAL; + shot->h = GUN_SHOT_VERTICAL; + shot->img = g_shot_lasserX; + break; + case TUX_UP : + case TUX_DOWN : + shot->w = GUN_SHOT_VERTICAL; + shot->h = GUN_LASSER_HORIZONTAL; + shot->img = g_shot_lasserY; + break; + } +} + +static void transformShot(shot_t *shot, int position) +{ + int speed; + + speed = getSppedShot(shot); + + switch( position ) + { + case TUX_UP : + shot->px = 0; + shot->py = -speed; + break; + + case TUX_LEFT : + shot->px = -speed; + shot->py = 0; + break; + + case TUX_RIGHT : + shot->px = speed; + shot->py = 0; + break; + + case TUX_DOWN : + shot->px = 0; + shot->py = +speed; + break; + } + + shot->position = position; + shot->isCanKillAuthor = TRUE; + + if( shot->gun == GUN_LASSER ) + { + eventOnlyLasser(shot); + } +} + +void moveShot(shot_t *shot, int position, int src_x, int src_y, + int dist_x, int dist_y, int dist_w, int dist_h) +{ + int offset; + + switch( shot->position ) + { + case TUX_UP : + case TUX_DOWN : + offset = shot->x - src_x; + break; + + case TUX_RIGHT : + case TUX_LEFT : + offset = shot->y - src_y; + break; + } + + transformShot(shot, position); + + switch( shot->position ) + { + case TUX_UP : + shot->x = dist_x + offset; + shot->y = dist_y; + break; + + case TUX_LEFT : + shot->x = dist_x; + shot->y = dist_y + offset; + break; + + case TUX_RIGHT : + shot->x = dist_x + dist_w; + shot->y = dist_y + offset; + break; + + case TUX_DOWN : + shot->x = dist_x + offset; + shot->y = dist_y + dist_h; + break; + } +} + void destroyShot(shot_t *p) { assert( p != NULL ); diff --git a/src/teleport.c b/src/teleport.c new file mode 100644 index 0000000..f0d9c57 --- /dev/null +++ b/src/teleport.c @@ -0,0 +1,197 @@ + +#include <stdlib.h> +#include <assert.h> + +#include "tux.h" +#include "teleport.h" +#include "layer.h" +#include "screen_world.h" +#include "shot.h" +#include "sound.h" + +teleport_t* newTeleport(int x, int y, int w, int h, int layer, SDL_Surface *img) +{ + teleport_t *new; + + assert( img != NULL ); + + new = malloc( sizeof(teleport_t) ); + assert( new != NULL ); + + new->x = x; + new->y = y; + new->w = w; + new->h = h; + new->layer = layer; + new->img = img; + + return new; +} + +void drawTeleport(teleport_t *p) +{ + assert( p != NULL ); + + addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, p->layer); +} + +void drawListTeleport(list_t *listTeleport) +{ + teleport_t *thisTeleport; + int i; + + assert( listTeleport != NULL ); + + for( i = 0 ; i < listTeleport->count ; i++ ) + { + thisTeleport = (teleport_t *)listTeleport->list[i]; + assert( thisTeleport != NULL ); + drawTeleport(thisTeleport); + } +} + +teleport_t* isConflictWithListTeleport(list_t *listTeleport, int x, int y, int w, int h) +{ + teleport_t *thisTeleport; + int i; + + assert( listTeleport != NULL ); + + for( i = 0 ; i < listTeleport->count ; i++ ) + { + thisTeleport = (teleport_t *)listTeleport->list[i]; + assert( thisTeleport != NULL ); + + if( conflictSpace(x, y, w, h, + thisTeleport->x, thisTeleport->y, thisTeleport->w, thisTeleport->h) ) + { + return thisTeleport; + } + } + + return NULL; +} + +static teleport_t* getRandomTeleportBut(list_t *listTeleport, teleport_t *teleport) +{ + int x; + + do{ + x = random() % listTeleport->count; + }while( listTeleport->list[x] == teleport ); + + return (teleport_t *) listTeleport->list[x]; +} + +static int getRandomPosition() +{ + switch( random() % 4 ) + { + case 0 : + return TUX_UP; + + case 1 : + return TUX_LEFT; + + case 2 : + return TUX_RIGHT; + + case 3 : + return TUX_DOWN; + } + + assert( ! "Stupid error ! " ); +} + +static void moveShotFromTeleport(shot_t *shot, teleport_t *teleport, list_t *listTeleport) +{ + teleport_t *distTeleport; + + distTeleport = getRandomTeleportBut(listTeleport, teleport); + + moveShot(shot, getRandomPosition(), teleport->x, teleport->y, + distTeleport->x, distTeleport->y, distTeleport->w, distTeleport->h); +} + +void eventConflictShotWithTeleport(list_t *listTeleport, list_t *listShot) +{ + shot_t *thisShot; + teleport_t *thisTeleport; + int i; + + assert( listTeleport != NULL ); + assert( listShot != NULL ); + + for( i = 0 ; i < listShot->count ; i++ ) + { + thisShot = (shot_t *)listShot->list[i]; + assert( thisShot != NULL ); + + if( ( thisTeleport = isConflictWithListTeleport(listTeleport, thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) != NULL ) + { + if( thisShot->author->bonus == BONUS_GHOST && + thisShot->author->bonus_time > 0 ) + { + continue; + } + + moveShotFromTeleport(thisShot, thisTeleport, listTeleport); + } + } +} + +void eventTeleportTux(list_t *listTeleport, teleport_t *teleport, tux_t *tux) +{ + teleport_t *distTeleport; + int current_x, current_y; + int dist_x, dist_y; + + if( tux->bonus == BONUS_GHOST ) + { + return; + } + + distTeleport = getRandomTeleportBut(listTeleport, teleport); + + getTuxProportion(tux, ¤t_x, ¤t_y, NULL, NULL); + + switch( tux->position ) + { + case TUX_UP : + dist_x = distTeleport->x + distTeleport->w/2; + dist_y = distTeleport->y - ( TUX_HEIGHT + 10 ); + break; + + case TUX_LEFT : + dist_y = distTeleport->y + distTeleport->h/2; + dist_x = distTeleport->x - ( TUX_WIDTH + 10 ); + break; + + case TUX_RIGHT : + dist_y = distTeleport->y + distTeleport->h/2; + dist_x = distTeleport->x + distTeleport->w + 10; + break; + + case TUX_DOWN : + dist_x = distTeleport->x + distTeleport->w/2; + dist_y = distTeleport->y + distTeleport->h + 10; + break; + + default : + assert( ! "premenna p->control ma zlu hodnotu !" ); + break; + } + + if( isFreeSpace(dist_x, dist_y, TUX_WIDTH, TUX_HEIGHT) ) + { + setTuxProportion(tux, dist_x, dist_y); + playSound("teleport", SOUND_GROUP_BASE); + } +} + +void destroyTeleport(teleport_t *p) +{ + assert( p != NULL ); + free(p); +} + @@ -13,6 +13,8 @@ #include "shot.h" #include "gun.h" #include "wall.h" +#include "teleport.h" +#include "pipe.h" #include "item.h" #include "arena.h" #include "myTimer.h" @@ -385,7 +387,7 @@ void tuxTeleport(tux_t *tux) } } -void eventConflictShotWithTux(list_t *listTux, list_t *listShot) +void eventConflictTuxWithShot(list_t *listTux, list_t *listShot) { shot_t *thisShot; tux_t *thisTux; @@ -428,6 +430,29 @@ void eventConflictShotWithTux(list_t *listTux, list_t *listShot) } } +void eventConflictTuxWithTeleport(list_t *listTux, list_t *listTeleport) +{ + teleport_t *thisTeleport; + tux_t *thisTux; + + int i; + + assert( listTux != NULL ); + assert( listTeleport != NULL ); + + for( i = 0 ; i < listTeleport->count ; i++ ) + { + thisTeleport = (teleport_t *)listTeleport->list[i]; + assert( thisTeleport != NULL ); + + if( ( thisTux = isConflictWithListTux(listTux, thisTeleport->x, thisTeleport->y, + thisTeleport->w, thisTeleport->h) ) != NULL ) + { + eventTeleportTux(listTeleport, thisTeleport, thisTux); + } + } +} + void moveTux(tux_t *tux, int n) { int px, py; @@ -480,9 +505,11 @@ void moveTux(tux_t *tux, int n) getTuxProportion(tux, &x, &y, &w, &h); + if( tux->bonus != BONUS_GHOST && ( isConflictTuxWithListTux(tux, arena->listTux) || - isConflictWithListWall(arena->listWall, x, y, w, h) ) ) + isConflictWithListWall(arena->listWall, x, y, w, h) || + isConflictWithListPipe(arena->listPipe, x, y, w, h) ) ) { tux->x = zal_x; tux->y = zal_y; diff --git a/src/zal_pipe.c b/src/zal_pipe.c new file mode 100644 index 0000000..65ba6b2 --- /dev/null +++ b/src/zal_pipe.c @@ -0,0 +1,256 @@ + +#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 int myAbs(int n) +{ + return ( n > 0 ? n : -n ); +} + +static int getSppedShot(shot_t *shot) +{ + return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); +} + +static void transformShot(shot_t *shot, int position) +{ + int speed; + + speed = getSppedShot(shot); + + switch( position ) + { + case TUX_UP : + shot->px = 0; + shot->py = -speed; + break; + + case TUX_LEFT : + shot->px = -speed; + shot->py = 0; + break; + + case TUX_RIGHT : + shot->px = speed; + shot->py = 0; + break; + + case TUX_DOWN : + shot->px = 0; + shot->py = +speed; + break; + + } + + shot->position = position; + shot->isCanKillAuthor = TRUE; +} + +static void moveShot(shot_t *shot, pipe_t *pipe, list_t *listPipe) +{ + pipe_t *distPipe; + int offset; + + distPipe = getPipeId(listPipe, pipe->id_out); + + if( distPipe == NULL ) + { + fprintf(stderr, "Pipe %d ID not found\n", pipe->id); + return; + } + + printf("XXX\n"); + + switch( shot->position ) + { + case TUX_UP : + case TUX_DOWN : + offset = shot->x - pipe->x; + break; + + case TUX_RIGHT : + case TUX_LEFT : + offset = shot->y - pipe->y; + break; + } + + transformShot(shot, distPipe->position); + + switch( shot->position ) + { + case TUX_UP : + shot->x = distPipe->x + offset; + shot->y = distPipe->y; + break; + + case TUX_LEFT : + shot->x = distPipe->x; + shot->y = distPipe->y + offset; + break; + + case TUX_RIGHT : + shot->x = distPipe->x + distPipe->w; + shot->y = distPipe->y + offset; + break; + + case TUX_DOWN : + shot->x = distPipe->x + offset; + shot->y = distPipe->y + distPipe->h; + break; + } +} + +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 ) + { + moveShot(thisShot, thisPipe, listPipe); + } + else + { + delListItem(listShot, i, destroyShot); + i--; + } + } + } +} + +void destroyPipe(pipe_t *p) +{ + assert( p != NULL ); + free(p); +} + |