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;
32 Bullet::init(float x, float y, float xm, int dir)
40 base.xm = BULLET_XM + xm;
45 base.xm = -BULLET_XM + xm;
49 base.ym = BULLET_STARTING_YM;
56 std::vector<Bullet>& bullets = World::current()->bullets;
57 for(std::vector<Bullet>::iterator i = bullets.begin();
58 i != bullets.end(); ++i) {
69 Bullet::action(double frame_ratio)
71 base.x = base.x + base.xm * frame_ratio;
72 base.y = base.y + base.ym * frame_ratio;
74 collision_swept_object_map(&old_base,&base);
76 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
79 base.y = (int)(base.y / 32) * 32;
82 base.ym = base.ym + GRAVITY;
84 if (base.x < scroll_x ||
85 base.x > scroll_x + screen->w ||
88 issolid(base.x + 4, base.y + 2) ||
89 issolid(base.x, base.y + 2))
99 if (base.x >= scroll_x - base.width &&
100 base.x <= scroll_x + screen->w)
102 img_bullet->draw( base.x - scroll_x, base.y, 255,
108 Bullet::collision(int c_object)
110 if(c_object == CO_BADGUY) {
116 Upgrade::init(float x_, float y_, int dir_, int kind_)
128 physic.enable_gravity(false);
130 if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
131 physic.set_velocity(dir == LEFT ? -1 : 1, 4);
132 physic.enable_gravity(true);
134 } else if (kind == UPGRADE_ICEFLOWER) {
137 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
144 std::vector<Upgrade>& upgrades = World::current()->upgrades;
145 for(std::vector<Upgrade>::iterator i = upgrades.begin();
146 i != upgrades.end(); ++i) {
147 if( & (*i) == this) {
157 Upgrade::action(double frame_ratio)
159 if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
160 if (base.height < 32) {
162 base.height = base.height + 0.7 * frame_ratio;
170 /* Off screen? Kill it! */
171 if(base.x < scroll_x - base.width || base.y > screen->h) {
177 physic.apply(frame_ratio, base.x, base.y);
178 if(kind == UPGRADE_GROWUP) {
179 collision_swept_object_map(&old_base, &base);
183 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
185 if(physic.get_velocity_y() != 0) {
186 if(issolid(base.x, base.y + base.height)) {
187 base.y = int(base.y / 32) * 32;
189 if(kind == UPGRADE_GROWUP) {
190 physic.enable_gravity(false);
191 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
192 } else if(kind == UPGRADE_HERRING) {
193 physic.set_velocity(dir == LEFT ? -2 : 2, 3);
197 if((physic.get_velocity_x() < 0
198 && !issolid(base.x+base.width, base.y + base.height))
199 || (physic.get_velocity_x() > 0
200 && !issolid(base.x, base.y + base.height))) {
201 physic.enable_gravity(true);
206 // horizontal bounce?
207 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
208 if ( (physic.get_velocity_x() < 0
209 && issolid(base.x, (int) base.y + base.height/2))
210 || (physic.get_velocity_x() > 0
211 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
212 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
213 dir = dir == LEFT ? RIGHT : LEFT;
222 if (base.height < 32)
226 dest.x = (int)(base.x - scroll_x);
227 dest.y = (int)(base.y + 32 - base.height);
229 dest.h = (int)base.height;
231 if (kind == UPGRADE_GROWUP)
232 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
233 else if (kind == UPGRADE_ICEFLOWER)
234 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
235 else if (kind == UPGRADE_HERRING)
236 img_golden_herring->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
237 else if (kind == UPGRADE_1UP)
238 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
242 if (kind == UPGRADE_GROWUP)
245 base.x - scroll_x, base.y);
247 else if (kind == UPGRADE_ICEFLOWER)
250 base.x - scroll_x, base.y);
252 else if (kind == UPGRADE_HERRING)
254 img_golden_herring->draw(
255 base.x - scroll_x, base.y);
257 else if (kind == UPGRADE_1UP)
259 img_1up->draw( base.x - scroll_x, base.y);
265 Upgrade::collision(void* p_c_object, int c_object)
267 Player* pplayer = NULL;
272 /* Remove the upgrade: */
274 /* p_c_object is CO_PLAYER, so assign it to pplayer */
275 pplayer = (Player*) p_c_object;
277 /* Affect the player: */
279 if (kind == UPGRADE_GROWUP)
281 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
283 pplayer->base.height = 64;
284 pplayer->base.y -= 32;
285 if(collision_object_map(&pplayer->base))
287 pplayer->base.height = 32;
288 pplayer->base.y += 32;
289 pplayer->duck = true;
292 else if (kind == UPGRADE_ICEFLOWER)
294 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
295 pplayer->got_coffee = true;
297 else if (kind == UPGRADE_HERRING)
299 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
300 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
301 /* play the herring song ^^ */
302 if (get_current_music() != HURRYUP_MUSIC)
304 set_current_music(HERRING_MUSIC);
305 play_current_music();
308 else if (kind == UPGRADE_1UP)
310 if(player_status.lives < MAX_LIVES) {
311 player_status.lives++;
312 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
321 void load_special_gfx()
323 img_growup = new Surface(datadir + "/images/shared/egg.png", USE_ALPHA);
324 img_iceflower = new Surface(datadir + "/images/shared/iceflower.png",
326 img_golden_herring = new Surface(datadir +
327 "/images/shared/star.png", USE_ALPHA);
328 img_1up = new Surface(datadir + "/images/shared/1up.png",
331 img_bullet = new Surface(datadir + "/images/shared/bullet.png",
335 void free_special_gfx()
338 delete img_iceflower;
340 delete img_golden_herring;