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

Root Sapling (a.k.a. Corrupted Mole) #2698

Merged
merged 58 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8af51da
Initial sprites for Root Sapling [ci skip]
Rusty-Box Dec 10, 2023
4baf94d
Update root_attack.sprite [ci skip]
Rusty-Box Dec 15, 2023
c1ea7fb
Delete data/images/creatures/mole/corrupted/root_base.sprite [ci skip]
Rusty-Box Dec 15, 2023
6a93716
Rename root_attack.sprite to root.sprite [ci skip]
Rusty-Box Dec 15, 2023
1c2e4cf
wip root sapling
MatusGuy Dec 16, 2023
ebc10d6
root sapling basic behaviour
MatusGuy Dec 17, 2023
586a7fa
Merge branch 'SuperTux:master' into root-sapling
Rusty-Box Dec 17, 2023
7f4380d
Particles, fine tuning, and death
MatusGuy Dec 17, 2023
b173066
Merge branch 'root-sapling' of https://github.com/Rusty-Box/supertux …
MatusGuy Dec 17, 2023
cba5ca4
summon roots on different ground levels
MatusGuy Dec 17, 2023
b71d000
Add root to game object factory
MatusGuy Dec 20, 2023
50bff43
Root will only kill COLGROUP_MOVING objects
MatusGuy Dec 20, 2023
ef11852
Add glow sprites for the Root Sapling's core [ci skip]
Rusty-Box Dec 21, 2023
9d840ca
Glowing root sapling
MatusGuy Dec 21, 2023
bbce263
Root sapling do not spawn in thin platforms
MatusGuy Dec 21, 2023
86ee558
Update objects.stoi [ci skip]
Rusty-Box Dec 21, 2023
3a82433
Adjustments
MatusGuy Dec 21, 2023
3241702
Merge branch 'root-sapling' of github.com:Rusty-Box/supertux into roo…
MatusGuy Dec 21, 2023
2892df7
remove unused variables
MatusGuy Dec 25, 2023
7b26652
construct function + wip support all directions
MatusGuy Jan 2, 2024
d60dd60
Merge branch 'root-sapling' of github.com:Rusty-Box/supertux into roo…
MatusGuy Jan 2, 2024
5ae94bf
aeiou
MatusGuy Jan 2, 2024
19dfa71
Support for down + actions for all sides
MatusGuy Jan 7, 2024
94635e7
horizontal textures
MatusGuy Jan 22, 2024
5182555
all sides!!!!!
MatusGuy Jan 22, 2024
6c269b2
hit down facing saplings
MatusGuy Jan 22, 2024
4a99708
Update Root Sapling sprites [ci skip]
Rusty-Box Jan 23, 2024
aea5873
Preparing for crusher new roots
MatusGuy Jan 23, 2024
ed042f6
Merge branch 'root-sapling' of https://github.com/Rusty-Box/supertux …
MatusGuy Jan 23, 2024
bad5506
Merge branch 'SuperTux:master' into root-sapling
MatusGuy Jan 26, 2024
1ee0c0e
fixes
MatusGuy Jan 26, 2024
73cd7bd
Merge branch 'root-sapling' of https://github.com/Rusty-Box/supertux …
MatusGuy Jan 26, 2024
72b8d12
Revert is_free_of_tiles and fix detection
MatusGuy Feb 26, 2024
f02508f
fix more bugs
MatusGuy Feb 26, 2024
d7ecaa8
Merge branch 'SuperTux:master' into root-sapling
Rusty-Box Feb 26, 2024
da354a1
picky compiler
MatusGuy Feb 26, 2024
e59ee84
Merge branch 'root-sapling' of https://github.com/Rusty-Box/supertux …
MatusGuy Feb 26, 2024
f0648e1
oops
MatusGuy Feb 26, 2024
e659c62
fix layers and bottom root sapling spawning even when not full
MatusGuy Mar 2, 2024
41d593e
whoops
MatusGuy Mar 2, 2024
a0f058f
moving tilemaps are stupid
MatusGuy Mar 3, 2024
21a0e72
fix warnings
MatusGuy Mar 10, 2024
584c72c
Fix get_action_surfaces warning
MatusGuy Mar 10, 2024
87354f0
Fix summon check when theres a moving tilemap
MatusGuy Mar 10, 2024
f37b90b
fix the fixes
MatusGuy Mar 13, 2024
5a4f34c
Fix down/right not choosing the right position
MatusGuy Mar 20, 2024
396bba9
remove todo [ci skip]
MatusGuy Mar 22, 2024
4ce2da0
Give Mole bigger hill size [ci skip]
Rusty-Box Mar 23, 2024
4c76868
Merge branch 'SuperTux:master' into root-sapling
MatusGuy Mar 23, 2024
d110442
random mole rock & mole bounce on squish
MatusGuy Mar 23, 2024
a074434
Code style fixes
Vankata453 Mar 24, 2024
86dceab
support multiple players
MatusGuy Mar 26, 2024
1719b09
mole is snipable
MatusGuy Mar 26, 2024
6cba68a
Merge branch 'root-sapling' of https://github.com/Rusty-Box/supertux …
MatusGuy Mar 26, 2024
4e0b393
Replace `return` with `continue`
Vankata453 Mar 26, 2024
32ba221
fix down root sapling
MatusGuy Mar 27, 2024
a6f40e2
bonk on down root sapling inverts velocity
MatusGuy Mar 27, 2024
128837f
faster root sapling
MatusGuy Mar 27, 2024
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
10 changes: 6 additions & 4 deletions src/badguy/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "audio/sound_manager.hpp"
#include "math/random.hpp"
#include "object/sprite_particle.hpp"
#include "util/reader_mapping.hpp"
#include "supertux/sector.hpp"
#include "util/reader_mapping.hpp"

