[Super-tux-commit] supertux/src/badguy nolok_01.cpp,NONE,1.1 nolok_01.h,NONE,1.1 bouncing_snowball.c
Brought to you by:
wkendrick
From: Marek M. <wa...@us...> - 2004-11-25 11:16:15
|
Update of /cvsroot/super-tux/supertux/src/badguy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29929/src/badguy Modified Files: bouncing_snowball.cpp bouncing_snowball.h dispenser.cpp Added Files: nolok_01.cpp nolok_01.h Log Message: added badguy Nolok_01, as he may appear as the boss of world 1 (still very basic). added sprite "Dummyguy" which can be used for badguys that don't have sprites yet (i.e. nolok and dispenser). added new test level "noloktest.stl", moved dispenser and secretarea tests to that level. Bugs: Nolok can only be killed when he's jumping; no idea why, probably set the offsets wrong. Also, currently there's no limit on how many snowballs he can throw, so kill him quickly :-) This is the last thing I'll add before fixing all my other stuff. :-) --- NEW FILE: nolok_01.h --- #ifndef __NOLOK01_H__ #define __NOLOK01_H__ #include "badguy.h" #include "timer.h" class Nolok_01 : public BadGuy { public: Nolok_01(LispReader& reader); Nolok_01(float pos_x, float pos_y); void activate(); void write(LispWriter& writer); void active_action(float elapsed_time); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); protected: bool collision_squished(Player& player); Timer2 action_timer; Timer2 idle_timer; Timer2 jump_timer; }; #endif Index: bouncing_snowball.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy/bouncing_snowball.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- bouncing_snowball.cpp 25 Nov 2004 00:49:34 -0000 1.4 +++ bouncing_snowball.cpp 25 Nov 2004 11:16:03 -0000 1.5 @@ -11,14 +11,17 @@ reader.read_float("y", start_position.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("bouncingsnowball"); + set_direction = false; } -BouncingSnowball::BouncingSnowball(float pos_x, float pos_y) +BouncingSnowball::BouncingSnowball(float pos_x, float pos_y, Direction d) { start_position.x = pos_x; start_position.y = pos_y; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("bouncingsnowball"); + set_direction = true; + initial_direction = d; } void @@ -35,6 +38,7 @@ void BouncingSnowball::activate() { + if (set_direction) {dir = initial_direction;} physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } Index: bouncing_snowball.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy/bouncing_snowball.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- bouncing_snowball.h 24 Nov 2004 17:33:49 -0000 1.2 +++ bouncing_snowball.h 25 Nov 2004 11:16:03 -0000 1.3 @@ -7,7 +7,7 @@ { public: BouncingSnowball(LispReader& reader); - BouncingSnowball(float pos_x, float pos_y); + BouncingSnowball(float pos_x, float pos_y, Direction d); void activate(); void write(LispWriter& writer); @@ -15,6 +15,8 @@ protected: bool collision_squished(Player& player); + bool set_direction; + Direction initial_direction; }; #endif --- NEW FILE: nolok_01.cpp --- #include <config.h> #include "nolok_01.h" #include "badguy/bouncing_snowball.h" #include "trigger/door.h" #define SHOOT_TIME 2.5 #define IDLE_TIME 0.4 #define JUMP_TIME 0.3 static const float WALKSPEED = 80; //TODO: Create sprite, give multiple hitpoints, limit max number of snowballs // Can only be killed when jumping, no idea why Nolok_01::Nolok_01(LispReader& reader) { reader.read_float("x", start_position.x); reader.read_float("y", start_position.y); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("dummyguy"); } Nolok_01::Nolok_01(float pos_x, float pos_y) { start_position.x = pos_x; start_position.y = pos_y; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("dummyguy"); } void Nolok_01::write(LispWriter& writer) { writer.start_list("nolok01"); writer.write_float("x", get_pos().x); writer.write_float("y", get_pos().y); writer.end_list("nolok01"); } void Nolok_01::activate() { physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); action_timer.start(SHOOT_TIME, true); } void Nolok_01::active_action(float elapsed_time) { movement = physic.get_movement(elapsed_time); if (action_timer.check()) { physic.set_velocity_y(700); jump_timer.start(JUMP_TIME); } if (jump_timer.check()) { sprite->set_action("throw"); idle_timer.start(IDLE_TIME); } if (idle_timer.check()) { Sector::current()->add_object(new BouncingSnowball(get_pos().x-32, get_pos().y, LEFT)); Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y, RIGHT)); physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } } bool Nolok_01::collision_squished(Player& player) { sprite->set_action("dead"); kill_squished(player); Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2")); return true; } HitResponse Nolok_01::collision_solid(GameObject& , const CollisionHit& hit) { if(fabsf(hit.normal.y) > .5) { // hit floor or roof? //physic.set_velocity_y(0); } else { // hit right or left dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "left" : "right"); physic.set_velocity_x(-physic.get_velocity_x()); } return CONTINUE; } Index: dispenser.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy/dispenser.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- dispenser.cpp 24 Nov 2004 23:10:05 -0000 1.4 +++ dispenser.cpp 25 Nov 2004 11:16:03 -0000 1.5 @@ -13,7 +13,8 @@ reader.read_string("badguy", badguy); bbox.set_size(32, 32); //FIXME: Create dispenser sprite - sprite = sprite_manager->create("snowball"); + sprite = sprite_manager->create("dummyguy"); + sprite->set_action("stand"); } void @@ -69,6 +70,7 @@ //TODO: Add launching velocity to badguys // Add more badguys and randomizer // Clean up stuff I copied without understanding what it does :) +// Stop dispensing when game is paused // Lots-O-Stuff (tm) void Dispenser::launch_badguy() @@ -78,7 +80,7 @@ if (badguy == "snowball") Sector::current()->add_object(new SnowBall(get_pos().x-2, get_pos().y)); else if (badguy == "bouncingsnowball") - Sector::current()->add_object(new BouncingSnowball(get_pos().x-2, get_pos().y)); + Sector::current()->add_object(new BouncingSnowball(get_pos().x-2, get_pos().y, dir)); else if (badguy == "random") {} } |