Debian Codegraph @

src/jj2/level/jj2levelplayer.h

raw symbols SCIP
1
2 /**
3 *
4 * @file jj2levelplayer.h
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created OpenJazz.h
10 * - 31st January 2006: Created player.h from parts of OpenJazz.h
11 * - 24th June 2010: Created levelplayer.h from parts of player.h
12 * - 29th June 2010: Created jj2levelplayer.h from parts of levelplayer.h
13 *
14 * @par Licence:
15 * Copyright (c) 2005-2017 AJ Thomson
16 *
17 * OpenJazz is distributed under the terms of
18 * the GNU General Public License, version 2.0
19 *
20 */
21
22
23 /* "Tile" is a flexible term. Here it is used to refer specifically to the
24 individual elements of the tile set.
25 "Tiles" in the context of level units are referred to as grid elements. */
26
27
28 #ifndef _JJ2LEVELPLAYER_H
29 #define _JJ2LEVELPLAYER_H
30
31
32 #include "jj2level.h"
33
34 #include "level/levelplayer.h"
35 #include "player/player.h"
36 #include "OpenJazz.h"
37
38
39 // Constants
40
41 // Colour offsets
42 #define JJ2PCO_GREY 72
43 #define JJ2PCO_SGREEN 16
44 #define JJ2PCO_BLUE 35
45 #define JJ2PCO_RED 24
46 #define JJ2PCO_LGREEN 16
47 #define JJ2PCO_LEVEL1 96
48 #define JJ2PCO_YELLOW 59
49 #define JJ2PCO_LEVEL2 112
50 #define JJ2PCO_ORANGE 43
51 #define JJ2PCO_LEVEL3 128
52 #define JJ2PCO_LEVEL4 144
53 #define JJ2PCO_SANIM 160
54 #define JJ2PCO_LANIM 176
55 #define JJ2PCO_LEVEL5 208
56
57 // Colour lengths
58 #define JJ2PCL_GREY 8
59 #define JJ2PCL_SGREEN 8
60 #define JJ2PCL_BLUE 5
61 #define JJ2PCL_RED 8
62 #define JJ2PCL_LGREEN 8
63 #define JJ2PCL_LEVEL1 16
64 #define JJ2PCL_YELLOW 5
65 #define JJ2PCL_LEVEL2 16
66 #define JJ2PCL_ORANGE 5
67 #define JJ2PCL_LEVEL3 16
68 #define JJ2PCL_LEVEL4 16
69 #define JJ2PCL_SANIM 16
70 #define JJ2PCL_LANIM 32
71 #define JJ2PCL_LEVEL5 16
72
73 // Player reaction times
74 #define JJ2PRT_HURT 1000
75 #define JJ2PRT_HURTANIM 200
76 #define JJ2PRT_KILLED 2000
77 #define JJ2PRT_INVINCIBLE 10000
78
79 // Other time periods
80 #define T_FASTFEET 25000
81 #define T_WARP 1000
82
83 // Player offsets
84 #define JJ2PXO_MID F16
85 #define JJ2PXO_L (JJ2PXO_MID - F10)
86 #define JJ2PXO_ML (JJ2PXO_MID - F4)
87 #define JJ2PXO_MR (JJ2PXO_MID + F4)
88 #define JJ2PXO_R (JJ2PXO_MID + F10)
89 #define JJ2PYO_TOP (-F20)
90 #define JJ2PYO_MID (-F10)
91 #define JJ2PYO_JUMP ITOF(92)
92
93 // Player speeds
94 #define JJ2PXS_LIMIT ITOF(500)
95 #define JJ2PYS_LIMIT ITOF(500)
96
97 #define JJ2PXS_WALK ITOF(300)
98 #define JJ2PXS_RUN ITOF(325)
99 #define JJ2PXS_FFRUN ITOF(500)
100 #define JJ2PYS_FALL ITOF(350)
101 #define JJ2PYS_SINK ITOF(150)
102 #define JJ2PYS_JUMP -ITOF(350)
103
104 #define JJ2PXS_POLE ITOF(500)
105 #define JJ2PYS_POLE ITOF(500)
106 #define JJ2PYS_SPRING -ITOF(500)
107
108 // Player accelerations
109 #define JJ2PXA_REVERSE 900
110 #define JJ2PXA_STOP 1000
111 #define JJ2PXA_WALK 500
112 #define JJ2PXA_RUN 200
113 #define JJ2PXA_FFRUN 200
114 #define JJ2PYA_GRAVITY 2750
115 #define JJ2PYA_SINK 1000
116
117
118 // Enum
119
120 /// JJ2 player event types
121 enum JJ2PlayerEvent {
122
123 JJ2PE_NONE, ///< No event
124 JJ2PE_SPRING, ///< Spring
125 JJ2PE_FLOAT, ///< Float up
126 JJ2PE_PLATFORM ///< Moving platform
127
128 };
129
130 /// JJ2 player reaction type
131 enum JJ2PlayerReaction {
132
133 JJ2PR_NONE, ///< Not reacting
134 JJ2PR_HURT, ///< Hurt
135 JJ2PR_KILLED, ///< Killed
136 JJ2PR_INVINCIBLE ///< Invincibility
137
138 };
139
140 /// JJ2 shield type
141 enum JJ2Shield {
142
143 JJ2S_NONE = 0, ///< No shield
144 JJ2S_FLAME = 1, ///< Flame shield
145 JJ2S_BUBBLE = 2, ///< Bubble shield
146 JJ2S_PLASMA = 3, ///< Plasma shield
147 JJ2S_LASER = 4 ///< Laser shield
148
149 };
150
151
152 // Classes
153
154 class Anim;
155 class JJ2Event;
156
157 /// JJ2 level player
158 class JJ2LevelPlayer final : public LevelPlayer {
159
160 private:
161 int birds; ///< Placeholder for eventual JJ2Bird objects
162 Anim* anims[JJ2PANIMS]; ///< Animations
163 Anim* flippedAnims[JJ2PANIMS]; ///< Animations (flipped)
164 JJ2Modifier* mod; ///< Modifier currently affecting player
165 int energy; ///< 0 = dead, 3 or 5 = maximum
166 JJ2Shield shield; ///< Current shield
167 int floating; ///< 0 = normal, 1 = helicopter ears, 2 = boarding
168 bool facing; ///< false = left, true = right
169 unsigned char animType; ///< Current animation
170 JJ2PlayerEvent event; ///< Event type
171 int lookTime; ///< Negative if looking up, positive if looking down, 0 if neither
172 JJ2PlayerReaction reaction; ///< Reaction type
173 unsigned int reactionTime; ///< Time reaction will end
174 unsigned int fireTime; ///< The next time the player can fire
175 fixed jumpHeight; ///< The height the player can reach when jumping
176 fixed throwX; ///< Having been thrown, the x-coordinate the player can reach
177 fixed throwY; ///< Having been thrown, the y-coordinate the player can reach
178 unsigned int fastFeetTime; ///< Time fast feet will expire
179 unsigned int stopTime; ///< Time a modifier will cease stopping the player
180 int gems[4]; ///< Gems collected
181 int coins; ///< Value of coins collected
182
183 bool checkMaskDown (fixed yOffset, bool drop);
184 bool checkMaskUp (fixed yOffset);
185
186 void centreX ();
187 void centreY ();
188 void ground ();
189 void modify (JJ2Modifier* nextMod, unsigned int ticks);
190
191 public:
192 JJ2LevelPlayer (Player* parent, Anim** newAnims, Anim** newFlippedAnims, unsigned char startX, unsigned char startY, int flockSize);
193 ~JJ2LevelPlayer ();
194
195 void reset (int startX, int startY) override;
196
197 void addGem (int colour);
198 int countBirds () override;
199 Anim* getAnim ();
200 int getEnemies ();
201 int getEnergy ();
202 bool getFacing ();
203 int getGems (int colour);
204 bool hit (Player* source, unsigned int ticks);
205 void kill (Player* source, unsigned int ticks);
206 bool overlap (fixed left, fixed top, fixed width, fixed height);
207 JJ2PlayerReaction reacted (unsigned int ticks);
208 void setPosition (fixed newX, fixed newY);
209 void setSpeed (fixed newDx, fixed newDy);
210 bool touchEvent (JJ2Event* touched, unsigned int ticks, int msps);
211
212 void send (unsigned char* buffer) override;
213 void receive (unsigned char* buffer) override;
214
215 void control (unsigned int ticks, int msps);
216 void move (unsigned int ticks, int msps);
217 void view (unsigned int ticks, int mspf, int change);
218 void draw (unsigned int ticks, int change);
219
220 };
221
222 #endif
223