static const float HATCH_TIME = 0.7f;
static const float APPEAR_TIME = 0.5f;
Expand All @@ -29,6 +29,7 @@ static const float RETREAT_TIME = 1.f;
Root::Root(const ReaderMapping& reader) :
BadGuy(reader, "images/creatures/mole/corrupted/root.sprite" , LAYER_TILES-10),
m_base_surface(nullptr),
m_timer(),
m_state(STATE_HATCHING),
m_delay(HATCH_TIME),
m_maxheight(0.f),
Expand All @@ -41,8 +42,9 @@ Root::Root(const ReaderMapping& reader) :

Root::Root(const Vector& pos, Direction dir, const std::string& sprite,
float delay, bool play_sound) :
BadGuy(pos, dir, sprite, LAYER_TILES-10),
BadGuy(pos, dir, sprite, LAYER_TILES - 10),
m_base_surface(nullptr),
m_timer(),
m_state(STATE_HATCHING),
m_delay(delay == -1 ? HATCH_TIME : delay),
m_maxheight(0.f),
Expand Down Expand Up @@ -133,7 +135,7 @@ Root::initialize()
}

void
Root::draw(DrawingContext &context)
Root::draw(DrawingContext& context)
{
BadGuy::draw(context);

Expand Down Expand Up @@ -252,7 +254,7 @@ Root::active_update(float dt_sec)
}

HitResponse
Root::collision_badguy(BadGuy &other, const CollisionHit &hit)
Root::collision_badguy(BadGuy& other, const CollisionHit& hit)
{
if (other.get_group() == COLGROUP_MOVING && other.is_snipable())
{
Expand Down
16 changes: 11 additions & 5 deletions src/badguy/root.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define HEADER_SUPERTUX_BADGUY_ROOT_HPP

#include "badguy/badguy.hpp"

#include "supertux/timer.hpp"

class Root final : public BadGuy
Expand All @@ -28,9 +29,9 @@ class Root final : public BadGuy
float delay = -1, bool play_sound = true);

virtual void initialize() override;
virtual void draw(DrawingContext &context) override;
virtual void draw(DrawingContext& context) override;
virtual void active_update(float dt_sec) override;
virtual HitResponse collision_badguy(BadGuy &other, const CollisionHit &hit) override;
virtual HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit) override;
virtual void kill_fall() override;

static std::string class_name() { return "root"; }
Expand All @@ -40,21 +41,26 @@ class Root final : public BadGuy

virtual bool is_flammable() const override { return false; }
virtual bool is_freezable() const override { return false; }
virtual bool is_snipable () const override { return false; }
virtual bool is_snipable() const override { return false; }

virtual std::vector<Direction> get_allowed_directions() const override;

private:
enum State { STATE_HATCHING, STATE_APPEARING, STATE_RETREATING };

void construct(float delay = -1, bool play_sound = true);

enum State { STATE_HATCHING, STATE_APPEARING, STATE_RETREATING };
Copy link
Member

Choose a reason for hiding this comment

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

I thought types came first

Copy link
Member

Choose a reason for hiding this comment

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

Functions first, then enumerators and variables, so everything is fully organized.


