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);
202 physic.set_velocity(0, physic.get_velocity_y());
207 // horizontal bounce?
208 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
209 if ( (physic.get_velocity_x() < 0
210 && issolid(base.x, (int) base.y + base.height/2))
211 || (physic.get_velocity_x() > 0
212 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
213 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
214 dir = dir == LEFT ? RIGHT : LEFT;
223 if (base.height < 32)
227 dest.x = (int)(base.x - scroll_x);
228 dest.y = (int)(base.y + 32 - base.height);
230 dest.h = (int)base.height;
232 if (kind == UPGRADE_GROWUP)
233 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
234 else if (kind == UPGRADE_ICEFLOWER)
235 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
236 else if (kind == UPGRADE_HERRING)
237 img_golden_herring->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
238 else if (kind == UPGRADE_1UP)
239 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
243 if (kind == UPGRADE_GROWUP)
246 base.x - scroll_x, base.y);
248 else if (kind == UPGRADE_ICEFLOWER)
251 base.x - scroll_x, base.y);
253 else if (kind == UPGRADE_HERRING)
255 img_golden_herring->draw(
256 base.x - scroll_x, base.y);
258 else if (kind == UPGRADE_1UP)
260 img_1up->draw( base.x - scroll_x, base.y);
266 Upgrade::collision(void* p_c_object, int c_object)
268 Player* pplayer = NULL;
273 /* Remove the upgrade: */
275 /* p_c_object is CO_PLAYER, so assign it to pplayer */
276 pplayer = (Player*) p_c_object;
278 /* Affect the player: */
280 if (kind == UPGRADE_GROWUP)
282 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
284 pplayer->base.height = 64;
285 pplayer->base.y -= 32;
286 if(collision_object_map(&pplayer->base))
288 pplayer->base.height = 32;
289 pplayer->base.y += 32;
290 pplayer->duck = true;
293 else if (kind == UPGRADE_ICEFLOWER)
295 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
296 pplayer->got_coffee = true;
298 else if (kind == UPGRADE_HERRING)
300 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
301 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
302 /* play the herring song ^^ */
303 if (get_current_music() != HURRYUP_MUSIC)
305 set_current_music(HERRING_MUSIC);
306 play_current_music();
309 else if (kind == UPGRADE_1UP)
311 if(pplayer->lives < MAX_LIVES) {
313 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
322 void load_special_gfx()
324 img_growup = new Surface(datadir + "/images/shared/egg.png", USE_ALPHA);
325 img_iceflower = new Surface(datadir + "/images/shared/iceflower.png",
327 img_golden_herring = new Surface(datadir +
328 "/images/shared/star.png", USE_ALPHA);
329 img_1up = new Surface(datadir + "/images/shared/1up.png",
332 img_bullet = new Surface(datadir + "/images/shared/bullet.png",
336 void free_special_gfx()
339 delete img_iceflower;
341 delete img_golden_herring;