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/shot.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'src/shot.c') diff --git a/src/shot.c b/src/shot.c index d57d2df..48fd223 100644 --- a/src/shot.c +++ b/src/shot.c @@ -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 ); -- cgit v1.2.3