private:
SurfacePtr m_base_surface;
Timer m_timer;
State m_state;
float m_delay;
float m_maxheight;
bool m_play_sound;

private:
Root(const Root&) = delete;
Root& operator=(const Root&) = delete;
};

#endif
Expand Down
100 changes: 48 additions & 52 deletions src/badguy/root_sapling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include "supertux/sector.hpp"
#include "util/reader_mapping.hpp"

static const float ROOT_SAPLING_RANGE = 32.f*20;
static const float ROOT_SAPLING_RANGE = 32.f * 20;
static const float ROOT_SAPLING_SPAWN_TIME = 2.f;

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"),
LAYER_TILES - 15, "images/creatures/mole/corrupted/core_glow/core_glow.sprite"),
m_root_timer(),
m_dead(false)
{
Expand Down Expand Up @@ -84,15 +84,15 @@ RootSapling::collision_squished(GameObject& object)
set_colgroup_active(COLGROUP_DISABLED);

auto player = dynamic_cast<Player*>(&object);
if (player) {
if (player)
player->bounce(*this);
}

run_dead_script();
return true;
}

HitResponse RootSapling::collision_player(Player &player, const CollisionHit &hit)
HitResponse
RootSapling::collision_player(Player& player, const CollisionHit& hit)
{
if (m_dir != Direction::DOWN || !hit.bottom)
return BadGuy::collision_player(player, hit);
Expand Down Expand Up @@ -158,9 +158,9 @@ RootSapling::summon_root()
(*axis) = player->get_bbox().get_bottom() + 1;

bool should_summon = false;
for (TileMap* map : Sector::get().get_solid_tilemaps())
for (TileMap* tilemap : Sector::get().get_solid_tilemaps())
Copy link
Member

Choose a reason for hiding this comment

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

what!!!

Copy link
Member

Choose a reason for hiding this comment

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

Just a more verbose variable name.

{
const Tile& tile = map->get_tile_at(pos);
const Tile& tile = tilemap->get_tile_at(pos);
if (tile.is_solid())
{
should_summon = true;
Expand All @@ -177,23 +177,23 @@ RootSapling::summon_root()
switch (m_dir)
{
case Direction::UP:
eye = {player->get_bbox().get_middle().x, player->get_bbox().get_bottom() + 1};
end = {eye.x, eye.y + ROOT_SAPLING_RANGE};
eye = { player->get_bbox().get_middle().x, player->get_bbox().get_bottom() + 1 };
end = { eye.x, eye.y + ROOT_SAPLING_RANGE };
break;

case Direction::DOWN:
eye = {player->get_bbox().get_middle().x, player->get_bbox().get_top() - 1};
end = {eye.x, eye.y - ROOT_SAPLING_RANGE};
eye = { player->get_bbox().get_middle().x, player->get_bbox().get_top() - 1 };
end = { eye.x, eye.y - ROOT_SAPLING_RANGE };
break;

case Direction::LEFT:
eye = {player->get_bbox().get_right() + 1, player->get_bbox().get_middle().y};
end = {eye.x + ROOT_SAPLING_RANGE, eye.y};
eye = { player->get_bbox().get_right() + 1, player->get_bbox().get_middle().y };
end = { eye.x + ROOT_SAPLING_RANGE, eye.y };
break;

case Direction::RIGHT:
eye = {player->get_bbox().get_left() - 1, player->get_bbox().get_middle().y};
end = {eye.x - ROOT_SAPLING_RANGE, eye.y};
eye = { player->get_bbox().get_left() - 1, player->get_bbox().get_middle().y };
end = { eye.x - ROOT_SAPLING_RANGE, eye.y };
break;

default: assert(false); break;
Expand All @@ -204,37 +204,33 @@ RootSapling::summon_root()
reverse_raycast(eye, end);

auto tile_p = std::get_if<const Tile*>(&result.hit);
if (tile_p && !result.box.empty())
{
switch (m_dir)
{
case Direction::UP:
case Direction::DOWN:
if ((*tile_p)->is_unisolid())
return;
(*axis) = result.box.p1().y;
break;

case Direction::LEFT:
case Direction::RIGHT:
if ((*tile_p)->is_unisolid())
return;
(*axis) = result.box.p1().x;
break;

/*
case Direction::DOWN:
case Direction::RIGHT:
(*axis) = reverse_raycast(result.box);
break;
*/

default: assert(false); break;
}
}
else
{
if (!tile_p || result.box.empty())
return;

switch (m_dir)
{
case Direction::UP:
case Direction::DOWN:
if ((*tile_p)->is_unisolid())
return;
(*axis) = result.box.p1().y;
break;

case Direction::LEFT:
case Direction::RIGHT:
if ((*tile_p)->is_unisolid())
return;
(*axis) = result.box.p1().x;
break;

/*
case Direction::DOWN:
case Direction::RIGHT:
(*axis) = reverse_raycast(result.box);
break;
*/

default: assert(false); break;
}
}

Expand Down Expand Up @@ -280,22 +276,22 @@ RootSapling::summon_root()
bool
RootSapling::should_summon_root(const Rectf& bbox)
{
for (const auto& solids : Sector::get().get_solid_tilemaps()) {
for (const auto& solids : Sector::get().get_solid_tilemaps())
{
if (solids->get_path())
// Do not support moving tilemaps. Not planned.
continue;
continue; // Do not support moving tilemaps. Not planned.

// Test with all tiles in the root's hitbox
const Rect test_tiles = solids->get_tiles_overlapping(bbox);

for (int x = test_tiles.left; x < test_tiles.right; ++x) {
for (int y = test_tiles.top; y < test_tiles.bottom; ++y) {
for (int x = test_tiles.left; x < test_tiles.right; ++x)
{
for (int y = test_tiles.top; y < test_tiles.bottom; ++y)
{
const Tile& tile = solids->get_tile(x, y);

if (!(tile.get_attributes() & Tile::SOLID))
{
goto next_tilemap;
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/badguy/root_sapling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
class RootSapling final : public BadGuy
{
public:
RootSapling(const ReaderMapping& );
RootSapling(const ReaderMapping& reader);

virtual void kill_fall() override;
virtual HitResponse collision_badguy(BadGuy&other, const CollisionHit&hit) override;
virtual HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit) override;
virtual bool collision_squished(GameObject& object) override;
virtual HitResponse collision_player(Player &player, const CollisionHit &hit) override;
virtual HitResponse collision_player(Player& player, const CollisionHit& hit) override;
virtual void active_update(float) override;

virtual bool is_flammable() const override { return false; }
virtual bool is_freezable() const override { return false; }
virtual bool is_snipable () const override { return false; }
virtual bool is_snipable() const override { return false; }

static std::string class_name() { return "root_sapling"; }
virtual std::string get_class_name() const override { return class_name(); }
Expand All @@ -53,6 +53,7 @@ class RootSapling final : public BadGuy
/** Fix raycasting down/right. More info in the implementation. */
CollisionSystem::RaycastResult reverse_raycast(const Vector& line_start, const Vector& line_end);

private:
Timer m_root_timer;
bool m_dead;

Expand Down
3 changes: 2 additions & 1 deletion src/sprite/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ Sprite::get_height() const
return static_cast<int>(m_action->surfaces[m_frameidx]->get_height());
}

const std::optional<std::vector<SurfacePtr>> Sprite::get_action_surfaces(const std::string& name) const
const std::optional<std::vector<SurfacePtr>>
Sprite::get_action_surfaces(const std::string& name) const
{
const SpriteData::Action* action = m_data.get_action(name);
if (!action) return std::nullopt;
Expand Down
3 changes: 1 addition & 2 deletions src/sprite/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class Sprite final
Blend get_blend() const;

bool has_action (const std::string& name) const { return (m_data.get_action(name) != nullptr); }

std::size_t get_actions_count() { return m_data.actions.size(); }
size_t get_actions_count() const { return m_data.actions.size(); }
Copy link
Member

Choose a reason for hiding this comment

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

what

Copy link
Member

Choose a reason for hiding this comment

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

Nowhere does the code specify std:: for size_t, since there is no need to. It's a nitpick but I was editing the code anyways, so...


private:
void update();
Expand Down
18 changes: 12 additions & 6 deletions src/supertux/direction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ string_to_dir(const std::string& dir_str)
Direction
invert_dir(const Direction& dir)
{
switch (dir) {
case Direction::RIGHT: return Direction::LEFT;
case Direction::LEFT: return Direction::RIGHT;
case Direction::DOWN: return Direction::UP;
case Direction::UP: return Direction::DOWN;
default: return Direction::NONE;
switch (dir)
{
case Direction::RIGHT:
return Direction::LEFT;
case Direction::LEFT:
return Direction::RIGHT;
case Direction::DOWN:
return Direction::UP;
case Direction::UP:
return Direction::DOWN;
default:
return Direction::NONE;
}
}

Expand Down
Loading