summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--mazeoflife.cpp14
-rw-r--r--mazeoflife.h2
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 @@
1PROJECT = mazeoflife 1PROJECT = mazeoflife
2LTARGET = build/$(PROJECT) 2LTARGET = build/$(PROJECT)
3WTARGET = build/$(PROJECT).exe 3WTARGET = build/$(PROJECT).exe
4CC = g++ 4CC = g++
5WINCC = i586-mingw32msvc-g++ 5WINCC = i586-mingw32msvc-g++
6WINDRES = i586-mingw32msvc-windres 6WINDRES = i586-mingw32msvc-windres
7FILES = $(addprefix build/,$(wildcard *.cpp)) 7FILES = $(addprefix build/,$(wildcard *.cpp))
8HEADERS = $(wildcard *.h)
8MODULES = $(patsubst %.cpp,%,$(FILES)) 9MODULES = $(patsubst %.cpp,%,$(FILES))
9SOURCES = $(addsuffix .o,$(MODULES)) 10SOURCES = $(addsuffix .o,$(MODULES))
10WINSRC = $(addsuffix win,$(SOURCES)) 11WINSRC = $(addsuffix win,$(SOURCES))
11IMAGES = $(wildcard *.bmp) 12IMAGES = $(wildcard *.bmp)
12CIMAGES = $(addprefix build/,$(IMAGES:.bmp=.bmp.o)) 13CIMAGES = $(addprefix build/,$(IMAGES:.bmp=.bmp.o))
13LINCCFL = `sdl-config --cflags` 14LINCCFL = `sdl-config --cflags`
14LINLDFL = `sdl-config --libs` 15LINLDFL = `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
40build/winres.o: winres.rc 41build/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
93Uint32 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
4const int WIDTH = 30; 4const int WIDTH = 30;
5const int HEIGHT = 30; 5const int HEIGHT = 30;
6const int TICKDELAY = 10;
6 7
7void wrap(int* x, int* y); 8void wrap(int* x, int* y);
8Uint32 getColor(int r, int g, int b); 9Uint32 getColor(int r, int g, int b);
9void changeState(State* nState); 10void changeState(State* nState);
11Uint32 tick(Uint32 interval, void *param);
10 12
11#endif 13#endif