diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-03-07 21:12:57 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-03-07 21:12:57 +0000 |
| commit | 858f01dedbb681c8e62c9dae4d7c3174991844bf (patch) | |
| tree | efe86d519ff4965373b1a2fe1f59b30e14d73d7e /src/shot.c | |
| parent | 44404eb5063bd5f040c7a4d8605aa3d43e3a968a (diff) | |
-podpora teleportov
-podpora rur
git-svn-id: http://opensvn.csie.org/tuxanci_ng@9 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/shot.c')
| -rw-r--r-- | src/shot.c | 112 |
1 files changed, 112 insertions, 0 deletions
@@ -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 ); |