diff options
| -rw-r--r-- | config.h | 3 | ||||
| -rw-r--r-- | include/client.h | 2 | ||||
| -rw-r--r-- | include/tux.h | 3 | ||||
| -rwxr-xr-x | src/interface.c | 2 | ||||
| -rw-r--r-- | src/item.c | 108 | ||||
| -rw-r--r-- | src/proto.c | 9 | ||||
| -rw-r--r-- | src/screen_world.c | 2 | ||||
| -rw-r--r-- | src/server.c | 6 | ||||
| -rw-r--r-- | src/tux.c | 6 |
9 files changed, 89 insertions, 52 deletions
@@ -1,4 +1,3 @@ - /* #define DEBUG_SERVER_SEND #define DEBUG_SERVER_RECV @@ -6,7 +5,7 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn27" +#define TUXANCI_NG_VERSION "svn32" #define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP diff --git a/include/client.h b/include/client.h index aee5e81..fe28eed 100644 --- a/include/client.h +++ b/include/client.h @@ -7,7 +7,7 @@ #if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP -#define CLIENT_TIMEOUT 2500 +#define CLIENT_TIMEOUT 1000 #define SERVER_TIMEOUT_ALIVE 5000 #endif diff --git a/include/tux.h b/include/tux.h index ebc8ac7..3cb6699 100644 --- a/include/tux.h +++ b/include/tux.h @@ -8,7 +8,10 @@ #define TUX_STEP 6 #define TUX_LAYER 0 + #define TUX_MAX_ANIMATION_FRAME 10 +#define TUX_KEY 1 + #define TUX_MAX_PICKUP 50 #define TUX_MAX_BONUS 500 diff --git a/src/interface.c b/src/interface.c index 8e07c32..2353bed 100755 --- a/src/interface.c +++ b/src/interface.c @@ -65,7 +65,7 @@ int initSDL() SDL_WM_SetCaption(WINDOW_TITLE, NULL); //SDL_ShowCursor(0); - //SDL_EnableKeyRepeat(1,1); + SDL_EnableKeyRepeat(1,1); timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL); srand((unsigned)time(NULL)); @@ -333,7 +333,7 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot) x = ( thisItem->x + thisItem->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2; y = ( thisItem->y + thisItem->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2; - addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, NULL) ); + addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, thisItem->author) ); delListItem(listItem, j, destroyItem); j--; @@ -355,11 +355,75 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot) } } -void eventGiveTuxItem(tux_t *tux, list_t *listItem) +static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item) +{ + if( tux->bonus == BONUS_GHOST ) + { + return; + } + + if( tux->bonus == BONUS_TELEPORT ) + { + tuxTeleport(tux); + } + + if( item->author != NULL && item->author != tux ) + { +#ifndef BUBLIC_SERVER + char term_msg[STR_SIZE]; + + sprintf(term_msg, "tux with id %d set score to %d\n", + item->author->id, item->author->score+1); + + appendTextInTerm(term_msg); +#endif + item->author->score++; + + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_score_server(PROTO_SEND_ALL, NULL, item->author); + } + } + + countRoundInc(); + eventTuxIsDead(tux); +} + +static void tuxGiveBonus(tux_t *tux, item_t *item) { #ifndef BUBLIC_SERVER char msg[STR_SIZE]; + playSound("item_bonus", SOUND_GROUP_BASE); #endif + tux->bonus = item->type; + tux->bonus_time = TUX_MAX_BONUS; + +#ifndef BUBLIC_SERVER + sprintf(msg, "tux with id %d bonus enabled\n", tux->id); + appendTextInTerm(msg); +#endif +} + +static void tuxGiveGun(tux_t *tux, item_t *item) +{ +#ifndef BUBLIC_SERVER + char msg[STR_SIZE]; + playSound("item_gun", SOUND_GROUP_BASE); +#endif + + tux->pickup_time = 0; + tux->shot[ item->type ] += GUN_MAX_SHOT; + tux->gun = item->type; + +#ifndef BUBLIC_SERVER + sprintf(msg, "tux with id %d has new gun\n", tux->id); + appendTextInTerm(msg); +#endif + +} + +void eventGiveTuxItem(tux_t *tux, list_t *listItem) +{ item_t *thisItem; int x, y, w, h; int i; @@ -388,45 +452,26 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem) case GUN_SCATTER : case GUN_LASSER : case GUN_MINE : - tux->pickup_time = 0; -#ifndef BUBLIC_SERVER - playSound("item_gun", SOUND_GROUP_BASE); -#endif - tux->shot[ thisItem->type ] += GUN_MAX_SHOT; - tux->gun = thisItem->type; + tuxGiveGun(tux, thisItem); delListItem(listItem, i, destroyItem); i--; - -#ifndef BUBLIC_SERVER - sprintf(msg, "tux with id %d has new gun\n", tux->id); - appendTextInTerm(msg); -#endif break; case ITEM_MINE : if( tux->bonus != BONUS_GHOST ) { - if( thisItem->author != NULL ) - { - thisItem->author->score++; - } + //eventTuxIsDeadWithItem(tux, thisItem); + addList(listItem, newItem(x, y, + ITEM_EXPLOSION, thisItem->author) ); delListItem(listItem, i, destroyItem); - addList(listItem, newItem(x, y, ITEM_EXPLOSION, NULL) ); i--; } break; case ITEM_EXPLOSION : case ITEM_BIG_EXPLOSION : - if( tux->bonus == BONUS_TELEPORT ) - { - tuxTeleport(tux); - } - else - { - eventTuxIsDead(tux); - } + eventTuxIsDeadWithItem(tux, thisItem); break; case BONUS_SPEED : @@ -435,18 +480,9 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem) case BONUS_GHOST : case BONUS_4X : case BONUS_HIDDEN : -#ifndef BUBLIC_SERVER - playSound("item_bonus", SOUND_GROUP_BASE); -#endif - tux->bonus = thisItem->type; - tux->bonus_time = TUX_MAX_BONUS; + tuxGiveBonus(tux, thisItem); delListItem(listItem, i, destroyItem); i--; - -#ifndef BUBLIC_SERVER - sprintf(msg, "tux with id %d bonus enabled\n", tux->id); - appendTextInTerm(msg); -#endif break; } diff --git a/src/proto.c b/src/proto.c index 4372217..974f84c 100644 --- a/src/proto.c +++ b/src/proto.c @@ -219,9 +219,10 @@ void proto_recv_event_server(client_t *client, char *msg) sscanf(msg, "%s %d", cmd, &action); + proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action); + actionTux(client->tux, action); - proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action); } void proto_send_newtux_server(int type, client_t *client, tux_t *tux) @@ -517,12 +518,6 @@ void proto_send_ping_client() void proto_recv_ping_server(client_t *client, char *msg) { - assert( msg != NULL ); - assert( client != NULL ); - -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP - client->lastPing = getMyTime(); -#endif } #ifndef BUBLIC_SERVER diff --git a/src/screen_world.c b/src/screen_world.c index 49d94ac..a1ef1c1 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -97,7 +97,7 @@ void countRoundInc() } count++; - printf("count %d\n", count); + printf("count = %d\n", count); if( count >= max_count ) { diff --git a/src/server.c b/src/server.c index e1dacf1..98fc96c 100644 --- a/src/server.c +++ b/src/server.c @@ -296,7 +296,7 @@ void sendInfoCreateClient(client_t *client) thisClient = (client_t *) listClient->list[i]; thisTux = thisClient->tux; - if( thisTux != client->tux ) + if( thisTux != NULL && thisTux != client->tux ) { proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); @@ -402,6 +402,10 @@ static void eventClientBuffer(client_t *client) if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_server(client, line); if( strncmp(line, "end", 3) == 0 )proto_recv_end_server(client, line); } + +#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP + client->lastPing = getMyTime(); +#endif } } @@ -201,7 +201,7 @@ void drawTux(tux_t *tux) addLayer(g_image, tux->x - TUX_IMG_WIDTH / 2, ( tux->y + TUX_HEIGHT / 2 ) - TUX_IMG_HEIGHT, - tux->frame * TUX_IMG_WIDTH, 0, + (tux->frame/TUX_KEY) * TUX_IMG_WIDTH, 0, TUX_IMG_WIDTH, TUX_IMG_HEIGHT, TUX_LAYER); } @@ -583,9 +583,9 @@ void moveTux(tux_t *tux, int n) } else { + eventGiveTuxItem(tux, getWorldArena()->listItem); tux->frame++; - - if( tux->frame == TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; + if( tux->frame == TUX_KEY * TUX_MAX_ANIMATION_FRAME ) tux->frame = 0; } // printf("move %d %d %d\n", tux->id, tux->x, tux->y); |