diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-09 20:49:15 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-09 20:49:15 +0000 |
| commit | ec218f423abf60b6e776d7a5a9ebee408de45a60 (patch) | |
| tree | 47304e931ff78ad6dc62226d845ec6faa7b0af2e /src/tux.c | |
| parent | 601a366b8c665f760463259552fedd7be43e5754 (diff) | |
- oprava chyby, pri zmeneni zbrane zo samopala, alebo lassera ( informoval xHire )
- prepis sietoveho protokolu, teraz je bezpecnejsi
git-svn-id: http://opensvn.csie.org/tuxanci_ng@3 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/tux.c')
| -rw-r--r-- | src/tux.c | 120 |
1 files changed, 73 insertions, 47 deletions
@@ -58,6 +58,7 @@ tux_t* newTux() new->id = last_id++; new->status = TUX_STATUS_ALIVE; new->control = TUX_CONTROL_NONE; + findFreeSpace(&new->x, &new->y, TUX_WIDTH, TUX_HEIGHT); new->position = TUX_DOWN; new->gun = GUN_SIMPLE; @@ -291,21 +292,12 @@ static void timer_spawnTux(void *p) tux->status = TUX_STATUS_ALIVE; findFreeSpace(&tux->x, &tux->y, TUX_WIDTH, TUX_HEIGHT); tux->gun = GUN_SIMPLE; - - memset(tux->shot, 0, sizeof(int) * GUN_COUNT); - tux->shot[ tux->gun ] = GUN_MAX_SHOT; - - tux->bonus = BONUS_NONE; - tux->bonus_time = 0; - - tux->isCanShot = TRUE; - tux->isCanSwitchGun = TRUE; addNewItem(arena->listItem); if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_settux(tux); + proto_send_newtux_server(NULL, tux); } } @@ -339,40 +331,6 @@ static void timer_tuxCanSwitchGun(void *p) tux->isCanSwitchGun = TRUE; } -void switchTuxGun(tux_t *tux) -{ - int i; - - if( tux->isCanSwitchGun == FALSE ) - { - return; - } - - playSound("switch_gun", SOUND_GROUP_BASE); - - for( i = tux->gun+1 ; i < GUN_COUNT ; i++ ) - { - if( tux->shot[i] > 0 ) - { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); - return; - } - } - - for( i = 0 ; i < GUN_COUNT ; i++ ) - { - if( tux->shot[i] > 0 ) - { - tux->gun = i; - tux->isCanSwitchGun = FALSE; - addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); - return; - } - } -} - void eventTuxIsDead(tux_t *tux) { if( tux->status == TUX_STATUS_DEAD ) @@ -381,7 +339,17 @@ void eventTuxIsDead(tux_t *tux) } playSound("dead", SOUND_GROUP_BASE); + tux->status = TUX_STATUS_DEAD; + memset(tux->shot, 0, sizeof(int) * GUN_COUNT); + tux->gun = GUN_SIMPLE; + tux->shot[ tux->gun ] = GUN_MAX_SHOT; + + tux->bonus = BONUS_NONE; + tux->bonus_time = 0; + + tux->isCanShot = TRUE; + tux->isCanSwitchGun = TRUE; if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) { @@ -405,7 +373,7 @@ void tuxTeleport(tux_t *tux) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_settux(tux); + proto_send_newtux_server(NULL, tux); } } @@ -465,7 +433,6 @@ void moveTux(tux_t *tux, int n) if( tux->position != n ) { tux->position = n; - if( getNetTypeGame() != NET_GAME_TYPE_NONE )proto_send_settux(tux); return; } @@ -518,7 +485,40 @@ void moveTux(tux_t *tux, int n) tux->frame++; if( tux->frame == TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; - if( getNetTypeGame() != NET_GAME_TYPE_NONE )proto_send_settux(tux); + } +} + +void switchTuxGun(tux_t *tux) +{ + int i; + + if( tux->isCanSwitchGun == FALSE ) + { + return; + } + + playSound("switch_gun", SOUND_GROUP_BASE); + + for( i = tux->gun+1 ; i < GUN_COUNT ; i++ ) + { + if( tux->shot[i] > 0 ) + { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); + return; + } + } + + for( i = 0 ; i < GUN_COUNT ; i++ ) + { + if( tux->shot[i] > 0 ) + { + tux->gun = i; + tux->isCanSwitchGun = FALSE; + addTimer(timer_tuxCanSwitchGun, newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN ); + return; + } } } @@ -548,6 +548,27 @@ void shotTux(tux_t *tux) } } +void actionTux(tux_t *tux, int action) +{ + switch( action ) + { + case TUX_UP : + case TUX_LEFT : + case TUX_RIGHT : + case TUX_DOWN : + moveTux(tux, action); + break; + + case TUX_SHOT : + shotTux(tux); + break; + + case TUX_SWITCH_GUN : + switchTuxGun(tux); + break; + } +} + static void pickUpGun(tux_t *tux) { if( isTuxAnyGun(tux) == FALSE ) @@ -587,6 +608,11 @@ static void eventBonus(tux_t *tux) } tux->bonus = BONUS_NONE; + + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_newtux_server(NULL, tux); + } } } } |