1 /* 2 * GNUjump 3 * ======= 4 * 5 * Copyright (C) 2005-2008, Juan Pedro Bolivar Puente 6 * 7 * GNUjump is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * GNUjump is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef _GAME_H_ 22 #define _GAME_H_ 23 24 /* What to return when the player is dead */ 25 #define DEAD -1 26 27 #define PAUSED 2 28 #define ENDMATCH 2 29 30 #define MSGTIME 300 31 32 /* Size of the gaming grid (it has 1 row more at the begining) */ 33 #define GRIDWIDTH 32 34 #define GRIDHEIGHT 24 35 36 /* Size of a square in the grid*/ 37 #define BLOCKSIZE 16 38 #define HEROSIZE 32 39 40 /* The minimum space on top*/ 41 #define MINSKY 80 42 #define MINSKYGRID 6 43 44 /* Space (in grid squares) between one floor and another */ 45 #define FLOORGAP 5 46 47 /* Sounds */ 48 enum 49 { 50 S_JUMP = 1, 51 S_FALL = 2, 52 S_DIE = 4 53 }; 54 55 56 typedef struct key 57 { 58 Sint8 pressed; 59 int def; 60 } L_key; 61 62 typedef struct timer 63 { 64 Uint32 framecount; 65 float rateticks; 66 Uint32 lastticks; 67 float ms; 68 Uint32 mscount; 69 Uint32 rate; 70 Uint32 totalms; 71 Uint32 notdelayed; 72 int ratechanged; 73 } L_timer; 74 75 typedef struct 76 { 77 void *buf; 78 void *bst; 79 int bufsize; 80 int bodysize; 81 int nframes; 82 int fps; 83 int totalms; 84 int record; 85 86 int speed; 87 int deadHero[MAX_PLAYERS]; 88 int scrolls; 89 int sounds; 90 float timer; 91 float mspf; 92 } replay_t; 93 94 typedef struct trail_s 95 { 96 float x0, y0; 97 float x1, y1; 98 int alpha; 99 struct trail_s *next; 100 } trail_t; 101 102 typedef struct blur_s 103 { 104 JPB_surfaceRot *pic; 105 float x, y; 106 int angle; 107 int alpha; 108 struct blur_s *next; 109 } blur_t; 110 111 typedef struct particle_s 112 { 113 JPB_surfaceRot *pic; 114 float x, y; 115 float vx, vy; 116 float ax, ay; 117 int rot; 118 int rv; 119 int alpha; 120 int av; 121 122 struct particle_s *next; 123 } particle_t; 124 125 typedef struct hero 126 { 127 trail_t *trail; 128 blur_t *blur; 129 130 L_spriteCtlRot sprite[HEROANIMS]; 131 L_key up; 132 L_key left; 133 L_key right; 134 float x; 135 float y; 136 float vx; 137 float vy; 138 float jump; 139 int id; 140 int previd; 141 int dir; 142 int st; 143 144 float angle; 145 float rotateto; 146 float angspeed; 147 148 int floor; 149 int prevFloor; 150 int dead; 151 int lives; 152 int prevLives; 153 } hero_t; 154 155 typedef struct game 156 { 157 int floorTop; 158 int mapIndex; 159 double scrollTotal; 160 double scrollCount; 161 int floor_l[GRIDHEIGHT]; 162 int floor_r[GRIDHEIGHT]; 163 164 hero_t *heros; 165 int numHeros; 166 int deadHeros; 167 168 float T_speed; 169 float T_count; 170 float T_timer; 171 172 replay_t replay; 173 } game_t; 174 175 void drawCredits (data_t * gfx); 176 177 void softScrollUp (game_t * game, float scroll); 178 179 int drawBg (JPB_surface * surf, int x, int y, int w, int h); 180 181 void drawAnimatedSquare (data_t * gfx, Uint32 color, Uint8 alpha, int x, 182 int y, int w, int h, int time); 183 184 void drawScore (data_t * gfx, game_t * game, Uint32 currtime); 185 186 int drawFloor (data_t * gfx, int x, int y, int bw); 187 188 void makeFloor (game_t * game, int y); 189 190 void hardScrollUp (game_t * game); 191 192 void scrollGrid (game_t * game); 193 194 void initGame (game_t * game, data_t * gfx, int numHeros); 195 196 void playHeroSounds (data_t * gfx, hero_t * hero); 197 198 int playGame (data_t * gfx, int numHeros); 199 200 int pauseGame (data_t * gfx, game_t * game, char *text); 201 202 int endMatch (data_t * gfx, game_t * game, int time); 203 204 void playHeroSound (data_t * gfx, int sound, replay_t * rep); 205 206 void continueTimer (L_timer * time); 207 208 int yesNoQuestion (data_t * gfx, game_t * game, char *text); 209 210 int updateInput (); 211 212 void freeGame (); 213 214 void drawGame (data_t * gfx, game_t * game); 215 216 void markHeroKeys (SDL_Event * event, hero_t * hero); 217 218 void unmarkHeroKeys (SDL_Event * event, hero_t * hero); 219 220 void initHeroKeys (hero_t * hero, int num); 221 222 int isFloor (game_t * game, int x, int y); 223 224 void scrollHeros (game_t * game, float scroll); 225 226 int isStand (game_t * game, int ix, int iy); 227 228 int updateHero (game_t * game, data_t * gfx, int num, float ms); 229 230 void reliveHero (game_t * game, int num); 231 232 int updateHeroPosition (game_t * game, int num, float fact); 233 234 int updateGame (game_t * game, data_t * gfx, float ms); 235 236 void drawHero (data_t * gfx, hero_t * hero); 237 238 void initTimer (L_timer * time, int rate); 239 240 Uint32 updateTimer (L_timer * time); 241 242 void rotateHero (hero_t * hero, float ms); 243 244 void updateScore (data_t * gfx, game_t * game, Uint32 currtime); 245 246 void drawRecords (data_t * gfx, records_t * rtab, int hl); 247 248 void setFpsTimer (L_timer * time, int rate); 249 250 #endif //_GAME_H_ 251