Debian Codegraph @

src/jj1/level/jj1bullet.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file jj1bullet.cpp
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created level.c
10 * - 1st January 2006: Created events.c from parts of level.c
11 * - 3rd February 2009: Renamed events.c to events.cpp
12 * - 11th February 2009: Created bullet.cpp from parts of events.cpp
13 * - 1st August 2012: Renamed bullet.cpp to jj1bullet.cpp
14 *
15 * @par Licence:
16 * Copyright (c) 2005-2012 AJ Thomson
17 *
18 * OpenJazz is distributed under the terms of
19 * the GNU General Public License, version 2.0
20 *
21 */
22
23
24 #include "jj1bullet.h"cxx . . $ `<file>/src/jj1/level/jj1bullet.h`/
25 #include "event/jj1event.h"cxx . . $ `<file>/src/jj1/level/event/jj1event.h`/
26 #include "jj1level.h"cxx . . $ `<file>/src/jj1/level/jj1level.h`/
27 #include "jj1bird.h"cxx . . $ `<file>/src/jj1/level/jj1bird.h`/
28 #include "jj1levelplayer.h"cxx . . $ `<file>/src/jj1/level/jj1levelplayer.h`/
29
30 #include "game/game.h"cxx . . $ `<file>/src/game/game.h`/
31 #include "io/gfx/sprite.h"cxx . . $ `<file>/src/io/gfx/sprite.h`/
32 #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/
33 #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/
34
35 #include <stdlib.h>
36
37
38 /**
39 * Generic bullet constructor.
40 *
41 * @param nextBullet The next bullet
42 * @param sourcePlayer The player that fired the bullet (if any)
43 * @param startX The starting x-coordinate of the bullet
44 * @param startY The starting y-coordinate of the bullet
45 * @param bullet Type
46 * @param newDirection The direction of the bullet
47 * @param ticks Time
48 */
49 JJ1Bulletcxx . . $ JJ1Bullet#::JJ1Bulletcxx . . $ JJ1Bullet#JJ1Bullet(a203ab6b566bf851). (JJ1Bulletcxx . . $ JJ1Bullet#* nextBullet, JJ1LevelPlayercxx . . $ JJ1LevelPlayer#* sourcePlayer, fixedcxx . . $ fixed# startX, fixedcxx . . $ fixed# startY, signed char* bullet, int newDirection, unsigned int ticks) {
50
51 nextcxx . . $ JJ1Bullet#next. = nextBullet;
52 sourcecxx . . $ JJ1Bullet#source. = sourcePlayer;
53 setcxx . . $ JJ1Bullet#set. = bullet;
54 directioncxx . . $ JJ1Bullet#direction. = newDirection;
55
56 xcxx . . $ Movable#x. = startX;
57 ycxx . . $ Movable#y. = startY;
58 dxcxx . . $ Movable#dx. = setcxx . . $ JJ1Bullet#set.[B_XSPEEDcxx . . $ `src/jj1/level/jj1bullet.h:37:9`! + directioncxx . . $ JJ1Bullet#direction.] << 18;
59 dycxx . . $ Movable#dy. = setcxx . . $ JJ1Bullet#set.[B_YSPEEDcxx . . $ `src/jj1/level/jj1bullet.h:38:9`! + directioncxx . . $ JJ1Bullet#direction.] << 16;
60
61 if (sourcecxx . . $ JJ1Bullet#source.) {
62
63 if ((newDirection & 1) == 0) {
64
65 if (dxcxx . . $ Movable#dx. > 0) dxcxx . . $ Movable#dx. = -dxcxx . . $ Movable#dx.;
66
67 } else {
68
69 if (dxcxx . . $ Movable#dx. < 0) dxcxx . . $ Movable#dx. = -dxcxx . . $ Movable#dx.;
70
71 }
72
73 if (setcxx . . $ JJ1Bullet#set.[B_BEHAVIOURcxx . . $ `src/jj1/level/jj1bullet.h:42:9`!] == 4) dxcxx . . $ Movable#dx. += sourcecxx . . $ JJ1Bullet#source.->getXSpeedcxx . . $ JJ1LevelPlayer#getXSpeed(b126dc7c1de90089).();
74
75 }
76
77 spritecxx . . $ JJ1Bullet#sprite. = levelcxx . . $ level.->getSpritecxx . . $ JJ1Level#getSprite(a0024ee756d0a8).(reinterpret_cast<unsigned char*>(setcxx . . $ JJ1Bullet#set.)[B_SPRITEcxx . . $ `src/jj1/level/jj1bullet.h:36:9`! + directioncxx . . $ JJ1Bullet#direction.]);
78
79 timecxx . . $ JJ1Bullet#time. = ticks + T_BULLETcxx . . $ `src/jj1/level/jj1bullet.h:47:9`!;
80
81 }
82
83
84 /**
85 * Delete all bullets.
86 */
87 JJ1Bulletcxx . . $ JJ1Bullet#::~cxx . . $ JJ1Bullet#`~JJ1Bullet`(49f6e7a06ebc5aa8).JJ1Bulletcxx . . $ JJ1Bullet# () {
88
89 if (nextcxx . . $ JJ1Bullet#next.) delete nextcxx . . $ JJ1Bullet#next.;
90
91 }
92
93
94 /**
95 * Delete this bullet.
96 *
97 * @return The next bullet
98 */
99 JJ1Bulletcxx . . $ JJ1Bullet#* JJ1Bulletcxx . . $ JJ1Bullet#::removecxx . . $ JJ1Bullet#remove(f6cadfcf90bd3d3b). () {
100
101 JJ1Bulletcxx . . $ JJ1Bullet#* oldNext;
102
103 oldNext = nextcxx . . $ JJ1Bullet#next.;
104 nextcxx . . $ JJ1Bullet#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
105 delete this;
106
107 return oldNext;
108
109 }
110
111
112 /**
113 * Get the player responsible for this bullet.
114 *
115 * @return The player (NULL if fired by an event)
116 */
117 JJ1LevelPlayercxx . . $ JJ1LevelPlayer#* JJ1Bulletcxx . . $ JJ1Bullet#::getSourcecxx . . $ JJ1Bullet#getSource(cf23ec4c0d6db922). () {
118
119 return sourcecxx . . $ JJ1Bullet#source.;
120
121 }
122
123
124 /**
125 * Bullet iteration.
126 *
127 * @param ticks Time
128 *
129 * @return Remaining bullet
130 */
131 JJ1Bulletcxx . . $ JJ1Bullet#* JJ1Bulletcxx . . $ JJ1Bullet#::stepcxx . . $ JJ1Bullet#step(c90693087d4d5c05). (unsigned int ticks) {
132
133 // Process the next bullet
134 if (nextcxx . . $ JJ1Bullet#next.) nextcxx . . $ JJ1Bullet#next. = nextcxx . . $ JJ1Bullet#next.->stepcxx . . $ JJ1Bullet#step(c90693087d4d5c05).(ticks);
135
136
137 if (levelcxx . . $ level.->getStagecxx . . $ Level#getStage(5189a4c765e66121).() != LS_ENDcxx . . $ LS_END.) {
138
139 // If the time has expired, destroy the bullet
140 if (ticks > timecxx . . $ JJ1Bullet#time.) return removecxx . . $ JJ1Bullet#remove(f6cadfcf90bd3d3b).();
141
142
143 // Check if a player has been hit
144 for (int i = 0; i < nPlayerscxx . . $ nPlayers.; i++) {
145
146 if (playerscxx . . $ players.[i].getJJ1LevelPlayercxx . . $ Player#getJJ1LevelPlayer(cf23ec4c0d6db922).()->overlapcxx . . $ JJ1LevelPlayer#overlap(a1642a0ee405ca20).(xcxx . . $ Movable#x., ycxx . . $ Movable#y.,
147 ITOFcxx . . $ `src/types.h:53:9`!(sprite->getWidth()), ITOFcxx . . $ `src/types.h:53:9`!(sprite->getHeight()))) {
148
149 // If the hit was successful, destroy the bullet
150 if (playerscxx . . $ players.[i].getJJ1LevelPlayercxx . . $ Player#getJJ1LevelPlayer(cf23ec4c0d6db922).()->hitcxx . . $ JJ1LevelPlayer#hit(4e7745a556f6f965).(sourcecxx . . $ JJ1Bullet#source.? sourcecxx . . $ JJ1Bullet#source.->playercxx . . $ LevelPlayer#player.: NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, ticks)) return removecxx . . $ JJ1Bullet#remove(f6cadfcf90bd3d3b).();
151
152 }
153
154 }
155
156
157 if (sourcecxx . . $ JJ1Bullet#source.) {
158
159 // Check if an event has been hit
160
161 JJ1Eventcxx . . $ JJ1Event#* event = levelcxx . . $ level.->getEventscxx . . $ JJ1Level#getEvents(31caec775bb17100).();
162
163 while (event) {
164
165 // Check if the event has been hit
166 if (event->overlapcxx . . $ JJ1Event#overlap(a1642a0ee405ca20).(xcxx . . $ Movable#x., ycxx . . $ Movable#y.,
167 ITOFcxx . . $ `src/types.h:53:9`!(sprite->getWidth()), ITOFcxx . . $ `src/types.h:53:9`!(sprite->getHeight()))) {
168
169 // If the event is hittable, hit it and destroy the bullet
170 if (event->hitcxx . . $ JJ1Event#hit(a041df1a1d9c3254).(sourcecxx . . $ JJ1Bullet#source., 1, ticks)) return removecxx . . $ JJ1Bullet#remove(f6cadfcf90bd3d3b).();
171
172 }
173
174 event = event->getNextcxx . . $ JJ1Event#getNext(31caec775bb17100).();
175
176 }
177
178 }
179
180
181 }
182
183
184 // If the scenery has been hit and this is not a bouncer, destroy the bullet
185 if (levelcxx . . $ level.->checkMaskUpcxx . . $ JJ1Level#checkMaskUp(cf9ef193275fa6d8).(xcxx . . $ Movable#x., ycxx . . $ Movable#y.) && (setcxx . . $ JJ1Bullet#set.[B_BEHAVIOURcxx . . $ `src/jj1/level/jj1bullet.h:42:9`!] != 4)) {
186
187 // FIXME: rewrite "set"
188 auto se = static_cast<SEcxx . . $ SE/::Typecxx . . $ SE/Type#>(setcxx . . $ JJ1Bullet#set.[B_FINISHSOUNDcxx . . $ `src/jj1/level/jj1bullet.h:41:9`!]);
189 playSoundcxx . . $ playSound(80b838f98135e5b).(se);
190
191 return removecxx . . $ JJ1Bullet#remove(f6cadfcf90bd3d3b).();
192
193 }
194
195
196 // Calculate trajectory
197 if (setcxx . . $ JJ1Bullet#set.[B_BEHAVIOURcxx . . $ `src/jj1/level/jj1bullet.h:42:9`!] == 4) {
198
199 if (levelcxx . . $ level.->checkMaskDowncxx . . $ JJ1Level#checkMaskDown(cf9ef193275fa6d8).(xcxx . . $ Movable#x., ycxx . . $ Movable#y. - F1cxx . . $ `src/types.h:31:9`!)) {
200
201 // Bounce the bullet away from a vertical surface
202 if (dxcxx . . $ Movable#dx. < 0) directioncxx . . $ JJ1Bullet#direction. |= 1;
203 else directioncxx . . $ JJ1Bullet#direction. &= ~1;
204
205 dxcxx . . $ Movable#dx. = -dxcxx . . $ Movable#dx.;
206 dycxx . . $ Movable#dy. = 0;
207
208 }
209
210 if (levelcxx . . $ level.->checkMaskDowncxx . . $ JJ1Level#checkMaskDown(cf9ef193275fa6d8).(xcxx . . $ Movable#x., ycxx . . $ Movable#y. + (dycxx . . $ Movable#dy. >> 6) - F1cxx . . $ `src/types.h:31:9`!)) {
211
212 // Bounce the bullet against a horizontal surface
213 if (dycxx . . $ Movable#dy. < 0) dycxx . . $ Movable#dy. = 0;
214 else dycxx . . $ Movable#dy. = -dycxx . . $ Movable#dy. - (abscxx . . $ abs(7864480464b09eea).(dxcxx . . $ Movable#dx. - (setcxx . . $ JJ1Bullet#set.[B_XSPEEDcxx . . $ `src/jj1/level/jj1bullet.h:37:9`! + directioncxx . . $ JJ1Bullet#direction.] << 18)) >> 1);
215
216 } else {
217
218 // Respond to gravity
219 dycxx . . $ Movable#dy. += F32cxx . . $ `src/types.h:40:9`! * setcxx . . $ JJ1Bullet#set.[B_GRAVITYcxx . . $ `src/jj1/level/jj1bullet.h:39:9`!];
220
221 }
222
223 } else {
224
225 dycxx . . $ Movable#dy. += F32cxx . . $ `src/types.h:40:9`! * setcxx . . $ JJ1Bullet#set.[B_GRAVITYcxx . . $ `src/jj1/level/jj1bullet.h:39:9`!];
226
227 if (sourcecxx . . $ JJ1Bullet#source. && (abscxx . . $ abs(7864480464b09eea).(sourcecxx . . $ JJ1Bullet#source.->getXSpeedcxx . . $ JJ1LevelPlayer#getXSpeed(b126dc7c1de90089).() + dxcxx . . $ Movable#dx.) > abscxx . . $ abs(7864480464b09eea).(dxcxx . . $ Movable#dx.))) {
228
229 xcxx . . $ Movable#x. += sourcecxx . . $ JJ1Bullet#source.->getXSpeedcxx . . $ JJ1LevelPlayer#getXSpeed(b126dc7c1de90089).() >> 6;
230
231 }
232
233 }
234
235
236 // Apply trajectory
237 xcxx . . $ Movable#x. += dxcxx . . $ Movable#dx. >> 6;
238 ycxx . . $ Movable#y. += dycxx . . $ Movable#dy. >> 6;
239
240
241 // Do not destroy the bullet
242 return this;
243
244 }
245
246
247 /**
248 * Draw the bullet.
249 *
250 * @param change Time since last iteration
251 */
252 void JJ1Bulletcxx . . $ JJ1Bullet#::drawcxx . . $ JJ1Bullet#draw(d4f767463ce0a6b3). (int change) {
253
254 if (nextcxx . . $ JJ1Bullet#next.) nextcxx . . $ JJ1Bullet#next.->drawcxx . . $ JJ1Bullet#draw(d4f767463ce0a6b3).(change);
255
256 // Show the bullet
257 spritecxx . . $ JJ1Bullet#sprite.->drawcxx . . $ Sprite#draw(6908015b96d379c0).(FTOIcxx . . $ `src/types.h:52:9`!(getDrawX(change)), FTOIcxx . . $ `src/types.h:52:9`!(getDrawY(change)), false);
258
259 }