Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Mole, Root Sapling, and Corrupted Big Granito a StickyBadguy #3135

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum class Direction;
class Player;
class Bullet;

static const char* BADGUY_LIGHT_SPRITE_NAME = "images/objects/lightmap_light/lightmap_light-medium.sprite";
static const char* BADGUY_ICE_SPRITE_NAME = "images/creatures/overlays/iceoverlay/iceoverlay.sprite";

/**
* Base class for moving sprites that can hurt the Player.

Expand All @@ -43,17 +46,17 @@ class BadGuy : public MovingSprite,

public:
BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS,
const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite",
const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite");
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer = LAYER_OBJECTS,
const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite",
const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite");
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
BadGuy(const ReaderMapping& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS,
const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite",
const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite");
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
BadGuy(const ReaderMapping& reader, const std::string& sprite_name, Direction default_direction, int layer = LAYER_OBJECTS,
const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite",
const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite");
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
Comment on lines +49 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day we need to fix all this sprite parameter stuff because this looks pretty tedious hahaha


/** Called when the badguy is drawn. The default implementation
simply draws the badguy sprite on screen */
Expand Down
7 changes: 4 additions & 3 deletions src/badguy/corrupted_granito_big.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static const float CRACK_TIME = 1.f; // seconds
static const float SHAKE_TIME = 0.1f; // seconds

CorruptedGranitoBig::CorruptedGranitoBig(const ReaderMapping& reader) :
BadGuy(reader, "images/creatures/granito/corrupted/big/rock_mine.sprite", LAYER_OBJECTS-3),
StickyBadguy(reader, "images/creatures/granito/corrupted/big/rock_mine.sprite", LAYER_OBJECTS-3),
m_state(STATE_READY),
m_crack_timer(),
m_shake_timer(),
Expand All @@ -49,7 +49,7 @@ CorruptedGranitoBig::CorruptedGranitoBig(const ReaderMapping& reader) :
void
CorruptedGranitoBig::initialize()
{
BadGuy::initialize();
StickyBadguy::initialize();

m_state = STATE_READY;
set_action("idle", m_dir);
Expand All @@ -59,7 +59,8 @@ CorruptedGranitoBig::initialize()
void
CorruptedGranitoBig::active_update(float dt_sec)
{
BadGuy::active_update(dt_sec);
if (m_sticky) sticky_update(dt_sec);
StickyBadguy::active_update(dt_sec);

if (m_state == STATE_BROKEN) return;

Expand Down
3 changes: 2 additions & 1 deletion src/badguy/corrupted_granito_big.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#define HEADER_SUPERTUX_BADGUY_CORRUPTED_GRANITO_BIG_HPP

#include "badguy/badguy.hpp"
#include "object/sticky_object.hpp"

/** Granito, which explodes into shards when player comes close to it. */
class CorruptedGranitoBig final : public BadGuy
class CorruptedGranitoBig final : public StickyBadguy
{
public:
explicit CorruptedGranitoBig(const ReaderMapping& reader);
Expand Down
6 changes: 4 additions & 2 deletions src/badguy/mole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "math/random.hpp"
#include "math/util.hpp"
#include "object/player.hpp"
#include "object/sticky_object.hpp"
#include "sprite/sprite.hpp"
#include "supertux/flip_level_transformer.hpp"
#include "supertux/sector.hpp"
Expand All @@ -33,7 +34,7 @@ static const float THROW_INTERVAL = 1; /**< Time between two thrown rocks. */
static const float THROW_VELOCITY = 400; /**< Initial velocity of thrown rocks. */

Mole::Mole(const ReaderMapping& reader) :
BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
StickyBadguy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
state(PRE_THROWING),
timer(),
throw_timer(),
Expand Down Expand Up @@ -96,7 +97,8 @@ Mole::throw_rock()
void
Mole::active_update(float dt_sec)
{
BadGuy::active_update(dt_sec);
if (m_sticky) sticky_update(dt_sec);
StickyBadguy::active_update(dt_sec);

switch (state) {
case PRE_THROWING:
Expand Down
3 changes: 2 additions & 1 deletion src/badguy/mole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#define HEADER_SUPERTUX_BADGUY_MOLE_HPP

#include "badguy/badguy.hpp"
#include "object/sticky_object.hpp"

class Mole final : public BadGuy
class Mole final : public StickyBadguy
{
public:
Mole(const ReaderMapping& );
Expand Down
5 changes: 3 additions & 2 deletions src/badguy/root_sapling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static const float ROOT_SAPLING_RANGE = 32.f * 20;
static const float ROOT_SAPLING_SPAWN_TIME = 1.35f;

RootSapling::RootSapling(const ReaderMapping& reader) :
BadGuy(reader, "images/creatures/mole/corrupted/root_sapling.sprite", Direction::UP,
LAYER_TILES - 15, "images/creatures/mole/corrupted/core_glow/core_glow.sprite"),
StickyBadguy(reader, "images/creatures/mole/corrupted/root_sapling.sprite", Direction::UP,
LAYER_TILES - 15, COLGROUP_MOVING, "images/creatures/mole/corrupted/core_glow/core_glow.sprite"),
m_root_timer(),
m_dead(false)
{
Expand Down Expand Up @@ -105,6 +105,7 @@ RootSapling::collision_player(Player& player, const CollisionHit& hit)
void
RootSapling::active_update(float dt_sec)
{
if (m_sticky) sticky_update(dt_sec);
if (m_dead) return;

BadGuy::active_update(dt_sec);
Expand Down
3 changes: 2 additions & 1 deletion src/badguy/root_sapling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#define HEADER_SUPERTUX_BADGUY_ROOT_SAPLING_HPP

#include "badguy/badguy.hpp"
#include "object/sticky_object.hpp"

#include "collision/collision_system.hpp"

class RootSapling final : public BadGuy
class RootSapling final : public StickyBadguy
{
public:
RootSapling(const ReaderMapping& reader);
Expand Down
9 changes: 5 additions & 4 deletions src/object/sticky_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ StickyObject::move_for_owner(MovingObject& object)
m_col.set_pos(object.get_pos() + m_displacement_from_owner);
}

StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, Direction default_direction, int layer, CollisionGroup collision_group) :
BadGuy(mapping, sprite_name, default_direction, layer),
StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, Direction default_direction, int layer, CollisionGroup collision_group,
const std::string& light_sprite_name, const std::string& ice_sprite_name) :
BadGuy(mapping, sprite_name, default_direction, layer, light_sprite_name, ice_sprite_name),
m_sticky(),
m_sticking(),
m_displacement_from_owner()
{
set_group(collision_group);
}

StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, int layer, CollisionGroup collision_group) :
BadGuy(mapping, sprite_name, layer),
StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, int layer, CollisionGroup collision_group, const std::string& light_sprite_name, const std::string& ice_sprite_name) :
BadGuy(mapping, sprite_name, layer, light_sprite_name, ice_sprite_name),
m_sticky(),
m_sticking(),
m_displacement_from_owner()
Expand Down
8 changes: 6 additions & 2 deletions src/object/sticky_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ class StickyBadguy : public BadGuy
{
public:
StickyBadguy(const ReaderMapping& reader, const std::string& sprite_name, Direction default_direction,
int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING,
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
StickyBadguy(const ReaderMapping& reader, const std::string& sprite_name,
int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING);
int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING,
const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME,
const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME);
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(StickyBadguy)); }

virtual void sticky_update(float dt_sec);
Expand Down
Loading