diff options
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | acinclude.m4 | 129 | ||||
-rw-r--r-- | chlstate.cpp | 50 | ||||
-rw-r--r-- | chlstate.h | 16 | ||||
-rw-r--r-- | configure.ac | 42 | ||||
-rw-r--r-- | gamestate.cpp | 317 | ||||
-rw-r--r-- | gamestate.h | 59 | ||||
-rw-r--r-- | highscore.cpp | 2 | ||||
-rw-r--r-- | hsglobal.cpp | 63 | ||||
-rw-r--r-- | hsglobal.h | 18 | ||||
-rw-r--r-- | hslist.cpp | 15 | ||||
-rw-r--r-- | hslist.h | 4 | ||||
-rw-r--r-- | hslocal.cpp | 82 | ||||
-rw-r--r-- | hslocal.h | 18 | ||||
-rw-r--r-- | hsnew.cpp | 220 | ||||
-rw-r--r-- | hsnew.h | 35 | ||||
-rw-r--r-- | hssubmit.cpp | 226 | ||||
-rw-r--r-- | hssubmit.h | 34 | ||||
-rw-r--r-- | htpstate.cpp | 57 | ||||
-rw-r--r-- | htpstate.h | 18 | ||||
-rw-r--r-- | icon.ico | bin | 6766 -> 0 bytes | |||
-rw-r--r-- | includes.h | 23 | ||||
-rw-r--r-- | mazeoflife.cpp | 141 | ||||
-rw-r--r-- | mazeoflife.h | 8 | ||||
-rw-r--r-- | state.h | 8 | ||||
-rw-r--r-- | titlestate.cpp | 84 | ||||
-rw-r--r-- | titlestate.h | 14 | ||||
-rw-r--r-- | util.cpp | 69 | ||||
-rw-r--r-- | util.h | 14 | ||||
-rw-r--r-- | winres.rc | 1 |
31 files changed, 270 insertions, 1500 deletions
diff --git a/.hgignore b/.hgignore index 85018a3..45a2263 100644 --- a/.hgignore +++ b/.hgignore | |||
@@ -11,3 +11,4 @@ missing | |||
11 | install-sh | 11 | install-sh |
12 | depcomp | 12 | depcomp |
13 | mazeoflife | 13 | mazeoflife |
14 | Makefile | ||
diff --git a/Makefile.am b/Makefile.am index f1b00a1..803036c 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -2,6 +2,6 @@ AUTOMAKE_OPTIONS = subdir-objects | |||
2 | ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} | 2 | ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} |
3 | 3 | ||
4 | bin_PROGRAMS = mazeoflife | 4 | bin_PROGRAMS = mazeoflife |
5 | mazeoflife_SOURCES = chlstate.cpp gamestate.cpp highscore.cpp hsglobal.cpp hslist.cpp hslocal.cpp hsnew.cpp hssubmit.cpp htpstate.cpp mazeoflife.cpp titlestate.cpp | 5 | mazeoflife_SOURCES = highscore.cpp hslist.cpp mazeoflife.cpp util.cpp titlestate.cpp |
6 | AM_CXXFLAGS = $(SDLTTF_CXXFLAGS) $(SDLNET_CXXFLAGS) | 6 | AM_CXXFLAGS = $(SDLTTF_CXXFLAGS) $(SDLNET_CXXFLAGS) |
7 | mazeoflife_LDADD = $(SDLTTF_LIBS) $(SDLNET_LIBS) | 7 | mazeoflife_LDADD = $(SDLTTF_LIBS) $(SDLNET_LIBS) |
diff --git a/acinclude.m4 b/acinclude.m4 index 0d44c45..a03b2d2 100644 --- a/acinclude.m4 +++ b/acinclude.m4 | |||
@@ -7,12 +7,12 @@ | |||
7 | 7 | ||
8 | # serial 1 | 8 | # serial 1 |
9 | 9 | ||
10 | dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) | 10 | dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) |
11 | dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS | 11 | dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS |
12 | dnl | 12 | dnl |
13 | AC_DEFUN([AM_PATH_SDL], | 13 | AC_DEFUN([AM_PATH_SDL2], |
14 | [dnl | 14 | [dnl |
15 | dnl Get the cflags and libraries from the sdl-config script | 15 | dnl Get the cflags and libraries from the sdl2-config script |
16 | dnl | 16 | dnl |
17 | AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], | 17 | AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], |
18 | sdl_prefix="$withval", sdl_prefix="") | 18 | sdl_prefix="$withval", sdl_prefix="") |
@@ -21,50 +21,63 @@ AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL | |||
21 | AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], | 21 | AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], |
22 | , enable_sdltest=yes) | 22 | , enable_sdltest=yes) |
23 | 23 | ||
24 | if test x$sdl_exec_prefix != x ; then | 24 | min_sdl_version=ifelse([$1], ,2.0.0,$1) |
25 | sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" | 25 | |
26 | if test x${SDL_CONFIG+set} != xset ; then | 26 | if test "x$sdl_prefix$sdl_exec_prefix" = x ; then |
27 | SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config | 27 | PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version], |
28 | [sdl_pc=yes], | ||
29 | [sdl_pc=no]) | ||
30 | else | ||
31 | sdl_pc=no | ||
32 | if test x$sdl_exec_prefix != x ; then | ||
33 | sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" | ||
34 | if test x${SDL2_CONFIG+set} != xset ; then | ||
35 | SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config | ||
36 | fi | ||
28 | fi | 37 | fi |
29 | fi | 38 | if test x$sdl_prefix != x ; then |
30 | if test x$sdl_prefix != x ; then | 39 | sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" |
31 | sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" | 40 | if test x${SDL2_CONFIG+set} != xset ; then |
32 | if test x${SDL_CONFIG+set} != xset ; then | 41 | SDL2_CONFIG=$sdl_prefix/bin/sdl2-config |
33 | SDL_CONFIG=$sdl_prefix/bin/sdl-config | 42 | fi |
34 | fi | 43 | fi |
35 | fi | 44 | fi |
36 | 45 | ||
37 | as_save_PATH="$PATH" | 46 | if test "x$sdl_pc" = xyes ; then |
38 | if test "x$prefix" != xNONE; then | 47 | no_sdl="" |
39 | PATH="$prefix/bin:$prefix/usr/bin:$PATH" | 48 | SDL2_CONFIG="pkg-config sdl2" |
40 | fi | ||
41 | AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH]) | ||
42 | PATH="$as_save_PATH" | ||
43 | min_sdl_version=ifelse([$1], ,0.11.0,$1) | ||
44 | AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) | ||
45 | no_sdl="" | ||
46 | if test "$SDL_CONFIG" = "no" ; then | ||
47 | no_sdl=yes | ||
48 | else | 49 | else |
49 | SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags` | 50 | as_save_PATH="$PATH" |
50 | SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs` | 51 | if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then |
52 | PATH="$prefix/bin:$prefix/usr/bin:$PATH" | ||
53 | fi | ||
54 | AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH]) | ||
55 | PATH="$as_save_PATH" | ||
56 | AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) | ||
57 | no_sdl="" | ||
51 | 58 | ||
52 | sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \ | 59 | if test "$SDL2_CONFIG" = "no" ; then |
53 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` | 60 | no_sdl=yes |
54 | sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \ | 61 | else |
55 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` | 62 | SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags` |
56 | sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ | 63 | SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs` |
57 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` | 64 | |
58 | if test "x$enable_sdltest" = "xyes" ; then | 65 | sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \ |
59 | ac_save_CFLAGS="$CFLAGS" | 66 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` |
60 | ac_save_CXXFLAGS="$CXXFLAGS" | 67 | sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \ |
61 | ac_save_LIBS="$LIBS" | 68 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` |
62 | CFLAGS="$CFLAGS $SDL_CFLAGS" | 69 | sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \ |
63 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" | 70 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` |
64 | LIBS="$LIBS $SDL_LIBS" | 71 | if test "x$enable_sdltest" = "xyes" ; then |
72 | ac_save_CFLAGS="$CFLAGS" | ||
73 | ac_save_CXXFLAGS="$CXXFLAGS" | ||
74 | ac_save_LIBS="$LIBS" | ||
75 | CFLAGS="$CFLAGS $SDL_CFLAGS" | ||
76 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" | ||
77 | LIBS="$LIBS $SDL_LIBS" | ||
65 | dnl | 78 | dnl |
66 | dnl Now check if the installed SDL is sufficiently new. (Also sanity | 79 | dnl Now check if the installed SDL is sufficiently new. (Also sanity |
67 | dnl checks the results of sdl-config to some extent | 80 | dnl checks the results of sdl2-config to some extent |
68 | dnl | 81 | dnl |
69 | rm -f conf.sdltest | 82 | rm -f conf.sdltest |
70 | AC_TRY_RUN([ | 83 | AC_TRY_RUN([ |
@@ -114,32 +127,36 @@ int main (int argc, char *argv[]) | |||
114 | } | 127 | } |
115 | else | 128 | else |
116 | { | 129 | { |
117 | printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); | 130 | printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); |
118 | printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); | 131 | printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); |
119 | printf("*** best to upgrade to the required version.\n"); | 132 | printf("*** best to upgrade to the required version.\n"); |
120 | printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); | 133 | printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n"); |
121 | printf("*** to point to the correct copy of sdl-config, and remove the file\n"); | 134 | printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); |
122 | printf("*** config.cache before re-running configure\n"); | 135 | printf("*** config.cache before re-running configure\n"); |
123 | return 1; | 136 | return 1; |
124 | } | 137 | } |
125 | } | 138 | } |
126 | 139 | ||
127 | ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) | 140 | ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) |
128 | CFLAGS="$ac_save_CFLAGS" | 141 | CFLAGS="$ac_save_CFLAGS" |
129 | CXXFLAGS="$ac_save_CXXFLAGS" | 142 | CXXFLAGS="$ac_save_CXXFLAGS" |
130 | LIBS="$ac_save_LIBS" | 143 | LIBS="$ac_save_LIBS" |
131 | fi | 144 | fi |
145 | fi | ||
146 | if test "x$no_sdl" = x ; then | ||
147 | AC_MSG_RESULT(yes) | ||
148 | else | ||
149 | AC_MSG_RESULT(no) | ||
150 | fi | ||
132 | fi | 151 | fi |
133 | if test "x$no_sdl" = x ; then | 152 | if test "x$no_sdl" = x ; then |
134 | AC_MSG_RESULT(yes) | 153 | ifelse([$2], , :, [$2]) |
135 | ifelse([$2], , :, [$2]) | ||
136 | else | 154 | else |
137 | AC_MSG_RESULT(no) | 155 | if test "$SDL2_CONFIG" = "no" ; then |
138 | if test "$SDL_CONFIG" = "no" ; then | 156 | echo "*** The sdl2-config script installed by SDL could not be found" |
139 | echo "*** The sdl-config script installed by SDL could not be found" | ||
140 | echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" | 157 | echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" |
141 | echo "*** your path, or set the SDL_CONFIG environment variable to the" | 158 | echo "*** your path, or set the SDL2_CONFIG environment variable to the" |
142 | echo "*** full path to sdl-config." | 159 | echo "*** full path to sdl2-config." |
143 | else | 160 | else |
144 | if test -f conf.sdltest ; then | 161 | if test -f conf.sdltest ; then |
145 | : | 162 | : |
@@ -169,7 +186,7 @@ int main(int argc, char *argv[]) | |||
169 | [ echo "*** The test program failed to compile or link. See the file config.log for the" | 186 | [ echo "*** The test program failed to compile or link. See the file config.log for the" |
170 | echo "*** exact error that occured. This usually means SDL was incorrectly installed" | 187 | echo "*** exact error that occured. This usually means SDL was incorrectly installed" |
171 | echo "*** or that you have moved SDL since it was installed. In the latter case, you" | 188 | echo "*** or that you have moved SDL since it was installed. In the latter case, you" |
172 | echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) | 189 | echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ]) |
173 | CFLAGS="$ac_save_CFLAGS" | 190 | CFLAGS="$ac_save_CFLAGS" |
174 | CXXFLAGS="$ac_save_CXXFLAGS" | 191 | CXXFLAGS="$ac_save_CXXFLAGS" |
175 | LIBS="$ac_save_LIBS" | 192 | LIBS="$ac_save_LIBS" |
@@ -182,4 +199,4 @@ int main(int argc, char *argv[]) | |||
182 | AC_SUBST(SDL_CFLAGS) | 199 | AC_SUBST(SDL_CFLAGS) |
183 | AC_SUBST(SDL_LIBS) | 200 | AC_SUBST(SDL_LIBS) |
184 | rm -f conf.sdltest | 201 | rm -f conf.sdltest |
185 | ]) \ No newline at end of file | 202 | ]) |
diff --git a/chlstate.cpp b/chlstate.cpp deleted file mode 100644 index 5c9f488..0000000 --- a/chlstate.cpp +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | ChooseHighscoreListState::ChooseHighscoreListState() | ||
4 | { | ||
5 | background = SDL_LoadBMP("resources/chl.bmp"); | ||
6 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
7 | |||
8 | selection = 0; | ||
9 | } | ||
10 | |||
11 | void ChooseHighscoreListState::input(SDL_keysym key) | ||
12 | { | ||
13 | if ((key.sym == SDLK_UP) && (selection != 0)) | ||
14 | { | ||
15 | selection--; | ||
16 | } else if ((key.sym == SDLK_DOWN) && (selection != 2)) | ||
17 | { | ||
18 | selection++; | ||
19 | } else if (key.sym == SDLK_RETURN) | ||
20 | { | ||
21 | switch (selection) | ||
22 | { | ||
23 | case 0: | ||
24 | changeState(new LocalHighscoreListState(false)); | ||
25 | |||
26 | break; | ||
27 | case 1: | ||
28 | changeState(new GlobalHighscoreListState()); | ||
29 | |||
30 | break; | ||
31 | case 2: | ||
32 | changeState(new TitleState()); | ||
33 | |||
34 | break; | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void ChooseHighscoreListState::render(SDL_Surface* screen) | ||
40 | { | ||
41 | SDL_BlitSurface(background, NULL, screen, NULL); | ||
42 | |||
43 | SDL_Rect pSpace; | ||
44 | pSpace.x = 127; | ||
45 | pSpace.y = (selection==0?306:(selection==1?336:396)); | ||
46 | pSpace.w = pointer->w; | ||
47 | pSpace.h = pointer->h; | ||
48 | |||
49 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
50 | } | ||
diff --git a/chlstate.h b/chlstate.h deleted file mode 100644 index 15f1d05..0000000 --- a/chlstate.h +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #ifndef CHLSTATE_H | ||
2 | #define CHLSTATE_H | ||
3 | |||
4 | class ChooseHighscoreListState : public State { | ||
5 | public: | ||
6 | ChooseHighscoreListState(); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | SDL_Surface* background; | ||
12 | SDL_Surface* pointer; | ||
13 | int selection; | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/configure.ac b/configure.ac index f311aa6..4206e6b 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,44 +1,44 @@ | |||
1 | AC_INIT(mazeoflife, version-2.0) | 1 | AC_INIT(mazeoflife, version-3.0) |
2 | AC_PREREQ([2.59]) | 2 | AC_PREREQ([2.59]) |
3 | AM_INIT_AUTOMAKE([1.10 no-define foreign]) | 3 | AM_INIT_AUTOMAKE([1.10 no-define foreign]) |
4 | AC_PROG_CXX | 4 | AC_PROG_CXX |
5 | AC_CONFIG_FILES([Makefile]) | 5 | AC_CONFIG_FILES([Makefile]) |
6 | 6 | ||
7 | dnl Check for SDL | 7 | dnl Check for SDL |
8 | SDL_VERSION=1.2.0 | 8 | SDL_VERSION=2.0.0 |
9 | AM_PATH_SDL($SDL_VERSION, | 9 | AM_PATH_SDL2($SDL_VERSION, |
10 | :, | 10 | :, |
11 | AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!]) | 11 | AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!]) |
12 | ) | 12 | ) |
13 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" | 13 | CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" |
14 | LIBS="$LIBS $SDL_LIBS" | 14 | LIBS="$LIBS $SDL_LIBS" |
15 | 15 | ||
16 | dnl Check for SDL_ttf | 16 | dnl Check for SDL2_ttf |
17 | AC_ARG_WITH([sdl-ttf-include-path], | 17 | AC_ARG_WITH([sdl-ttf2-include-path], |
18 | [AS_HELP_STRING([--with-sdl-ttf-include-path], | 18 | [AS_HELP_STRING([--with-sdl2-ttf-include-path], |
19 | [location of the SDL_ttf headers, defaults to /usr/include/SDL])], | 19 | [location of the SDL2_ttf headers, defaults to /usr/include/SDL2])], |
20 | [SDLTTF_CXXFLAGS="-I$withval"], | 20 | [SDLTTF_CXXFLAGS="-I$withval"], |
21 | [SDLTTF_CXXFLAGS="-I/usr/include/SDL"]) | 21 | [SDLTTF_CXXFLAGS="-I/usr/include/SDL2"]) |
22 | AC_SUBST([SDLTTF_CXXFLAGS]) | 22 | AC_SUBST([SDLTTF_CXXFLAGS]) |
23 | 23 | ||
24 | AC_ARG_WITH([sdl-ttf-lib-path], | 24 | AC_ARG_WITH([sdl2-ttf-lib-path], |
25 | [AS_HELP_STRING([--with-sdl-ttf-lib-path], [location of the SDL_ttf library])], | 25 | [AS_HELP_STRING([--with-sdl2-ttf-lib-path], [location of the SDL2_ttf library])], |
26 | [SDLTTF_LIBS="-L$withval -lsdl_ttf"], | 26 | [SDLTTF_LIBS="-L$withval -lsdl2_ttf"], |
27 | [SDLTTF_LIBS="-lsdl_ttf"]) | 27 | [SDLTTF_LIBS="-lsdl2_ttf"]) |
28 | AC_SUBST([SDLTTF_LIBS]) | 28 | AC_SUBST([SDLTTF_LIBS]) |
29 | 29 | ||
30 | dnl Check for SDL_net | 30 | dnl Check for SDL2_net |
31 | AC_ARG_WITH([sdl-net-include-path], | 31 | AC_ARG_WITH([sdl2-net-include-path], |
32 | [AS_HELP_STRING([--with-sdl-net-include-path], | 32 | [AS_HELP_STRING([--with-sdl2-net-include-path], |
33 | [location of the SDL_net headers, defaults to /usr/include/SDL])], | 33 | [location of the SDL2_net headers, defaults to /usr/include/SDL2])], |
34 | [SDLNET_CXXFLAGS="-I$withval"], | 34 | [SDLNET_CXXFLAGS="-I$withval"], |
35 | [SDLNET_CXXFLAGS="-I/usr/include/SDL"]) | 35 | [SDLNET_CXXFLAGS="-I/usr/include/SDL2"]) |
36 | AC_SUBST([SDLNET_CXXFLAGS]) | 36 | AC_SUBST([SDLNET_CXXFLAGS]) |
37 | 37 | ||
38 | AC_ARG_WITH([sdl-net-lib-path], | 38 | AC_ARG_WITH([sdl2-net-lib-path], |
39 | [AS_HELP_STRING([--with-sdl-net-lib-path], [location of the SDL_net library])], | 39 | [AS_HELP_STRING([--with-sdl2-net-lib-path], [location of the SDL2_net library])], |
40 | [SDLNET_LIBS="-L$withval -lsdl_net"], | 40 | [SDLNET_LIBS="-L$withval -lsdl2_net"], |
41 | [SDLNET_LIBS="-lsdl_net"]) | 41 | [SDLNET_LIBS="-lsdl2_net"]) |
42 | AC_SUBST([SDLNET_LIBS]) | 42 | AC_SUBST([SDLNET_LIBS]) |
43 | 43 | ||
44 | AC_OUTPUT \ No newline at end of file | 44 | AC_OUTPUT \ No newline at end of file |
diff --git a/gamestate.cpp b/gamestate.cpp deleted file mode 100644 index fcf865f..0000000 --- a/gamestate.cpp +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | GameState::GameState() | ||
4 | { | ||
5 | player_color = getColor(255, 255, 0); | ||
6 | event_color = getColor(0, 0, 255); | ||
7 | |||
8 | newGame = false; | ||
9 | |||
10 | info = new Info(); | ||
11 | info->playerx = 1; | ||
12 | info->playery = 1; | ||
13 | info->level = Level(); | ||
14 | info->doneMaking = false; | ||
15 | board = Board(info); | ||
16 | } | ||
17 | |||
18 | void GameState::input(SDL_keysym key) | ||
19 | { | ||
20 | if (info->doneMaking) | ||
21 | { | ||
22 | switch (key.sym) | ||
23 | { | ||
24 | case SDLK_LEFT: | ||
25 | move(info->playerx-1, info->playery); | ||
26 | |||
27 | break; | ||
28 | case SDLK_RIGHT: | ||
29 | move(info->playerx+1, info->playery); | ||
30 | |||
31 | break; | ||
32 | case SDLK_UP: | ||
33 | move(info->playerx, info->playery-1); | ||
34 | |||
35 | break; | ||
36 | case SDLK_DOWN: | ||
37 | move(info->playerx, info->playery+1); | ||
38 | |||
39 | break; | ||
40 | case SDLK_ESCAPE: | ||
41 | std::ifstream exists(getDataFile()); | ||
42 | if (exists) | ||
43 | { | ||
44 | FILE* hslist = fopen(getDataFile(), "r"); | ||
45 | int scores; | ||
46 | Highscore* h; | ||
47 | |||
48 | fscanf(hslist, "%d%*c", &scores); | ||
49 | |||
50 | if (scores < 10) | ||
51 | { | ||
52 | fclose(hslist); | ||
53 | |||
54 | changeState(new NewHighscoreState(info->level.getLevel())); | ||
55 | } else { | ||
56 | for (int i=0; i<scores; i++) | ||
57 | { | ||
58 | int namelen; | ||
59 | char namelens[4]; | ||
60 | char* name = (char*) calloc(25, sizeof(char)); | ||
61 | int score; | ||
62 | |||
63 | fscanf(hslist, "%d", &namelen); | ||
64 | sprintf(namelens, "%%%dc", namelen); | ||
65 | fscanf(hslist, namelens, name); | ||
66 | fscanf(hslist, "%d%*c", &score); | ||
67 | |||
68 | h = new Highscore(name, score); | ||
69 | } | ||
70 | |||
71 | fclose(hslist); | ||
72 | |||
73 | if (h->getLevel() < info->level.getLevel()) | ||
74 | { | ||
75 | changeState(new NewHighscoreState(info->level.getLevel())); | ||
76 | } else { | ||
77 | changeState(new LocalHighscoreListState(true)); | ||
78 | } | ||
79 | } | ||
80 | } else { | ||
81 | changeState(new NewHighscoreState(info->level.getLevel())); | ||
82 | } | ||
83 | |||
84 | break; | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | void GameState::tick() | ||
90 | { | ||
91 | if (newGame) | ||
92 | { | ||
93 | switch (rand()%4) | ||
94 | { | ||
95 | case 0: info->playerx = 1; info->playery = 1; break; | ||
96 | case 1: info->playerx = 1; info->playery = HEIGHT-2; break; | ||
97 | case 2: info->playerx = WIDTH-2; info->playery = HEIGHT-2; break; | ||
98 | case 3: info->playerx = WIDTH-2; info->playery = 1; break; | ||
99 | } | ||
100 | |||
101 | info->level.incrementLevel(); | ||
102 | info->doneMaking = false; | ||
103 | info->gens = 0; | ||
104 | board = Board(info); | ||
105 | newGame = false; | ||
106 | } | ||
107 | |||
108 | board.tick(); | ||
109 | } | ||
110 | |||
111 | void GameState::move(int x, int y) | ||
112 | { | ||
113 | wrap(&x, &y); | ||
114 | |||
115 | if (board.isObstructed(x,y)) return; | ||
116 | if ((x==15)&&(y==15)) newGame = true; | ||
117 | |||
118 | info->playerx = x; | ||
119 | info->playery = y; | ||
120 | } | ||
121 | |||
122 | void GameState::render(SDL_Surface* screen) | ||
123 | { | ||
124 | // Paint maze | ||
125 | board.render(screen); | ||
126 | |||
127 | // Paint event | ||
128 | SDL_Rect block; | ||
129 | block.x = 15*16; | ||
130 | block.y = 15*16; | ||
131 | block.w = 16; | ||
132 | block.h = 16; | ||
133 | |||
134 | SDL_FillRect(screen, &block, event_color); | ||
135 | |||
136 | if (!info->doneMaking) | ||
137 | { | ||
138 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
139 | char levelnum[8]; | ||
140 | sprintf(levelnum, "%d", info->level.getLevel()); | ||
141 | SDL_Surface* title = TTF_RenderText_Solid(loadFont(100), levelnum, fontColor); | ||
142 | SDL_Rect tSpace = {240-(title->w/2), 240-(title->h/2), title->w, title->h}; | ||
143 | SDL_FillRect(screen, NULL, info->level.getDeadColor()); | ||
144 | SDL_BlitSurface(title, NULL, screen, &tSpace); | ||
145 | } | ||
146 | |||
147 | // Paint player | ||
148 | block.x = info->playerx*16; | ||
149 | block.y = info->playery*16; | ||
150 | |||
151 | SDL_FillRect(screen, &block, player_color); | ||
152 | } | ||
153 | |||
154 | GameState::Level::Level() | ||
155 | { | ||
156 | level = 0; | ||
157 | |||
158 | alive[0] = getColor(0, 0, 0); // Black | ||
159 | alive[1] = getColor(255, 0, 0); // Red | ||
160 | alive[2] = getColor(0, 255, 0); // Green | ||
161 | alive[3] = getColor(85, 85, 85); // Dark Gray | ||
162 | alive[4] = getColor(255, 0, 255); // Magenta | ||
163 | |||
164 | dead[0] = getColor(255, 255, 255); // White | ||
165 | dead[1] = getColor(255, 192, 203); // Pink | ||
166 | dead[2] = getColor(0, 255, 255); // Cyan | ||
167 | dead[3] = getColor(170, 170, 170); // Light Gray | ||
168 | dead[4] = getColor(255, 128, 0); // Orange | ||
169 | } | ||
170 | |||
171 | int GameState::Level::getLevel() | ||
172 | { | ||
173 | return level; | ||
174 | } | ||
175 | |||
176 | bool GameState::Level::checkSquare(int x, int y) | ||
177 | { | ||
178 | switch (level/10+1) | ||
179 | { | ||
180 | case 1: | ||
181 | return ((x>13)&&(x<17)&&(y>13)&&(y<17)); | ||
182 | case 2: | ||
183 | case 3: | ||
184 | return ((x>12)&&(x<18)&&(y>12)&&(y<18)); | ||
185 | case 4: | ||
186 | case 5: | ||
187 | return ((x>11)&&(x<19)&&(y>11)&&(y<19)); | ||
188 | default: | ||
189 | return true; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | Uint32 GameState::Level::getAliveColor() | ||
194 | { | ||
195 | return alive[(level/10)%5]; | ||
196 | } | ||
197 | |||
198 | Uint32 GameState::Level::getDeadColor() | ||
199 | { | ||
200 | return dead[(level/10)%5]; | ||
201 | } | ||
202 | |||
203 | void GameState::Level::incrementLevel() | ||
204 | { | ||
205 | level++; | ||
206 | } | ||
207 | |||
208 | GameState::Board::Board() | ||
209 | { | ||
210 | GameState::Board::Board(new GameState::Info()); | ||
211 | } | ||
212 | |||
213 | GameState::Board::Board(GameState::Info* info) | ||
214 | { | ||
215 | this->info = info; | ||
216 | |||
217 | int x,y; | ||
218 | for (y=0;y<HEIGHT;y++) | ||
219 | { | ||
220 | for (x=0;x<WIDTH;x++) | ||
221 | { | ||
222 | if (info->level.checkSquare(x, y)) | ||
223 | { | ||
224 | blocks[x][y] = rand() % 2; | ||
225 | } else { | ||
226 | blocks[x][y] = false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | blocks[15][15] = false; | ||
232 | } | ||
233 | |||
234 | bool GameState::Board::isObstructed(int x, int y) | ||
235 | { | ||
236 | return blocks[x][y]; | ||
237 | } | ||
238 | |||
239 | void GameState::Board::render(SDL_Surface* screen) | ||
240 | { | ||
241 | SDL_Rect block; | ||
242 | block.w = 16; | ||
243 | block.h = 16; | ||
244 | |||
245 | int x,y; | ||
246 | |||
247 | for (y=0;y<HEIGHT;y++) | ||
248 | { | ||
249 | for (x=0;x<WIDTH;x++) | ||
250 | { | ||
251 | block.x = x*16; | ||
252 | block.y = y*16; | ||
253 | |||
254 | SDL_FillRect(screen, &block, (blocks[x][y] ? info->level.getAliveColor() : info->level.getDeadColor())); | ||
255 | } | ||
256 | } | ||
257 | } | ||
258 | |||
259 | void GameState::Board::tick() | ||
260 | { | ||
261 | bool temp[WIDTH][HEIGHT]; | ||
262 | int x,y; | ||
263 | for (x=0;x<WIDTH;x++) | ||
264 | { | ||
265 | for (y=0;y<HEIGHT;y++) | ||
266 | { | ||
267 | temp[x][y] = blocks[x][y]; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | for (x=0;x<WIDTH;x++) | ||
272 | { | ||
273 | for (y=0;y<HEIGHT;y++) | ||
274 | { | ||
275 | if ((x==15)&&(y==15)) | ||
276 | { | ||
277 | continue; | ||
278 | } | ||
279 | |||
280 | int neighbors = 0; | ||
281 | |||
282 | incrementIfNeighbor(x-1,y-1,temp,&neighbors); | ||
283 | incrementIfNeighbor(x-1,y,temp,&neighbors); | ||
284 | incrementIfNeighbor(x-1,y+1,temp,&neighbors); | ||
285 | incrementIfNeighbor(x,y-1,temp,&neighbors); | ||
286 | incrementIfNeighbor(x,y+1,temp,&neighbors); | ||
287 | incrementIfNeighbor(x+1,y-1,temp,&neighbors); | ||
288 | incrementIfNeighbor(x+1,y,temp,&neighbors); | ||
289 | incrementIfNeighbor(x+1,y+1,temp,&neighbors); | ||
290 | |||
291 | if (temp[x][y]) | ||
292 | { | ||
293 | blocks[x][y] = ((neighbors >= 1) && (neighbors <= 4)); | ||
294 | } else { | ||
295 | blocks[x][y] = (neighbors == 3); | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | |||
300 | if (!info->doneMaking && ++info->gens > 50) info->doneMaking = true; | ||
301 | } | ||
302 | |||
303 | void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) | ||
304 | { | ||
305 | int nx = x; | ||
306 | int ny = y; | ||
307 | |||
308 | wrap(&x, &y); | ||
309 | |||
310 | if (!((nx!=x)&&(ny!=y))) | ||
311 | { | ||
312 | if ((temp[x][y])||((info->playerx==x)&&(info->playery==y))||((x==15)&&(y==15))) | ||
313 | { | ||
314 | ++*tick; | ||
315 | } | ||
316 | } | ||
317 | } | ||
diff --git a/gamestate.h b/gamestate.h deleted file mode 100644 index 28b85c0..0000000 --- a/gamestate.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | #ifndef GAMESTATE_H | ||
2 | #define GAMESTATE_H | ||
3 | |||
4 | class GameState : public State { | ||
5 | public: | ||
6 | GameState(); | ||
7 | void input(SDL_keysym key); | ||
8 | void tick(); | ||
9 | void render(SDL_Surface* screen); | ||
10 | |||
11 | class Level | ||
12 | { | ||
13 | private: | ||
14 | int level; | ||
15 | Uint32 alive[5]; | ||
16 | Uint32 dead[5]; | ||
17 | |||
18 | public: | ||
19 | Level(); | ||
20 | int getLevel(); | ||
21 | int getLevelGroup(); | ||
22 | bool checkSquare(int x, int y); | ||
23 | Uint32 getAliveColor(); | ||
24 | Uint32 getDeadColor(); | ||
25 | void incrementLevel(); | ||
26 | }; | ||
27 | |||
28 | struct Info { | ||
29 | int playerx, playery; | ||
30 | Level level; | ||
31 | bool doneMaking; | ||
32 | int gens; | ||
33 | }; | ||
34 | |||
35 | class Board | ||
36 | { | ||
37 | private: | ||
38 | bool blocks[WIDTH][HEIGHT]; | ||
39 | void incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick); | ||
40 | GameState::Info* info; | ||
41 | |||
42 | public: | ||
43 | Board(); | ||
44 | Board(GameState::Info* info); | ||
45 | bool isObstructed(int x, int y); | ||
46 | void render(SDL_Surface* screen); | ||
47 | void tick(); | ||
48 | }; | ||
49 | |||
50 | private: | ||
51 | Uint32 player_color; | ||
52 | Uint32 event_color; | ||
53 | bool newGame; | ||
54 | Info* info; | ||
55 | Board board; | ||
56 | void move(int x, int y); | ||
57 | }; | ||
58 | |||
59 | #endif | ||
diff --git a/highscore.cpp b/highscore.cpp index 6811fa8..7133e1a 100644 --- a/highscore.cpp +++ b/highscore.cpp | |||
@@ -1,4 +1,4 @@ | |||
1 | #include "includes.h" | 1 | #include "highscore.h" |
2 | 2 | ||
3 | Highscore::Highscore(char* name, int level) | 3 | Highscore::Highscore(char* name, int level) |
4 | { | 4 | { |
diff --git a/hsglobal.cpp b/hsglobal.cpp deleted file mode 100644 index 3076403..0000000 --- a/hsglobal.cpp +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | GlobalHighscoreListState::GlobalHighscoreListState() | ||
4 | { | ||
5 | options = SDL_LoadBMP("resources/hlo_rtm.bmp"); | ||
6 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
7 | |||
8 | list = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); | ||
9 | Uint32 bgColor = SDL_MapRGB(list->format, 255, 255, 255); | ||
10 | SDL_FillRect(list, NULL, bgColor); | ||
11 | SDL_SetColorKey(list, SDL_SRCCOLORKEY, bgColor); | ||
12 | TTF_Font* dataFont = loadFont(25); | ||
13 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
14 | SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Fetching highscores....", fontColor); | ||
15 | SDL_Rect aSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; | ||
16 | SDL_BlitSurface(text, NULL, list, &aSpace); | ||
17 | |||
18 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); | ||
19 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
20 | SDL_BlitSurface(title, NULL, list, &tSpace); | ||
21 | |||
22 | SDL_Rect oSpace = {0, 440, options->w, options->h}; | ||
23 | SDL_BlitSurface(options, NULL, list, &oSpace); | ||
24 | |||
25 | SDL_CreateThread(&LoadHighscoreList, this); | ||
26 | } | ||
27 | |||
28 | int GlobalHighscoreListState::LoadHighscoreList(void* pParam) | ||
29 | { | ||
30 | GlobalHighscoreList* lhl = new GlobalHighscoreList(); | ||
31 | ((GlobalHighscoreListState*)pParam)->list = lhl->render(); | ||
32 | |||
33 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
34 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); | ||
35 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
36 | SDL_BlitSurface(title, NULL, ((GlobalHighscoreListState*)pParam)->list, &tSpace); | ||
37 | |||
38 | SDL_Rect oSpace = {0, 440, ((GlobalHighscoreListState*)pParam)->options->w, ((GlobalHighscoreListState*)pParam)->options->h}; | ||
39 | SDL_BlitSurface(((GlobalHighscoreListState*)pParam)->options, NULL, ((GlobalHighscoreListState*)pParam)->list, &oSpace); | ||
40 | } | ||
41 | |||
42 | void GlobalHighscoreListState::input(SDL_keysym key) | ||
43 | { | ||
44 | if (key.sym == SDLK_RETURN) | ||
45 | { | ||
46 | changeState(new ChooseHighscoreListState()); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | void GlobalHighscoreListState::render(SDL_Surface* screen) | ||
51 | { | ||
52 | SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); | ||
53 | |||
54 | SDL_BlitSurface(list, NULL, screen, NULL); | ||
55 | |||
56 | SDL_Rect pSpace; | ||
57 | pSpace.x = 137; | ||
58 | pSpace.y = 449; | ||
59 | pSpace.w = pointer->w; | ||
60 | pSpace.h = pointer->h; | ||
61 | |||
62 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
63 | } | ||
diff --git a/hsglobal.h b/hsglobal.h deleted file mode 100644 index 5b92b0e..0000000 --- a/hsglobal.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef HSGLOBAL_H | ||
2 | #define HSGLOBAL_H | ||
3 | |||
4 | class GlobalHighscoreListState : public State { | ||
5 | public: | ||
6 | GlobalHighscoreListState(); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | static int LoadHighscoreList(void* pParam); | ||
12 | |||
13 | SDL_Surface* list; | ||
14 | SDL_Surface* options; | ||
15 | SDL_Surface* pointer; | ||
16 | }; | ||
17 | |||
18 | #endif | ||
diff --git a/hslist.cpp b/hslist.cpp index ec99a77..80e0801 100644 --- a/hslist.cpp +++ b/hslist.cpp | |||
@@ -1,11 +1,16 @@ | |||
1 | #include "includes.h" | 1 | #include "hslist.h" |
2 | #include <SDL_ttf.h> | ||
3 | #include <SDL_net.h> | ||
4 | #include <sstream> | ||
5 | #include <fstream> | ||
6 | #include "util.h" | ||
2 | 7 | ||
3 | SDL_Surface* HighscoreList::render() | 8 | SDL_Surface* HighscoreList::render() |
4 | { | 9 | { |
5 | SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); | 10 | SDL_Surface* tmp = SDL_CreateRGBSurface(0, 480, 480, 32, 0,0,0,0); |
6 | Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); | 11 | Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); |
7 | SDL_FillRect(tmp, NULL, bgColor); | 12 | SDL_FillRect(tmp, NULL, bgColor); |
8 | SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, bgColor); | 13 | SDL_SetColorKey(tmp, SDL_TRUE, bgColor); |
9 | TTF_Font* posFont = loadFont(40); | 14 | TTF_Font* posFont = loadFont(40); |
10 | TTF_Font* dataFont = loadFont(25); | 15 | TTF_Font* dataFont = loadFont(25); |
11 | SDL_Color fontColor = {0, 0, 0, 0}; | 16 | SDL_Color fontColor = {0, 0, 0, 0}; |
@@ -181,10 +186,10 @@ SDL_Surface* GlobalHighscoreList::render() | |||
181 | { | 186 | { |
182 | if (fail) | 187 | if (fail) |
183 | { | 188 | { |
184 | SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); | 189 | SDL_Surface* tmp = SDL_CreateRGBSurface(0, 480, 480, 32, 0,0,0,0); |
185 | Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); | 190 | Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); |
186 | SDL_FillRect(tmp, NULL, bgColor); | 191 | SDL_FillRect(tmp, NULL, bgColor); |
187 | SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, bgColor); | 192 | SDL_SetColorKey(tmp, SDL_TRUE, bgColor); |
188 | TTF_Font* dataFont = loadFont(25); | 193 | TTF_Font* dataFont = loadFont(25); |
189 | SDL_Color fontColor = {0, 0, 0, 0}; | 194 | SDL_Color fontColor = {0, 0, 0, 0}; |
190 | SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Error retrieving highscores", fontColor); | 195 | SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Error retrieving highscores", fontColor); |
diff --git a/hslist.h b/hslist.h index bebb85a..80e1c31 100644 --- a/hslist.h +++ b/hslist.h | |||
@@ -1,3 +1,7 @@ | |||
1 | #include <SDL.h> | ||
2 | #include <vector> | ||
3 | #include "highscore.h" | ||
4 | |||
1 | #ifndef HSLIST_H | 5 | #ifndef HSLIST_H |
2 | #define HSLIST_H | 6 | #define HSLIST_H |
3 | 7 | ||
diff --git a/hslocal.cpp b/hslocal.cpp deleted file mode 100644 index eec87e2..0000000 --- a/hslocal.cpp +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | LocalHighscoreListState::LocalHighscoreListState(bool fromGame) | ||
4 | { | ||
5 | this->fromGame = fromGame; | ||
6 | |||
7 | if (fromGame) | ||
8 | { | ||
9 | options = SDL_LoadBMP("resources/hlo_paartm.bmp"); | ||
10 | } else { | ||
11 | options = SDL_LoadBMP("resources/hlo_rtm.bmp"); | ||
12 | } | ||
13 | |||
14 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
15 | |||
16 | LocalHighscoreList* lhl = new LocalHighscoreList(); | ||
17 | list = lhl->render(); | ||
18 | |||
19 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
20 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); | ||
21 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
22 | SDL_BlitSurface(title, NULL, list, &tSpace); | ||
23 | |||
24 | SDL_Rect oSpace = {0, 440, options->w, options->h}; | ||
25 | SDL_BlitSurface(options, NULL, list, &oSpace); | ||
26 | |||
27 | selection = 0; | ||
28 | } | ||
29 | |||
30 | void LocalHighscoreListState::input(SDL_keysym key) | ||
31 | { | ||
32 | if (fromGame) | ||
33 | { | ||
34 | if ((key.sym == SDLK_LEFT) && (selection != 0)) | ||
35 | { | ||
36 | selection--; | ||
37 | } else if ((key.sym == SDLK_RIGHT) && (selection != 1)) | ||
38 | { | ||
39 | selection++; | ||
40 | } else if (key.sym == SDLK_RETURN) | ||
41 | { | ||
42 | switch (selection) | ||
43 | { | ||
44 | case 0: | ||
45 | changeState(new GameState()); | ||
46 | |||
47 | break; | ||
48 | case 1: | ||
49 | changeState(new TitleState()); | ||
50 | |||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | } else { | ||
55 | if (key.sym == SDLK_RETURN) | ||
56 | { | ||
57 | changeState(new ChooseHighscoreListState()); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | void LocalHighscoreListState::render(SDL_Surface* screen) | ||
63 | { | ||
64 | SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); | ||
65 | |||
66 | SDL_BlitSurface(list, NULL, screen, NULL); | ||
67 | |||
68 | SDL_Rect pSpace; | ||
69 | pSpace.w = pointer->w; | ||
70 | pSpace.h = pointer->h; | ||
71 | |||
72 | if (fromGame) | ||
73 | { | ||
74 | pSpace.x = (selection==0?52:225); | ||
75 | pSpace.y = 447; | ||
76 | } else { | ||
77 | pSpace.x = 137; | ||
78 | pSpace.y = 449; | ||
79 | } | ||
80 | |||
81 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
82 | } | ||
diff --git a/hslocal.h b/hslocal.h deleted file mode 100644 index 8708d03..0000000 --- a/hslocal.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef HSLOCAL_H | ||
2 | #define HSLOCAL_H | ||
3 | |||
4 | class LocalHighscoreListState : public State { | ||
5 | public: | ||
6 | LocalHighscoreListState(bool fromGame); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | SDL_Surface* list; | ||
12 | SDL_Surface* options; | ||
13 | SDL_Surface* pointer; | ||
14 | int selection; | ||
15 | bool fromGame; | ||
16 | }; | ||
17 | |||
18 | #endif | ||
diff --git a/hsnew.cpp b/hsnew.cpp deleted file mode 100644 index b4894c2..0000000 --- a/hsnew.cpp +++ /dev/null | |||
@@ -1,220 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | NewHighscoreState::NewHighscoreState(int level) | ||
4 | { | ||
5 | this->level = level; | ||
6 | |||
7 | options = SDL_LoadBMP("resources/hlo_passartm.bmp"); | ||
8 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
9 | |||
10 | lhl = new NewHighscoreList(level); | ||
11 | newpos = lhl->getNewPos(); | ||
12 | list = lhl->render(); | ||
13 | |||
14 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
15 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor); | ||
16 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
17 | SDL_BlitSurface(title, NULL, list, &tSpace); | ||
18 | |||
19 | this->enterName = true; | ||
20 | this->lp = 0; | ||
21 | this->hsname = (char*) calloc(25, sizeof(char)); | ||
22 | |||
23 | SDL_Surface* text = TTF_RenderText_Blended(loadFont(25), "Enter Your Name", fontColor); | ||
24 | SDL_Rect oSpace = {240-(text->w/2), 440, text->w, text->h}; | ||
25 | SDL_BlitSurface(text, NULL, list, &oSpace); | ||
26 | |||
27 | selection = 0; | ||
28 | |||
29 | int posw, posh; | ||
30 | char pos[3]; // 2 max characters in rank plus the colon at the end | ||
31 | sprintf(pos, "%d:", newpos); | ||
32 | char name[26]; // 25 max characters in username plus the space at the beginning | ||
33 | sprintf(name, " %s", hsname); | ||
34 | newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); | ||
35 | TTF_SizeText(loadFont(40), pos, &posw, &posh); | ||
36 | rntSpace.x = posw; | ||
37 | rntSpace.y = newpos*40+((posh/2)-(newName->h/2)); | ||
38 | rntSpace.w = newName->w; | ||
39 | rntSpace.h = newName->h; | ||
40 | |||
41 | SDL_EnableUNICODE(1); | ||
42 | } | ||
43 | |||
44 | void NewHighscoreState::input(SDL_keysym key) | ||
45 | { | ||
46 | if (enterName) | ||
47 | { | ||
48 | if ((key.sym == SDLK_BACKSPACE) && (lp > 0)) | ||
49 | { | ||
50 | hsname[--lp] = 0; | ||
51 | |||
52 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
53 | char name[26]; // 25 max characters in username plus the space at the beginning | ||
54 | sprintf(name, " %s", hsname); | ||
55 | newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); | ||
56 | rntSpace.w = newName->w; | ||
57 | rntSpace.h = newName->h; | ||
58 | } else if ((key.sym == SDLK_RETURN) && (hsname[0] != 0)) | ||
59 | { | ||
60 | SDL_EnableUNICODE(0); | ||
61 | enterName = false; | ||
62 | |||
63 | lhl->addToList(hsname); | ||
64 | LocalHighscoreList* lhl2 = new LocalHighscoreList(); | ||
65 | list = lhl2->render(); | ||
66 | |||
67 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
68 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor); | ||
69 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
70 | SDL_BlitSurface(title, NULL, list, &tSpace); | ||
71 | |||
72 | SDL_Rect oSpace = {0, 440, options->w, options->h}; | ||
73 | SDL_BlitSurface(options, NULL, list, &oSpace); | ||
74 | } else if (((key.unicode & 0xFF80) == 0) && (key.unicode >= 32 && key.unicode < 127) && (lp < 25)) | ||
75 | { | ||
76 | hsname[lp++] = key.unicode & 0x7f; | ||
77 | hsname[lp] = 0; | ||
78 | |||
79 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
80 | char name[26]; // 25 max characters in username plus the space at the beginning | ||
81 | sprintf(name, " %s", hsname); | ||
82 | newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); | ||
83 | rntSpace.w = newName->w; | ||
84 | rntSpace.h = newName->h; | ||
85 | } | ||
86 | } else { | ||
87 | if ((key.sym == SDLK_LEFT) && (selection != 0)) | ||
88 | { | ||
89 | selection--; | ||
90 | } else if ((key.sym == SDLK_RIGHT) && (selection != 2)) | ||
91 | { | ||
92 | selection++; | ||
93 | } else if (key.sym == SDLK_RETURN) | ||
94 | { | ||
95 | switch (selection) | ||
96 | { | ||
97 | case 0: | ||
98 | changeState(new GameState()); | ||
99 | |||
100 | break; | ||
101 | case 1: | ||
102 | changeState(new SubmitHighscoreListState(hsname, level)); | ||
103 | |||
104 | break; | ||
105 | case 2: | ||
106 | changeState(new TitleState()); | ||
107 | |||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | void NewHighscoreState::render(SDL_Surface* screen) | ||
115 | { | ||
116 | SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); | ||
117 | |||
118 | SDL_Rect eSpace = {0, newpos*40, 480, 40}; | ||
119 | SDL_FillRect(screen, &eSpace, SDL_MapRGB(screen->format, 255, 255, 0)); | ||
120 | |||
121 | SDL_BlitSurface(list, NULL, screen, NULL); | ||
122 | |||
123 | if (enterName) | ||
124 | { | ||
125 | SDL_BlitSurface(newName, NULL, screen, &rntSpace); | ||
126 | } else { | ||
127 | SDL_Rect pSpace; | ||
128 | pSpace.x = (selection==0?13:(selection==1?138:284)); | ||
129 | pSpace.y = 448; | ||
130 | pSpace.w = pointer->w; | ||
131 | pSpace.h = pointer->h; | ||
132 | |||
133 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | NewHighscoreState::NewHighscoreList::NewHighscoreList(int level) | ||
138 | { | ||
139 | this->hslist = getLocalHighscores(); | ||
140 | |||
141 | if (this->hslist.empty()) | ||
142 | { | ||
143 | Highscore n = Highscore("", level); | ||
144 | n.setRank(1); | ||
145 | |||
146 | this->hslist.push_back(n); | ||
147 | this->newpos = n.getRank(); | ||
148 | } else { | ||
149 | std::vector<Highscore>::iterator it; | ||
150 | bool found = false; | ||
151 | int lastrank; | ||
152 | int i=0; | ||
153 | |||
154 | for (it=this->hslist.begin(); it<this->hslist.end(); it++) | ||
155 | { | ||
156 | Highscore h = *it; | ||
157 | lastrank = h.getRank(); | ||
158 | |||
159 | if (!found) | ||
160 | { | ||
161 | if (h.getLevel() < level) | ||
162 | { | ||
163 | Highscore n = Highscore("", level); | ||
164 | n.setRank(h.getRank()); | ||
165 | |||
166 | this->hslist.insert(it, n); | ||
167 | this->newpos = n.getRank(); | ||
168 | |||
169 | if (this->hslist.size() > 10) | ||
170 | { | ||
171 | this->hslist.pop_back(); | ||
172 | } | ||
173 | |||
174 | found = true; | ||
175 | } | ||
176 | } else { | ||
177 | //this->hslist[i].setRank(h.getRank()+1); | ||
178 | } | ||
179 | |||
180 | i++; | ||
181 | } | ||
182 | |||
183 | if (!found) | ||
184 | { | ||
185 | Highscore n = Highscore("", level); | ||
186 | n.setRank(lastrank+1); | ||
187 | |||
188 | this->hslist.push_back(n); | ||
189 | this->newpos = n.getRank(); | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | |||
194 | int NewHighscoreState::NewHighscoreList::getNewPos() | ||
195 | { | ||
196 | return newpos; | ||
197 | } | ||
198 | |||
199 | void NewHighscoreState::NewHighscoreList::addToList(char* name) | ||
200 | { | ||
201 | FILE* hsfile = fopen(getDataFile(), "w"); | ||
202 | fprintf(hsfile, "%d ", this->hslist.size()); | ||
203 | |||
204 | std::vector<Highscore>::iterator it; | ||
205 | |||
206 | for (it=this->hslist.begin(); it<this->hslist.end(); it++) | ||
207 | { | ||
208 | Highscore h = *it; | ||
209 | |||
210 | if (h.getName() == "") | ||
211 | { | ||
212 | h = Highscore(name, h.getLevel()); | ||
213 | h.setRank(newpos); | ||
214 | } | ||
215 | |||
216 | fprintf(hsfile, "%d%s%d ", strlen(h.getName()), h.getName(), h.getLevel()); | ||
217 | } | ||
218 | |||
219 | fclose(hsfile); | ||
220 | } | ||
diff --git a/hsnew.h b/hsnew.h deleted file mode 100644 index 123ac53..0000000 --- a/hsnew.h +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | #ifndef HSNEW_H | ||
2 | #define HSNEW_H | ||
3 | |||
4 | class NewHighscoreState : public State { | ||
5 | public: | ||
6 | NewHighscoreState(int level); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | class NewHighscoreList : public HighscoreList { | ||
12 | public: | ||
13 | NewHighscoreList(int level); | ||
14 | int getNewPos(); | ||
15 | void addToList(char* name); | ||
16 | |||
17 | private: | ||
18 | int newpos; | ||
19 | }; | ||
20 | |||
21 | SDL_Surface* list; | ||
22 | SDL_Surface* options; | ||
23 | SDL_Surface* pointer; | ||
24 | int selection; | ||
25 | int level; | ||
26 | int newpos; | ||
27 | int lp; | ||
28 | char* hsname; | ||
29 | bool enterName; | ||
30 | SDL_Rect rntSpace; | ||
31 | SDL_Surface* newName; | ||
32 | NewHighscoreList* lhl; | ||
33 | }; | ||
34 | |||
35 | #endif | ||
diff --git a/hssubmit.cpp b/hssubmit.cpp deleted file mode 100644 index eaacb88..0000000 --- a/hssubmit.cpp +++ /dev/null | |||
@@ -1,226 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | SubmitHighscoreListState::SubmitHighscoreListState(char* hsname, int level) | ||
4 | { | ||
5 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
6 | |||
7 | this->hsname = hsname; | ||
8 | this->level = level; | ||
9 | this->scoreSent = false; | ||
10 | this->selection = 0; | ||
11 | |||
12 | list = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); | ||
13 | Uint32 bgColor = SDL_MapRGB(list->format, 255, 255, 255); | ||
14 | SDL_FillRect(list, NULL, bgColor); | ||
15 | SDL_SetColorKey(list, SDL_SRCCOLORKEY, bgColor); | ||
16 | TTF_Font* dataFont = loadFont(25); | ||
17 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
18 | SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Sending highscore....", fontColor); | ||
19 | SDL_Rect aSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; | ||
20 | SDL_BlitSurface(text, NULL, list, &aSpace); | ||
21 | |||
22 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); | ||
23 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
24 | SDL_BlitSurface(title, NULL, list, &tSpace); | ||
25 | |||
26 | SDL_CreateThread(&LoadHighscoreList, this); | ||
27 | } | ||
28 | |||
29 | int SubmitHighscoreListState::LoadHighscoreList(void* pParam) | ||
30 | { | ||
31 | SubmitHighscoreList* lhl = new SubmitHighscoreList(((SubmitHighscoreListState*)pParam)->hsname, ((SubmitHighscoreListState*)pParam)->level); | ||
32 | ((SubmitHighscoreListState*)pParam)->list = lhl->render(); | ||
33 | |||
34 | SDL_Color fontColor = {0, 0, 0, 0}; | ||
35 | SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); | ||
36 | SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; | ||
37 | SDL_BlitSurface(title, NULL, ((SubmitHighscoreListState*)pParam)->list, &tSpace); | ||
38 | |||
39 | if (lhl->hasFailed()) | ||
40 | { | ||
41 | ((SubmitHighscoreListState*)pParam)->options = SDL_LoadBMP("resources/hlo_passartm.bmp"); | ||
42 | } else { | ||
43 | ((SubmitHighscoreListState*)pParam)->options = SDL_LoadBMP("resources/hlo_paartm.bmp"); | ||
44 | } | ||
45 | |||
46 | SDL_Rect oSpace = {0, 440, ((SubmitHighscoreListState*)pParam)->options->w, ((SubmitHighscoreListState*)pParam)->options->h}; | ||
47 | SDL_BlitSurface(((SubmitHighscoreListState*)pParam)->options, NULL, ((SubmitHighscoreListState*)pParam)->list, &oSpace); | ||
48 | |||
49 | ((SubmitHighscoreListState*)pParam)->fail = lhl->hasFailed(); | ||
50 | ((SubmitHighscoreListState*)pParam)->newpos = lhl->getNewPos(); | ||
51 | ((SubmitHighscoreListState*)pParam)->scoreSent = true; | ||
52 | } | ||
53 | |||
54 | void SubmitHighscoreListState::input(SDL_keysym key) | ||
55 | { | ||
56 | if (scoreSent) | ||
57 | { | ||
58 | if ((key.sym == SDLK_LEFT) && (selection != 0)) | ||
59 | { | ||
60 | selection--; | ||
61 | } else if ((key.sym == SDLK_RIGHT) && (selection != (fail?2:1))) | ||
62 | { | ||
63 | selection++; | ||
64 | } else if (key.sym == SDLK_RETURN) | ||
65 | { | ||
66 | if (fail) | ||
67 | { | ||
68 | switch (selection) | ||
69 | { | ||
70 | case 0: | ||
71 | changeState(new GameState()); | ||
72 | |||
73 | break; | ||
74 | case 1: | ||
75 | changeState(new SubmitHighscoreListState(hsname, level)); | ||
76 | |||
77 | break; | ||
78 | case 2: | ||
79 | changeState(new TitleState()); | ||
80 | |||
81 | break; | ||
82 | } | ||
83 | } else { | ||
84 | switch (selection) | ||
85 | { | ||
86 | case 0: | ||
87 | changeState(new GameState()); | ||
88 | |||
89 | break; | ||
90 | case 1: | ||
91 | changeState(new TitleState()); | ||
92 | |||
93 | break; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | void SubmitHighscoreListState::render(SDL_Surface* screen) | ||
101 | { | ||
102 | SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); | ||
103 | |||
104 | if (scoreSent) | ||
105 | { | ||
106 | SDL_Rect pSpace; | ||
107 | if (fail) | ||
108 | { | ||
109 | pSpace.x = (selection==0?13:(selection==1?138:284)); | ||
110 | pSpace.y = 448; | ||
111 | } else { | ||
112 | pSpace.x = (selection==0?52:225); | ||
113 | pSpace.y = 447; | ||
114 | } | ||
115 | pSpace.w = pointer->w; | ||
116 | pSpace.h = pointer->h; | ||
117 | |||
118 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
119 | |||
120 | SDL_Rect eSpace = {0, newpos*40, 480, 40}; | ||
121 | SDL_FillRect(screen, &eSpace, SDL_MapRGB(screen->format, 255, 255, 0)); | ||
122 | } | ||
123 | |||
124 | SDL_BlitSurface(list, NULL, screen, NULL); | ||
125 | } | ||
126 | |||
127 | SubmitHighscoreListState::SubmitHighscoreList::SubmitHighscoreList(char* hsname, int level) | ||
128 | { | ||
129 | fail = false; | ||
130 | |||
131 | try | ||
132 | { | ||
133 | IPaddress ipaddress; | ||
134 | |||
135 | if (SDLNet_ResolveHost(&ipaddress, "other.fourisland.com", 80) == -1) | ||
136 | { | ||
137 | printf("Could not resolve host \"other.fourisland.com\": %s\n", SDLNet_GetError()); | ||
138 | throw 1; | ||
139 | } | ||
140 | |||
141 | TCPsocket tcpsock = SDLNet_TCP_Open(&ipaddress); | ||
142 | if (!tcpsock) | ||
143 | { | ||
144 | printf("Could not connect to host \"other.fourisland.com\": %s\n", SDLNet_GetError()); | ||
145 | throw 2; | ||
146 | } | ||
147 | |||
148 | char body[256]; | ||
149 | sprintf(body, "name=%s&level=%d", hsname, level); | ||
150 | char headers[256]; | ||
151 | sprintf(headers, "POST /mol/hslist.php?add HTTP/1.1\nHost: other.fourisland.com\nUser-Agent: Maze Of Life v2.0\nAccept: text/plain\nKeep-Alive: 300\nConnection: keep-alive\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n%s\n", strlen(body), body); | ||
152 | if (SDLNet_TCP_Send(tcpsock, headers, strlen(headers)+1) < strlen(headers)) | ||
153 | { | ||
154 | printf("Connection closed by peer: %s\n", SDLNet_GetError()); | ||
155 | throw 3; | ||
156 | } | ||
157 | |||
158 | std::stringstream download(std::stringstream::in | std::stringstream::out); | ||
159 | char hslist[1024]; | ||
160 | SDLNet_TCP_Recv(tcpsock, hslist, 1024); | ||
161 | download << hslist; | ||
162 | SDLNet_TCP_Close(tcpsock); | ||
163 | |||
164 | char temps[256]; | ||
165 | download.getline(temps,256); | ||
166 | while (strlen(temps) != 1) | ||
167 | { | ||
168 | download.getline(temps,256); | ||
169 | } | ||
170 | |||
171 | int rank; | ||
172 | download.getline(temps, 256); | ||
173 | if (sscanf(temps, "%d%*c", &rank) != 1) | ||
174 | { | ||
175 | printf("Recieved data is of an invalid format: %s\n", temps); | ||
176 | throw 4; | ||
177 | } | ||
178 | |||
179 | this->hslist = getGlobalHighscores(); | ||
180 | |||
181 | if (this->hslist.empty()) | ||
182 | { | ||
183 | printf("Global Highscore List cannot be empty after adding a score to it.\n"); | ||
184 | throw 5; | ||
185 | } | ||
186 | |||
187 | if (rank > 10) | ||
188 | { | ||
189 | Highscore temph(hsname, level); | ||
190 | temph.setRank(rank); | ||
191 | |||
192 | this->hslist[9] = temph; | ||
193 | this->newpos = 10; | ||
194 | } else { | ||
195 | std::vector<Highscore>::iterator it; | ||
196 | bool found = false; | ||
197 | |||
198 | for (it=this->hslist.begin(); it<this->hslist.end(); it++) | ||
199 | { | ||
200 | Highscore h = *it; | ||
201 | |||
202 | if (!found) | ||
203 | { | ||
204 | if ((strcmp(h.getName(),hsname) == 0) && (h.getLevel() == level)) | ||
205 | { | ||
206 | this->newpos = h.getRank(); | ||
207 | found = true; | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | } catch (int e) | ||
213 | { | ||
214 | fail = true; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | int SubmitHighscoreListState::SubmitHighscoreList::getNewPos() | ||
219 | { | ||
220 | return newpos; | ||
221 | } | ||
222 | |||
223 | bool SubmitHighscoreListState::SubmitHighscoreList::hasFailed() | ||
224 | { | ||
225 | return fail; | ||
226 | } | ||
diff --git a/hssubmit.h b/hssubmit.h deleted file mode 100644 index 243dab8..0000000 --- a/hssubmit.h +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | #ifndef HSSUBMIT_H | ||
2 | #define HSSUBMIT_H | ||
3 | |||
4 | class SubmitHighscoreListState : public State { | ||
5 | public: | ||
6 | SubmitHighscoreListState(char* hsname, int level); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | static int LoadHighscoreList(void* pParam); | ||
12 | |||
13 | class SubmitHighscoreList : public GlobalHighscoreList { | ||
14 | public: | ||
15 | SubmitHighscoreList(char* hsname, int level); | ||
16 | int getNewPos(); | ||
17 | bool hasFailed(); | ||
18 | |||
19 | private: | ||
20 | int newpos; | ||
21 | }; | ||
22 | |||
23 | SDL_Surface* list; | ||
24 | SDL_Surface* options; | ||
25 | SDL_Surface* pointer; | ||
26 | char* hsname; | ||
27 | int level; | ||
28 | bool scoreSent; | ||
29 | int selection; | ||
30 | int newpos; | ||
31 | bool fail; | ||
32 | }; | ||
33 | |||
34 | #endif | ||
diff --git a/htpstate.cpp b/htpstate.cpp deleted file mode 100644 index 0771290..0000000 --- a/htpstate.cpp +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | #include "includes.h" | ||
2 | |||
3 | HowToPlayState::HowToPlayState() | ||
4 | { | ||
5 | background1 = SDL_LoadBMP("resources/htp1.bmp"); | ||
6 | background2 = SDL_LoadBMP("resources/htp2.bmp"); | ||
7 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | ||
8 | |||
9 | secondPage = false; | ||
10 | selection = 0; | ||
11 | } | ||
12 | |||
13 | void HowToPlayState::input(SDL_keysym key) | ||
14 | { | ||
15 | if ((key.sym == SDLK_LEFT) && (selection != 0)) | ||
16 | { | ||
17 | selection--; | ||
18 | } else if ((key.sym == SDLK_RIGHT) && (selection != 1)) | ||
19 | { | ||
20 | selection++; | ||
21 | } else if (key.sym == SDLK_RETURN) | ||
22 | { | ||
23 | switch (selection) | ||
24 | { | ||
25 | case 0: | ||
26 | secondPage = !secondPage; | ||
27 | |||
28 | break; | ||
29 | case 1: | ||
30 | changeState(new TitleState()); | ||
31 | |||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | void HowToPlayState::render(SDL_Surface* screen) | ||
38 | { | ||
39 | SDL_Rect pSpace; | ||
40 | |||
41 | if (!secondPage) | ||
42 | { | ||
43 | SDL_BlitSurface(background1, NULL, screen, NULL); | ||
44 | |||
45 | pSpace.x = (selection==0?74:216); | ||
46 | } else { | ||
47 | SDL_BlitSurface(background2, NULL, screen, NULL); | ||
48 | |||
49 | pSpace.x = (selection==0?45:238); | ||
50 | } | ||
51 | |||
52 | pSpace.y = 430; | ||
53 | pSpace.w = pointer->w; | ||
54 | pSpace.h = pointer->h; | ||
55 | |||
56 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
57 | } | ||
diff --git a/htpstate.h b/htpstate.h deleted file mode 100644 index 79c66ba..0000000 --- a/htpstate.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef HTPSTATE_H | ||
2 | #define HTPSTATE_H | ||
3 | |||
4 | class HowToPlayState : public State { | ||
5 | public: | ||
6 | HowToPlayState(); | ||
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | SDL_Surface* background1; | ||
12 | SDL_Surface* background2; | ||
13 | SDL_Surface* pointer; | ||
14 | bool secondPage; | ||
15 | int selection; | ||
16 | }; | ||
17 | |||
18 | #endif | ||
diff --git a/icon.ico b/icon.ico deleted file mode 100644 index 37e9db6..0000000 --- a/icon.ico +++ /dev/null | |||
Binary files differ | |||
diff --git a/includes.h b/includes.h deleted file mode 100644 index 38523b7..0000000 --- a/includes.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | #include <SDL.h> | ||
2 | #include <SDL/SDL_ttf.h> | ||
3 | #include <SDL/SDL_net.h> | ||
4 | #include <SDL_thread.h> | ||
5 | #include <stdio.h> | ||
6 | #include <time.h> | ||
7 | #include <string> | ||
8 | #include <vector> | ||
9 | #include <fstream> | ||
10 | #include <sstream> | ||
11 | #include <exception> | ||
12 | #include "state.h" | ||
13 | #include "mazeoflife.h" | ||
14 | #include "titlestate.h" | ||
15 | #include "htpstate.h" | ||
16 | #include "chlstate.h" | ||
17 | #include "gamestate.h" | ||
18 | #include "highscore.h" | ||
19 | #include "hslist.h" | ||
20 | #include "hslocal.h" | ||
21 | #include "hsnew.h" | ||
22 | #include "hsglobal.h" | ||
23 | #include "hssubmit.h" | ||
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 107a640..a020f6c 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp | |||
@@ -1,7 +1,12 @@ | |||
1 | #include "includes.h" | 1 | #include "mazeoflife.h" |
2 | 2 | #include <SDL.h> | |
3 | SDL_Surface *screen; | 3 | #include <SDL_ttf.h> |
4 | State* state; | 4 | #include <SDL_net.h> |
5 | #include <cstdlib> | ||
6 | #include <ctime> | ||
7 | #include <iostream> | ||
8 | #include "state.h" | ||
9 | #include "titlestate.h" | ||
5 | 10 | ||
6 | int main(int argc, char *argv[]) | 11 | int main(int argc, char *argv[]) |
7 | { | 12 | { |
@@ -24,118 +29,30 @@ int main(int argc, char *argv[]) | |||
24 | printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); | 29 | printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); |
25 | exit(-1); | 30 | exit(-1); |
26 | } | 31 | } |
27 | 32 | ||
28 | /* Clean up on exit */ | 33 | SDL_Window* window = SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN); |
29 | atexit(SDL_Quit); | 34 | if (window == NULL) |
30 | atexit(TTF_Quit); | ||
31 | atexit(SDLNet_Quit); | ||
32 | |||
33 | SDL_WM_SetCaption("Maze Of Life", NULL); | ||
34 | |||
35 | SDL_Surface* icon; | ||
36 | icon = SDL_LoadBMP("resources/icon.bmp"); | ||
37 | SDL_WM_SetIcon(icon, NULL); | ||
38 | |||
39 | /* | ||
40 | * Initialize the display in a 640x480 8-bit palettized mode, | ||
41 | * requesting a software surface | ||
42 | */ | ||
43 | screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF); | ||
44 | if ( screen == NULL ) { | ||
45 | fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError()); | ||
46 | exit(1); | ||
47 | } | ||
48 | |||
49 | SDL_EnableKeyRepeat(100, 70); | ||
50 | |||
51 | state = new TitleState(); | ||
52 | |||
53 | SDL_AddTimer(TICKDELAY, *tick, NULL); | ||
54 | |||
55 | SDL_Event anEvent; | ||
56 | for (;;) | ||
57 | { | 35 | { |
58 | while (SDL_PollEvent(&anEvent)) | 36 | std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; |
59 | { | 37 | return 1; |
60 | switch (anEvent.type) | ||
61 | { | ||
62 | case SDL_QUIT: | ||
63 | exit(0); | ||
64 | |||
65 | break; | ||
66 | case SDL_KEYDOWN: | ||
67 | if (anEvent.key.keysym.sym == SDLK_F4) | ||
68 | { | ||
69 | SDL_WM_ToggleFullScreen(screen); | ||
70 | } else { | ||
71 | state->input(anEvent.key.keysym); | ||
72 | } | ||
73 | |||
74 | break; | ||
75 | } | ||
76 | } | ||
77 | } | 38 | } |
78 | 39 | ||
79 | exit(0); | 40 | SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); |
80 | } | 41 | if (renderer == NULL) |
81 | |||
82 | void wrap(int* x, int* y) | ||
83 | { | ||
84 | if (*x < 0) | ||
85 | { | ||
86 | *x = WIDTH-(0-*x); | ||
87 | } else if (*y < 0) | ||
88 | { | 42 | { |
89 | *y = HEIGHT-(0-*y); | 43 | std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl; |
90 | } else if (*x >= WIDTH) | 44 | return 1; |
91 | { | ||
92 | *x = *x-WIDTH; | ||
93 | } else if (*y >= HEIGHT) | ||
94 | { | ||
95 | *y = *y-HEIGHT; | ||
96 | } | 45 | } |
97 | } | ||
98 | |||
99 | Uint32 getColor(int r, int g, int b) | ||
100 | { | ||
101 | return SDL_MapRGB(screen->format, r, g, b); | ||
102 | } | ||
103 | |||
104 | void changeState(State* nState) | ||
105 | { | ||
106 | state = nState; | ||
107 | } | ||
108 | |||
109 | Uint32 tick(Uint32 interval, void *param) | ||
110 | { | ||
111 | state->tick(); | ||
112 | state->render(screen); | ||
113 | 46 | ||
114 | SDL_Flip(screen); | 47 | State* state = new TitleState(); |
115 | 48 | while (state != NULL) | |
116 | return interval; | ||
117 | } | ||
118 | |||
119 | TTF_Font* loadFont(int size) | ||
120 | { | ||
121 | TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size); | ||
122 | |||
123 | if (tmpfont == NULL) | ||
124 | { | 49 | { |
125 | printf("Unable to load font: %s\n", TTF_GetError()); | 50 | state = (*state)(renderer); |
126 | exit(1); | ||
127 | } | 51 | } |
128 | 52 | ||
129 | return tmpfont; | 53 | SDL_DestroyRenderer(renderer); |
130 | } | 54 | SDL_DestroyWindow(window); |
131 | 55 | SDLNet_Quit(); | |
132 | const char* getDataFile() | 56 | TTF_Quit(); |
133 | { | 57 | SDL_Quit(); |
134 | #ifdef WINDOWS | 58 | } \ No newline at end of file |
135 | char* dir = getenv("USERPROFILE"); | ||
136 | #else | ||
137 | char* dir = getenv("HOME"); | ||
138 | #endif | ||
139 | |||
140 | return (std::string(dir) + "/.molhslist").c_str(); | ||
141 | } | ||
diff --git a/mazeoflife.h b/mazeoflife.h index 00a31cf..3cc6d6d 100644 --- a/mazeoflife.h +++ b/mazeoflife.h | |||
@@ -3,13 +3,5 @@ | |||
3 | 3 | ||
4 | const int WIDTH = 30; | 4 | const int WIDTH = 30; |
5 | const int HEIGHT = 30; | 5 | const int HEIGHT = 30; |
6 | const int TICKDELAY = 5; | ||
7 | |||
8 | void wrap(int* x, int* y); | ||
9 | Uint32 getColor(int r, int g, int b); | ||
10 | void changeState(State* nState); | ||
11 | Uint32 tick(Uint32 interval, void *param); | ||
12 | TTF_Font* loadFont(int size); | ||
13 | const char* getDataFile(); | ||
14 | 6 | ||
15 | #endif | 7 | #endif |
diff --git a/state.h b/state.h index 7373940..2d6f804 100644 --- a/state.h +++ b/state.h | |||
@@ -1,12 +1,12 @@ | |||
1 | #include <SDL.h> | ||
2 | |||
1 | #ifndef STATE_H | 3 | #ifndef STATE_H |
2 | #define STATE_H | 4 | #define STATE_H |
3 | 5 | ||
4 | class State | 6 | class State |
5 | { | 7 | { |
6 | public: | 8 | public: |
7 | virtual void input(SDL_keysym key) {}; | 9 | virtual State* operator() (SDL_Renderer* renderer) {return NULL;}; |
8 | virtual void tick() {}; | ||
9 | virtual void render(SDL_Surface* screen) {}; | ||
10 | }; | 10 | }; |
11 | 11 | ||
12 | #endif | 12 | #endif \ No newline at end of file |
diff --git a/titlestate.cpp b/titlestate.cpp index 5a9b91e..8375c4a 100644 --- a/titlestate.cpp +++ b/titlestate.cpp | |||
@@ -1,52 +1,44 @@ | |||
1 | #include "includes.h" | 1 | #include "titlestate.h" |
2 | #include "util.h" | ||
2 | 3 | ||
3 | TitleState::TitleState() | 4 | State* TitleState::operator() (SDL_Renderer* renderer) |
4 | { | 5 | { |
5 | background = SDL_LoadBMP("resources/title.bmp"); | 6 | SDL_Texture* background = loadImage(renderer, "resources/title.bmp"); |
6 | pointer = SDL_LoadBMP("resources/pointer.bmp"); | 7 | SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); |
7 | 8 | int selection = 0; | |
8 | selection = 0; | 9 | SDL_Event e; |
9 | } | 10 | |
10 | 11 | for (;;) | |
11 | void TitleState::input(SDL_keysym key) | ||
12 | { | ||
13 | if ((key.sym == SDLK_UP) && (selection != 0)) | ||
14 | { | 12 | { |
15 | selection--; | 13 | while (SDL_PollEvent(&e)) |
16 | } else if ((key.sym == SDLK_DOWN) && (selection != 3)) | ||
17 | { | ||
18 | selection++; | ||
19 | } else if (key.sym == SDLK_RETURN) | ||
20 | { | ||
21 | switch (selection) | ||
22 | { | 14 | { |
23 | case 0: | 15 | if (e.type == SDL_QUIT) |
24 | changeState(new GameState()); | 16 | { |
25 | 17 | return NULL; | |
26 | break; | 18 | } else if (e.type == SDL_KEYDOWN) |
27 | case 1: | 19 | { |
28 | changeState(new HowToPlayState()); | 20 | if ((e.key.keysym.sym == SDLK_UP) && (selection != 0)) |
29 | 21 | { | |
30 | break; | 22 | selection--; |
31 | case 2: | 23 | } else if ((e.key.keysym.sym == SDLK_DOWN) && (selection != 3)) |
32 | changeState(new ChooseHighscoreListState()); | 24 | { |
33 | 25 | selection++; | |
34 | break; | 26 | } else if (e.key.keysym.sym == SDLK_RETURN) |
35 | case 3: | 27 | { |
36 | exit(0); | 28 | switch (selection) |
29 | { | ||
30 | //case 0: return new GameState(); | ||
31 | //case 1: return new HowToPlayState(); | ||
32 | //case 2: return new ChooseHighscoreListState(); | ||
33 | case 3: return NULL; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | } | 37 | } |
38 | |||
39 | SDL_RenderClear(renderer); | ||
40 | SDL_RenderCopy(renderer, background, NULL, NULL); | ||
41 | applyTexture(renderer, pointer, 136, selection==0?316:(selection==1?350:(selection==2?381:417))); | ||
42 | SDL_RenderPresent(renderer); | ||
38 | } | 43 | } |
39 | } | 44 | } \ No newline at end of file |
40 | |||
41 | void TitleState::render(SDL_Surface* screen) | ||
42 | { | ||
43 | SDL_BlitSurface(background, NULL, screen, NULL); | ||
44 | |||
45 | SDL_Rect pSpace; | ||
46 | pSpace.x = 136; | ||
47 | pSpace.y = (selection==0?316:(selection==1?350:(selection==2?381:417))); | ||
48 | pSpace.w = pointer->w; | ||
49 | pSpace.h = pointer->h; | ||
50 | |||
51 | SDL_BlitSurface(pointer, NULL, screen, &pSpace); | ||
52 | } | ||
diff --git a/titlestate.h b/titlestate.h index 6519ecf..11d16d7 100644 --- a/titlestate.h +++ b/titlestate.h | |||
@@ -1,16 +1,12 @@ | |||
1 | #include <SDL.h> | ||
2 | #include "state.h" | ||
3 | |||
1 | #ifndef TITLESTATE_H | 4 | #ifndef TITLESTATE_H |
2 | #define TITLESTATE_H | 5 | #define TITLESTATE_H |
3 | 6 | ||
4 | class TitleState : public State { | 7 | class TitleState : public State { |
5 | public: | 8 | public: |
6 | TitleState(); | 9 | State* operator() (SDL_Renderer* renderer); |
7 | void input(SDL_keysym key); | ||
8 | void render(SDL_Surface* screen); | ||
9 | |||
10 | private: | ||
11 | SDL_Surface* background; | ||
12 | SDL_Surface* pointer; | ||
13 | int selection; | ||
14 | }; | 10 | }; |
15 | 11 | ||
16 | #endif | 12 | #endif \ No newline at end of file |
diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000..b021146 --- /dev/null +++ b/util.cpp | |||
@@ -0,0 +1,69 @@ | |||
1 | #include "util.h" | ||
2 | #include "mazeoflife.h" | ||
3 | #include <iostream> | ||
4 | |||
5 | void wrap(int* x, int* y) | ||
6 | { | ||
7 | if (*x < 0) | ||
8 | { | ||
9 | *x = WIDTH-(0-*x); | ||
10 | } else if (*y < 0) | ||
11 | { | ||
12 | *y = HEIGHT-(0-*y); | ||
13 | } else if (*x >= WIDTH) | ||
14 | { | ||
15 | *x = *x-WIDTH; | ||
16 | } else if (*y >= HEIGHT) | ||
17 | { | ||
18 | *y = *y-HEIGHT; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | TTF_Font* loadFont(int size) | ||
23 | { | ||
24 | TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size); | ||
25 | |||
26 | if (tmpfont == NULL) | ||
27 | { | ||
28 | printf("Unable to load font: %s\n", TTF_GetError()); | ||
29 | exit(1); | ||
30 | } | ||
31 | |||
32 | return tmpfont; | ||
33 | } | ||
34 | |||
35 | const char* getDataFile() | ||
36 | { | ||
37 | #ifdef WINDOWS | ||
38 | char* dir = getenv("USERPROFILE"); | ||
39 | #else | ||
40 | char* dir = getenv("HOME"); | ||
41 | #endif | ||
42 | |||
43 | return (std::string(dir) + "/.molhslist").c_str(); | ||
44 | } | ||
45 | |||
46 | SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file) | ||
47 | { | ||
48 | SDL_Surface* surface = SDL_LoadBMP(file.c_str()); | ||
49 | if (surface == NULL) | ||
50 | { | ||
51 | std::cout << SDL_GetError() << std::endl; | ||
52 | return NULL; | ||
53 | } | ||
54 | |||
55 | SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
56 | SDL_FreeSurface(surface); | ||
57 | |||
58 | return texture; | ||
59 | } | ||
60 | |||
61 | void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y) | ||
62 | { | ||
63 | SDL_Rect pos; | ||
64 | pos.x = x; | ||
65 | pos.y = y; | ||
66 | SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h); | ||
67 | |||
68 | SDL_RenderCopy(renderer, tex, NULL, &pos); | ||
69 | } \ No newline at end of file | ||
diff --git a/util.h b/util.h new file mode 100644 index 0000000..365a759 --- /dev/null +++ b/util.h | |||
@@ -0,0 +1,14 @@ | |||
1 | #include <SDL.h> | ||
2 | #include <SDL_ttf.h> | ||
3 | #include <string> | ||
4 | |||
5 | #ifndef UTIL_H | ||
6 | #define UTIL_H | ||
7 | |||
8 | void wrap(int* x, int* y); | ||
9 | TTF_Font* loadFont(int size); | ||
10 | const char* getDataFile(); | ||
11 | SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file); | ||
12 | void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y); | ||
13 | |||
14 | #endif \ No newline at end of file | ||
diff --git a/winres.rc b/winres.rc deleted file mode 100644 index 1bc463a..0000000 --- a/winres.rc +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | IDI_ICON1 ICON DISCARDABLE "icon.ico" | ||