summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-08 20:19:05 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-08 20:19:05 +0000
commitda85e88878251f6a980fef95bd47109169a3cf7c (patch)
tree83b8b61c4afad0f6ccbb7940176a03f3ad4d2dc5
parentf8bc51b580a5b9a8445f38b614a87209c074143a (diff)
- hra si vytvara domovskt adresar
- moznost ulozit konfiguraciu - lasserove streli boli lepsie posunute git-svn-id: http://opensvn.csie.org/tuxanci_ng@12 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
-rw-r--r--control2
-rwxr-xr-xdeb-build.sh3
-rw-r--r--include/configFile.h12
-rwxr-xr-xinclude/homeDirector.h11
-rwxr-xr-xinclude/interface.h2
-rwxr-xr-xsrc/Makefile7
-rw-r--r--src/arenaFile.c102
-rw-r--r--src/configFile.c130
-rw-r--r--src/gun.c45
-rwxr-xr-xsrc/homeDirector.c42
-rw-r--r--src/main.c3
-rw-r--r--src/screen_choiceArena.c2
-rw-r--r--src/screen_setting.c98
-rw-r--r--src/shot.c2
14 files changed, 345 insertions, 116 deletions
diff --git a/control b/control
index 27cd999..7bdffef 100644
--- a/control
+++ b/control
@@ -1,5 +1,5 @@
Package: tuxanci-ng
-Version: svn8
+Version: svn11
Section: Game
Priority: optional
Depends: libc6 (>= 2.2.4-4), libsdl1.2debian (>= 1.2), libsdl-image1.2 (>= 1.2), libsdl-mixer1.2 (>= 1.2), libsdl-ttf2.0-0 (>= 2.0)
diff --git a/deb-build.sh b/deb-build.sh
index 91787f3..16f3da2 100755
--- a/deb-build.sh
+++ b/deb-build.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
rm -rf deb
@@ -22,4 +23,4 @@ md5sum `find ./ -type f | awk '/.\// { print substr($0, 3) }'` > DEBIAN/md5sums
cd ..
rm -rf *.deb
-dpkg -b ./deb tuxanci-ng_svn8-1_i386.deb
+dpkg -b ./deb tuxanci-ng_svn11-1_i386.deb
diff --git a/include/configFile.h b/include/configFile.h
index 8ceb75c..a57fb16 100644
--- a/include/configFile.h
+++ b/include/configFile.h
@@ -5,7 +5,15 @@
#include "textFile.h"
-extern char* getValueInConfigFile(textFile_t *p, char *s);
-extern void delRemInConfigFile(textFile_t *p);
+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/include/homeDirector.h b/include/homeDirector.h
new file mode 100755
index 0000000..6dbf5a2
--- /dev/null
+++ b/include/homeDirector.h
@@ -0,0 +1,11 @@
+
+#ifndef HOMEDIRECTOR_H
+
+#define HOMEDIRECTOR_H
+
+#define HOMEDIRECTOR_NAME ".tuxanci-ng"
+
+extern void createHomeDirector();
+extern char *getHomeDirector();
+
+#endif
diff --git a/include/interface.h b/include/interface.h
index 2012632..850fe19 100755
--- a/include/interface.h
+++ b/include/interface.h
@@ -23,7 +23,7 @@
#define WINDOW_SIZE_Y 600
//napis na okne
-#define WINDOW_TITLE "Tuxanci next generation SVN revision 8"
+#define WINDOW_TITLE "Tuxanci next generation SVN revision 11"
#define WIN_BPP 0
#define USR_EVT_TIMER 0
diff --git a/src/Makefile b/src/Makefile
index 2aafa95..f96674f 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,8 +1,8 @@
CC = gcc
-#CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
CFLAGS = -g -O0 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
+#CFLAGS = -O2 -DDISTDIR=\"$(DISTDIR)\" `sdl-config --cflags` -I../include -Wall
LIBS = `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_mixer
@@ -11,7 +11,7 @@ FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o
buffer.o dynamicInt.o arena.o arenaFile.o textFile.o sound.o audio.o music.o gun.o \
item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \
widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \
- widget_buttonimage.o screen_credits.o teleport.o pipe.o
+ widget_buttonimage.o screen_credits.o teleport.o pipe.o homeDirector.o
tuxanci-ng: $(FILES)
$(CC) $(CFLAGS) $(LIBS) -o tuxanci-ng $(FILES)
@@ -139,5 +139,8 @@ teleport.o: teleport.c ../include/teleport.h
pipe.o: pipe.c ../include/pipe.h
$(CC) $(CFLAGS) -o pipe.o -c pipe.c
+homeDirector.o: homeDirector.c ../include/homeDirector.h
+ $(CC) $(CFLAGS) -o homeDirector.o -c homeDirector.c
+
clean:
rm -rf *.o *.c~ *.h~ tuxanci-ng
diff --git a/src/arenaFile.c b/src/arenaFile.c
index 64e59a4..76780c6 100644
--- a/src/arenaFile.c
+++ b/src/arenaFile.c
@@ -7,6 +7,7 @@
#include "main.h"
#include "list.h"
#include "textFile.h"
+#include "configFile.h"
#include "arenaFile.h"
#include "arena.h"
#include "tux.h"
@@ -30,56 +31,15 @@ bool_t isAreaFileInicialized()
return isArenaFileInit;
}
-static int setValue(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);
-
- //printf("%s %s\n", line, env);
-
- offset_env = strstr(line, clone_env);
- //printf("offset_env = %s\n", offset_env);
- if( offset_env == NULL )return -1;
-
- offset_val_begin = strchr(offset_env, '"');
- //printf("offset_val_begin = %s\n", offset_val_begin);
- if( offset_val_begin == NULL )return -1;
-
- offset_val_end = strchr(offset_val_begin+1, '"');
- //printf("offset_val_end = %s\n", offset_val_end);
- 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;
- //printf("val_len = %d\n", val_len);
-
- memset(val, 0, len);
- memcpy(val, offset_val_begin+1, val_len);
- //printf("val = %s\n", val);
- return 0;
-}
-
-static int isYesOrNO(char *s)
-{
- if( s[0] == 'Y' || s[0] == 'y' )return 1;
- return 0;
-}
-
static void cmd_loadImage(char *line)
{
char str_file[STR_SIZE];
char str_name[STR_SIZE];
char str_alpha[STR_SIZE];
- if( setValue(line, "file", str_file, STR_SIZE) != 0 )return;
- if( setValue(line, "name", str_name, STR_SIZE) != 0 )return;
- if( setValue(line, "alpha", str_alpha, STR_SIZE) != 0 )return;
+ if( getValue(line, "file", str_file, STR_SIZE) != 0 )return;
+ if( getValue(line, "name", str_name, STR_SIZE) != 0 )return;
+ if( getValue(line, "alpha", str_alpha, STR_SIZE) != 0 )return;
addImageData(str_file, isYesOrNO(str_alpha), str_name, IMAGE_GROUP_USER);
}
@@ -89,8 +49,8 @@ static void cmd_loadMusic(char *line)
char str_file[STR_SIZE];
char str_name[STR_SIZE];
- if( setValue(line, "file", str_file, STR_SIZE) != 0 )return;
- if( setValue(line, "name", str_name, STR_SIZE) != 0 )return;
+ if( getValue(line, "file", str_file, STR_SIZE) != 0 )return;
+ if( getValue(line, "name", str_name, STR_SIZE) != 0 )return;
addMusic(str_file, str_name, MUSIC_GROUP_USER);
}
@@ -99,7 +59,7 @@ static void cmd_background(arena_t *arena, char *line)
{
char str_image[STR_SIZE];
- if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+ if( getValue(line, "image", str_image, STR_SIZE) != 0 )return;
arena->background = getImage(IMAGE_GROUP_USER, str_image);
}
@@ -108,7 +68,7 @@ static void cmd_playMusic(arena_t *arena, char *line)
{
char str_music[STR_SIZE];
- if( setValue(line, "music", str_music, STR_SIZE) != 0 )return;
+ if( getValue(line, "music", str_music, STR_SIZE) != 0 )return;
strcpy(arena->music, str_music);
}
@@ -125,14 +85,14 @@ static void cmd_wall(arena_t *arena, char *line)
char str_image[STR_SIZE];
wall_t *new;
- if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "img_x", str_img_x, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "img_y", str_img_y, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+ if( getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "img_x", str_img_x, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "img_y", str_img_y, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "image", str_image, STR_SIZE) != 0 )return;
new = newWall(atoi(str_x), atoi(str_y),
atoi(str_w), atoi(str_h),
@@ -152,12 +112,12 @@ static void cmd_teleport(arena_t *arena, char *line)
char str_image[STR_SIZE];
teleport_t *new;
- if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+ if( getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "image", str_image, STR_SIZE) != 0 )return;
new = newTeleport(atoi(str_x), atoi(str_y),
atoi(str_w), atoi(str_h),
@@ -179,15 +139,15 @@ static void cmd_pipe(arena_t *arena, char *line)
char str_image[STR_SIZE];
pipe_t *new;
- if( setValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "id", str_id, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "position", str_position, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
- if( setValue(line, "image", str_image, STR_SIZE) != 0 )return;
+ if( getValue(line, "x", str_x, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "y", str_y, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "w", str_w, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "h", str_h, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "id", str_id, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "id_out", str_id_out, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "position", str_position, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "layer", str_layer, STR_NUM_SIZE) != 0 )return;
+ if( getValue(line, "image", str_image, STR_SIZE) != 0 )return;
new = newPipe(atoi(str_x), atoi(str_y),
atoi(str_w), atoi(str_h),
diff --git a/src/configFile.c b/src/configFile.c
index 5bbbf97..1c19e3f 100644
--- a/src/configFile.c
+++ b/src/configFile.c
@@ -4,47 +4,133 @@
#include <string.h>
#include <assert.h>
+#include "main.h"
#include "configFile.h"
-char* getValueInConfigFile(textFile_t *p, char *s)
+int isYesOrNO(char *s)
{
- int i;
+ 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;
- assert( s != NULL );
- assert( p != NULL );
+ strcpy(clone_env, " ");
+ strcat(clone_env, env);
- for( i = 0 ; i < p->text->count ; i++ )
- {
- char *line;
- char *offset;
+ 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);
- line = (char *) (p->text->list[i]);
+ return strdup( clone );
+}
- if( ( offset = strstr(line, s) ) != NULL )
+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 offset + ( strlen(s) + 1 );
+ return getValue(line, env, val, len);
}
}
- return NULL;
+ return -1;
}
-void delRemInConfigFile(textFile_t *p)
+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);
- assert( p != NULL );
+ if( ret != NULL )
+ {
+ delListItem(textFile->text, i, free);
+ insList(textFile->text, i, ret);
- for( i = 0 ; i < p->text->count ; i++ )
+ 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;
- char *offset;
+ char line[STR_SIZE];
- line = (char *) (p->text->list[i]);
+ sprintf(line, " %s=\"%s\"", env, butVal);
+ addList(textFile->text, strdup(line) );
- if( ( offset = strchr(line, '#') ) != NULL )
- {
- *offset = '\0';
- }
+ printf("Add line \"%s\" in config file.\n", line);
}
}
diff --git a/src/gun.c b/src/gun.c
index 3ad1bac..6938a88 100644
--- a/src/gun.c
+++ b/src/gun.c
@@ -44,16 +44,40 @@ static void modificiationCopuse(int courser, int right_x, int right_y, int *dest
}
}
-static void addShot(tux_t *tux,int x, int y, int px, int py)
+static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun)
{
- int dest_x, dest_y;
- int dest_px, dest_py;
+ int dest_x = 0, dest_y = 0;
+ int dest_px = 0, dest_py = 0;
arena_t *arena;
shot_t *shot;
- int gun;
arena = getWorldArena();
+ modificiationCopuse(tux->position, px, py, &dest_px, &dest_py);
+ modificiationCopuse(tux->position, x, y, &dest_x, &dest_y);
+
+ switch( tux->position )
+ {
+ case TUX_UP :
+ dest_y -= TUX_WIDTH;
+ break;
+ case TUX_RIGHT :
+ break;
+ case TUX_LEFT :
+ dest_x -= TUX_WIDTH;
+ break;
+ case TUX_DOWN :
+ break;
+ }
+
+ shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux);
+ addList( arena->listShot, shot );
+}
+
+static void addShot(tux_t *tux,int x, int y, int px, int py)
+{
+ int gun;
+
if( tux->gun == GUN_LASSER )
{
gun = GUN_LASSER;
@@ -80,22 +104,14 @@ static void addShot(tux_t *tux,int x, int y, int px, int py)
case 3 : tux->position = TUX_DOWN; break;
}
- modificiationCopuse(tux->position, x, y, &dest_x, &dest_y);
- modificiationCopuse(tux->position, px, py, &dest_px, &dest_py);
-
- shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux);
- addList( arena->listShot, shot );
+ addShotTrivial(tux, x, y, px, py, gun);
}
tux->position = zal;
}
else
{
- modificiationCopuse(tux->position, x, y, &dest_x, &dest_y);
- modificiationCopuse(tux->position, px, py, &dest_px, &dest_py);
-
- shot = newShot(tux->x + dest_x, tux->y + dest_y, dest_px, dest_py, gun, tux);
- addList( arena->listShot, shot );
+ addShotTrivial(tux, x, y, px, py, gun);
}
}
@@ -162,6 +178,7 @@ static void timer_addLaserTimer(void *p)
if( tux == NULL )return;
+
gun = tux->gun;
tux->gun = GUN_LASSER;
addShot(tux, 0, 0, +25, 0);
diff --git a/src/homeDirector.c b/src/homeDirector.c
new file mode 100755
index 0000000..e90caae
--- /dev/null
+++ b/src/homeDirector.c
@@ -0,0 +1,42 @@
+
+#include "main.h"
+#include "homeDirector.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+static char homeDirector[STR_PATH_SIZE];
+
+void createHomeDirector()
+{
+ char *envHome;
+
+ envHome = getenv("HOME");
+
+ if( envHome == NULL )
+ {
+ fprintf(stderr, "Environment HOME not found !\n");
+ exit(0);
+ }
+
+ sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME);
+
+ if ( access(homeDirector, F_OK) != 0 )
+ {
+ printf("Create home director %s\n", homeDirector);
+
+ if( mkdir(homeDirector, 0755) != 0 )
+ {
+ fprintf(stderr, "Can't create home directory!\n");
+ exit(0);
+ }
+ }
+}
+
+char *getHomeDirector()
+{
+ return homeDirector;
+}
diff --git a/src/main.c b/src/main.c
index 22c691c..780c4b6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,6 +15,7 @@
#include "screen_gameType.h"
#include "screen_choiceArena.h"
#include "screen_credits.h"
+#include "homeDirector.h"
#include "wall.h"
#include "shot.h"
#include "panel.h"
@@ -30,6 +31,8 @@ static char **my_argv;
static void init()
{
+ createHomeDirector();
+
initSDL();
initLayer();
initFont("DejaVuSans.ttf", 16);
diff --git a/src/screen_choiceArena.c b/src/screen_choiceArena.c
index 0b36ca5..50cd9c2 100644
--- a/src/screen_choiceArena.c
+++ b/src/screen_choiceArena.c
@@ -136,7 +136,7 @@ void initScreenChoiceArena()
image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE);
x = 100 + 200 * ( i - 3 * ( i/3 ) );
- y = 150 + 200*(i/3);
+ y = 150 + 200 * ( i/3 );
widget_buttonimage = newWidgetButtonimage(image,
x, y, eventWidgetButtonImage);
diff --git a/src/screen_setting.c b/src/screen_setting.c
index 6d8248d..9c4675c 100644
--- a/src/screen_setting.c
+++ b/src/screen_setting.c
@@ -10,8 +10,11 @@
#include "sound.h"
#include "screen_mainMenu.h"
#include "list.h"
+#include "homeDirector.h"
#include "screen_setting.h"
#include "tux.h"
+#include "textFile.h"
+#include "configFile.h"
#include "widget_label.h"
#include "widget_button.h"
@@ -51,6 +54,8 @@ static widget_textfield_t *textfield_count_cound;
static widget_textfield_t *textfield_name_player1;
static widget_textfield_t *textfield_name_player2;
+static textFile_t *configFile;
+
void startScreenSetting()
{
playMusic("menu", MUSIC_GROUP_BASE);
@@ -154,6 +159,92 @@ static void eventWidget(void *p)
}
}
+static void initSettingFile()
+{
+ char path[STR_PATH_SIZE];
+ char val[STR_SIZE];
+
+ sprintf(path, "%s/tuxanci-ng.conf", getHomeDirector());
+
+ configFile = loadTextFile(path);
+
+ if( configFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ configFile = newTextFile(path);
+ }
+
+ if( configFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return;
+ }
+
+ loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15");
+ strcpy(textfield_count_cound->text, val);
+ loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, "name1");
+ strcpy(textfield_name_player1->text, val);
+ loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, "name2");
+ strcpy(textfield_name_player2->text, val);
+
+ loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, "YES");
+ check[GUN_DUAL_SIMPLE]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES");
+ check[GUN_TOMMY]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES");
+ check[GUN_LASSER]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES");
+ check[GUN_MINE]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES");
+ check[GUN_BOMBBALL]->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES");
+ check[BONUS_SPEED]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES");
+ check[BONUS_SHOT]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, "YES");
+ check[BONUS_TELEPORT]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES");
+ check[BONUS_GHOST]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES");
+ check[BONUS_4X]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES");
+ check[BONUS_HIDDEN]->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES");
+ check_music->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES");
+ check_sound->status = isYesOrNO(val);
+}
+
+static void saveAndDestroyConfigFile()
+{
+ setValueInConfigFile(configFile, "COUNT_ROUND", textfield_count_cound->text );
+ setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", textfield_name_player1->text );
+ setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", textfield_name_player2->text );
+
+ setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(check[GUN_DUAL_SIMPLE]->status) );
+ setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(check[GUN_TOMMY]->status) );
+ setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(check[GUN_LASSER]->status) );
+ setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(check[GUN_MINE]->status) );
+ setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(check[GUN_BOMBBALL]->status) );
+ setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(check[BONUS_SPEED]->status) );
+ setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(check[BONUS_SHOT]->status) );
+ setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(check[BONUS_TELEPORT]->status) );
+ setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(check[BONUS_GHOST]->status) );
+ setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(check[BONUS_4X]->status) );
+ setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(check[BONUS_HIDDEN]->status) );
+
+ setValueInConfigFile(configFile, "MUSIC", getYesOrNo(check_music->status) );
+ setValueInConfigFile(configFile, "SOUND", getYesOrNo(check_sound->status) );
+
+ saveTextFile(configFile);
+ destroyTextFile(configFile);
+}
+
void initScreenSetting()
{
SDL_Surface *image;
@@ -237,6 +328,11 @@ void initScreenSetting()
registerScreen( newScreen("setting", startScreenSetting, eventScreenSetting,
drawScreenSetting, stopScreenSetting) );
+
+ initSettingFile();
+
+ eventWidget(check_music);
+ eventWidget(check_sound);
}
void getSettingNameRight(char *s)
@@ -286,6 +382,8 @@ void quitScreenSetting()
{
int i;
+ saveAndDestroyConfigFile();
+
destroyWidgetImage(image_backgorund);
destroyWidgetLabel(label_count_round);
diff --git a/src/shot.c b/src/shot.c
index 48fd223..bccc252 100644
--- a/src/shot.c
+++ b/src/shot.c
@@ -223,7 +223,7 @@ static void transformShot(shot_t *shot, int position)
void moveShot(shot_t *shot, int position, int src_x, int src_y,
int dist_x, int dist_y, int dist_w, int dist_h)
{
- int offset;
+ int offset = 0;
switch( shot->position )
{