From 63934f5f4c15f059c9b60499575870ebb7c923a0 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Tue, 20 Apr 2004 19:55:23 +0000 Subject: [PATCH] - turned LEFT/RIGHT defines into enum, turned BadGuyModes into enum SVN-Revision: 602 --- src/badguy.h | 66 +++++++++++++++++++++++++++++------------------------ src/defines.h | 7 ++---- src/level.cpp | 2 +- src/leveleditor.cpp | 1 - src/player.cpp | 10 ++++---- src/player.h | 4 +++- src/special.cpp | 4 ++-- src/special.h | 6 ++--- src/world.cpp | 6 ++--- src/world.h | 6 ++--- 10 files changed, 58 insertions(+), 54 deletions(-) diff --git a/src/badguy.h b/src/badguy.h index 94b544420..7ec03e325 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -36,27 +36,6 @@ extern Sprite* img_bsod_left; extern Sprite* img_bsod_right; extern Sprite* img_laptop_left; -/* Enemy modes: */ -enum { - NORMAL=0, - FLAT, - KICK, - HELD, - - MONEY_JUMP, - - BOMB_TICKING, - BOMB_EXPLODE, - - STALACTITE_SHAKING, - STALACTITE_FALL, - - FISH_WAIT, - - FLY_UP, - FLY_DOWN -}; - /* Bad guy kinds: */ enum BadGuyKind { BAD_BSOD, @@ -83,12 +62,13 @@ struct BadGuyData BadGuyKind kind; int x; int y; + bool stay_on_platform; - BadGuyData(BadGuyKind kind_, int x_, int y_) - : kind(kind_), x(x_), y(y_) {} + BadGuyData(BadGuyKind kind_, int x_, int y_, bool stay_on_platform_) + : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {} BadGuyData() - : kind(BAD_BSOD), x(0), y(0) {} + : kind(BAD_BSOD), x(0), y(0), stay_on_platform(false) {} }; class Player; @@ -97,12 +77,38 @@ class Player; class BadGuy { public: - DyingType dying; - base_type base; + /* Enemy modes: */ + enum BadGuyMode { + NORMAL=0, + FLAT, + KICK, + HELD, + + MONEY_JUMP, + + BOMB_TICKING, + BOMB_EXPLODE, + + STALACTITE_SHAKING, + STALACTITE_FALL, + + FISH_WAIT, + + FLY_UP, + FLY_DOWN + }; +public: + DyingType dying; + base_type base; BadGuyKind kind; - int mode; + BadGuyMode mode; + + /** If true the enemy will stay on its current platform, ie. if he + reaches the edge he will turn around and walk into the other + direction, if false the enemy will jump or walk of the edge */ bool stay_on_platform; - int dir; + + Direction dir; private: bool seen; @@ -124,7 +130,7 @@ public: void draw(); void collision(void* p_c_object, int c_object, - CollisionType type = COLLISION_NORMAL); + CollisionType type = COLLISION_NORMAL); /** this functions tries to kill the badguy and lets him fall off the * screen. Some badguys like the flame might ignore this. @@ -167,7 +173,7 @@ private: void squish_me(Player* player); /** set image of the badguy */ void set_sprite(Sprite* left, Sprite* right, - int animlength = 1, float animspeed = 1); + int animlength = 1, float animspeed = 1); }; #endif /*SUPERTUX_BADGUY_H*/ diff --git a/src/defines.h b/src/defines.h index ef93b9337..7d9173f39 100644 --- a/src/defines.h +++ b/src/defines.h @@ -32,6 +32,8 @@ #define FPS (1000 / 25) +enum Direction { LEFT = 0, RIGHT = 1 }; + /* Direction (keyboard/joystick) states: */ #define UP 0 @@ -51,11 +53,6 @@ enum DyingType { #define KILL 0 #define SHRINK 1 -/* Directions: */ - -#define LEFT 0 -#define RIGHT 1 - /* Sizes: */ #define SMALL 0 diff --git a/src/level.cpp b/src/level.cpp index 43fd6a46a..7e6e1820b 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -416,7 +416,7 @@ Level::load(const std::string& filename) if (*i == '0' || *i == '1' || *i == '2') { badguy_data.push_back(BadGuyData(static_cast(*i-'0'), - x*32, y*32)); + x*32, y*32, false)); *i = 0; } else diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index bc521cf96..f20ff31c5 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -44,7 +44,6 @@ /* definitions to aid development */ - /* definitions that affect gameplay */ #define KEY_CURSOR_SPEED 32 #define KEY_CURSOR_FASTSPEED 64 diff --git a/src/player.cpp b/src/player.cpp index baedf1253..7fb220605 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -702,18 +702,18 @@ Player::collision(void* p_c_object, int c_object) /* Hurt player if he touches a badguy */ if (!pbad_c->dying && !dying && !safe_timer.started() && - pbad_c->mode != HELD) + pbad_c->mode != BadGuy::HELD) { - if (pbad_c->mode == FLAT && input.fire == DOWN) + if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN) { - pbad_c->mode = HELD; + pbad_c->mode = BadGuy::HELD; pbad_c->base.y-=8; } - else if (pbad_c->mode == FLAT) + else if (pbad_c->mode == BadGuy::FLAT) { // Don't get hurt if we're kicking a flat badguy! } - else if (pbad_c->mode == KICK) + else if (pbad_c->mode == BadGuy::KICK) { /* Hurt if you get hit by kicked laptop: */ if (!invincible_timer.started()) diff --git a/src/player.h b/src/player.h index 2d63f43f7..0632c6cd4 100644 --- a/src/player.h +++ b/src/player.h @@ -110,7 +110,9 @@ public: int size; bool duck; DyingType dying; - int dir; + + Direction dir; + bool jumping; int frame_; int frame_main; diff --git a/src/special.cpp b/src/special.cpp index 8016dc549..227251270 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -40,7 +40,7 @@ Sprite* img_1up; #define GROWUP_SPEED 1.0f void -Bullet::init(float x, float y, float xm, int dir) +Bullet::init(float x, float y, float xm, Direction dir) { base.width = 4; base.height = 4; @@ -124,7 +124,7 @@ Bullet::collision(int c_object) } void -Upgrade::init(float x_, float y_, int dir_, UpgradeKind kind_) +Upgrade::init(float x_, float y_, Direction dir_, UpgradeKind kind_) { kind = kind_; dir = dir_; diff --git a/src/special.h b/src/special.h index 7ba652dcd..b5b518e24 100644 --- a/src/special.h +++ b/src/special.h @@ -47,12 +47,12 @@ class Upgrade { public: UpgradeKind kind; - int dir; + Direction dir; base_type base; base_type old_base; Physic physic; - void init(float x, float y, int dir, UpgradeKind kind); + void init(float x, float y, Direction dir, UpgradeKind kind); void action(double frame_ratio); void draw(); void collision(void* p_c_object, int c_object); @@ -71,7 +71,7 @@ class Bullet base_type base; base_type old_base; - void init(float x, float y, float xm, int dir); + void init(float x, float y, float xm, Direction dir); void action(double frame_ratio); void draw(); void collision(int c_object); diff --git a/src/world.cpp b/src/world.cpp index 5e8857b02..b0a46734f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -389,7 +389,7 @@ World::add_bad_guy(float x, float y, BadGuyKind kind) } void -World::add_upgrade(float x, float y, int dir, UpgradeKind kind) +World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind) { Upgrade new_upgrade; new_upgrade.init(x,y,dir,kind); @@ -397,7 +397,7 @@ World::add_upgrade(float x, float y, int dir, UpgradeKind kind) } void -World::add_bullet(float x, float y, float xm, int dir) +World::add_bullet(float x, float y, float xm, Direction dir) { Bullet new_bullet; new_bullet.init(x,y,xm,dir); @@ -453,7 +453,7 @@ World::trybreakbrick(float x, float y, bool small) /* Empty a box: */ void -World::tryemptybox(float x, float y, int col_side) +World::tryemptybox(float x, float y, Direction col_side) { Tile* tile = gettile(x,y); if (!tile->fullbox) diff --git a/src/world.h b/src/world.h index 95b460330..00ea9a056 100644 --- a/src/world.h +++ b/src/world.h @@ -87,8 +87,8 @@ class World void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym); void add_bouncy_brick(float x, float y); void add_bad_guy(float x, float y, BadGuyKind kind); - void add_upgrade(float x, float y, int dir, UpgradeKind kind); - void add_bullet(float x, float y, float xm, int dir); + void add_upgrade(float x, float y, Direction dir, UpgradeKind kind); + void add_bullet(float x, float y, float xm, Direction dir); /** Try to grab the coin at the given coordinates */ void trygrabdistro(float x, float y, int bounciness); @@ -97,7 +97,7 @@ class World void trybreakbrick(float x, float y, bool small); /** Try to get the content out of a bonus box, thus emptying it */ - void tryemptybox(float x, float y, int col_side); + void tryemptybox(float x, float y, Direction col_side); /** Try to bumb a badguy that might we walking above Tux, thus shaking the tile which the badguy is walking on an killing him this way */ -- 2.11.0