diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-06-22 17:52:37 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-06-22 17:52:37 -0400 |
commit | f2ab9f3f0d5fe1ad19881b7dba79b31e3673748a (patch) | |
tree | eab6ed709b3dfa5876c3f52c15f3cd8471a4d833 | |
parent | 71a493de351277cc61a36aee47501f64f76cca87 (diff) | |
download | mazeoflife-f2ab9f3f0d5fe1ad19881b7dba79b31e3673748a.tar.gz mazeoflife-f2ab9f3f0d5fe1ad19881b7dba79b31e3673748a.tar.bz2 mazeoflife-f2ab9f3f0d5fe1ad19881b7dba79b31e3673748a.zip |
Added tick delay
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | mazeoflife.cpp | 14 | ||||
-rw-r--r-- | mazeoflife.h | 2 |
3 files changed, 20 insertions, 11 deletions
diff --git a/Makefile b/Makefile index 4face93..e44f590 100644 --- a/Makefile +++ b/Makefile | |||
@@ -1,14 +1,15 @@ | |||
1 | PROJECT = mazeoflife | 1 | PROJECT = mazeoflife |
2 | LTARGET = build/$(PROJECT) | 2 | LTARGET = build/$(PROJECT) |
3 | WTARGET = build/$(PROJECT).exe | 3 | WTARGET = build/$(PROJECT).exe |
4 | CC = g++ | 4 | CC = g++ |
5 | WINCC = i586-mingw32msvc-g++ | 5 | WINCC = i586-mingw32msvc-g++ |
6 | WINDRES = i586-mingw32msvc-windres | 6 | WINDRES = i586-mingw32msvc-windres |
7 | FILES = $(addprefix build/,$(wildcard *.cpp)) | 7 | FILES = $(addprefix build/,$(wildcard *.cpp)) |
8 | HEADERS = $(wildcard *.h) | ||
8 | MODULES = $(patsubst %.cpp,%,$(FILES)) | 9 | MODULES = $(patsubst %.cpp,%,$(FILES)) |
9 | SOURCES = $(addsuffix .o,$(MODULES)) | 10 | SOURCES = $(addsuffix .o,$(MODULES)) |
10 | WINSRC = $(addsuffix win,$(SOURCES)) | 11 | WINSRC = $(addsuffix win,$(SOURCES)) |
11 | IMAGES = $(wildcard *.bmp) | 12 | IMAGES = $(wildcard *.bmp) |
12 | CIMAGES = $(addprefix build/,$(IMAGES:.bmp=.bmp.o)) | 13 | CIMAGES = $(addprefix build/,$(IMAGES:.bmp=.bmp.o)) |
13 | LINCCFL = `sdl-config --cflags` | 14 | LINCCFL = `sdl-config --cflags` |
14 | LINLDFL = `sdl-config --libs` | 15 | LINLDFL = `sdl-config --libs` |
@@ -28,14 +29,14 @@ clean: | |||
28 | $(LTARGET): $(SOURCES) $(CIMAGES) | 29 | $(LTARGET): $(SOURCES) $(CIMAGES) |
29 | $(CC) $(SOURCES) $(CIMAGES) -o $(LTARGET) $(LINLDFL) | 30 | $(CC) $(SOURCES) $(CIMAGES) -o $(LTARGET) $(LINLDFL) |
30 | 31 | ||
31 | $(SOURCES): build/%.o: %.cpp | 32 | $(SOURCES): build/%.o: %.cpp $(HEADERS) |
32 | $(CC) -c $? -o $@ $(LINCCFL) | 33 | $(CC) -c $< -o $@ $(LINCCFL) |
33 | 34 | ||
34 | $(WTARGET): $(WINSRC) $(CIMAGES) build/winres.o | 35 | $(WTARGET): $(WINSRC) $(CIMAGES) build/winres.o |
35 | $(WINCC) $(WINSRC) $(CIMAGES) build/winres.o -o $(WTARGET) $(WINLDFL) | 36 | $(WINCC) $(WINSRC) $(CIMAGES) build/winres.o -o $(WTARGET) $(WINLDFL) |
36 | 37 | ||
37 | $(WINSRC): build/%.owin: %.cpp | 38 | $(WINSRC): build/%.owin: %.cpp $(HEADERS) |
38 | $(WINCC) -c $? -o $@ $(WINCCFL) | 39 | $(WINCC) -c $< -o $@ $(WINCCFL) |
39 | 40 | ||
40 | build/winres.o: winres.rc | 41 | build/winres.o: winres.rc |
41 | $(WINDRES) $? $@ | 42 | $(WINDRES) $? $@ |
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index ba5faa9..0dbca55 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp | |||
@@ -7,8 +7,7 @@ int main(int argc, char *argv[]) | |||
7 | { | 7 | { |
8 | srand(time(NULL)); | 8 | srand(time(NULL)); |
9 | 9 | ||
10 | /* Initialize defaults, Video and Audio */ | 10 | if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)==-1)) { |
11 | if((SDL_Init(SDL_INIT_VIDEO)==-1)) { | ||
12 | printf("Could not initialize SDL: %s.\n", SDL_GetError()); | 11 | printf("Could not initialize SDL: %s.\n", SDL_GetError()); |
13 | exit(-1); | 12 | exit(-1); |
14 | } | 13 | } |
@@ -36,11 +35,11 @@ int main(int argc, char *argv[]) | |||
36 | 35 | ||
37 | state = new TitleState(); | 36 | state = new TitleState(); |
38 | 37 | ||
38 | SDL_AddTimer(TICKDELAY, *tick, NULL); | ||
39 | |||
39 | SDL_Event anEvent; | 40 | SDL_Event anEvent; |
40 | for (;;) | 41 | for (;;) |
41 | { | 42 | { |
42 | state->tick(); | ||
43 | |||
44 | while (SDL_PollEvent(&anEvent)) | 43 | while (SDL_PollEvent(&anEvent)) |
45 | { | 44 | { |
46 | switch (anEvent.type) | 45 | switch (anEvent.type) |
@@ -90,3 +89,10 @@ void changeState(State* nState) | |||
90 | { | 89 | { |
91 | state = nState; | 90 | state = nState; |
92 | } | 91 | } |
92 | |||
93 | Uint32 tick(Uint32 interval, void *param) | ||
94 | { | ||
95 | state->tick(); | ||
96 | |||
97 | return interval; | ||
98 | } | ||
diff --git a/mazeoflife.h b/mazeoflife.h index d81c3ea..1f43214 100644 --- a/mazeoflife.h +++ b/mazeoflife.h | |||
@@ -3,9 +3,11 @@ | |||
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 = 10; | ||
6 | 7 | ||
7 | void wrap(int* x, int* y); | 8 | void wrap(int* x, int* y); |
8 | Uint32 getColor(int r, int g, int b); | 9 | Uint32 getColor(int r, int g, int b); |
9 | void changeState(State* nState); | 10 | void changeState(State* nState); |
11 | Uint32 tick(Uint32 interval, void *param); | ||
10 | 12 | ||
11 | #endif | 13 | #endif |