summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-08 21:43:44 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-08 21:43:44 +0000
commit4919e623c6695a80aaf96187253756dcbb72bf87 (patch)
tree948fbcc211b1a8f13e3830853edef6505234bab2
parenta8110d0786e7931715a0d7116ed7d4c23697bdb6 (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
-rw-r--r--arena/construction_site.map3
-rw-r--r--arena/for_a_good_night.map2
-rw-r--r--arena/in_a_captivity_of_8-bit.map2
-rw-r--r--arena/night_workshift.map2
-rw-r--r--config.h2
-rw-r--r--include/arena.h3
-rw-r--r--include/proto.h7
-rw-r--r--include/screen_world.h1
-rw-r--r--include/server.h2
-rw-r--r--include/tux.h1
-rw-r--r--src/arena.c63
-rw-r--r--src/arenaFile.c12
-rwxr-xr-xsrc/layer.c15
-rw-r--r--src/proto.c14
-rw-r--r--src/screen_world.c41
-rw-r--r--src/server.c56
-rw-r--r--src/shot.c7
-rw-r--r--src/tux.c25
18 files changed, 191 insertions, 67 deletions
diff --git a/arena/construction_site.map b/arena/construction_site.map
index 1a3bcb2..3422b85 100644
--- a/arena/construction_site.map
+++ b/arena/construction_site.map
@@ -14,7 +14,8 @@ loadImage file="l4.tvarnice.png" name="tvarnice" alpha="yes"
loadImage file="l4.palety.png" name="palety" alpha="yes"
loadImage file="l4.overlay.png" name="overlay" alpha="yes"
-background image="pozadi"
+arena background="pozadi" w="800" h="600"
+
playMusic music="night_workshift"
wall x="96" y="423" w="162" h="96" img_x="86" img_y="235" layer="0" image="bagr"
diff --git a/arena/for_a_good_night.map b/arena/for_a_good_night.map
index bf2711d..0680404 100644
--- a/arena/for_a_good_night.map
+++ b/arena/for_a_good_night.map
@@ -13,7 +13,7 @@ loadImage file="l1.peduncle.png" name="peduncle" alpha="yes"
loadImage file="l1.tree.png" name="tree" alpha="yes"
loadImage file="l1.wood.png" name="wood" alpha="yes"
-background image="grow"
+arena background="grow" w="800" h="600"
playMusic music="for_a_good_night"
diff --git a/arena/in_a_captivity_of_8-bit.map b/arena/in_a_captivity_of_8-bit.map
index d0a8180..02316d4 100644
--- a/arena/in_a_captivity_of_8-bit.map
+++ b/arena/in_a_captivity_of_8-bit.map
@@ -14,7 +14,7 @@ loadImage file="l3.kvader1.png" name="kvader1" alpha="yes"
loadImage file="l3.kvader2.png" name="kvader2" alpha="yes"
loadImage file="l3.teleport.png" name="teleport" alpha="yes"
-background image="nic"
+arena background="nic" w="800" h="600"
playMusic music="in_a_captivity_of_8-bit"
diff --git a/arena/night_workshift.map b/arena/night_workshift.map
index 0dd83b2..2211665 100644
--- a/arena/night_workshift.map
+++ b/arena/night_workshift.map
@@ -19,7 +19,7 @@ loadImage file="l2.trubka6.png" name="trubka6" alpha="yes"
loadImage file="l2.trubka4.png" name="trubka4" alpha="yes"
loadImage file="l2.trubka8.png" name="trubka8" alpha="yes"
-background image="pitch"
+arena background="pitch" w="800" h="600"
playMusic music="night_workshift"
diff --git a/config.h b/config.h
index 1b1e335..7319228 100644
--- a/config.h
+++ b/config.h
@@ -6,7 +6,7 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn60"
+#define TUXANCI_NG_VERSION "svn62"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_SDL_UDP
diff --git a/include/arena.h b/include/arena.h
index b79c094..c800169 100644
--- a/include/arena.h
+++ b/include/arena.h
@@ -16,7 +16,7 @@ typedef struct arena_struct
SDL_Surface *background;
#endif
-
+ int w, h;
list_t *listTimer;
list_t *listTux;
list_t *listShot;
@@ -29,6 +29,7 @@ extern arena_t* newArena();
extern int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2);
extern int isFreeSpace(arena_t *arena, int x, int y, int w, int h);
extern void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h);
+extern void getCenterScreen(int *screen_x, int *screen_y, int x, int y);
#ifndef PUBLIC_SERVER
extern void drawArena(arena_t *arena);
#endif
diff --git a/include/proto.h b/include/proto.h
index f392aaa..569339e 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -37,9 +37,10 @@
#include "publicServer.h"
#endif
-#define PROTO_SEND_ONE 0
-#define PROTO_SEND_ALL 1
-#define PROTO_SEND_BUT 2
+#define PROTO_SEND_ONE 0
+#define PROTO_SEND_ALL 1
+#define PROTO_SEND_BUT 3
+#define PROTO_SEND_ALL_SEES_TUX 4
#define PROTO_ERROR_CODE_UNKNOWN 0
#define PROTO_ERROR_CODE_BAD_VERSION 1
diff --git a/include/screen_world.h b/include/screen_world.h
index 955e0fc..b6a4259 100644
--- a/include/screen_world.h
+++ b/include/screen_world.h
@@ -19,6 +19,7 @@ extern void setLagServer(my_time_t lag);
extern void countRoundInc();
extern void setWorldEnd();
extern void setMaxCountRound(int n);
+extern tux_t* getControlTux(int control_type);
extern void tuxControl(tux_t *p);
extern void drawWorld();
extern void eventWorld();
diff --git a/include/server.h b/include/server.h
index 08a8af2..8d97ed3 100644
--- a/include/server.h
+++ b/include/server.h
@@ -76,11 +76,13 @@ extern void setServerMaxClients(int n);
extern void sendClient(client_t *p, char *msg);
extern void sendAllClientBut(char *msg, client_t *p);
extern void sendAllClient(char *msg);
+extern void sendAllClientSeesTux(char *msg, tux_t *tux);
extern void addMsgClient(client_t *p, char *msg, int id);
extern void addMsgAllClientBut(char *msg, client_t *p, int id);
extern void addMsgAllClient(char *msg, int id);
+extern tux_t *getServerTux();
extern void eventClientListBuffer();
extern void sendInfoCreateClient(client_t *client);
extern void eventServer();
diff --git a/include/tux.h b/include/tux.h
index 4b655ff..c07cf0a 100644
--- a/include/tux.h
+++ b/include/tux.h
@@ -122,6 +122,7 @@ extern void eventListTux(list_t *listTux);
extern tux_t* getTuxID(list_t *listTux, int id);
extern void getTuxProportion(tux_t *tux, int *x,int *y, int *w, int *h);
extern void replaceTuxID(tux_t *tux, int id);
+extern int isTuxSeesTux(tux_t *tux, tux_t *thisTux);
extern void setTuxProportion(tux_t *tux, int x, int y);
extern void destroyTux(tux_t *tux);
extern void quitTux();
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;
diff --git a/src/shot.c b/src/shot.c
index f19e99c..2db8424 100644
--- a/src/shot.c
+++ b/src/shot.c
@@ -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--;
diff --git a/src/tux.c b/src/tux.c
index c925019..8c89207 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -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;