2 // C Implementation: special
7 // Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
23 #include "resources.h"
26 Surface* img_golden_herring;
28 Surface* img_iceflower;
31 #define GROWUP_SPEED 1.0f
34 Bullet::init(float x, float y, float xm, int dir)
42 base.xm = BULLET_XM + xm;
47 base.xm = -BULLET_XM + xm;
51 base.ym = BULLET_STARTING_YM;
58 std::vector<Bullet>& bullets = World::current()->bullets;
59 for(std::vector<Bullet>::iterator i = bullets.begin();
60 i != bullets.end(); ++i) {
71 Bullet::action(double frame_ratio)
73 base.x = base.x + base.xm * frame_ratio;
74 base.y = base.y + base.ym * frame_ratio;
76 collision_swept_object_map(&old_base,&base);
78 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
81 base.y = (int)(base.y / 32) * 32;
84 base.ym = base.ym + GRAVITY;
86 if (base.x < scroll_x ||
87 base.x > scroll_x + screen->w ||
90 issolid(base.x + 4, base.y + 2) ||
91 issolid(base.x, base.y + 2))
101 if (base.x >= scroll_x - base.width &&
102 base.x <= scroll_x + screen->w)
104 img_bullet->draw( base.x - scroll_x, base.y, 255,
110 Bullet::collision(int c_object)
112 if(c_object == CO_BADGUY) {
118 Upgrade::init(float x_, float y_, int dir_, UpgradeKind kind_)
130 physic.enable_gravity(false);
132 if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
133 physic.set_velocity(dir == LEFT ? -1 : 1, 4);
134 physic.enable_gravity(true);
136 } else if (kind == UPGRADE_ICEFLOWER) {
138 } else if (kind == UPGRADE_GROWUP) {
139 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
141 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
148 std::vector<Upgrade>& upgrades = World::current()->upgrades;
149 for(std::vector<Upgrade>::iterator i = upgrades.begin();
150 i != upgrades.end(); ++i) {
151 if( & (*i) == this) {
161 Upgrade::action(double frame_ratio)
163 if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
164 if (base.height < 32) {
166 base.height = base.height + 0.7 * frame_ratio;
174 /* Off screen? Kill it! */
175 if(base.x < scroll_x - base.width || base.y > screen->h) {
181 physic.apply(frame_ratio, base.x, base.y);
182 if(kind == UPGRADE_GROWUP) {
183 collision_swept_object_map(&old_base, &base);
187 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
189 if(physic.get_velocity_y() != 0) {
190 if(issolid(base.x, base.y + base.height)) {
191 base.y = int(base.y / 32) * 32;
193 if(kind == UPGRADE_GROWUP) {
194 physic.enable_gravity(false);
195 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
196 } else if(kind == UPGRADE_HERRING) {
197 physic.set_velocity(dir == LEFT ? -2 : 2, 3);
201 if((physic.get_velocity_x() < 0
202 && !issolid(base.x+base.width, base.y + base.height))
203 || (physic.get_velocity_x() > 0
204 && !issolid(base.x, base.y + base.height))) {
205 physic.enable_gravity(true);
210 // horizontal bounce?
211 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
212 if ( (physic.get_velocity_x() < 0
213 && issolid(base.x, (int) base.y + base.height/2))
214 || (physic.get_velocity_x() > 0
215 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
216 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
217 dir = dir == LEFT ? RIGHT : LEFT;
226 if (base.height < 32)
230 dest.x = (int)(base.x - scroll_x);
231 dest.y = (int)(base.y + 32 - base.height);
233 dest.h = (int)base.height;
235 if (kind == UPGRADE_GROWUP)
236 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
237 else if (kind == UPGRADE_ICEFLOWER)
238 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
239 else if (kind == UPGRADE_HERRING)
240 img_golden_herring->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
241 else if (kind == UPGRADE_1UP)
242 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
246 if (kind == UPGRADE_GROWUP)
249 base.x - scroll_x, base.y);
251 else if (kind == UPGRADE_ICEFLOWER)
254 base.x - scroll_x, base.y);
256 else if (kind == UPGRADE_HERRING)
258 img_golden_herring->draw(
259 base.x - scroll_x, base.y);
261 else if (kind == UPGRADE_1UP)
263 img_1up->draw( base.x - scroll_x, base.y);
269 Upgrade::collision(void* p_c_object, int c_object)
271 Player* pplayer = NULL;
276 /* Remove the upgrade: */
278 /* p_c_object is CO_PLAYER, so assign it to pplayer */
279 pplayer = (Player*) p_c_object;
281 /* Affect the player: */
283 if (kind == UPGRADE_GROWUP)
285 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
287 pplayer->base.height = 64;
288 pplayer->base.y -= 32;
289 if(collision_object_map(&pplayer->base))
291 pplayer->base.height = 32;
292 pplayer->base.y += 32;
293 pplayer->duck = true;
296 else if (kind == UPGRADE_ICEFLOWER)
298 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
299 pplayer->got_coffee = true;
301 else if (kind == UPGRADE_HERRING)
303 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
304 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
305 /* play the herring song ^^ */
306 if (get_current_music() != HURRYUP_MUSIC)
308 set_current_music(HERRING_MUSIC);
309 play_current_music();
312 else if (kind == UPGRADE_1UP)
314 if(player_status.lives < MAX_LIVES) {
315 player_status.lives++;
316 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
325 void load_special_gfx()
327 img_growup = new Surface(datadir + "/images/shared/egg.png", USE_ALPHA);
328 img_iceflower = new Surface(datadir + "/images/shared/iceflower.png",
330 img_golden_herring = new Surface(datadir + "/images/shared/star.png", USE_ALPHA);
331 img_1up = new Surface(datadir + "/images/shared/1up.png",
334 img_bullet = new Surface(datadir + "/images/shared/bullet.png",
338 void free_special_gfx()
341 delete img_iceflower;
343 delete img_golden_herring;