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 /** Cell definition file.
24  * @file    HCCell.h
25  * @author  Juan Carlos Seijo P�rez
26  * @date    30/04/2004
27  * @version 0.0.1 - 30/04/2004 - First version.
28  */
29 
30 #ifndef _HCCELL_INCLUDED
31 #define _HCCELL_INCLUDED
32 
33 #include <JLib/Util/JTypes.h>
34 #include <JLib/Graphics/JDrawable.h>
35 #include <JLib/Graphics/JImage.h>
36 #include <JLib/Graphics/JImageSprite.h>
37 
38 /** Cell types.
39  */
40 typedef enum
41 {
42   HCCELLTYPE_BLANK = 0,                  /**< Blank cell. */
43   HCCELLTYPE_FLOOR,                      /**< Floor cell. */
44   HCCELLTYPE_CONTFLOOR,                  /**< Continuous floor cell. */
45   HCCELLTYPE_LADDER,                     /**< Ladder cell. */
46   HCCELLTYPE_BAR,                        /**< Firefighter bar cell. */
47   HCCELLTYPE_BREAK,                      /**< Breakable floor cell. */
48 } HCCellType;
49 
50 /** Actions allowed in a cell.
51  */
52 typedef enum
53 {
54   HCACTION_UP = 1,                       /**< Go up. */
55   HCACTION_DOWN = 2,                     /**< Go down. */
56   HCACTION_LEFT = 4,                     /**< Go left. */
57   HCACTION_RIGHT = 8,                    /**< Go right. */
58   HCACTION_FALL = 16,                    /**< Fall. */
59   HCACTION_SLIDE = 32,                   /**< Slide. */
60 } HCAction;
61 
62 /** Generic 2D blank cell.
63  */
64 class HCCell : public JDrawable
65 {
66  protected:
67   HCCellType type;                       /**< Type of this cell. */
68   s32 subtype;                           /**< Subtype of this cell. */
69   u32 actionMask;                        /**< Mask of allowed actions within this cell. */
70 
71  public:
72   /** Creates an empty cell of type HCCELLTYPE_BLANK by default and
73    * movement to the sides, down and falling as actions allowed.
74    */
75   HCCell(HCCellType t = HCCELLTYPE_BLANK, u32 actions = HCACTION_FALL | HCACTION_LEFT | HCACTION_RIGHT)
type(t)76 	: type(t), subtype(0), actionMask(actions)
77   {}
78 
79   /** Returns the mask of allowed actions for this cell.
80    * @return the mask of allowed actions for this cell.
81    */
Actions()82   u32 Actions()
83   {
84     return actionMask;
85   }
86 
87   /** Enables the specified actions over this cell.
88    * @param  actions OR'ed combination of the actions to allow for this cell.
89    */
Enable(u32 actions)90   void Enable(u32 actions)
91   {
92     actionMask |= actions;
93   }
94 
95   /**Disables the specified actions over this cell.
96    * @param  actions OR'ed combination of the actions to allow for this cell.
97    */
Disable(u32 actions)98   void Disable(u32 actions)
99   {
100     actionMask &= ~(actions);
101   }
102 
103   /** Gets the type of this cell.
104    * @return Type of this cell.
105    */
Type()106   const HCCellType & Type() {return type;}
107 
108   /** Sets the type of this cell.
109    * @param newType New type of this cell.
110    */
Type(const HCCellType & newType)111   void Type(const HCCellType &newType) {type = newType;}
112 
113   /** Gets the subtype of this cell.
114    * @return Subtype of this cell.
115    */
Subtype()116   s32 Subtype() {return subtype;}
117 
118   /** Sets the subtype of this cell.
119    * @param newSubtype New type of this cell.
120    */
Subtype(s32 newSubtype)121   void Subtype(s32 newSubtype) {subtype = newSubtype;}
122 
123   /** Destroys the object.
124    */
~HCCell()125   virtual ~HCCell()
126   {}
127 };
128 
129 class HCDrawableCell : public HCCell
130 {
131  protected:
132 	JImage drawable;                      /**< Graphical representation of the cell. */
133 
134  public:
135 	/** Creates the cell.
136 	 */
HCCell(t,actions)137 	HCDrawableCell(HCCellType t, JImage *d, u32 actions = HCACTION_LEFT | HCACTION_RIGHT) : HCCell(t, actions)
138 	{
139 		if (d)
140 			drawable.Ref(*d);
141 	}
142 
143   /** Draws the cell.
144    */
Draw()145   virtual void Draw() {drawable.Draw();}
146 
147 	/** Positions this cell.
148 	 * @param  xPos New x coordinate.
149 	 * @param  yPos New y coordinate.
150 	 */
Pos(float xPos,float yPos)151 	virtual void Pos(float xPos, float yPos)
152 	{pos.x = xPos; pos.y = yPos; drawable.Pos(xPos, yPos);}
153 
154 	/** Destroys the cell.
155 	 */
~HCDrawableCell()156 	virtual ~HCDrawableCell()
157 	{}
158 };
159 
160 /** Represents a simple floor or wall
161  */
162 class HCFloorCell : public HCDrawableCell
163 {
164  public:
HCDrawableCell(HCCELLTYPE_FLOOR,d,actions)165 	HCFloorCell(JImage *d, u32 actions = 0) : HCDrawableCell(HCCELLTYPE_FLOOR, d, actions)
166 	{}
167 
~HCFloorCell()168 	virtual ~HCFloorCell() {}
169 };
170 
171 /** Represents a bar
172  */
173 class HCBarCell : public HCDrawableCell
174 {
175  public:
HCDrawableCell(HCCELLTYPE_BAR,d,actions)176 	HCBarCell(JImage *d, u32 actions = HCACTION_SLIDE | HCACTION_DOWN | HCACTION_LEFT | HCACTION_RIGHT) : HCDrawableCell(HCCELLTYPE_BAR, d, actions)
177 	{}
178 
~HCBarCell()179 	virtual ~HCBarCell() {}
180 };
181 
182 /** Represents a ladder
183  */
184 class HCLadderCell : public HCDrawableCell
185 {
186  public:
HCDrawableCell(HCCELLTYPE_LADDER,d,actions)187 	HCLadderCell(JImage *d, u32 actions = HCACTION_UP | HCACTION_DOWN | HCACTION_LEFT | HCACTION_RIGHT) : HCDrawableCell(HCCELLTYPE_LADDER, d, actions)
188 	{}
189 
~HCLadderCell()190 	virtual ~HCLadderCell() {}
191 };
192 
193 #endif // _HCCELL_INCLUDED
194