From 902a1a1fe3dc37b1ce6e63f35ee93e735009e87a Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 12 May 2004 17:56:34 +0000 Subject: [PATCH] First implementation of the ice power. SVN-Revision: 1136 --- src/badguy.cpp | 12 +++++++++++- src/badguy.h | 1 + src/defines.h | 4 +++- src/gameloop.cpp | 6 +++++- src/player.cpp | 15 +++++++++------ src/player.h | 4 +++- src/resources.cpp | 16 ++++++++++++++++ src/special.cpp | 27 +++++++++++++++++++++------ src/special.h | 10 +++++++++- src/world.cpp | 19 +++++++++++++++---- src/worldmap.cpp | 3 ++- 11 files changed, 95 insertions(+), 22 deletions(-) diff --git a/src/badguy.cpp b/src/badguy.cpp index ab515b5d6..5241e2acf 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -151,6 +151,7 @@ BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_) old_base = base; dir = LEFT; seen = false; + frozen_timer.init(true); animation_offset = 0; sprite_left = sprite_right = 0; physic.reset(); @@ -683,6 +684,9 @@ BadGuy::action(double frame_ratio) if(!seen) return; + if(frozen_timer.check()) + return; + switch (kind) { case BAD_MRICEBLOCK: @@ -939,6 +943,7 @@ void BadGuy::collision(void *p_c_object, int c_object, CollisionType type) { BadGuy* pbad_c = NULL; + Bullet* pbullet_c = NULL; if(type == COLLISION_BUMP) { bump(); @@ -955,7 +960,12 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) switch (c_object) { case CO_BULLET: - kill_me(10); + pbullet_c = (Bullet*) p_c_object; + + if(pbullet_c->kind == FIRE_BULLET) + kill_me(10); + else if(pbullet_c->kind == ICE_BULLET) + frozen_timer.start(FROZEN_TIME); break; case CO_BADGUY: diff --git a/src/badguy.h b/src/badguy.h index caaa8e99c..87b03fee7 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -96,6 +96,7 @@ private: bool removable; bool seen; int squishcount; /// number of times this enemy was squiched + Timer frozen_timer; // gets frozen when a ice shot hits it Timer timer; Physic physic; diff --git a/src/defines.h b/src/defines.h index 616fcee38..3079638f2 100644 --- a/src/defines.h +++ b/src/defines.h @@ -69,7 +69,9 @@ enum DyingType { #define START_LIVES 4 -#define MAX_BULLETS 2 +#define MAX_FIRE_BULLETS 2 +#define MAX_ICE_BULLETS 1 +#define FROZEN_TIME 3000 #define YM_FOR_JUMP 6.0 #define WALK_ACCELERATION_X 0.03 diff --git a/src/gameloop.cpp b/src/gameloop.cpp index e2c44b9f0..9c52c9f10 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -343,7 +343,11 @@ GameSession::process_events() break; case SDLK_DELETE: if(debug_mode) - tux.got_coffee = 1; + tux.got_power = tux.FIRE_POWER; + break; + case SDLK_HOME: + if(debug_mode) + tux.got_power = tux.ICE_POWER; break; case SDLK_INSERT: if(debug_mode) diff --git a/src/player.cpp b/src/player.cpp index ac5018fb9..873445799 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -37,6 +37,7 @@ Sprite* largetux_star; PlayerSprite smalltux; PlayerSprite largetux; +PlayerSprite icetux; PlayerSprite firetux; PlayerKeymap keymap; @@ -72,7 +73,7 @@ Player::init() base.height = 32; size = SMALL; - got_coffee = false; + got_power = NONE_POWER; base.x = plevel->start_pos_x; base.y = plevel->start_pos_y; @@ -453,7 +454,7 @@ Player::handle_input() /* Shoot! */ - if (input.fire == DOWN && input.old_fire == UP && got_coffee) + if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER) { World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir); input.old_fire = DOWN; @@ -559,8 +560,10 @@ Player::draw() if (size == SMALL) sprite = &smalltux; - else if (got_coffee) + else if (got_power == FIRE_POWER) sprite = &firetux; + else if (got_power == ICE_POWER) + sprite = &icetux; else sprite = &largetux; @@ -709,9 +712,9 @@ Player::kill(HurtMode mode) if (mode == SHRINK && size == BIG) { - if (got_coffee) + if (got_power != NONE_POWER) { - got_coffee = false; + got_power = NONE_POWER; } else { @@ -751,7 +754,7 @@ bool Player::is_dead() void Player::remove_powerups() { - got_coffee = false; + got_power = NONE_POWER; size = SMALL; base.height = 32; } diff --git a/src/player.h b/src/player.h index 0f87dba64..da36ef8c2 100644 --- a/src/player.h +++ b/src/player.h @@ -103,14 +103,16 @@ struct PlayerSprite extern PlayerSprite smalltux; extern PlayerSprite largetux; extern PlayerSprite firetux; +extern PlayerSprite icetux; class Player : public GameObject { public: enum HurtMode { KILL, SHRINK }; + enum Power { NONE_POWER, FIRE_POWER, ICE_POWER }; player_input_type input; - bool got_coffee; + int got_power; int size; bool duck; bool holding_something; diff --git a/src/resources.cpp b/src/resources.cpp index 60f6799f8..cdef725a5 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -97,6 +97,22 @@ void loadshared() firetux.duck_left = sprite_manager->load("firetux-duck-left"); firetux.duck_right = sprite_manager->load("firetux-duck-right"); + icetux.stand_left = sprite_manager->load("icetux-stand-left"); + icetux.stand_right = sprite_manager->load("icetux-stand-right"); + icetux.walk_left = sprite_manager->load("icetux-walk-left"); + icetux.walk_right = sprite_manager->load("icetux-walk-right"); + icetux.jump_left = sprite_manager->load("icetux-jump-left"); + icetux.jump_right = sprite_manager->load("icetux-jump-right"); + icetux.kick_left = sprite_manager->load("icetux-kick-left"); + icetux.kick_right = sprite_manager->load("icetux-kick-right"); + icetux.skid_right = sprite_manager->load("icetux-skid-right"); + icetux.skid_left = sprite_manager->load("icetux-skid-left"); + icetux.grab_left = sprite_manager->load("icetux-grab-left"); + icetux.grab_right = sprite_manager->load("icetux-grab-right"); + icetux.duck_left = sprite_manager->load("icetux-duck-left"); + icetux.duck_right = sprite_manager->load("icetux-duck-right"); + + /* Water: */ img_water = new Surface(datadir + "/images/shared/water.png", IGNORE_ALPHA); diff --git a/src/special.cpp b/src/special.cpp index a4da6d36f..68cfb8550 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -31,7 +31,8 @@ #include "sprite_manager.h" #include "resources.h" -Sprite* img_bullet; +Sprite* img_firebullet; +Sprite* img_icebullet; Sprite* img_star; Sprite* img_growup; Sprite* img_iceflower; @@ -43,7 +44,7 @@ Sprite* img_1up; #define BULLET_XM 6 void -Bullet::init(float x, float y, float xm, Direction dir) +Bullet::init(float x, float y, float xm, Direction dir, int kind_) { life_count = 3; base.width = 4; @@ -63,6 +64,7 @@ Bullet::init(float x, float y, float xm, Direction dir) base.y = y; base.ym = BULLET_STARTING_YM; old_base = base; + kind = kind_; } void @@ -103,7 +105,10 @@ Bullet::action(double frame_ratio) life_count -= 1; } - base.ym = base.ym + 0.5 * frame_ratio; + if(kind == FIRE_BULLET) + base.ym = base.ym + 0.5 * frame_ratio; + else if(kind == FIRE_BULLET) + base.ym = 0; if (base.x < scroll_x || base.x > scroll_x + screen->w || @@ -123,7 +128,10 @@ Bullet::draw() if (base.x >= scroll_x - base.width && base.x <= scroll_x + screen->w) { - img_bullet->draw(base.x, base.y); + if(kind == FIRE_BULLET) + img_firebullet->draw(base.x, base.y); + else if(kind == FIRE_BULLET) + img_icebullet->draw(base.x, base.y); } } @@ -333,11 +341,17 @@ Upgrade::collision(void* p_c_object, int c_object, CollisionType type) play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER); pplayer->grow(); } + else if (kind == UPGRADE_FIREFLOWER) + { + play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER); + pplayer->grow(); + pplayer->got_power = pplayer->FIRE_POWER; + } else if (kind == UPGRADE_ICEFLOWER) { play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER); pplayer->grow(); - pplayer->got_coffee = true; + pplayer->got_power = pplayer->ICE_POWER; } else if (kind == UPGRADE_HERRING) { @@ -365,7 +379,8 @@ void load_special_gfx() img_star = sprite_manager->load("star"); img_1up = sprite_manager->load("1up"); - img_bullet = sprite_manager->load("bullet"); + img_firebullet = sprite_manager->load("firebullet"); + img_icebullet = sprite_manager->load("icebullet"); } void free_special_gfx() diff --git a/src/special.h b/src/special.h index 24ce8c21c..a28c7421f 100644 --- a/src/special.h +++ b/src/special.h @@ -32,6 +32,7 @@ enum UpgradeKind { UPGRADE_GROWUP, + UPGRADE_FIREFLOWER, UPGRADE_ICEFLOWER, UPGRADE_HERRING, UPGRADE_1UP @@ -65,14 +66,21 @@ private: void bump(Player* player); }; +enum BulletsKind { + FIRE_BULLET, + ICE_BULLET +}; + class Bullet : public GameObject { public: int life_count; base_type base; base_type old_base; + + int kind; - void init(float x, float y, float xm, Direction dir); + void init(float x, float y, float xm, Direction dir, int kind_); void action(double frame_ratio); void draw(); void collision(int c_object); diff --git a/src/world.cpp b/src/world.cpp index da3774c78..daa399b88 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -89,7 +89,7 @@ World::apply_bonuses() break; case PlayerStatus::FLOWER_BONUS: - tux.got_coffee = true; + tux.got_power = tux.FIRE_POWER; // FIXME: add ice power to here // fall through case PlayerStatus::GROWUP_BONUS: @@ -546,11 +546,22 @@ World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind) void World::add_bullet(float x, float y, float xm, Direction dir) { - if(bullets.size() > MAX_BULLETS-1) - return; + if(tux.got_power == tux.FIRE_POWER) + { + if(bullets.size() > MAX_FIRE_BULLETS-1) + return; + } + else if(tux.got_power == tux.ICE_POWER) + { + if(bullets.size() > MAX_ICE_BULLETS-1) + return; + } Bullet new_bullet; - new_bullet.init(x,y,xm,dir); + if(tux.got_power == tux.FIRE_POWER) + new_bullet.init(x,y,xm,dir, FIRE_BULLET); + else if(tux.got_power == tux.ICE_POWER) + new_bullet.init(x,y,xm,dir, ICE_BULLET); bullets.push_back(new_bullet); play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 30d988273..17cb39d7f 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -648,7 +648,8 @@ WorldMap::update(float delta) bool old_level_state = level->solved; level->solved = true; - if (session.get_world()->get_tux()->got_coffee) + if (session.get_world()->get_tux()->got_power != + session.get_world()->get_tux()->NONE_POWER) player_status.bonus = PlayerStatus::FLOWER_BONUS; else if (session.get_world()->get_tux()->size == BIG) player_status.bonus = PlayerStatus::GROWUP_BONUS; -- 2.11.0