3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "sprite_manager.h"
31 #include "resources.h"
37 Sprite* img_iceflower;
40 #define GROWUP_SPEED 1.0f
43 Bullet::init(float x, float y, float xm, int dir)
51 base.xm = BULLET_XM + xm;
56 base.xm = -BULLET_XM + xm;
60 base.ym = BULLET_STARTING_YM;
67 std::vector<Bullet>& bullets = World::current()->bullets;
68 for(std::vector<Bullet>::iterator i = bullets.begin();
69 i != bullets.end(); ++i) {
80 Bullet::action(double frame_ratio)
82 base.x = base.x + base.xm * frame_ratio;
83 base.y = base.y + base.ym * frame_ratio;
85 collision_swept_object_map(&old_base,&base);
87 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
90 base.y = (int)(base.y / 32) * 32;
93 base.ym = base.ym + GRAVITY;
95 if (base.x < scroll_x ||
96 base.x > scroll_x + screen->w ||
99 issolid(base.x + 4, base.y + 2) ||
100 issolid(base.x, base.y + 2))
110 if (base.x >= scroll_x - base.width &&
111 base.x <= scroll_x + screen->w)
113 img_bullet->draw( base.x - scroll_x, base.y, 255,
119 Bullet::collision(int c_object)
121 if(c_object == CO_BADGUY) {
127 Upgrade::init(float x_, float y_, int dir_, UpgradeKind kind_)
139 physic.enable_gravity(false);
141 if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
142 physic.set_velocity(dir == LEFT ? -1 : 1, 4);
143 physic.enable_gravity(true);
145 } else if (kind == UPGRADE_ICEFLOWER) {
147 } else if (kind == UPGRADE_GROWUP) {
148 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
150 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
157 std::vector<Upgrade>& upgrades = World::current()->upgrades;
158 for(std::vector<Upgrade>::iterator i = upgrades.begin();
159 i != upgrades.end(); ++i) {
160 if( & (*i) == this) {
170 Upgrade::action(double frame_ratio)
172 if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
173 if (base.height < 32) {
175 base.height = base.height + 0.7 * frame_ratio;
183 /* Off screen? Kill it! */
184 if(base.x < scroll_x - base.width || base.y > screen->h) {
190 physic.apply(frame_ratio, base.x, base.y);
191 if(kind == UPGRADE_GROWUP) {
192 collision_swept_object_map(&old_base, &base);
196 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
198 if(physic.get_velocity_y() != 0) {
199 if(issolid(base.x, base.y + base.height)) {
200 base.y = int(base.y / 32) * 32;
202 if(kind == UPGRADE_GROWUP) {
203 physic.enable_gravity(false);
204 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
205 } else if(kind == UPGRADE_HERRING) {
206 physic.set_velocity(dir == LEFT ? -2 : 2, 3);
210 if((physic.get_velocity_x() < 0
211 && !issolid(base.x+base.width, base.y + base.height))
212 || (physic.get_velocity_x() > 0
213 && !issolid(base.x, base.y + base.height))) {
214 physic.enable_gravity(true);
219 // horizontal bounce?
220 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
221 if ( (physic.get_velocity_x() < 0
222 && issolid(base.x, (int) base.y + base.height/2))
223 || (physic.get_velocity_x() > 0
224 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
225 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
226 dir = dir == LEFT ? RIGHT : LEFT;
235 if (base.height < 32)
239 dest.x = (int)(base.x - scroll_x);
240 dest.y = (int)(base.y + 32 - base.height);
242 dest.h = (int)base.height;
244 if (kind == UPGRADE_GROWUP)
245 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
246 else if (kind == UPGRADE_ICEFLOWER)
247 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
248 else if (kind == UPGRADE_HERRING)
249 img_star->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
250 else if (kind == UPGRADE_1UP)
251 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
255 if (kind == UPGRADE_GROWUP)
258 base.x - scroll_x, base.y);
260 else if (kind == UPGRADE_ICEFLOWER)
263 base.x - scroll_x, base.y);
265 else if (kind == UPGRADE_HERRING)
268 base.x - scroll_x, base.y);
270 else if (kind == UPGRADE_1UP)
272 img_1up->draw( base.x - scroll_x, base.y);
278 Upgrade::collision(void* p_c_object, int c_object)
280 Player* pplayer = NULL;
285 /* Remove the upgrade: */
287 /* p_c_object is CO_PLAYER, so assign it to pplayer */
288 pplayer = (Player*) p_c_object;
290 /* Affect the player: */
292 if (kind == UPGRADE_GROWUP)
294 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
296 pplayer->base.height = 64;
297 pplayer->base.y -= 32;
298 if(collision_object_map(&pplayer->base))
300 pplayer->base.height = 32;
301 pplayer->base.y += 32;
302 pplayer->duck = true;
305 else if (kind == UPGRADE_ICEFLOWER)
307 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
308 pplayer->got_coffee = true;
310 else if (kind == UPGRADE_HERRING)
312 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
313 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
314 /* play the herring song ^^ */
315 if (get_current_music() != HURRYUP_MUSIC)
317 set_current_music(HERRING_MUSIC);
318 play_current_music();
321 else if (kind == UPGRADE_1UP)
323 if(player_status.lives < MAX_LIVES) {
324 player_status.lives++;
325 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
334 void load_special_gfx()
336 img_growup = sprite_manager->load("egg");
337 img_iceflower = sprite_manager->load("iceflower");
338 img_star = sprite_manager->load("star");
339 img_1up = sprite_manager->load("1up");
341 img_bullet = new Surface(datadir + "/images/shared/bullet.png",
345 void free_special_gfx()