#include "app/gettext.h"
#include "special/sprite_manager.h"
#include "player.h"
-#include "defines.h"
-#include "scene.h"
#include "tile.h"
+#include "player_status.h"
#include "special/sprite.h"
#include "sector.h"
#include "resources.h"
keymap.jump = SDLK_SPACE;
}
-void player_input_init(player_input_type* pplayer_input)
+PlayerInputType::PlayerInputType()
{
- pplayer_input->up = UP;
- pplayer_input->old_up = UP;
- pplayer_input->down = UP;
- pplayer_input->fire = UP;
- pplayer_input->left = UP;
- pplayer_input->old_fire = UP;
- pplayer_input->right = UP;
- pplayer_input->jump = UP;
- pplayer_input->old_jump = UP;
- pplayer_input->activate = UP;
+ reset();
+}
+
+void
+PlayerInputType::reset()
+{
+ up = false;
+ old_up = false;
+ down = false;
+ fire = false;
+ old_fire = false;
+ left = false;
+ right = false;
+ jump = false;
+ old_jump = false;
+ activate = false;
}
void
duck = false;
dead = false;
- dying = DYING_NOT;
+ dying = false;
last_ground_y = 0;
fall_mode = ON_GROUND;
jumping = false;
on_ground_flag = false;
grabbed_object = 0;
- player_input_init(&input);
-
+ input.reset();
physic.reset();
}
-int
-Player::key_event(SDLKey key, int state)
+bool
+Player::key_event(SDLKey key, bool state)
{
idle_timer.start(IDLE_TIME, true);
}
else if(key == keymap.up)
{
- if(state == UP)
- input.old_up = UP;
+ if(state == false)
+ input.old_up = false;
input.up = state;
/* Up key also opens activates stuff */
input.activate = state;
}
else if(key == keymap.power)
{
- if (state == UP)
- input.old_fire = UP;
+ if(state == false)
+ input.old_fire = false;
input.fire = state;
return true;
}
else if(key == keymap.jump)
{
- if (state == UP)
- input.old_jump = UP;
+ if(state == false)
+ input.old_jump = false;
input.jump = state;
return true;
}
move(Vector(100, 170));
duck = false;
- dying = DYING_NOT;
+ dying = false;
- player_input_init(&input);
+ input.reset();
on_ground_flag = false;
return;
}
- if(input.fire == UP)
+ if(input.fire == false)
grabbed_object = 0;
- if(dying == DYING_NOT)
+ if(!dying)
handle_input();
movement = physic.get_movement(elapsed_time);
float ay = physic.get_acceleration_y();
float dirsign = 0;
- if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
+ if(!duck || physic.get_velocity_y() != 0) {
+ if(input.left && !input.right) {
old_dir = dir;
dir = LEFT;
dirsign = -1;
- } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
+ } else if(!input.left && input.right) {
old_dir = dir;
dir = RIGHT;
dirsign = 1;
+ }
}
- if (input.fire == UP) {
- ax = dirsign * WALK_ACCELERATION_X;
- // limit speed
- if(vx >= MAX_WALK_XM && dirsign > 0) {
- vx = MAX_WALK_XM;
- ax = 0;
- } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
- vx = -MAX_WALK_XM;
- ax = 0;
- }
+ if (!input.fire) {
+ ax = dirsign * WALK_ACCELERATION_X;
+ // limit speed
+ if(vx >= MAX_WALK_XM && dirsign > 0) {
+ vx = MAX_WALK_XM;
+ ax = 0;
+ } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
+ vx = -MAX_WALK_XM;
+ ax = 0;
+ }
} else {
- ax = dirsign * RUN_ACCELERATION_X;
- // limit speed
- if(vx >= MAX_RUN_XM && dirsign > 0) {
- vx = MAX_RUN_XM;
- ax = 0;
- } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
- vx = -MAX_RUN_XM;
- ax = 0;
- }
+ ax = dirsign * RUN_ACCELERATION_X;
+ // limit speed
+ if(vx >= MAX_RUN_XM && dirsign > 0) {
+ vx = MAX_RUN_XM;
+ ax = 0;
+ } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
+ vx = -MAX_RUN_XM;
+ ax = 0;
+ }
}
// we can reach WALK_SPEED without any acceleration
}
// Press jump key
- if(input.jump == DOWN && can_jump && on_ground())
+ if(input.jump && can_jump && on_ground())
{
if(duck) { // only jump a little bit when in duck mode {
physic.set_velocity_y(300);
SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
}
// Let go of jump key
- else if(input.jump == UP)
+ else if(!input.jump)
{
if (!flapping && !duck && !falling_from_flap && !on_ground())
{
{
// Flapping, Ricardo's version
// similar to SM3 Fox
- if(input.jump == DOWN && input.old_jump == UP && can_flap &&
- flaps_nb < 3)
+ if(input.jump && !input.old_jump && can_flap && flaps_nb < 3)
{
physic.set_velocity_y(350);
physic.set_velocity_x(physic.get_velocity_x() * 35);
else if(flapping_mode == MAREK_FLAP)
{
// Flapping, Marek's version
- if (input.jump == DOWN && can_flap)
+ if (input.jump && can_flap)
{
if (!flapping_timer.started())
{
else if(flapping_mode == RYAN_FLAP)
{
// Flapping, Ryan's version
- if (input.jump == DOWN && can_flap)
+ if (input.jump && can_flap)
{
if (!flapping_timer.started())
{
#if 0
/* In case the player has pressed Down while in a certain range of air,
enable butt jump action */
- if (input.down == DOWN && !butt_jump && !duck)
+ if (input.down && !butt_jump && !duck)
if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
butt_jump = true;
#endif
/* When Down is not held anymore, disable butt jump */
- if(butt_jump && input.down == UP)
+ if(butt_jump && !input.down)
butt_jump = false;
// Do butt jump
get_pos().y + bbox.get_height() + 64))
&& jumping == false
&& can_jump == false
- && input.jump == DOWN
- && input.old_jump == UP)
+ && input.jump && !input.old_jump)
{
can_jump = true;
}
#endif
+ // FIXME: why the heck is this here and not somewhere where the keys are
+ // checked?!?
input.old_jump = input.jump;
}
handle_horizontal_input();
/* Jump/jumping? */
- if (on_ground() && input.jump == UP)
+ if (on_ground() && !input.jump)
can_jump = true;
handle_vertical_input();
/* Shoot! */
- if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER) {
+ if (input.fire && !input.old_fire && got_power != NONE_POWER) {
if(Sector::current()->add_bullet(
// get_pos() + Vector(0, bbox.get_height()/2),
get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
: Vector(32, bbox.get_height()/2)),
physic.get_velocity_x(), dir))
shooting_timer.start(SHOOTING_TIME);
- input.old_fire = DOWN;
+ // FIXME: why the heck is this here
+ input.old_fire = false;
}
/* Duck! */
- if (input.down == DOWN && size == BIG && !duck
+ if (input.down && size == BIG && !duck
&& physic.get_velocity_y() == 0 && on_ground())
{
duck = true;
bbox.move(Vector(0, 32));
bbox.set_height(31.8);
}
- else if(input.down == UP && size == BIG && duck)
+ else if(!input.down && size == BIG && duck)
{
// try if we can really unduck
bbox.move(Vector(0, -32));
}
/* Draw Tux */
- if (dying == DYING_SQUISHED) {
- smalltux_gameover->draw(context, get_pos(), LAYER_FOREGROUNDTILES+1);
+ if(dying) {
+ smalltux_gameover->draw(context, get_pos(), layer);
} else if(growing_timer.get_timeleft() > 0) {
if(size == SMALL)
{
Player::collision(GameObject& other, const CollisionHit& hit)
{
Portable* portable = dynamic_cast<Portable*> (&other);
- if(portable && grabbed_object == 0 && input.fire == DOWN
+ if(portable && grabbed_object == 0 && input.fire
&& fabsf(hit.normal.x) > .9) {
grabbed_object = portable;
return CONTINUE;
TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
if(trigger) {
- if(input.up == DOWN && input.old_up == UP)
+ if(input.up && !input.old_up)
trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
}
physic.set_acceleration(0, 0);
physic.set_velocity(0, 700);
--player_status.lives;
- dying = DYING_SQUISHED;
+ dying = true;
dying_timer.start(3.0);
flags |= FLAG_NO_COLLDET;
}