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 /** Exit gadget for Holtz's castle game. 24 * @file HCExit.h 25 * @author Juan Carlos Seijo P�rez 26 * @date 17/08/2004 27 * @version 0.0.1 - 17/08/2004 - First version. 28 */ 29 30 #ifndef _HCEXIT_INCLUDED 31 #define _HCEXIT_INCLUDED 32 33 #include <JLib/Graphics/JDrawable.h> 34 #include <JLib/Util/JTypes.h> 35 #include <JLib/Util/JTimer.h> 36 #include <JLib/Util/JApp.h> 37 #include <HCCharacter.h> 38 #include <HCMap.h> 39 40 /** State of this exit object. 41 */ 42 typedef enum 43 { 44 HCEXITSTATE_LOCKED = 0, /**< The exit is closed. */ 45 HCEXITSTATE_UNLOCKED, /**< The exit is opened. */ 46 HCEXITSTATE_SWALLOWING, /**< The exit is swallowing a character. */ 47 HCEXITSTATE_SWALLOWED /**< The exit has just swallowed the character. */ 48 } HCExitState; 49 50 /** A spark. 51 */ 52 struct HCExitSpark 53 { 54 float x0, y0, x, y; /**< Position of this spark. */ 55 float vx, vy; /**< Veloccity of this spark. */ 56 SDL_Color c; /**< Color of this spark. */ 57 u8 dc; /**< Color variation rate. */ 58 }; 59 60 /** Exit for a level. The character must be aligned with it to reach it. 61 */ 62 class HCExit : public JDrawable 63 { 64 protected: 65 HCMap *map; /**< Map for this exit. */ 66 HCExitState state; /**< Current state. */ 67 float x1; /**< X of lower right box for sparkles. */ 68 float y1; /**< Y of lower right box for sparkles. */ 69 JTimer timer; /**< Timer for FPS count. */ 70 71 HCExitSpark *sparks; /**< Sparks. */ 72 s32 numSparks; /**< Number of sparkles. */ 73 74 HCCharacter *character; /**< Character to swallow. */ 75 JImage *imgCharacter; /**< Frame of the character being swallowed. */ 76 77 public: 78 /** Creates the exit. Init must be called before starting to use it. 79 */ 80 HCExit(); 81 82 /** Initializes the exit. 83 * @param _map Map for this exit. 84 * @return <b>true</b> if everything goes well, <b>false</b> otherwise. 85 */ 86 virtual bool Init(HCMap *_map, s32 nSparks, s32 w = 0); 87 88 /** Draws the exit. 89 */ 90 virtual void Draw(); 91 92 /** Updates the exit. 93 * @return Return value of the associated drawable's update. 94 */ 95 virtual s32 Update(); 96 97 /** Returns the state of the exit. Must use one of Lock(), Unlock() or Swallow() to change the state. 98 * @return the state of the exit. 99 */ State()100 HCExitState State() {return state;} 101 102 /** Returns the number of sparks. 103 * @return the number of sparks. 104 */ NumSparks()105 s32 NumSparks() {return numSparks;} 106 107 /** Returns the lower right x coordinate of the exit. 108 * @return the lower right x coordinate of the exit. 109 */ X1()110 float X1() {return x1;} 111 112 /** Returns the lower right y coordinate of the exit. 113 * @return the lower right y coordinate of the exit. 114 */ Y1()115 float Y1() {return y1;} 116 117 /** Locks the exit. 118 */ Lock()119 void Lock() {state = HCEXITSTATE_LOCKED;} 120 121 /** Unlocks the exit. 122 */ 123 void Unlock(); 124 125 /** Swallows the character. 126 * @param ch Character to swallow. 127 */ 128 void Swallow(HCCharacter *ch); 129 130 /** Positions this object. 131 * @param xPos New x coordinate. 132 * @param yPos New y coordinate. 133 */ 134 virtual void Pos(float xPos, float yPos); 135 136 137 /** Destroys this exit. 138 */ 139 void Destroy(); 140 141 /** Destroys this exit. Allows scalar destruction. 142 */ 143 virtual ~HCExit(); 144 }; 145 146 #endif // _HCEXIT_INCLUDED 147