// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#include <math.h>
+#include <cmath>
#include <iostream>
#include <cassert>
+
#include "gameloop.h"
-#include "globals.h"
+#include "app/globals.h"
#include "player.h"
#include "defines.h"
#include "scene.h"
#include "tile.h"
-#include "sprite.h"
+#include "special/sprite.h"
#include "sector.h"
#include "tilemap.h"
#include "camera.h"
#include "gameobjs.h"
#include "resources.h"
#include "interactive_object.h"
-#include "screen/screen.h"
+#include "video/screen.h"
// behavior definitions:
#define TILES_FOR_BUTTJUMP 3
// animation times (in ms):
#define SHOOTING_TIME 320
+#define STOMP_TIME 250
// others stuff:
#define AUTOSCROLL_DEAD_INTERVAL 300
jumping = false;
can_jump = true;
butt_jump = false;
-
+
+ stomp_pos = Vector(0,0);
frame_main = 0;
frame_ = 0;
if(dying == DYING_NOT)
handle_input();
- physic.apply(elapsed_time, base.x, base.y);
+ physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
if(dying == DYING_NOT)
{
if (isbrick(base.x, base.y) ||
isfullbox(base.x, base.y))
{
- Sector::current()->trygrabdistro(
+ Sector::current()->trygrabdistro(
Vector(base.x, base.y - 32), BOUNCE);
Sector::current()->trybumpbadguy(Vector(base.x, base.y - 64));
if (isbrick(base.x+ 31, base.y) ||
isfullbox(base.x+ 31, base.y))
{
- Sector::current()->trygrabdistro(
+ Sector::current()->trygrabdistro(
Vector(base.x+ 31, base.y - 32), BOUNCE);
Sector::current()->trybumpbadguy(Vector(base.x+ 31, base.y - 64));
if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
skidding_timer.start(SKID_TIME);
- sound_manager->play_sound(sounds[SND_SKID]);
+ SoundManager::get()->play_sound(IDToSound(SND_SKID));
ax *= 2.5;
} else {
ax *= 2;
jumping = true;
can_jump = false;
if (size == SMALL)
- sound_manager->play_sound(sounds[SND_JUMP]);
+ SoundManager::get()->play_sound(IDToSound(SND_JUMP));
else
- sound_manager->play_sound(sounds[SND_BIGJUMP]);
+ SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
}
// Let go of jump key
else if(input.up == UP && jumping && physic.get_velocity_y() > 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)
+ if (input.down == DOWN && !butt_jump && !duck)
if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
butt_jump = true;
// Do butt jump
if (butt_jump && on_ground() && size == BIG)
{
+
+ if (duck)
+ stomp_pos = Vector(base.x - 32, base.y);
+ else
+ stomp_pos = Vector(base.x - 32, base.y + 32);
+ stomp_timer.start(STOMP_TIME);
+
butt_jump = false;
// Break bricks beneath Tux
BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
if(badguy)
{
- if (fabsf(base.x - badguy->base.x) < 300 &&
- fabsf(base.y - badguy->base.y) < 300 &&
+
+ if (fabsf(base.x - badguy->base.x) < 150 &&
+ fabsf(base.y - badguy->base.y) < 60 &&
(issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
badguy->kill_me(25);
{
Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
-
Sector::current()->trygrabdistro(
Vector(base.x, base.y + base.height), NO_BOUNCE);
Sector::current()->trygrabdistro(
if(size == BIG)
{
- Sector::current()->trygrabdistro(
+ Sector::current()->trygrabdistro(
Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
Sector::current()->trygrabdistro(
Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
if(player_status.lives < MAX_LIVES)
++player_status.lives;
/*We want to hear the sound even, if MAX_LIVES is reached*/
- sound_manager->play_sound(sounds[SND_LIFEUP]);
+ SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
}
}
{
if (dying == DYING_SQUISHED)
{
- smalltux_gameover->draw(context, pos, LAYER_OBJECTS+1);
+ smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
}
else
{
else
sprite->grab_left->draw(context, pos, LAYER_OBJECTS + 1);
}
+
+ // Draw stomp clouds when doing a butt jump
+ if (stomp_timer.check())
+ sprite->stomp->draw(context, stomp_pos, LAYER_OBJECTS + 1);
// Draw blinking star overlay
if (invincible_timer.started() &&
if(dying)
return;
- sound_manager->play_sound(sounds[SND_HURT]);
+ SoundManager::get()->play_sound(IDToSound(SND_HURT));
physic.set_velocity_x(0);
}
}
+void
+Player::bounce(BadGuy* badguy)
+{
+ if (input.up)
+ physic.set_velocity_y(5.2);
+ else
+ physic.set_velocity_y(2);
+
+ // Move the player a little bit above the badguy to avoid collision
+ // between badguy and player directly after the bounce has happend
+ base.y = badguy->base.y - base.height - 2;
+}
+
+/* EOF */
+