[Super-tux-commit] supertux/src/object portable.h,NONE,1.1 rock.cpp,NONE,1.1 rock.h,NONE,1.1 coin.h,
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-12-19 13:34:27
|
Update of /cvsroot/super-tux/supertux/src/object In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22644/src/object Modified Files: coin.h player.cpp player.h Added Files: portable.h rock.cpp rock.h Log Message: -german translation updates -some cleanups -a first version of grab&carry around code. It doesn't work too good yet but it was lying around too long on my HD... Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- player.h 26 Nov 2004 14:45:41 -0000 1.1 +++ player.h 19 Dec 2004 13:34:12 -0000 1.2 @@ -19,6 +19,7 @@ #ifndef SUPERTUX_PLAYER_H #define SUPERTUX_PLAYER_H +#include <vector> #include "SDL.h" #include "timer.h" @@ -31,6 +32,7 @@ using namespace SuperTux; class BadGuy; +class Portable; /* Times: */ @@ -40,18 +42,10 @@ #define TUX_FLAPPING_TIME 1 /* How long Tux can flap his wings to gain additional jump height */ #define TIME_WARNING 20 /* When to alert player they're low on time! */ -/* Scores: */ - -#define SCORE_BRICK 5 -#define SCORE_DISTRO 20 - /* Sizes: */ - #define SMALL 0 #define BIG 1 -#include <vector> - struct PlayerKeymap { public: @@ -88,9 +82,6 @@ extern Surface* tux_life; -extern Sprite* smalltux_gameover; -extern Sprite* smalltux_star; -extern Sprite* bigtux_star; #define GROWING_TIME 1.0 #define GROWING_FRAMES 7 @@ -137,7 +128,6 @@ int got_power; int size; bool duck; - bool holding_something; bool dead; DyingType dying; @@ -183,7 +173,6 @@ int key_event(SDLKey key, int state); void level_begin(); void handle_input(); - void grabdistros(); PlayerStatus& get_status(); @@ -196,11 +185,10 @@ { return invincible_timer.started(); } + void kill(HurtMode mode); void player_remove_powerups(); void check_bounds(Camera* camera); - bool on_ground(); - bool under_solid(); void grow(bool animate = false); void move(const Vector& vector); @@ -210,15 +198,19 @@ { return dead; } private: + bool on_ground(); + void init(); void handle_horizontal_input(); void handle_vertical_input(); void remove_powerups(); + + Portable* grabbed_object; + + Sprite* smalltux_gameover; + Sprite* smalltux_star; + Sprite* bigtux_star; }; #endif /*SUPERTUX_PLAYER_H*/ - -/* Local Variables: */ -/* mode:c++ */ -/* End: */ Index: coin.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/coin.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- coin.h 24 Nov 2004 23:10:07 -0000 1.2 +++ coin.h 19 Dec 2004 13:34:12 -0000 1.3 @@ -15,9 +15,9 @@ Coin(const Vector& pos); ~Coin(); - virtual HitResponse collision(GameObject& other, const CollisionHit& hit); - virtual void action(float elapsed_time); - virtual void draw(DrawingContext& context); + HitResponse collision(GameObject& other, const CollisionHit& hit); + void action(float elapsed_time); + void draw(DrawingContext& context); void collect(); Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- player.cpp 27 Nov 2004 14:14:30 -0000 1.2 +++ player.cpp 19 Dec 2004 13:34:12 -0000 1.3 @@ -25,6 +25,7 @@ #include "app/globals.h" #include "app/gettext.h" +#include "special/sprite_manager.h" #include "player.h" #include "defines.h" #include "scene.h" @@ -38,6 +39,7 @@ #include "object/tilemap.h" #include "object/camera.h" #include "object/gameobjs.h" +#include "object/portable.h" #include "trigger/trigger_base.h" static const int TILES_FOR_BUTTJUMP = 3; @@ -59,10 +61,6 @@ Surface* tux_life = 0; -Sprite* smalltux_gameover = 0; -Sprite* smalltux_star = 0; -Sprite* bigtux_star = 0; - TuxBodyParts* small_tux = 0; TuxBodyParts* big_tux = 0; TuxBodyParts* fire_tux = 0; @@ -123,19 +121,24 @@ } Player::Player() + : grabbed_object(0) { + smalltux_gameover = sprite_manager->create("smalltux-gameover"); + smalltux_star = sprite_manager->create("smalltux-star"); + bigtux_star = sprite_manager->create("bigtux-star"); init(); } Player::~Player() { + delete smalltux_gameover; + delete smalltux_star; + delete bigtux_star; } void Player::init() { - holding_something = false; - bbox.set_size(31.8, 31.8); size = SMALL; @@ -166,6 +169,7 @@ flaps_nb = 0; on_ground_flag = false; + grabbed_object = 0; player_input_init(&input); @@ -249,44 +253,32 @@ return; } - if (input.fire == UP) - holding_something = false; + if(input.fire == UP) + grabbed_object = 0; + if(dying == DYING_NOT) handle_input(); movement = physic.get_movement(elapsed_time); + on_ground_flag = false; #if 0 - // special exception for cases where we're stuck under tiles after - // being ducked. In this case we drift out - if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y - && collision_object_map(base)) - { - base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1); - previous_base = old_base = base; - } - - /* Reset score multiplier (for multi-hits): */ - if (!invincible_timer.started()) - { - if(player_status.score_multiplier > player_status.max_score_multiplier) - { - player_status.max_score_multiplier = player_status.score_multiplier; - - // show a message - char str[124]; - sprintf(str, _("New max combo: %d"), player_status.max_score_multiplier-1); - Sector::current()->add_floating_text(base, str); - } - player_status.score_multiplier = 1; - } - } - - } + // special exception for cases where we're stuck under tiles after + // being ducked. In this case we drift out + if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y + && collision_object_map(base)) { + base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1); + previous_base = old_base = base; + } #endif - on_ground_flag = false; + if(grabbed_object != 0) { + Vector pos = get_pos() + + Vector(dir == LEFT ? -16 : 16, + bbox.get_height()*0.66666 - 32); + grabbed_object->grab(*this, pos); + } } bool @@ -342,40 +334,36 @@ } // changing directions? - if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) - { - // let's skid! - if(fabs(vx)>SKID_XM && !skidding_timer.started()) - { - skidding_timer.start(SKID_TIME); - SoundManager::get()->play_sound(IDToSound(SND_SKID)); - // dust some partcles - Sector::current()->add_object( - new Particles( - Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0), - bbox.p2.y), - dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20, - Vector(280,-260), Vector(0,0.030), 3, Color(100,100,100), 3, .8, - LAYER_OBJECTS+1)); - - ax *= 2.5; - } - else - { - ax *= 2; - } + if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) { + // let's skid! + if(fabs(vx)>SKID_XM && !skidding_timer.started()) { + skidding_timer.start(SKID_TIME); + SoundManager::get()->play_sound(IDToSound(SND_SKID)); + // dust some partcles + Sector::current()->add_object( + new Particles( + Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0), + bbox.p2.y), + dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20, + Vector(280,-260), Vector(0,0.030), 3, Color(100,100,100), 3, .8, + LAYER_OBJECTS+1)); + + ax *= 2.5; + } else { + ax *= 2; } + } // we get slower when not pressing any keys if(dirsign == 0) { - if(fabs(vx) < WALK_SPEED) { - vx = 0; - ax = 0; - } else if(vx < 0) { - ax = WALK_ACCELERATION_X * 1.5; - } else { - ax = WALK_ACCELERATION_X * -1.5; - } + if(fabs(vx) < WALK_SPEED) { + vx = 0; + ax = 0; + } else if(vx < 0) { + ax = WALK_ACCELERATION_X * 1.5; + } else { + ax = WALK_ACCELERATION_X * -1.5; + } } #if 0 @@ -558,14 +546,6 @@ } } - // Hover - //(disabled by default, use cheat code "hover" to toggle on/off) - //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys - if (enable_hover && input.jump == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0) - { - physic.set_velocity_y(-100); - } - #if 0 /* In case the player has pressed Down while in a certain range of air, enable butt jump action */ @@ -712,11 +692,6 @@ } void -Player::grabdistros() -{ -} - -void Player::draw(DrawingContext& context) { TuxBodyParts* tux_body; @@ -799,7 +774,7 @@ } // Tux is holding something - if ((holding_something && physic.get_velocity_y() == 0) || + if ((grabbed_object != 0 && physic.get_velocity_y() == 0) || (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) { if (duck) @@ -872,6 +847,13 @@ HitResponse Player::collision(GameObject& other, const CollisionHit& hit) { + Portable* portable = dynamic_cast<Portable*> (&other); + if(portable && grabbed_object == 0 && input.fire == DOWN + && fabsf(hit.normal.x) > .9) { + grabbed_object = portable; + return CONTINUE; + } + if(other.get_flags() & FLAG_SOLID) { if(hit.normal.y < 0) { // landed on floor? if (physic.get_velocity_y() < 0) --- NEW FILE: portable.h --- #ifndef __PORTABLE_H__ #define __PORTABLE_H__ #include "special/moving_object.h" using namespace SuperTux; /** * An object that inherits from this object is considered "portable" and can * be carried around by the player. * The object has to additionally set the PORTABLE flag (this allows to * make the object only temporarily portable by resetting the flag) */ class Portable { public: /** * called each frame when the object has been grabbed. */ virtual void grab(MovingObject& object, const Vector& pos) = 0; }; #endif --- NEW FILE: rock.h --- #ifndef __ROCK_H__ #define __ROCK_H__ #include "special/moving_object.h" #include "math/physic.h" #include "lisp/lisp.h" #include "portable.h" #include "serializable.h" namespace SuperTux { class Sprite; } class Rock : public MovingObject, public Portable, public Serializable { public: Rock(const lisp::Lisp& reader); virtual ~Rock(); HitResponse collision(GameObject& other, const CollisionHit& hit); void action(float elapsed_time); void draw(DrawingContext& context); void write(lisp::Writer& writer); void grab(MovingObject& object, const Vector& pos); private: bool grabbed; Sprite* sprite; Physic physic; }; #endif --- NEW FILE: rock.cpp --- #include <config.h> #include "rock.h" #include "special/sprite.h" #include "special/sprite_manager.h" #include "lisp/writer.h" #include "video/drawing_context.h" #include "resources.h" Rock::Rock(const lisp::Lisp& reader) { reader.get("x", bbox.p1.x); reader.get("y", bbox.p1.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("rock"); grabbed = false; flags |= FLAG_SOLID; } Rock::~Rock() { delete sprite; } void Rock::write(lisp::Writer& writer) { writer.start_list("rock"); writer.write_float("x", bbox.p1.x); writer.write_float("y", bbox.p1.y); writer.end_list("rock"); } void Rock::draw(DrawingContext& context) { sprite->draw(context, get_pos(), LAYER_OBJECTS); } void Rock::action(float elapsed_time) { if(!grabbed) { flags |= FLAG_SOLID; flags &= ~FLAG_NO_COLLDET; movement = physic.get_movement(elapsed_time); } else { physic.set_velocity(0, 0); flags &= ~FLAG_SOLID; flags |= FLAG_NO_COLLDET; } grabbed = false; } HitResponse Rock::collision(GameObject& , const CollisionHit& ) { if(grabbed) return FORCE_MOVE; physic.set_velocity(0, 0); return CONTINUE; } void Rock::grab(MovingObject& , const Vector& pos) { movement = pos - get_pos(); grabbed = true; } |