diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
| commit | 6d4e1eae16b84918009625a866104ec26a234277 (patch) | |
| tree | a340a8a547a60c9f63c8dfafe8909242f9c9bbd8 /src/shot.c | |
nahranie tarballu tuxanci-ng na SVN server
Dusan Durech ( Oroborus )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@1 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/shot.c')
| -rw-r--r-- | src/shot.c | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/shot.c b/src/shot.c new file mode 100644 index 0000000..d57d2df --- /dev/null +++ b/src/shot.c @@ -0,0 +1,165 @@ + +#include <stdlib.h> +#include <assert.h> + +#include "main.h" +#include "shot.h" +#include "layer.h" +#include "image.h" +#include "gun.h" +#include "screen_world.h" + +static SDL_Surface *g_shot_simple; +static SDL_Surface *g_shot_lasserX; +static SDL_Surface *g_shot_lasserY; + +static bool_t isShotInit = FALSE; + +bool_t isShotInicialized() +{ + return isShotInit; +} + +void initShot() +{ + assert( isImageInicialized() == TRUE ); + + g_shot_simple = addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE); + g_shot_lasserX = addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX", IMAGE_GROUP_BASE); + g_shot_lasserY = addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY", IMAGE_GROUP_BASE); + + isShotInit = TRUE; +} + +shot_t* newShot(int x,int y, int px, int py, int gun, tux_t *author) +{ + shot_t *new; + static int last_id = 0; + + assert( author != NULL ); + + new = malloc( sizeof(shot_t) ); + memset(new, 0, sizeof(shot_t) ); + + new->id = ++last_id; + new->x = x; + new->y = y; + new->px = px; + new->py = py; + new->gun = gun; + new->author = author; + new->isCanKillAuthor = FALSE; + + switch( gun ) + { + case GUN_SIMPLE : + new->w = GUN_SHOT_WIDTH; + new->h = GUN_SHOT_HEIGHT; + new->img = g_shot_simple; + break; + + case GUN_LASSER : + switch( author-> position ) + { + case TUX_RIGHT : + case TUX_LEFT : + new->w = GUN_LASSER_HORIZONTAL; + new->h = GUN_SHOT_VERTICAL; + new->img = g_shot_lasserX; + break; + case TUX_UP : + case TUX_DOWN : + new->w = GUN_SHOT_VERTICAL; + new->h = GUN_LASSER_HORIZONTAL; + new->img = g_shot_lasserY; + break; + } + break; + + default : + assert( ! "Premenna weapon ma zlu hodnotu !" ); + break; + } + + return new; +} + +void drawShot(shot_t *p) +{ + assert( p != NULL ); + addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER); +} + +void drawListShot(list_t *listShot) +{ + shot_t *thisShot; + int i; + + assert( listShot != NULL ); + + for( i = 0 ; i < listShot->count ; i++ ) + { + thisShot = (shot_t *)listShot->list[i]; + assert( thisShot != NULL ); + drawShot(thisShot); + } +} + +int isConflictWithListShot(list_t *listShot, int x, int y, int w, int h) +{ + shot_t *thisShot; + int i; + + assert( listShot != NULL ); + + for( i = 0 ; i < listShot->count ; i++ ) + { + thisShot = (shot_t *)listShot->list[i]; + assert( thisShot != NULL ); + + if( conflictSpace(x, y, w, h, + thisShot->x, thisShot->y, thisShot->w, thisShot->h) ) + { + return 1; + } + } + + return 0; +} + +void eventMoveListShot(list_t *listShot) +{ + shot_t *thisShot; + int i; + + assert( listShot != NULL ); + + for( i = 0 ; i < listShot->count ; i++ ) + { + thisShot = (shot_t *)listShot->list[i]; + assert( thisShot != NULL ); + + thisShot->x += thisShot->px; + thisShot->y += thisShot->py; + + if( thisShot->x+thisShot->w < 0 || thisShot->x > WINDOW_SIZE_X || + thisShot->y+thisShot->h < 0 || thisShot->y > WINDOW_SIZE_Y ) + { + delListItem(listShot, i, destroyShot); + i--; + continue; + } + } +} + +void destroyShot(shot_t *p) +{ + assert( p != NULL ); + free(p); +} + +void quitShot() +{ + isShotInit = FALSE; +} + |