1 /* 2 * Holotz's Castle 3 * Copyright (C) 2004 Juan Carlos Seijo P�rez 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 59 17 * Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Juan Carlos Seijo P�rez 20 * jacob@mainreactor.net 21 */ 22 23 /** Game level. Includes a map and its enemies. 24 * @file HCLevel.h 25 * @author Juan Carlos Seijo P�rez 26 * @date 29/05/2004 27 * @version 0.0.1 - 29/05/2004 - First version 28 */ 29 30 #ifndef _HCLEVEL_INCLUDED 31 #define _HCLEVEL_INCLUDED 32 33 #include <JLib/Util/JTypes.h> 34 #include <JLib/Sound/JChunk.h> 35 #include <JLib/Graphics/JDrawable.h> 36 #include <HCMap.h> 37 #include <HCRope.h> 38 #include <HCObject.h> 39 #include <HCCharacter.h> 40 #include <HCEnemyBall.h> 41 #include <HCEnemyStatic.h> 42 #include <HCEnemyRandom.h> 43 #include <HCEnemyMaker.h> 44 #include <HCEnemyChaser.h> 45 #include <HCText.h> 46 #include <HCExit.h> 47 #include <HCTimer.h> 48 #include <HCPreferences.h> 49 50 class HCLevel : public JDrawable 51 { 52 // Allows the editor to modify it at pleasure. 53 friend class HCed; 54 55 protected: 56 HCMap map; /**< Level map. */ 57 HCTheme theme; /**< Level theme. */ 58 HCExit levelExit; /**< Level exit. */ 59 JImage bg; /**< Level background. */ 60 61 HCCharacter character; /**< Main character. */ 62 63 s32 numEnemies; /**< Number of enemies. */ 64 HCEnemy **enemies; /**< Array of enemies. */ 65 66 s32 numRopes; /**< Number of ropes. */ 67 HCRope **ropes; /**< Array of ropes. */ 68 69 s32 remainingObjects; /**< Number of objects remaining to unlock the exit. */ 70 s32 numObjects; /**< Number of objects. */ 71 HCObject **objects; /**< Array of objects. */ 72 73 bool scripted; /**< Determines whether it has a script or not. */ 74 HCText *narrative; /**< Narrative to be shown. */ 75 76 bool wideMap; /**< Indicates wherther the map is wider than the movement window or not. */ 77 bool highMap; /**< Indicates wherther the map is higher than the movement window or not. */ 78 79 JVector spot; /**< Viewing spot. The level tries always to make it visible. */ 80 s32 viewRadius; /**< Radius of the viewing spot. */ 81 82 s32 maxTime; /**< Maximum time to complete the level. */ 83 HCTimer levelTimer; /**< Level timer. */ 84 JFont *timerFont; /**< Level timer font. */ 85 86 JChunk soundObjectAcquired; /**< Sound for object acquired. */ 87 JChunk musicEndLevel; /**< End level screen music. */ 88 JChunk soundExitUnlocked; /**< Exit unlocked sound. */ 89 90 public: 91 /** Creates an empty level. One must Load() or call Init and manipulate 92 * directly it (if editing). 93 */ 94 HCLevel(); 95 96 /** Initializes the level. Creates an empty background for it. 97 * @return <b>true</b> if successful, <b>false</b> otherwise. 98 */ 99 bool Init(); 100 101 /** Updates the level. 102 * @return 0 if no important event took place, 1 if player died, 2 if player went through the exit. 103 */ 104 s32 Update(); 105 106 /** Draws the level. 107 */ 108 void Draw(); 109 110 /** Process game input. 111 * @param input Action mask. 112 */ ProcessInput(u32 input)113 void ProcessInput(u32 input) {character.Act(input);} 114 115 /** Loads the level. 116 * @param file File opened and positioned already. 117 * @param filename name of the file opened. 118 * @return 0 if it succeeds, 1 if there is an I/O error, 2 if integrity error. 119 */ 120 u32 Load(JRW &file, const char *filename); 121 122 /** Saves the level. The file must be opened and positioned already. 123 * @param file File opened and positioned already. 124 * @return 0 if it succeeds, 1 if there is an I/O error, 2 if integrity error. 125 */ 126 u32 Save(JRW &file); 127 128 /** Returns this level's map. 129 * @return Map. 130 */ Map()131 HCMap & Map() {return map;} 132 133 /** Returns the number of enemies. 134 * @return Number of enemies. 135 */ NumEnemies()136 s32 NumEnemies() {return numEnemies;} 137 138 /** Returns the number of ropes. 139 * @return Number of ropes. 140 */ NumRopes()141 s32 NumRopes() {return numRopes;} 142 143 /** Returns the number of objects. 144 * @return Number of objects. 145 */ NumObjects()146 s32 NumObjects() {return numObjects;} 147 148 /** Returns the main character. 149 * @return Main character. 150 */ Character()151 HCCharacter *Character() {return &character;} 152 153 /** Returns the enemies. 154 * @return enemies. 155 */ Enemies()156 HCEnemy ** Enemies() {return enemies;} 157 158 /** Returns the ropes. 159 * @return ropes. 160 */ Ropes()161 HCRope ** Ropes() {return ropes;} 162 163 /** Returns the objects. 164 * @return objects. 165 */ Objects()166 HCObject ** Objects() {return objects;} 167 168 /** Returns the current narrative object. 169 * @return current narrative object. 170 */ Narrative()171 HCText *Narrative() {return narrative;} 172 173 /** Sets the current narrative object. 174 * @param Current narrative object to be shown. 175 */ Narrative(HCText * newNarrative)176 void Narrative(HCText *newNarrative) {narrative = newNarrative;} 177 178 /** Returns the exit object. 179 * @return exit object. 180 */ LevelExit()181 HCExit *LevelExit() {return &levelExit;} 182 183 /** Returns the theme. 184 * @return This level's theme. 185 */ Theme()186 HCTheme & Theme() {return theme;} 187 188 /** Positions this level. The background is centered respect to the map. 189 * @param xPos New x coordinate of either the background or the map, the widest. 190 * @param yPos New y coordinate of either the background or the map, the highest. 191 */ 192 virtual void Pos(float xPos, float yPos); 193 194 /** Checks if the character is over any object. 195 */ 196 void CheckObjects(); 197 198 /** Updates the number of objects to be acquired to end the level. 199 */ 200 void ObjectAcquired(HCObject *object); 201 202 /** Returns whether exit is unlocked or not. Unlocked, means that all 203 * the objects had been collected from the map. 204 * @return <b>true</b> if the exit is unlocked and the character can go 205 * to the next level, <b>false</b> if not. 206 */ IsExitUnlocked()207 bool IsExitUnlocked() {return remainingObjects == 0;} 208 209 /** Sets the scripted flag. 210 * @param newState New value for the flag. 211 */ Scripted(bool newState)212 void Scripted(bool newState) {scripted = newState;} 213 214 /** Gets the scripted flag. 215 * @return Whether it has an script or not. 216 */ Scripted()217 bool Scripted() {return scripted;} 218 219 /** Tests if the given characters overlap or not. 220 * @param c1 First character to test. 221 * @param c2 Second character to test. 222 * @return Whether they overlap or not. 223 */ 224 bool Collide(HCCharacter *c1, HCCharacter *c2); 225 226 /** Sets the font to render the timer. 227 * @param f Font to use to render the timer. 228 */ SetTimerFont(JFont * f)229 void SetTimerFont(JFont *f) {timerFont = f;} 230 231 /** Destroys the level, frees resources. 232 */ 233 void Destroy(); 234 235 /** Pauses or continues the level timer. 236 */ Pause(bool pause)237 void Pause(bool pause) {pause ? levelTimer.Pause() : levelTimer.Continue();} 238 239 /** Starts the timer. 240 */ Start()241 void Start() {levelTimer.Start();} 242 243 /** Destroys the level, frees resources, allows scalar destruction. 244 */ ~HCLevel()245 virtual ~HCLevel() {Destroy();} 246 }; 247 248 #endif // _HCLEVEL_INCLUDED 249