diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-08 21:43:44 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-08 21:43:44 +0000 |
| commit | 4919e623c6695a80aaf96187253756dcbb72bf87 (patch) | |
| tree | 948fbcc211b1a8f13e3830853edef6505234bab2 /src | |
| parent | a8110d0786e7931715a0d7116ed7d4c23697bdb6 (diff) | |
- kod bol prepisany tak aby dokazal pracovat aj s arenami vascimi ako je obrazovka okna
( ako pozadie na arenu sa da pouzit aj tepeta aj textura )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@62 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
| -rw-r--r-- | src/arena.c | 63 | ||||
| -rw-r--r-- | src/arenaFile.c | 12 | ||||
| -rwxr-xr-x | src/layer.c | 15 | ||||
| -rw-r--r-- | src/proto.c | 14 | ||||
| -rw-r--r-- | src/screen_world.c | 41 | ||||
| -rw-r--r-- | src/server.c | 56 | ||||
| -rw-r--r-- | src/shot.c | 7 | ||||
| -rw-r--r-- | src/tux.c | 25 |
8 files changed, 175 insertions, 58 deletions
diff --git a/src/arena.c b/src/arena.c index 38e5319..98ec0d8 100644 --- a/src/arena.c +++ b/src/arena.c @@ -13,6 +13,7 @@ #include "modules.h" #ifndef PUBLIC_SERVER +#include "screen_world.h" #include "layer.h" #endif @@ -73,21 +74,74 @@ void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h) assert( y != NULL ); do{ - z_x = random() % WINDOW_SIZE_X; - z_y = random() % (WINDOW_SIZE_Y); + z_x = random() % arena->w; + z_y = random() % arena->h; }while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 ); *x = z_x; *y = z_y; } +void getCenterScreen(int *screen_x, int *screen_y, int x, int y) +{ + arena_t *arena; + + arena = getCurrentArena(); + + *screen_x = x - WINDOW_SIZE_X/2; + *screen_y = y - WINDOW_SIZE_Y/2; + + if( *screen_x < 0 ) + { + *screen_x = 0; + } + + if( *screen_y < 0 ) + { + *screen_y = 0; + } + + if( *screen_x + WINDOW_SIZE_X >= arena->w ) + { + *screen_x = arena->w - WINDOW_SIZE_X; + } + + if( *screen_y + WINDOW_SIZE_Y >= arena->h ) + { + *screen_y = arena->h - WINDOW_SIZE_Y; + } +} + #ifndef PUBLIC_SERVER void drawArena(arena_t *arena) { + int screen_x, screen_y; tux_t *tux = NULL; + int i, j; + + tux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + +/* + screen_x = tux->x - WINDOW_SIZE_X/2; + screen_y = tux->y - WINDOW_SIZE_Y/2; +*/ - addLayer(arena->background, 0, 0, 0, 0, WINDOW_SIZE_X, WINDOW_SIZE_Y, -100); + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y); + + for( i = screen_y/arena->background->h ; + i <= screen_y/arena->background->h + WINDOW_SIZE_Y/arena->background->h ; i++ ) + { + for( j = screen_x/arena->background->w ; + j <= screen_x/arena->background->w + WINDOW_SIZE_X/arena->background->w ; j++ ) + { + addLayer(arena->background, + j * arena->background->w, + i * arena->background->h, + 0, 0, arena->background->w, arena->background->h, -100); + } + + } drawListTux(arena->listTux); //drawListWall(arena->listWall); @@ -96,9 +150,6 @@ void drawArena(arena_t *arena) drawListShot(arena->listShot); drawListItem(arena->listItem); -/* - tux = getControlTux( TUX_CONTROL_KEYBOARD_RIGHT ); -*/ if( tux == NULL ) { diff --git a/src/arenaFile.c b/src/arenaFile.c index 53b6138..f0971b3 100644 --- a/src/arenaFile.c +++ b/src/arenaFile.c @@ -68,13 +68,19 @@ static void cmd_loadMusic(char *line) addMusic(str_file, str_name, MUSIC_GROUP_USER); } -static void cmd_background(arena_t *arena, char *line) +static void cmd_arena(arena_t *arena, char *line) { char str_image[STR_SIZE]; + char str_w[STR_SIZE]; + char str_h[STR_SIZE]; - if( getValue(line, "image", str_image, STR_SIZE) != 0 )return; + if( getValue(line, "background", str_image, STR_SIZE) != 0 )return; + if( getValue(line, "w", str_w, STR_SIZE) != 0 )return; + if( getValue(line, "h", str_h, STR_SIZE) != 0 )return; arena->background = getImage(IMAGE_GROUP_USER, str_image); + arena->w = atoi(str_w); + arena->h = atoi(str_h); } static void cmd_playMusic(arena_t *arena, char *line) @@ -173,7 +179,7 @@ arena_t* getArena(int id) #ifndef PUBLIC_SERVER if( strncmp(line, "loadImage", 9) == 0 )cmd_loadImage(line); if( strncmp(line, "loadMusic", 9) == 0 )cmd_loadMusic(line); - if( strncmp(line, "background", 10) == 0 )cmd_background(arena, line); + if( strncmp(line, "arena", 5) == 0 )cmd_arena(arena, line); if( strncmp(line, "playMusic", 9) == 0 )cmd_playMusic(arena, line); #endif diff --git a/src/layer.c b/src/layer.c index d8740dc..07ec40f 100755 --- a/src/layer.c +++ b/src/layer.c @@ -109,20 +109,27 @@ void drawLayer() void drawLayerCenter(int x, int y) { layer_t *this; - int offset_x, offset_y; + int screen_x, screen_y; int i; - offset_x = x - WINDOW_SIZE_X/2; - offset_y = y - WINDOW_SIZE_Y/2; + getCenterScreen(&screen_x, &screen_y, x, y); for( i = 0 ; i < listLayer->count ; i++ ) { this = (layer_t *)listLayer->list[i]; + if( (this->x - screen_x) + this->w < 0 || (this->x - screen_x) > WINDOW_SIZE_X || + (this->y - screen_y) + this->h < 0 || (this->y - screen_y) > WINDOW_SIZE_Y ) + { + continue; + } + drawImage(this->image, - this->x - offset_x, this->y - offset_y, + this->x - screen_x, this->y - screen_y, this->px, this->py, this->w, this->h); + + //printf("%d %d\n", this->x - screen_x, this->y - screen_y); } destroyListItem(listLayer, free); diff --git a/src/proto.c b/src/proto.c index a31e640..c9aa408 100644 --- a/src/proto.c +++ b/src/proto.c @@ -51,6 +51,16 @@ static void proto_send(int type, client_t *client, char *msg) assert( client != NULL ); sendAllClientBut(msg, client); break; + case PROTO_SEND_ALL_SEES_TUX : + if( client != NULL ) + { + sendAllClientSeesTux(msg, client->tux); + } + else + { + sendAllClientSeesTux(msg, getServerTux()); + } + break; default : assert( ! "Premenna type ma zlu hodnotu !" ); break; @@ -358,13 +368,11 @@ void proto_recv_event_server(client_t *client, char *msg) assert( client != NULL ); assert( msg != NULL ); - sscanf(msg, "%s %d", cmd, &action); - proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action); + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action); actionTux(client->tux, action); - } void proto_send_newtux_server(int type, client_t *client, tux_t *tux) diff --git a/src/screen_world.c b/src/screen_world.c index 4f1e8d8..de2d591 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -110,24 +110,6 @@ void countRoundInc() } } -static tux_t* getControlTux(int control_type) -{ - tux_t *thisTux; - int i; - - for( i = 0 ; i < arena->listTux->count ; i++ ) - { - thisTux = (tux_t *)(arena->listTux->list[i]); - - if( thisTux->control == control_type ) - { - return thisTux; - } - } - - return NULL; -} - void prepareArena() { tux_t *tux; @@ -201,7 +183,7 @@ static void netAction(tux_t *tux, int action) { if( getSettingGameType() == NET_GAME_TYPE_SERVER ) { - proto_send_event_server(PROTO_SEND_ALL, NULL, tux , action); + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, NULL, tux , action); } if( getSettingGameType() == NET_GAME_TYPE_CLIENT ) @@ -409,6 +391,27 @@ static void eventEnd() } } +tux_t* getControlTux(int control_type) +{ + arena_t *arena; + tux_t *thisTux; + int i; + + arena = getCurrentArena(); + + for( i = 0 ; i < arena->listTux->count ; i++ ) + { + thisTux = (tux_t *)(arena->listTux->list[i]); + + if( thisTux->control == control_type ) + { + return thisTux; + } + } + + return NULL; +} + void tuxControl(tux_t *p) { assert( p != NULL ); diff --git a/src/server.c b/src/server.c index 8777e7a..b9a611e 100644 --- a/src/server.c +++ b/src/server.c @@ -92,28 +92,22 @@ static void eventPeriodicSyncClient(void *p_nothink) client_t *thisClientSend; tux_t *thisTux; int i, j; -/* - for( i = 0 ; i < getCurrentArena()->listItem->count; i++) - { - thisItem = (item_t *) getCurrentArena()->listItem->list[i]; - - if( thisItem->type != ITEM_EXPLOSION || thisItem->type != ITEM_BIG_EXPLOSION ) - { - proto_send_additem_server(PROTO_SEND_ALL, NULL, thisItem); - } - } -*/ + for( i = 0 ; i < listClient->count; i++) { thisClientSend = (client_t *) listClient->list[i]; - if( thisClientSend->tux != NULL ) + if( thisClientSend->tux == NULL ) { + continue; + } + #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, - (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX])); + thisTux = (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]); + + if( isTuxSeesTux(thisClientSend->tux, thisTux) ) + proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux); #endif - } for( j = 0 ; j < listClient->count; j++) { @@ -121,9 +115,8 @@ static void eventPeriodicSyncClient(void *p_nothink) thisTux = thisClientInfo->tux; if( thisTux != NULL && - thisClientSend->tux != NULL && - thisClientSend != thisClientInfo /*&& - thisTux->status == TUX_STATUS_ALIVE*/ ) + thisClientSend != thisClientInfo && + isTuxSeesTux(thisClientSend->tux, thisTux) ) { proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux); @@ -362,6 +355,28 @@ void sendAllClient(char *msg) sendAllClientBut(msg, NULL); } +void sendAllClientSeesTux(char *msg, tux_t *tux) +{ + int i; + + assert( msg != NULL ); + + for( i = 0 ; i < listClient->count ; i++ ) + { + client_t *thisClient; + tux_t *thisTux; + + thisClient = (client_t *)listClient->list[i]; + thisTux = (tux_t *)thisClient->tux; + + if( tux != thisTux && + isTuxSeesTux(thisTux, tux) ) + { + sendClient(thisClient, msg); + } + } +} + void addMsgClient(client_t *p, char *msg, int id) { assert( p != NULL ); @@ -398,6 +413,11 @@ void addMsgAllClient(char *msg, int id) addMsgAllClientBut(msg, NULL, id); } +tux_t *getServerTux() +{ + return (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]); +} + void sendInfoCreateClient(client_t *client) { client_t *thisClient; @@ -269,11 +269,14 @@ void transformOnlyLasser(shot_t *shot) void eventMoveListShot(list_t *listShot) { + arena_t *arena; shot_t *thisShot; int i; assert( listShot != NULL ); + arena = getCurrentArena(); + for( i = 0 ; i < listShot->count ; i++ ) { thisShot = (shot_t *)listShot->list[i]; @@ -298,8 +301,8 @@ void eventMoveListShot(list_t *listShot) } } */ - if( thisShot->x+thisShot->w < 0 || thisShot->x > WINDOW_SIZE_X || - thisShot->y+thisShot->h < 0 || thisShot->y > WINDOW_SIZE_Y ) + if( thisShot->x+thisShot->w < 0 || thisShot->x > arena->w || + thisShot->y+thisShot->h < 0 || thisShot->y > arena->h ) { delListItem(listShot, i, destroyShot); i--; @@ -248,6 +248,21 @@ void replaceTuxID(tux_t *tux, int id) tux->id = id; } +int isTuxSeesTux(tux_t *tux, tux_t *thisTux) +{ + int tux_x, tux_y, tux_w, tux_h; + int thisTux_x, thisTux_y, thisTux_w, thisTux_h; + int screen_x, screen_y; + + getTuxProportion(tux, &tux_x, &tux_y, &tux_w, &tux_h); + getTuxProportion(thisTux, &thisTux_x, &thisTux_y, &thisTux_w, &thisTux_h); + + getCenterScreen(&screen_x, &screen_y, tux->x, tux->y); + + return conflictSpace(screen_x, screen_y, + WINDOW_SIZE_X, WINDOW_SIZE_Y, thisTux_x, thisTux_y, thisTux_w, thisTux_h); +} + tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h) { tux_t *thisTux; @@ -565,6 +580,9 @@ void moveTux(tux_t *tux, int n) arena_t *arena; /* + printf("%d %d\n", tux->x, tux->y); +*/ +/* static my_time_t lastTime = 0; my_time_t currentTime; @@ -582,6 +600,8 @@ void moveTux(tux_t *tux, int n) assert( tux != NULL ); + arena = getCurrentArena(); + if( tux->position != n ) { tux->position = n; @@ -593,7 +613,7 @@ void moveTux(tux_t *tux, int n) return; } - if( n == TUX_RIGHT && tux->x+TUX_STEP >= WINDOW_SIZE_X ) + if( n == TUX_RIGHT && tux->x+TUX_STEP >= arena->w ) { return; } @@ -603,12 +623,11 @@ void moveTux(tux_t *tux, int n) return; } - if( n == TUX_DOWN && tux->y+TUX_STEP >= WINDOW_SIZE_Y ) + if( n == TUX_DOWN && tux->y+TUX_STEP >= arena->h ) { return; } - arena = getCurrentArena(); getCourse(tux->position, &px, &py); zal_x = tux->x; |