Merge lp:~damn-monkey-devs/damn-monkey/game-and-lives-management into lp:damn-monkey

Proposed by Vincent PEYROUSE (GodezInc)
Status: Merged
Approved by: Fabien LOISON
Approved revision: 30
Merged at revision: 26
Proposed branch: lp:~damn-monkey-devs/damn-monkey/game-and-lives-management
Merge into: lp:damn-monkey
Diff against target: 172 lines (+103/-3)
4 files modified
src/game.c (+99/-1)
src/game.h (+2/-1)
src/levels/level_01.c (+1/-0)
src/main.c (+1/-1)
To merge this branch: bzr merge lp:~damn-monkey-devs/damn-monkey/game-and-lives-management
Reviewer Review Type Date Requested Status
Fabien LOISON Approve
Review via email: mp+63365@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Fabien LOISON (flozz) wrote :

I think that the code that display the remaining lives should be in the lets_play_yeah() function instead of the level_01() function. And the lives must be on the LAYER_FG layer instead of the LAYER_MENU layer.

review: Needs Fixing
30. By Vincent PEYROUSE (GodezInc)

* Some code refactoring

Revision history for this message
Fabien LOISON (flozz) wrote :

All right :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'pixmaps/life.png'
2Binary files pixmaps/life.png 1970-01-01 00:00:00 +0000 and pixmaps/life.png 2011-06-03 11:21:31 +0000 differ
3=== modified file 'src/game.c'
4--- src/game.c 2011-05-19 17:22:16 +0000
5+++ src/game.c 2011-06-03 11:21:31 +0000
6@@ -44,6 +44,84 @@
7
8
9 #include "game.h"
10+#include "levels/level_01.h"
11+
12+
13+/**
14+ * \fn void game(SDL_Surface *screen)
15+ * \brief Play to the game.
16+ *
17+ * This function manage the levels and the lives.
18+ *
19+ * \param screen The main surface (called screen in the main() function).
20+ */
21+void game(SDL_Surface *screen)
22+{
23+ int current_level = 1;
24+ int levels_count = 1; //Number of levels
25+ JUMPMAN_LIVES = 3;
26+ GAME_SPEED = 1;
27+ GAME_STATE = GAME_STATE_PLAYING;
28+
29+ while (GAME_STATE != GAME_STATE_NONE && GAME_STATE != GAME_STATE_OVER)
30+ {
31+ //Launch the level
32+ switch (current_level)
33+ {
34+ case 1:
35+ level_01(screen);
36+ break;
37+ default:
38+ break;
39+ }
40+ //Check the status
41+ switch (GAME_STATE)
42+ {
43+ case GAME_STATE_LIFE_LOST:
44+ JUMPMAN_LIVES -= 1;
45+ if (JUMPMAN_LIVES <= 0)
46+ {
47+ GAME_STATE = GAME_STATE_OVER;
48+ }
49+ break;
50+ case GAME_STATE_LEVEL_COMPLETED:
51+ current_level += 1;
52+ if (current_level > levels_count)
53+ {
54+ current_level = 1; //Restart with the first level;
55+ GAME_SPEED++;
56+ }
57+ break;
58+ case GAME_STATE_NONE:
59+ break;
60+ default:
61+ printf("W: Abnormal game status: %i", GAME_STATE);
62+ GAME_STATE = GAME_STATE_NONE;
63+ break;
64+ }
65+ }
66+ if (GAME_STATE == GAME_STATE_OVER)
67+ {
68+ DM_Surface *bg = load_resource_as_dm_surface("menu_bg.png");
69+ int bg_refresh = ref_object(&LAYER_MENU, bg, surface_refresh_cb);
70+ DM_Surface *text = malloc(sizeof(DM_Surface));
71+ text->surface = str_to_surface("font_menu.png", "GAME OVER");
72+ text->rect.w = text->surface->w;
73+ text->rect.h = text->surface->h;
74+ text->rect.x = (screen->w - text->rect.w) / 2;
75+ text->rect.y = (screen->h / 3);
76+ int text_refresh = ref_object(&LAYER_MENU, text, surface_refresh_cb);
77+ //TODO : Make it became sexier with a picture and sad song
78+ SDL_Delay(2000);
79+ deref_object(&LAYER_MENU, bg_refresh);
80+ deref_object(&LAYER_MENU, text_refresh);
81+ SDL_Delay(20);
82+ free_dm_surface(bg);
83+ free_dm_surface(text);
84+ }
85+ //End of the game
86+ GAME_STATE == GAME_STATE_NONE;
87+}
88
89
90 /**
91@@ -155,6 +233,21 @@
92 Mix_Chunk *sound_die = load_sound_resource("die.wav");
93 //Initialize the GAME_STATE variable
94 GAME_STATE = GAME_STATE_PLAYING;
95+ //Load and show remaining lifes
96+ DM_Surface *life = load_resource_as_dm_surface("life.png");
97+ life->rect.x = 730;
98+ life->rect.y = 17;
99+ int life_refresh = ref_object(&LAYER_FG, life, surface_refresh_cb);
100+ DM_Surface *life_text = malloc(sizeof(DM_Surface));
101+ //"x <number of remaining lives>" surface creation
102+ char life_char[3];
103+ sprintf(life_char, "x%d", JUMPMAN_LIVES);
104+ life_text->surface = str_to_surface("font_main.png", life_char);
105+ life_text->rect.w = life_text->surface->w;
106+ life_text->rect.h = life_text->surface->h;
107+ life_text->rect.x = life->rect.x + life->rect.w + 5;
108+ life_text->rect.y = life->rect.y;
109+ int life_text_refresh = ref_object(&LAYER_FG, life_text, surface_refresh_cb);
110 //Set the start position of Jumpman
111 JUMPMAN.movement = map->start_look;
112 JUMPMAN.pos_x = map->start_point_x - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2;
113@@ -573,10 +666,15 @@
114
115 //TODO if the player win, play a music,...
116
117- //Dereference Jumpman
118+ //Dereference Jumpman and remaining lifes
119 deref_object(&LAYER_ACTIVE, jumpman_refresh);
120+ deref_object(&LAYER_FG, life_text_refresh);
121+ deref_object(&LAYER_FG, life_refresh);
122+ SDL_Delay(50);
123 //Free the memory
124 Mix_FreeChunk(sound_die);
125+ free_dm_surface(life_text);
126+ free_dm_surface(life);
127 //Return the game state
128 return GAME_STATE;
129 }
130
131=== modified file 'src/game.h'
132--- src/game.h 2011-05-13 18:40:34 +0000
133+++ src/game.h 2011-06-03 11:21:31 +0000
134@@ -233,11 +233,12 @@
135 int GAME_STATE;
136 /**
137 * \var JUMPMAN_LIVES
138- * \brief The remaining lives of Jumpman (FIXME not implemented yet).
139+ * \brief The remaining lives of Jumpman
140 */
141 int JUMPMAN_LIVES;
142
143
144+void game(SDL_Surface *screen);
145 void init_game();
146 void update_jumpman();
147 int lets_play_yeah(SDL_Surface *screen, DM_Map *map);
148
149=== modified file 'src/levels/level_01.c'
150--- src/levels/level_01.c 2011-05-13 18:51:52 +0000
151+++ src/levels/level_01.c 2011-06-03 11:21:31 +0000
152@@ -57,6 +57,7 @@
153
154 //Load the level infos (collides,...)
155 DM_Map *map = load_map_infos("level_01");
156+
157 lets_play_yeah(screen, map);
158
159 //Dereference objects and free the memory
160
161=== modified file 'src/main.c'
162--- src/main.c 2011-05-13 14:54:31 +0000
163+++ src/main.c 2011-06-03 11:21:31 +0000
164@@ -147,7 +147,7 @@
165 {
166 case MAIN_MENU_PLAY:
167 Mix_HaltMusic();
168- level_01(screen);
169+ game(screen);
170 Mix_PlayMusic(menu_music, -1);
171 break;
172 case MAIN_MENU_CREDITS:

Subscribers

People subscribed via source and target branches

to all changes: