summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
commit2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 (patch)
tree7cf274897bf540d5332d446f583ffd066e4e2e1d /src/client
parentb877ae23ac5d380ab3aa48d7724045cf4883b186 (diff)
- prekopanie adresarovej struktury, prva cast
git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile36
-rw-r--r--src/client/client.c305
-rw-r--r--src/client/client.h35
-rw-r--r--src/client/configFile.c136
-rw-r--r--src/client/configFile.h20
-rwxr-xr-xsrc/client/font.c99
-rwxr-xr-xsrc/client/font.h26
-rw-r--r--src/client/game.c120
-rw-r--r--src/client/game.h9
-rwxr-xr-xsrc/client/image.c149
-rwxr-xr-xsrc/client/image.h35
-rwxr-xr-xsrc/client/interface.c256
-rwxr-xr-xsrc/client/interface.h40
-rw-r--r--src/client/keytable.c136
-rw-r--r--src/client/keytable.h27
-rw-r--r--src/client/language.c157
-rw-r--r--src/client/language.h12
-rwxr-xr-xsrc/client/layer.c155
-rwxr-xr-xsrc/client/layer.h53
-rw-r--r--src/client/panel.c190
-rw-r--r--src/client/panel.h27
-rw-r--r--src/client/screen.c137
-rw-r--r--src/client/screen.h32
-rw-r--r--src/client/term.c106
-rw-r--r--src/client/term.h17
25 files changed, 2315 insertions, 0 deletions
diff --git a/src/client/Makefile b/src/client/Makefile
new file mode 100644
index 0000000..c5637ea
--- /dev/null
+++ b/src/client/Makefile
@@ -0,0 +1,36 @@
+
+
+all: client.o configFile.o font.o game.o image.o interface.o keytable.o language.o layer.o panel.o screen.o term.o
+
+client.o: client.c client.h
+ $(CC) $(CFLAGS) -o client.o -c client.c
+
+configFile.o: configFile.c configFile.h
+ $(CC) $(CFLAGS) -o configFile.o -c configFile.c
+
+font.o: font.c font.h
+ $(CC) $(CFLAGS) -o font.o -c font.c
+
+game.o: game.c game.h
+ $(CC) $(CFLAGS) -o game.o -c game.c
+
+image.o: image.c image.h
+ $(CC) $(CFLAGS) -o image.o -c image.c
+
+interface.o: interface.c interface.h
+ $(CC) $(CFLAGS) -o interface.o -c interface.c
+
+layer.o: layer.c layer.h
+ $(CC) $(CFLAGS) -o layer.o -c layer.c
+
+panel.o: panel.c panel.h
+ $(CC) $(CFLAGS) -o panel.o -c panel.c
+
+screen.o: screen.c screen.h
+ $(CC) $(CFLAGS) -o screen.o -c screen.c
+
+term.o: term.c term.h
+ $(CC) $(CFLAGS) -o term.o -c term.c
+
+clean:
+ rm -rf *.o
diff --git a/src/client/client.c b/src/client/client.c
new file mode 100644
index 0000000..975c9da
--- /dev/null
+++ b/src/client/client.c
@@ -0,0 +1,305 @@
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/tux.h"
+#include "base/proto.h"
+
+#include "client/client.h"
+#include "client/language.h"
+
+#include "screen/screen_analyze.h"
+#include "screen/screen_world.h"
+
+static int protocolType;
+
+#ifdef SUPPORT_NET_UNIX_UDP
+#include "net_unix/udp.h"
+static sock_udp_t *sock_server_udp;
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+#include "net_sdl/sdl_udp.h"
+static sock_sdl_udp_t *sock_server_sdl_udp;
+#endif
+
+static list_t *clientBuffer;
+static my_time_t lastPing;
+static my_time_t lastPingServerAlive;
+
+static void initClient()
+{
+ char name[STR_NAME_SIZE];
+
+ clientBuffer = newList();
+ lastPing = getMyTime();
+ lastPingServerAlive = getMyTime();
+
+ getSettingNameRight(name);
+ proto_send_hello_client(name);
+}
+
+#ifdef SUPPORT_NET_UNIX_UDP
+
+int initUdpClient(char *ip, int port, int proto)
+{
+ sock_server_udp = connectUdpSocket(ip, port, proto);
+
+ if( sock_server_udp == NULL )
+ {
+ return -1;
+ }
+
+ printf("connect UDP %s %d\n", ip, port);
+
+ protocolType = NET_PROTOCOL_TYPE_UDP;
+ initClient();
+
+ return 0;
+}
+
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+
+int initSdlUdpClient(char *ip, int port)
+{
+ sock_server_sdl_udp = connectSdlUdpSocket(ip, port);
+
+ if( sock_server_sdl_udp == NULL )
+ {
+ return -1;
+ }
+
+ printf("connect UDP %s %d\n", ip, port);
+
+ protocolType = NET_PROTOCOL_TYPE_UDP;
+ initClient();
+
+ return 0;
+}
+
+#endif
+
+void sendServer(char *msg)
+{
+ int ret;
+
+ assert( msg != NULL );
+
+#ifndef PUBLIC_SERVER
+ if( isParamFlag("--send") )
+ {
+ printf("send -> %s", msg);
+ }
+#endif
+
+#ifdef SUPPORT_NET_UNIX_UDP
+ ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg));
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+ ret = writeSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, msg, strlen(msg));
+#endif
+}
+
+static int eventServerSelect()
+{
+ char buffer[STR_PROTO_SIZE];
+ int ret;
+
+ memset(buffer,0 ,STR_PROTO_SIZE);
+
+#ifdef SUPPORT_NET_UNIX_UDP
+ ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1);
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+ ret = readSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, buffer, STR_PROTO_SIZE-1);
+
+ if( ret < 0 )
+ {
+ return ret;
+ }
+#endif
+
+ addList(clientBuffer, strdup(buffer) );
+/*
+ if( addBuffer(clientBuffer, buffer, ret) != 0 )
+ {
+ fprintf(stderr, "chyba, nemozem zapisovat do mojho buffera !\n");
+ setWorldEnd();
+ return ret;
+ }
+*/
+ return ret;
+}
+
+void eventServerBuffer()
+{
+ char *line;
+ int i;
+
+ /* obsluha udalosti od servera */
+
+ assert( clientBuffer != NULL );
+
+ for( i = 0 ; i < clientBuffer->count ; i++ )
+ {
+ line = (char *)clientBuffer->list[i];
+
+#ifndef PUBLIC_SERVER
+ if( isParamFlag("--recv") )
+ {
+ printf("recv -> %s", line);
+ }
+#endif
+ if( strncmp(line, "error", 5) == 0 )proto_recv_error_client(line);
+ if( strncmp(line, "init", 4) == 0 )proto_recv_init_client(line);
+ if( strncmp(line, "event", 5) == 0 )proto_recv_event_client(line);
+ if( strncmp(line, "newtux", 6) == 0 )proto_recv_newtux_client(line);
+ if( strncmp(line, "del", 3) == 0 )proto_recv_del_client(line);
+ if( strncmp(line, "additem", 7) == 0 )proto_recv_additem_client(line);
+ if( strncmp(line, "shot", 4) == 0 )proto_recv_shot_client(line);
+ if( strncmp(line, "kill", 4) == 0 )proto_recv_kill_client(line);
+ if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_client(line);
+ if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line);
+
+ lastPingServerAlive = getMyTime();
+ }
+
+ destroyListItem(clientBuffer, free);
+ clientBuffer = newList();
+}
+
+void eventPingServer()
+{
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastPing > CLIENT_TIMEOUT )
+ {
+ proto_send_ping_client();
+ lastPing = getMyTime();
+ }
+}
+
+bool_t isServerAlive()
+{
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastPingServerAlive > SERVER_TIMEOUT_ALIVE )
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#ifdef SUPPORT_NET_UNIX_UDP
+
+void selectClientUdpSocket()
+{
+ fd_set readfds;
+ struct timeval tv;
+ int max_fd;
+ bool_t isNext;
+
+ if( isServerAlive() == FALSE )
+ {
+ fprintf(stderr, "server neodpoveda !\n");
+ setWorldEnd();
+ return;
+ }
+
+ do{
+ isNext = FALSE;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&readfds);
+ FD_SET(sock_server_udp->sock, &readfds);
+ max_fd = sock_server_udp->sock;
+
+ select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
+
+ if( FD_ISSET(sock_server_udp->sock, &readfds) )
+ {
+ eventServerSelect();
+ isNext = TRUE;
+ }
+
+ }while( isNext == TRUE );
+
+}
+
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+
+void selectClientSdlUdpSocket()
+{
+ int ret;
+
+ if( isServerAlive() == FALSE )
+ {
+ setMsgToAnalyze(getMyText("ERROR_SERVER_DONT_ALIVE"));
+ setWorldEnd();
+ return;
+ }
+
+ do{
+ ret = eventServerSelect();
+ }while( ret > 0);
+}
+
+#endif
+
+static void quitClient()
+{
+ proto_send_end_client();
+ assert( clientBuffer != NULL );
+ destroyListItem(clientBuffer, free);
+}
+
+#ifdef SUPPORT_NET_UNIX_UDP
+
+void quitUdpClient()
+{
+ quitClient();
+
+ assert( sock_server_udp != NULL );
+ closeUdpSocket(sock_server_udp);
+
+ printf("quit UDP conenct\n");
+}
+
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+
+void quitSdlUdpClient()
+{
+ quitClient();
+
+ assert( sock_server_sdl_udp != NULL );
+ closeSdlUdpSocket(sock_server_sdl_udp);
+
+ printf("quit UDP conenct\n");
+}
+
+#endif
diff --git a/src/client/client.h b/src/client/client.h
new file mode 100644
index 0000000..639f924
--- /dev/null
+++ b/src/client/client.h
@@ -0,0 +1,35 @@
+
+#ifndef MY_CLIENT
+
+#define MY_CLIENT
+
+#include "base/main.h"
+
+#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP
+
+#define CLIENT_TIMEOUT 1000
+#define SERVER_TIMEOUT_ALIVE 5000
+
+#endif
+
+#ifdef SUPPORT_NET_UNIX_UDP
+extern int initUdpClient(char *ip, int port, int proto);
+extern void eventPingServer();
+extern void selectClientUdpSocket();
+extern void refreshPingServerAlive();
+extern void quitUdpClient();
+#endif
+
+#ifdef SUPPORT_NET_SDL_UDP
+extern int initSdlUdpClient(char *ip, int port);
+extern void eventPingServer();
+extern void selectClientSdlUdpSocket();
+extern void refreshPingServerAlive();
+extern bool_t isServerAlive();
+extern void quitSdlUdpClient();
+#endif
+
+extern void sendServer(char *msg);
+extern void eventServerBuffer();
+
+#endif
diff --git a/src/client/configFile.c b/src/client/configFile.c
new file mode 100644
index 0000000..acf7a1f
--- /dev/null
+++ b/src/client/configFile.c
@@ -0,0 +1,136 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "client/configFile.h"
+
+int isYesOrNO(char *s)
+{
+ if( s[0] == 'Y' || s[0] == 'y' )return 1;
+ return 0;
+}
+
+char* getYesOrNo(int n)
+{
+ return ( n != 0 ? "YES" : "NO" );
+}
+
+int getValue(char *line, char *env, char *val, int len)
+{
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ int val_len;
+
+ strcpy(clone_env, " ");
+ strcat(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if( offset_env == NULL )return -1;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if( offset_val_begin == NULL )return -1;
+
+ offset_val_end = strchr(offset_val_begin+1, '"');
+ if( offset_val_end == NULL )return -1;
+
+ val_len = (int)(offset_val_end - ( offset_val_begin + 1) );
+ if( val_len > len - 1 ) val_len = len - 1;
+
+ memset(val, 0, len);
+ memcpy(val, offset_val_begin+1, val_len);
+
+ return 0;
+}
+
+char* setValue(char *line, char *env, char *val)
+{
+ char *offset_env;
+ char *offset_val_begin;
+ char *offset_val_end;
+ char clone_env[STR_SIZE];
+ char clone[STR_SIZE];
+
+ //strcpy(clone_env, " ");
+ strcpy(clone_env, env);
+
+ offset_env = strstr(line, clone_env);
+ if( offset_env == NULL )return NULL;
+
+ offset_val_begin = strchr(offset_env, '"');
+ if( offset_val_begin == NULL )return NULL;
+
+ offset_val_end = strchr(offset_val_begin+1, '"');
+ if( offset_val_end == NULL )return NULL;
+
+ memset(clone, 0, STR_SIZE);
+ strncpy(clone, line, (int) ( (offset_val_begin - line) + 1 ) );
+ strcat(clone, val);
+ strcat(clone, offset_val_end);
+
+ return strdup( clone );
+}
+
+int getValueInConfigFile(textFile_t *textFile, char *env, char *val, int len)
+{
+ int i;
+ char *line;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ line = (char *) (textFile->text->list[i]);
+
+ if( strstr(line, env) != NULL )
+ {
+ return getValue(line, env, val, len);
+ }
+ }
+
+ return -1;
+}
+
+int setValueInConfigFile(textFile_t *textFile, char *env, char *val)
+{
+ int i;
+ char *line;
+ char *ret;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ line = (char *) (textFile->text->list[i]);
+
+ if( strstr(line, env) != NULL )
+ {
+ ret = setValue(line, env, val);
+
+ if( ret != NULL )
+ {
+ delListItem(textFile->text, i, free);
+ insList(textFile->text, i, ret);
+
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+void loadValueFromConfigFile(textFile_t *textFile, char *env, char *val, int len, char *butVal)
+{
+ strcpy(val, butVal);
+
+ if( getValueInConfigFile(textFile, env, val, len) != 0 )
+ {
+ char line[STR_SIZE];
+
+ sprintf(line, " %s=\"%s\"", env, butVal);
+ addList(textFile->text, strdup(line) );
+
+ printf("Add line \"%s\" in config file.\n", line);
+ }
+}
diff --git a/src/client/configFile.h b/src/client/configFile.h
new file mode 100644
index 0000000..67898e9
--- /dev/null
+++ b/src/client/configFile.h
@@ -0,0 +1,20 @@
+
+#ifndef CONFIGFILE_H
+
+#define CONFIGFILE_H
+
+#include "base/main.h"
+#include "base/textFile.h"
+
+extern int isYesOrNO(char *s);
+extern char* getYesOrNo(int n);
+
+extern int getValue(char *line, char *env, char *val, int len);
+extern char* setValue(char *line, char *env, char *val);
+
+extern int getValueInConfigFile(textFile_t *textFile, char *env, char *val, int len);
+extern int setValueInConfigFile(textFile_t *textFile, char *env, char *val);
+
+extern void loadValueFromConfigFile(textFile_t *textFile, char *env, char *val, int len, char *butVal);
+
+#endif
diff --git a/src/client/font.c b/src/client/font.c
new file mode 100755
index 0000000..91d15bb
--- /dev/null
+++ b/src/client/font.c
@@ -0,0 +1,99 @@
+
+#include "base/main.h"
+#include "client/interface.h"
+#include "client/font.h"
+
+static TTF_Font *g_font;
+static int fontSize;
+
+static bool_t isFontInit = FALSE;
+
+bool_t isFontInicialized()
+{
+ return isFontInit;
+}
+
+/*
+ * Inicialuzuje font.
+ * nacita font zo suboru *file o velkosti size
+ * Automaticky sa styk nastavy ako TTF_STYLE_BOLD
+ */
+void initFont(char *file,int size)
+{
+ char str[STR_PATH_SIZE];
+
+ assert( file != NULL );
+ assert( size > 0 );
+
+ assert( isInterfaceInicialized() == TRUE );
+
+ sprintf(str, PATH_FONT "%s", file);
+
+ if( TTF_Init() == -1 )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return;
+ }
+
+ accessExistFile(str);
+
+ g_font = TTF_OpenFont(str, size);
+ TTF_SetFontStyle(g_font, TTF_STYLE_NORMAL);
+
+ fontSize = size;
+
+ printf("init font.. (%s)\n", file);
+ isFontInit = TRUE;
+}
+
+/*
+ * Zobrazi text *s na suradnicu x y s farbou RGB
+ */
+void drawFont(char *s, int x, int y, int r, int g, int b)
+{
+ SDL_Rect dst_rect;
+ SDL_Surface *text;
+ SDL_Surface *p;
+ SDL_Color farba_pisma = {r, g, b, 0};
+
+ assert( s != NULL );
+
+ p = getSDL_Screen();
+
+ text = TTF_RenderUTF8_Blended(g_font, s, farba_pisma);
+
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ SDL_BlitSurface(text, NULL, p, &dst_rect);
+ SDL_FreeSurface(text);
+}
+
+/*
+ * Vrati velkost daneho fontu.
+ */
+int getFontSize()
+{
+ return fontSize;
+}
+
+void getTextSize(char *s, int *w, int *h)
+{
+ assert( s != NULL );
+ assert( w != NULL );
+ assert( h != NULL );
+
+ TTF_SizeUTF8(g_font, s, w, h);
+}
+
+/*
+ * Uvolni font z pamete.
+ */
+void quitFont()
+{
+ TTF_CloseFont(g_font);
+ TTF_Quit();
+
+ printf("quit font\n");
+ isFontInit = FALSE;
+}
diff --git a/src/client/font.h b/src/client/font.h
new file mode 100755
index 0000000..50b1494
--- /dev/null
+++ b/src/client/font.h
@@ -0,0 +1,26 @@
+
+#ifndef FONT_H
+
+#define FONT_H
+
+#include <SDL_ttf.h>
+#include <assert.h>
+#include "base/main.h"
+
+#define COLOR_WHITE 255, 255, 255
+#define COLOR_BLACK 0, 0, 0
+
+#define COLOR_RED 255, 0, 0
+#define COLOR_GREEN 0, 255, 0
+#define COLOR_BLUE 0, 0, 255
+
+#define COLOR_YELLOW 255, 255, 0
+
+extern bool_t isFontInicialized();
+extern void initFont(char *file,int size);
+extern void drawFont(char *s,int x,int y,int r,int g,int b);
+extern int getFontSize();
+extern void getTextSize(char *s, int *w, int *h);
+extern void quitFont();
+
+#endif
diff --git a/src/client/game.c b/src/client/game.c
new file mode 100644
index 0000000..9ea50ab
--- /dev/null
+++ b/src/client/game.c
@@ -0,0 +1,120 @@
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+#include "base/main.h"
+#include "base/tux.h"
+#include "base/homeDirector.h"
+#include "base/item.h"
+#include "base/shot.h"
+#include "base/arenaFile.h"
+
+#include "client/image.h"
+#include "client/layer.h"
+#include "client/interface.h"
+#include "client/screen.h"
+#include "client/font.h"
+#include "client/keytable.h"
+#include "client/language.h"
+#include "client/panel.h"
+
+#include "audio/audio.h"
+#include "audio/sound.h"
+#include "audio/music.h"
+
+#include "screen/screen_world.h"
+#include "screen/screen_mainMenu.h"
+#include "screen/screen_analyze.h"
+#include "screen/screen_setting.h"
+#include "screen/screen_gameType.h"
+#include "screen/screen_choiceArena.h"
+#include "screen/screen_table.h"
+#include "screen/screen_credits.h"
+
+static void initGame()
+{
+ createHomeDirector();
+
+ if( initLanguage() == -1 )
+ {
+ printf("fatal error !\n");
+ exit(-1);
+ }
+
+ initSDL();
+
+ initLayer();
+ initFont(getLanguageFont(), getLanguageSize());
+ initKeyTable();
+ initImageData();
+#ifndef NO_SOUND
+ initAudio();
+ initSound();
+ initMusic();
+#endif
+ initScreen();
+ initArenaFile();
+ initTux();
+ initItem();
+ initShot();
+ initPanel();
+ initWorld();
+ initScreenMainMenu();
+ initScreenAnalyze();
+ initScreenSetting();
+ initScreenGameType();
+ initScreenChoiceArena();
+ initScreenCredits();
+ initScreenTable();
+}
+
+void quitGame()
+{
+ quitSDL();
+ quitLayer();
+ quitFont();
+ quitKeyTable();
+ quitLanguage();
+ quitScreen();
+ quitArenaFile();
+ quitItem();
+ quitTux();
+ quitShot();
+ quitPanel();
+ quitWorld();
+ quitImageData();
+#ifndef NO_SOUND
+ quitSound();
+ quitMusic();
+ quitAudio();
+#endif
+ quitScreenMainMenu();
+ quitScreenAnalyze();
+ quitScreenSetting();
+ quitScreenGameType();
+ quitScreenChoiceArena();
+ quitScreenCredits();
+ quitScreenTable();
+
+ destroyList(listHelp);
+
+ printf("quit..\n");
+
+ exit(0);
+}
+
+void startGame()
+{
+ initGame();
+
+ setScreen("mainMenu");
+
+ eventSDL();
+ quitGame();
+}
diff --git a/src/client/game.h b/src/client/game.h
new file mode 100644
index 0000000..6ce694d
--- /dev/null
+++ b/src/client/game.h
@@ -0,0 +1,9 @@
+
+#ifndef GAME_H
+
+#define GAME_H
+
+extern void quitGame();
+extern void startGame();
+
+#endif
diff --git a/src/client/image.c b/src/client/image.c
new file mode 100755
index 0000000..98b2b8b
--- /dev/null
+++ b/src/client/image.c
@@ -0,0 +1,149 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/storage.h"
+
+#include "client/interface.h"
+#include "client/image.h"
+
+static list_t *listStorage;
+
+static bool_t isImageDataInit = FALSE;
+
+bool_t isImageInicialized()
+{
+ return isImageDataInit;
+}
+
+/*
+ * Inicialuzje globalny zoznam obrazkov
+ */
+void initImageData()
+{
+ assert( isInterfaceInicialized() == TRUE );
+
+ printf("init image database..\n");
+ listStorage = newStorage();
+ isImageDataInit = TRUE;
+}
+
+static SDL_Surface *loadImage(const char *filename, int alpha)
+{
+ SDL_Surface *tmp;
+ SDL_Surface *ret;
+
+ char str[STR_PATH_SIZE];
+
+
+ sprintf(str, PATH_IMAGE "%s", filename);
+
+ accessExistFile(str);
+
+ if( ( tmp = IMG_Load(str) ) == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return NULL;
+ }
+
+ if( ( ret = (alpha) ? SDL_DisplayFormatAlpha(tmp) : SDL_DisplayFormat(tmp) ) == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_FreeSurface(tmp);
+ return NULL;
+ }
+
+ SDL_FreeSurface(tmp);
+ return ret;
+}
+
+static void destroySDLSurface(void *p)
+{
+ assert( p != NULL );
+ SDL_FreeSurface((SDL_Surface *)p);
+}
+
+/*
+ * Prida obrazok do globalneho zoznamu obrazkov
+ * *file - nazov suboru v ktorom je obrazok ulozeny
+ * *name - nazov obrazku ( pouzije sa ako vyhadavaci retazec v zazanem )
+ * alpha - 0 - nema alpha kanal | 1 - ma alpha kanal
+ */
+SDL_Surface* addImageData(char *file, int alpha, char *name, char *group)
+{
+ SDL_Surface *new;
+
+ assert( file != NULL );
+ assert( name != NULL );
+ assert( group != NULL );
+
+ new = loadImage(file, alpha);
+
+ addItemToStorage(listStorage, group, name, new );
+
+ printf("load image %s\n", file);
+
+ return new;
+}
+
+/*
+ * Vrati odkaz na image_data v globalnom zozname obrazkov
+ * a nazvom *s
+ */
+SDL_Surface* getImage(char *group, char *name)
+{
+ assert( group != NULL );
+ assert( name != NULL );
+
+ return getItemFromStorage(listStorage, group, name);
+}
+
+void delImage(char *group, char *name)
+{
+ assert( group != NULL );
+ assert( name != NULL );
+
+ delItemFromStorage(listStorage, group, name, destroySDLSurface);
+}
+
+void delAllImageInGroup(char *group)
+{
+ assert( group != NULL );
+
+ delAllItemFromStorage(listStorage, group, destroySDLSurface);
+}
+
+void drawImage(SDL_Surface *p, int x,int y, int px, int py, int w, int h)
+{
+ static SDL_Surface *screen = NULL;
+ SDL_Rect dst_rect, src_rect;
+
+ if( screen == NULL )
+ {
+ screen = getSDL_Screen();
+ }
+
+ dst_rect.x = x;
+ dst_rect.y = y;
+
+ src_rect.x = px;
+ src_rect.y = py;
+ src_rect.w = w;
+ src_rect.h = h;
+
+ SDL_BlitSurface(p, &src_rect, screen, &dst_rect);
+}
+
+/*
+ * Odstrani zoznam obrazkov z pamate
+ */
+void quitImageData()
+{
+ printf("quit image database..\n");
+ destroyStorage(listStorage, destroySDLSurface);
+ isImageDataInit = FALSE;
+}
+
diff --git a/src/client/image.h b/src/client/image.h
new file mode 100755
index 0000000..5de6345
--- /dev/null
+++ b/src/client/image.h
@@ -0,0 +1,35 @@
+
+#ifndef IMAGE_H
+
+#define IMAGE_H
+
+#include "client/image.h"
+#include "client/interface.h"
+
+#define IMAGE_NO_ALPHA 0
+#define IMAGE_ALPHA 1
+
+#define IMAGE_GROUP_BASE "base"
+#define IMAGE_GROUP_EXTENDSIO "extension"
+#define IMAGE_GROUP_USER "user"
+#define IMAGE_GROUP_OTHER "other"
+
+/*
+typedef struct image_struct
+{
+ char *name;
+ char *group;
+ SDL_Surface *image;
+} image_data_t;
+*/
+
+extern bool_t isImageInicialized();
+extern void initImageData();
+extern SDL_Surface* addImageData(char *file, int alpha, char *name, char *group);
+extern SDL_Surface* getImage(char *group, char *name);
+extern void delImage(char *group, char *name);
+extern void delAllImageInGroup(char *group);
+extern void drawImage(SDL_Surface *p, int x,int y, int px, int py, int w, int h);
+extern void quitImageData();
+
+#endif
diff --git a/src/client/interface.c b/src/client/interface.c
new file mode 100755
index 0000000..570e3fd
--- /dev/null
+++ b/src/client/interface.c
@@ -0,0 +1,256 @@
+
+#include <stdlib.h>
+
+#include "base/main.h"
+#include "base/myTimer.h"
+
+#include "client/interface.h"
+#include "client/screen.h"
+
+//povrch okna
+static SDL_Surface *screen;
+//static SDL_Surface *my_surface;
+
+//casovac
+static SDL_TimerID timer;
+
+//priznaky okna
+static Uint32 g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
+
+static bool_t isInterfaceInit = FALSE;
+
+bool_t isInterfaceInicialized()
+{
+ return isInterfaceInit;
+}
+
+static Uint32 TimerCallback(Uint32 interval, void *param)
+{
+ SDL_Event event;
+ event.type = SDL_USEREVENT;
+ event.user.code = USR_EVT_TIMER;
+ event.user.data1 = NULL;
+ event.user.data2 = NULL;
+
+ SDL_PushEvent(&event);
+
+ return interval;
+}
+
+int initSDL()
+{
+ printf("init SDL..\n");
+
+ //inicializujem SDL
+ if( SDL_Init(SDL_SUBSYSTEMS) == -1 )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
+
+ //inicializujem okno
+ //screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, 0, g_win_flags);
+
+/*
+ my_surface = SDL_CreateRGBSurface(screen->flags, WINDOW_SIZE_X, WINDOW_SIZE_Y,
+ screen->format->BitsPerPixel,
+ screen->format->Rmask, screen->format->Gmask,
+ screen->format->Bmask, screen->format->Amask);
+
+ memset(my_surface->pixels, 128, 200);
+*/
+ if (screen == NULL )
+ {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ SDL_Quit();
+ return -1;
+ }
+
+ SDL_WM_SetCaption(WINDOW_TITLE, NULL);
+ //SDL_ShowCursor(0);
+ SDL_EnableKeyRepeat(1,1);
+ timer = SDL_AddTimer(INTERVAL, TimerCallback, NULL);
+
+ srand((unsigned)time(NULL));
+ isInterfaceInit = TRUE;
+
+ return 0;
+}
+
+SDL_Surface* getSDL_Screen()
+{
+ //return my_surface;
+ return screen;
+}
+
+void interfaceRefresh()
+{
+ //SDL_BlitSurface(my_surface, NULL, screen, NULL);
+ //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
+
+ //drawImage(my_surface, 200, 100, 0, 0, 200, 200);
+ SDL_Flip(screen);
+}
+
+int toggleFullscreen()
+{
+ if(g_win_flags & SDL_FULLSCREEN)
+ g_win_flags &= ~SDL_FULLSCREEN;
+ else
+ g_win_flags |= SDL_FULLSCREEN;
+
+ if( SDL_WM_ToggleFullScreen(screen) == 0 )
+ {
+ fprintf(stderr, "Nemozem prepnut do fullscreenu!\n");
+
+ SDL_FreeSurface(screen);
+ screen = SDL_SetVideoMode(WINDOW_SIZE_X, WINDOW_SIZE_Y, WIN_BPP, g_win_flags);
+
+ if(screen == NULL)
+ {
+ fprintf(stderr, "Nemozem premnut do okna:%s\n", SDL_GetError());
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+void getMousePosition(int *x, int *y)
+{
+ SDL_GetMouseState(x, y);
+}
+
+int isMouseClicked()
+{
+ return SDL_GetMouseState(NULL,NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
+}
+
+int isPessAnyKey()
+{
+ Uint8 *mapa;
+ int i;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
+ if( mapa[i] == SDL_PRESSED )
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+void printPessAnyKey()
+{
+ Uint8 *mapa;
+ int i;
+
+ mapa = SDL_GetKeyState(NULL);
+
+ for( i = SDLK_BACKSPACE ; i < SDLK_KP9 ; i++ )
+ if( mapa[i] == SDL_PRESSED )
+ {
+ printf("press key with code : %d\n", i);
+ }
+
+}
+
+
+/*
+static void action_esc()
+{
+ if( strcmp(getScreen(), "world") == 0 )
+ {
+ setScreen("analyze");
+ }
+
+ if( strcmp(getScreen(), "mainMenu") == 0 )
+ {
+ quit();
+ }
+
+}
+*/
+
+int eventAction()
+{
+ SDL_Event event;
+
+
+ while(SDL_WaitEvent(&event))
+ {
+ switch(event.type)
+ {
+ case SDL_KEYDOWN:
+ switch(event.key.keysym.sym)
+ {
+/*
+ case SDLK_ESCAPE:
+ action_esc();
+ return 0;
+ break;
+*/
+ case SDLK_F1:
+ if(!toggleFullscreen())return 0;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case SDL_USEREVENT:
+ switch(event.user.code)
+ {
+ case USR_EVT_TIMER:
+ drawScreen();
+ eventScreen();
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ // Zmena velikosti okna
+ case SDL_VIDEORESIZE:
+ screen = SDL_SetVideoMode(event.resize.w,event.resize.h, WIN_BPP, g_win_flags);
+
+ if(screen == NULL)
+ {
+ fprintf(stderr, "Nemozem zmenit rozlisene okna: %s\n",SDL_GetError());
+ return 0;
+ }
+ break;
+
+ // Pozadavek na ukonceni
+ case SDL_QUIT:
+ return -1;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+void eventSDL()
+{
+ while(1)
+ {
+ if ( eventAction() == -1 )return;
+ }
+}
+
+void quitSDL()
+{
+ printf("quit SDL..\n");
+ SDL_Quit();
+ isInterfaceInit = FALSE;
+}
diff --git a/src/client/interface.h b/src/client/interface.h
new file mode 100755
index 0000000..5804676
--- /dev/null
+++ b/src/client/interface.h
@@ -0,0 +1,40 @@
+
+#ifndef INTERFACE_H
+
+#define INTERFACE_H
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include <SDL.h>
+#include <SDL_image.h>
+#include <SDL_thread.h>
+#include "base/main.h"
+
+/*
+#include <SDL_net.h>
+*/
+
+#define SDL_SUBSYSTEMS SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_DOUBLEBUF
+
+//napis na okne
+#define WINDOW_TITLE "Tuxanci next generation " TUXANCI_NG_VERSION
+#define WIN_BPP 0
+#define USR_EVT_TIMER 0
+
+//interval pri ktorom sa spusta akcia();
+#define INTERVAL 50
+
+extern bool_t isInterfaceInicialized();
+extern int initSDL();
+extern SDL_Surface* getSDL_Screen();
+extern void getMousePosition(int *x, int *y);
+extern int isMouseClicked();
+extern int isPessAnyKey();
+extern void interfaceRefresh();
+extern void eventSDL();
+extern void quitSDL();
+
+
+#endif
diff --git a/src/client/keytable.c b/src/client/keytable.c
new file mode 100644
index 0000000..67811a7
--- /dev/null
+++ b/src/client/keytable.c
@@ -0,0 +1,136 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/homeDirector.h"
+#include "base/textFile.h"
+
+#include "client/keytable.h"
+#include "client/configFile.h"
+
+static textFile_t *keytableFile;
+static textFile_t *keycontrolFile;
+static int keytable[KEY_LENGTH];
+
+static int getKeyCode(char *s)
+{
+ char str[STR_SIZE];
+ char *find;
+ int i;
+
+ sprintf(str, "keycode %s = ", s);
+
+ for( i = 0 ; i < keytableFile->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (keytableFile->text->list[i]);
+
+ if( ( find = strstr(line, str) ) != NULL )
+ {
+ int ret;
+ ret = atoi( strchr(line, '=')+1 );
+ return ret;
+ }
+ }
+
+ return -1;
+}
+
+void initKeyTable()
+{
+ char path[STR_PATH_SIZE];
+ char val[STR_SIZE];
+/*
+ int i;
+*/
+ sprintf(path, PATH_CONFIG "keytable.conf");
+ keytableFile = loadTextFile(path);
+
+ if( keytableFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ return;
+ }
+
+ sprintf(path, "%s/keycontrol.conf", getHomeDirector());
+ keycontrolFile = loadTextFile(path);
+
+ if( keycontrolFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ keycontrolFile = newTextFile(path);
+ }
+
+ if( keycontrolFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return;
+ }
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, "SDLK_UP");
+ keytable[ KEY_TUX_RIGHT_MOVE_UP ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_RIGHT", val, STR_SIZE, "SDLK_RIGHT");
+ keytable[ KEY_TUX_RIGHT_MOVE_RIGHT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, "SDLK_LEFT");
+ keytable[ KEY_TUX_RIGHT_MOVE_LEFT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, "SDLK_DOWN");
+ keytable[ KEY_TUX_RIGHT_MOVE_DOWN ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, "SDLK_KP0");
+ keytable[ KEY_TUX_RIGHT_SHOOT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_SWITCH_WEAPON", val, STR_SIZE, "SDLK_KP1");
+ keytable[ KEY_TUX_RIGHT_SWITCH_WEAPON] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, "SDLK_w");
+ keytable[ KEY_TUX_LEFT_MOVE_UP ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, "SDLK_d");
+ keytable[ KEY_TUX_LEFT_MOVE_RIGHT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, "SDLK_a");
+ keytable[ KEY_TUX_LEFT_MOVE_LEFT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, "SDLK_s");
+ keytable[ KEY_TUX_LEFT_MOVE_DOWN ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_SHOOT", val, STR_SIZE, "SDLK_q");
+ keytable[ KEY_TUX_LEFT_SHOOT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_SWITCH_WEAPON", val, STR_SIZE, "SDLK_TAB");
+ keytable[ KEY_TUX_LEFT_SWITCH_WEAPON ] = getKeyCode(val);
+
+/*
+ for( i = 0 ; i < KEY_LENGTH ; i++)
+ {
+ printf("keytable[%d] = %d\n", i, keytable[i]);
+ }
+*/
+
+ saveTextFile(keycontrolFile);
+}
+
+int getKey(int n)
+{
+ assert( n >= 0 && n < KEY_LENGTH );
+/*
+ printf("keytable[n] = %d\n", keytable[n]);
+*/
+ return keytable[n];
+}
+
+void quitKeyTable()
+{
+ destroyTextFile(keycontrolFile);
+ destroyTextFile(keytableFile);
+}
+
diff --git a/src/client/keytable.h b/src/client/keytable.h
new file mode 100644
index 0000000..80ca258
--- /dev/null
+++ b/src/client/keytable.h
@@ -0,0 +1,27 @@
+
+#ifndef KEYTABLE_H
+
+#define KEYTABLE_H
+
+#define KEY_LENGTH 12
+
+#define KEY_TUX_RIGHT_MOVE_UP 0
+#define KEY_TUX_RIGHT_MOVE_RIGHT 1
+#define KEY_TUX_RIGHT_MOVE_LEFT 2
+#define KEY_TUX_RIGHT_MOVE_DOWN 3
+#define KEY_TUX_RIGHT_SHOOT 4
+#define KEY_TUX_RIGHT_SWITCH_WEAPON 5
+#define KEY_TUX_LEFT_MOVE_UP 6
+#define KEY_TUX_LEFT_MOVE_RIGHT 7
+#define KEY_TUX_LEFT_MOVE_LEFT 8
+#define KEY_TUX_LEFT_MOVE_DOWN 9
+#define KEY_TUX_LEFT_SHOOT 10
+#define KEY_TUX_LEFT_SWITCH_WEAPON 11
+
+extern void initKeyTable();
+extern int getKey(int n);
+extern void quitKeyTable();
+
+#endif
+
+
diff --git a/src/client/language.c b/src/client/language.c
new file mode 100644
index 0000000..5444253
--- /dev/null
+++ b/src/client/language.c
@@ -0,0 +1,157 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/homeDirector.h"
+#include "base/textFile.h"
+
+#include "client/configFile.h"
+#include "client/language.h"
+
+static textFile_t *languageFile;
+static char fontFile[STR_FILE_NAME_SIZE];
+static int fontSize;
+
+char* getHead(textFile_t *ts)
+{
+ int i;
+
+ for( i = 0 ; i < ts->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (ts->text->list[i]);
+
+ if( strncmp(line, "HEAD", 4) == 0 )
+ {
+ return line;
+ }
+ }
+
+ return NULL;
+}
+
+
+int initLanguage()
+{
+ textFile_t *languageTypeFile;
+ char path[STR_PATH_SIZE];
+ char *lang;
+ char *head;
+
+ sprintf(path, "%s/lang.conf", getHomeDirector());
+ printf("open %s\n", path);
+ languageTypeFile = loadTextFile(path);
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ languageTypeFile = newTextFile(path);
+ addList(languageTypeFile->text, strdup("en") );
+ saveTextFile(languageTypeFile);
+ }
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return -1;
+ }
+
+ if( languageTypeFile->text->count == 0 )
+ {
+ fprintf(stderr, "File %s empty\n", path);
+ return -1;
+ }
+
+ lang = ((char *)languageTypeFile->text->list[0]);
+ printf("select lang %s\n", lang);
+
+ sprintf(path, PATH_LANG "%s.lang", lang);
+
+ destroyTextFile(languageTypeFile);
+
+ accessExistFile(path);
+ languageFile = loadTextFile(path);
+
+ if( languageFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ return -1;
+ }
+
+ head = getHead(languageFile);
+
+ if( head != NULL )
+ {
+ char val[STR_SIZE];
+
+ if( getValue(head, "fontfile", val, STR_SIZE) == 0 )
+ {
+ strcpy(fontFile, val);
+ }
+ else
+ {
+ fprintf(stderr, "fontfile in lang file %s not found\n", path);
+ return -1;
+ }
+
+ if( getValue(head, "fontsize", val, STR_SIZE) == 0 )
+ {
+ fontSize = atoi(val);
+ }
+ else
+ {
+ fprintf(stderr, "fontsize in lang file %s not found\n", path);
+ return -1;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "head in lang file %s not found\n", path);
+ return -1;
+ }
+
+ return 0;
+}
+
+char* getMyText(char *key)
+{
+ int i;
+ int len;
+
+ len = strlen(key);
+
+ for( i = 0 ; i < languageFile->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (languageFile->text->list[i]);
+
+ if( strncmp(key, line, len) == 0 )
+ {
+ return line+strlen(key)+1;
+ }
+ }
+
+ return NULL;
+}
+
+char* getLanguageFont()
+{
+ return fontFile;
+}
+
+int getLanguageSize()
+{
+ return fontSize;
+}
+
+void quitLanguage()
+{
+ destroyTextFile(languageFile);
+}
+
diff --git a/src/client/language.h b/src/client/language.h
new file mode 100644
index 0000000..23fc1a4
--- /dev/null
+++ b/src/client/language.h
@@ -0,0 +1,12 @@
+
+#ifndef LANGUAGE_H
+
+#define LANGUAGE_H
+
+extern int initLanguage();
+extern char* getMyText(char *key);
+extern char* getLanguageFont();
+extern int getLanguageSize();
+extern void quitLanguage();
+
+#endif
diff --git a/src/client/layer.c b/src/client/layer.c
new file mode 100755
index 0000000..707184b
--- /dev/null
+++ b/src/client/layer.c
@@ -0,0 +1,155 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/tux.h"
+
+#include "client/interface.h"
+#include "client/layer.h"
+#include "client/image.h"
+
+#include "screen/screen_world.h"
+
+static list_t *listLayer;
+
+static bool_t isLayerInit = FALSE;
+
+bool_t isLayerInicialized()
+{
+ return isLayerInit;
+}
+
+/*
+ * Inicializuje globalny zoznam vsrtiev
+ */
+void initLayer()
+{
+ listLayer = newList();
+}
+
+/*
+ * Prida novu polozku do zoznamu vrstiev
+ * *img - obrazok, ktory obsahuje polozka
+ * x y w h - suradnca kam sa obrazok vykresli a jeho rozmery
+ * px py pw ph - suradnica casti obrazka *img ktora sa ma zobrazit
+ * layer - vrstva na ktorej sa zobrazi obrazok
+ */
+void addLayer(SDL_Surface *img,
+ int x,int y, int px,int py,
+ int w,int h, int player)
+{
+ layer_t *new;
+ layer_t *this;
+ int i;
+
+ assert( img != NULL );
+
+ new = malloc( sizeof(layer_t) );
+ new->x = x;
+ new->y = y;
+ new->w = w;
+ new->h = h;
+ new->px = px;
+ new->py = py;
+ new->layer = player;
+ new->image = img;
+
+ if( listLayer->count == 0 )
+ {
+ addList(listLayer, new);
+ return;
+ }
+
+ i = 0;
+ this = (layer_t *)listLayer->list[0];
+
+ //vyhladaj svoju vrstvu
+ while( i < listLayer->count && this->layer < new->layer )
+ {
+ this = (layer_t *)listLayer->list[++i];
+ }
+
+ //porovnaj s vyskami na tvojej vrstve,
+ //ak neexistuje, rovno to tam hod
+ this = (layer_t *)listLayer->list[i];
+
+ while( i < listLayer->count && this->y+this->h < new->y+new->h && new->layer == this->layer )
+ {
+ this = (layer_t *)listLayer->list[++i];
+ }
+
+ insList(listLayer, i, new);
+ isLayerInit = TRUE;
+}
+
+/*
+ * Vykresli vsetky polozky na obrazovku
+ * poukadane podla vrstvy a suradnice Y+H
+ * po dokresleni sa zoznam uvolni.
+ */
+void drawLayer()
+{
+ layer_t *this;
+ int i;
+
+ for( i = 0 ; i < listLayer->count ; i++ )
+ {
+ this = (layer_t *)listLayer->list[i];
+
+ drawImage(this->image,
+ this->x, this->y,
+ this->px, this->py,
+ this->w, this->h);
+ }
+
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+void drawLayerCenter(int x, int y)
+{
+ layer_t *this;
+ int screen_x, screen_y;
+ int i;
+
+ 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 - 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);
+ listLayer = newList();
+}
+
+void flushLayer()
+{
+ destroyListItem(listLayer, free);
+ listLayer = newList();
+}
+
+/*
+ * Odstrani zoznam vrtsiev z pamete.
+ */
+void quitLayer()
+{
+ destroyListItem(listLayer, free);
+ isLayerInit = FALSE;
+}
+
diff --git a/src/client/layer.h b/src/client/layer.h
new file mode 100755
index 0000000..3564ef8
--- /dev/null
+++ b/src/client/layer.h
@@ -0,0 +1,53 @@
+
+#ifndef MY_LAYER_H
+
+#define MY_LAYER_H
+
+#include "base/main.h"
+
+typedef struct layer_str
+{
+ int x; //suradnice obrazka na obrazovke
+ int y;
+
+ int w; //rozmery obrazka na obrazovke
+ int h;
+
+ int px; //suradnice casti surfrace
+ int py;
+
+ int pw; //rozmeri casti surfrace
+ int ph;
+
+ int layer;
+
+ SDL_Surface *image; //dane surfrace
+} layer_t;
+
+extern bool_t isLayerInicialized();
+extern void initLayer();
+
+/*
+ * Prida obrazok na vykreslenie do zoznamu
+ * *img - ponter na urfrace obrazka
+ * x,y - suradnice kam sa ma obrazok nakreslit
+ * w,h - rozmeri obrazka
+ * px,py - suradnice casti *img z ktorej sa bude obrazok vykreslovat
+ * ph,ph - rozmeri casti obrazka *img z ktorej sa bude obrazok vykreslovat
+ * layer - layer, na ktorej bude obrazok
+ * (0 - pod tuxancami | 1 - na tej istej ako tuxanci | 2 - nad tuxancami)
+ */
+
+extern void addLayer(SDL_Surface *img,
+ int x,int y, int px,int py,
+ int w,int h, int player);
+
+/*
+ * Vykresli zoznam na obrazovku
+ */
+extern void drawLayer();
+extern void drawLayerCenter(int x, int y);
+extern void flushLayer();
+extern void quitLayer();
+
+#endif
diff --git a/src/client/panel.c b/src/client/panel.c
new file mode 100644
index 0000000..af9cccb
--- /dev/null
+++ b/src/client/panel.c
@@ -0,0 +1,190 @@
+
+#include <stdio.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/tux.h"
+
+#include "client/interface.h"
+#include "client/image.h"
+#include "client/panel.h"
+#include "client/font.h"
+
+static SDL_Surface *g_panel;
+static SDL_Surface *g_shot;
+static SDL_Surface *g_icon[ITEM_COUNT];
+static SDL_Surface *g_bonus;
+
+static bool_t isPanelInit = FALSE;
+
+bool_t isPanelInicialized()
+{
+ return isPanelInit;
+}
+
+void initPanel()
+{
+ assert( isImageInicialized() == TRUE );
+ assert( isInterfaceInicialized() == TRUE );
+
+ g_panel = addImageData("panel.png", IMAGE_ALPHA, "panel", IMAGE_GROUP_BASE);
+ g_shot = addImageData("panel_shot.png", IMAGE_ALPHA, "panel_image_shot", IMAGE_GROUP_BASE);
+ g_bonus = addImageData("graf.bonus.png", IMAGE_ALPHA, "panel_graf_bonus", IMAGE_GROUP_BASE);
+
+ g_icon[GUN_SIMPLE] = addImageData("icon.gun.simple.png", IMAGE_ALPHA, "panel_gun", IMAGE_GROUP_BASE);
+ g_icon[GUN_DUAL_SIMPLE] = addImageData("icon.gun.dual.simple.png", IMAGE_ALPHA, "panel_dual", IMAGE_GROUP_BASE);
+ g_icon[GUN_TOMMY] = addImageData("icon.gun.tommy.png", IMAGE_ALPHA, "panel_tommy", IMAGE_GROUP_BASE);
+ g_icon[GUN_SCATTER] = addImageData("icon.gun.scatter.png", IMAGE_ALPHA, "panel_scatter", IMAGE_GROUP_BASE);
+ g_icon[GUN_LASSER] = addImageData("icon.gun.lasser.png", IMAGE_ALPHA, "panel_lasser", IMAGE_GROUP_BASE);
+ g_icon[GUN_MINE] = addImageData("icon.gun.mine.png", IMAGE_ALPHA, "panel_mine", IMAGE_GROUP_BASE);
+ g_icon[GUN_BOMBBALL] = addImageData("icon.gun.bombball.png", IMAGE_ALPHA, "panel_bombball", IMAGE_GROUP_BASE);
+
+ g_icon[BONUS_SPEED] = addImageData("icon.bonus.speed.png", IMAGE_ALPHA, "panel_speed", IMAGE_GROUP_BASE);
+ g_icon[BONUS_SHOT] = addImageData("icon.bonus.shot.png", IMAGE_ALPHA, "panel_shot", IMAGE_GROUP_BASE);
+ g_icon[BONUS_TELEPORT] = addImageData("icon.bonus.teleport.png", IMAGE_ALPHA, "panel_teleport", IMAGE_GROUP_BASE);
+ g_icon[BONUS_GHOST] = addImageData("icon.bonus.ghost.png", IMAGE_ALPHA, "panel_ghost", IMAGE_GROUP_BASE);
+ g_icon[BONUS_4X] = addImageData("icon.bonus.4x.png", IMAGE_ALPHA, "panel_4x", IMAGE_GROUP_BASE);
+ g_icon[BONUS_HIDDEN] = addImageData("icon.bonus.hidden.png", IMAGE_ALPHA, "panel_hidden", IMAGE_GROUP_BASE);
+
+ isPanelInit = TRUE;
+}
+
+static void setScoreline(list_t *listTux, char *str)
+{
+ tux_t *thisTux;
+ int i;
+
+ assert( listTux != NULL );
+ assert( str != NULL );
+
+ strcpy(str, "");
+
+ for( i = 0 ; i < listTux->count ; i++ )
+ {
+ char num[STR_SIZE];
+
+ thisTux = (tux_t *)listTux->list[i];
+ assert( thisTux != NULL );
+
+ sprintf(num, "%s%d", ( i == 0 ? "" : " : " ), thisTux->score);
+ strcat(str, num);
+ }
+}
+
+static void drawScore(list_t *listTux)
+{
+ char strScoreLine[STR_SIZE];
+ int w, h;
+
+ assert( listTux != NULL );
+
+ setScoreline(listTux, strScoreLine);
+ getTextSize(strScoreLine, &w , &h);
+ drawFont(strScoreLine, PANEL_SCORE_LOCATION_X, PANEL_SCORE_LOCATION_Y, COLOR_WHITE);
+}
+
+static void drawShot(int n, int x, int y)
+{
+ drawImage(g_shot, x, y,n * PANEL_SHOT_WIDTH, 0, PANEL_SHOT_WIDTH, PANEL_SHOT_HEIGHT);
+}
+
+static void drawShotInfo(tux_t *tux,int x, int y)
+{
+ int i;
+
+ if( tux->pickup_time > 0 )
+ {
+ for( i = 0 ; i < tux->pickup_time / 3 ; i++ )
+ {
+ drawShot(PANEL_SHOT_LINE, x + i * PANEL_SHOT_WIDTH, y);
+ }
+
+ return;
+ }
+
+ for( i = 0 ; i < GUN_MAX_SHOT ; i++ )
+ {
+ if( tux->shot[tux->gun] > i )
+ {
+ drawShot(PANEL_SHOT_FILL, x + i * ( PANEL_SHOT_WIDTH + 2 ), y);
+ }
+ else
+ {
+ drawShot(PANEL_SHOT_EMPTY, x + i * ( PANEL_SHOT_WIDTH + 2 ) , y);
+ }
+ }
+}
+
+static void drawGunInfo(tux_t *tux,int x, int y)
+{
+ drawImage(g_icon[ tux->gun ], x, y, 0, 0,
+ g_icon[ tux->gun ]->w, g_icon[ tux->gun ]->h);
+}
+
+static void drawBonusInfo(tux_t *tux,int x, int y)
+{
+ drawImage(g_icon[ tux->bonus ], x, y, 0, 0, g_icon[ tux->bonus ]->w, g_icon[ tux->bonus ]->h);
+}
+
+static void drawGrafBonus(tux_t *tux,int x, int y)
+{
+ int offset;
+
+ offset = tux->bonus_time / 5;
+ drawImage(g_bonus, x, y, 0, 0, g_bonus->w, g_bonus->h/2);
+ drawImage(g_bonus, x+1, y, 0, g_bonus->h/2, offset, g_bonus->h/2);
+}
+
+void drawPanel(list_t *listTux)
+{
+ int i;
+
+ assert( listTux != NULL );
+
+ drawImage(g_panel, PANEL_LOCATION_X, PANEL_LOCATION_Y, 0, 0, g_panel->w, g_panel->h);
+ drawScore(listTux);
+
+ for( i = 0 ; i < listTux->count ; i++ )
+ {
+ tux_t *thisTux;
+ int x, y;
+
+ thisTux = (tux_t *)listTux->list[i];
+ assert( thisTux != NULL );
+
+ x = PANEL_LOCATION_X;
+ y = PANEL_LOCATION_Y;
+
+ switch( i )
+ {
+ case 0 :
+ drawShotInfo(thisTux, x+8, y+34);
+ drawGunInfo(thisTux, x+130, y+30);
+
+ if( thisTux->bonus != BONUS_NONE )
+ {
+ drawGrafBonus(thisTux,x+200, y+50);
+ drawBonusInfo(thisTux,x+200, y+30);
+ }
+ break;
+
+ case 1 :
+ drawShotInfo(thisTux, x+740, y+34);
+ drawGunInfo(thisTux, x+620, y+30);
+
+ if( thisTux->bonus != BONUS_NONE )
+ {
+ drawGrafBonus(thisTux,x+460, y+50);
+ drawBonusInfo(thisTux,x+460, y+30);
+ }
+ break;
+ }
+ }
+}
+
+void quitPanel()
+{
+ isPanelInit = FALSE;
+}
+
diff --git a/src/client/panel.h b/src/client/panel.h
new file mode 100644
index 0000000..144ea02
--- /dev/null
+++ b/src/client/panel.h
@@ -0,0 +1,27 @@
+
+#ifndef PANEL_H
+
+#define PANEL_H
+
+#include "base/main.h"
+#include "base/list.h"
+
+#define PANEL_SCORE_LOCATION_X ( WINDOW_SIZE_X / 2 - w / 2 )
+#define PANEL_SCORE_LOCATION_Y ( WINDOW_SIZE_Y - 40 )
+
+#define PANEL_SHOT_WIDTH 4
+#define PANEL_SHOT_HEIGHT 8
+
+#define PANEL_LOCATION_X 0
+#define PANEL_LOCATION_Y (WINDOW_SIZE_Y-g_panel->h)
+
+#define PANEL_SHOT_FILL 0
+#define PANEL_SHOT_EMPTY 1
+#define PANEL_SHOT_LINE 2
+
+extern bool_t isPanelInicialized();
+extern void initPanel();
+extern void drawPanel(list_t *listTux);
+extern void quitPanel();
+
+#endif
diff --git a/src/client/screen.c b/src/client/screen.c
new file mode 100644
index 0000000..730476e
--- /dev/null
+++ b/src/client/screen.c
@@ -0,0 +1,137 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+
+#include "client/interface.h"
+#include "client/screen.h"
+#include "client/layer.h"
+
+static screen_t *currentScreen;
+static list_t *listScreen;
+
+static bool_t isScreenInit = FALSE;
+
+bool_t isScreenInicialized()
+{
+ return isScreenInit;
+}
+
+screen_t* newScreen(char *name,
+ void (*fce_start)(), void (*fce_event)(),
+ void (*fce_draw)(), void (*fce_stop)())
+{
+ screen_t *new;
+
+ assert( name != NULL );
+ assert( fce_start != NULL );
+ assert( fce_event != NULL );
+ assert( fce_draw != NULL );
+ assert( fce_stop != NULL );
+
+ new = malloc( sizeof(screen_t) );
+ new->name = strdup(name);
+ new->fce_start = fce_start;
+ new->fce_event = fce_event;
+ new->fce_draw = fce_draw;
+ new->fce_stop = fce_stop;
+
+ return new;
+}
+
+void destroyScreen(screen_t *p)
+{
+ assert( p != NULL );
+
+ free(p->name);
+ free(p);
+}
+
+void registerScreen(screen_t *p)
+{
+ assert( p != NULL );
+
+ printf("register screen %s..\n", p->name);
+ addList(listScreen, p);
+}
+
+void initScreen()
+{
+ listScreen = newList();
+ currentScreen = NULL;
+ isScreenInit = TRUE;
+}
+
+void setScreen(char *name)
+{
+ int i;
+ screen_t *this;
+
+ assert( name != NULL );
+
+ if( currentScreen != NULL &&
+ strcmp(currentScreen->name, name) == 0 )
+ {
+ return;
+ }
+
+ printf("switch screen %s..\n", name);
+
+ for( i = 0 ; i < listScreen->count ; i++ )
+ {
+ this = (screen_t *) (listScreen->list[i]);
+ assert( this != NULL );
+
+ if( strcmp(name, this->name) == 0 )
+ {
+ flushLayer();
+
+ if( currentScreen != NULL )
+ {
+ printf("stop screen %s..\n", currentScreen->name);
+ currentScreen->fce_stop();
+ }
+
+ currentScreen = this;
+ printf("start screen %s..\n", currentScreen->name);
+ currentScreen->fce_start();
+
+ return;
+ }
+ }
+
+ assert( ! "screen sa nenasiel !" );
+}
+
+char* getScreen()
+{
+ assert( currentScreen != NULL );
+ return currentScreen->name;
+}
+
+void drawScreen()
+{
+ assert( currentScreen != NULL );
+
+ currentScreen->fce_draw();
+
+ interfaceRefresh();
+}
+
+void eventScreen()
+{
+ assert( currentScreen != NULL );
+
+ currentScreen->fce_event();
+}
+
+void quitScreen()
+{
+ assert( listScreen != NULL );
+
+ destroyListItem(listScreen, destroyScreen);
+ isScreenInit = FALSE;
+}
+
diff --git a/src/client/screen.h b/src/client/screen.h
new file mode 100644
index 0000000..8049147
--- /dev/null
+++ b/src/client/screen.h
@@ -0,0 +1,32 @@
+
+#ifndef SCREEN_H
+
+#define SCREEN_H
+
+#include "base/main.h"
+
+typedef struct screen_struct
+{
+ char *name;
+ void (*fce_start)();
+ void (*fce_event)();
+ void (*fce_draw)();
+ void (*fce_stop)();
+} screen_t;
+
+extern bool_t isScreenInicialized();
+
+extern screen_t* newScreen(char *name,
+ void (*fce_start)(), void (*fce_event)(),
+ void (*fce_draw)(), void (*fce_stop)());
+
+extern void destroyScreen(screen_t *p);
+extern void registerScreen(screen_t *p);
+extern void initScreen();
+extern void setScreen(char *name);
+extern char* getScreen();
+extern void drawScreen();
+extern void eventScreen();
+extern void quitScreen();
+
+#endif
diff --git a/src/client/term.c b/src/client/term.c
new file mode 100644
index 0000000..3357f0b
--- /dev/null
+++ b/src/client/term.c
@@ -0,0 +1,106 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/myTimer.h"
+
+#include "client/interface.h"
+#include "client/term.h"
+#include "client/font.h"
+
+typedef struct struct_term_t
+{
+ char *text;
+ my_time_t delTime;
+} term_t;
+
+static list_t *listText;
+
+static term_t* newTermItem(char *s)
+{
+ term_t *new;
+ char *line;
+ int len;
+
+ assert( s != NULL );
+
+ line = strdup(s);
+ len = strlen(line);
+ line[len-1] = '\0';
+
+ new = malloc( sizeof(term_t) );
+ memset(new, 0, sizeof(term_t));
+
+ new->text = line;
+ new->delTime = getMyTime() + TERM_DEL_TEXT_TIMEOUT;
+
+ return new;
+}
+
+static void destroyTermItem(term_t *p)
+{
+ assert( p != NULL );
+
+ free(p->text);
+ free(p);
+}
+
+void initTerm()
+{
+ listText = newList();
+}
+
+void drawTerm()
+{
+ int i;
+
+ for( i = 0 ; i < listText->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)( (term_t *)listText->list[i] )->text;
+ drawFont(line, 10, 10 + i*20, COLOR_WHITE);
+ }
+}
+
+void eventTerm()
+{
+ my_time_t currentTime;
+ int i;
+
+ currentTime = getMyTime();
+
+
+ for( i = 0 ; i < listText->count ; i++ )
+ {
+ my_time_t thisTime;
+
+ thisTime = ( (term_t *)listText->list[i] )->delTime;
+
+ if( currentTime > thisTime )
+ {
+ delListItem(listText, i, destroyTermItem);
+ i--;
+ }
+ }
+
+}
+
+void appendTextInTerm(char *s)
+{
+
+ addList(listText, newTermItem(s) );
+
+ if( listText->count > TERM_MAX_LINES )
+ {
+ delListItem(listText, 0, destroyTermItem);
+ }
+}
+
+void quitTerm()
+{
+ assert( listText != NULL );
+ destroyListItem(listText, destroyTermItem);
+}
diff --git a/src/client/term.h b/src/client/term.h
new file mode 100644
index 0000000..548fda6
--- /dev/null
+++ b/src/client/term.h
@@ -0,0 +1,17 @@
+
+#ifndef TERM_H
+
+#define TERM_H
+
+#include "base/main.h"
+
+#define TERM_MAX_LINES 10
+#define TERM_DEL_TEXT_TIMEOUT 2000
+
+extern void initTerm();
+extern void drawTerm();
+extern void eventTerm();
+extern void appendTextInTerm(char *s);
+extern void quitTerm();
+
+#endif