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

Add scripting function for turning player invincible (without star) #3051

Open
wants to merge 1 commit 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: 17 additions & 2 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,18 @@ Player::get_visible() const
return m_visible;
}

void
Player::set_is_intentionally_safe(bool safe)
{
m_is_intentionally_safe = safe;
}

bool
Player::get_is_intentionally_safe() const
{
return m_is_intentionally_safe;
}

void
Player::kick()
{
Expand Down Expand Up @@ -2365,7 +2377,7 @@ Player::collision(GameObject& other, const CollisionHit& hit)

auto badguy = dynamic_cast<BadGuy*> (&other);
if (badguy != nullptr) {
if (m_safe_timer.started() || m_invincible_timer.started())
if (m_is_intentionally_safe || m_safe_timer.started() || m_invincible_timer.started())
return FORCE_MOVE;
if (m_stone)
return ABORT_MOVE;
Expand Down Expand Up @@ -2411,7 +2423,7 @@ Player::kill(bool completely)
if (m_dying || m_deactivated || is_winning() )
return;

if (!completely && (m_safe_timer.started() || m_invincible_timer.started()))
if (!completely && (m_is_intentionally_safe || m_safe_timer.started() || m_invincible_timer.started()))
return;

m_growing = false;
Expand Down Expand Up @@ -3078,6 +3090,8 @@ Player::register_class(ssq::VM& vm)
cls.addFunc("set_dir", &Player::set_dir);
cls.addFunc("set_visible", &Player::set_visible);
cls.addFunc("get_visible", &Player::get_visible);
cls.addFunc("set_is_intentionally_safe", &Player::set_is_intentionally_safe);
cls.addFunc("get_is_intentionally_safe", &Player::get_is_intentionally_safe);
cls.addFunc("kill", &Player::kill);
cls.addFunc("set_ghost_mode", &Player::set_ghost_mode);
cls.addFunc("get_ghost_mode", &Player::get_ghost_mode);
Expand All @@ -3100,6 +3114,7 @@ Player::register_class(ssq::VM& vm)
cls.addFunc("get_input_released", &Player::get_input_released);

cls.addVar("visible", &Player::m_visible);
cls.addVar("is_intentionally_safe", &Player::m_is_intentionally_safe);
}

/* EOF */
26 changes: 22 additions & 4 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class Player final : public MovingObject
bool is_dying() const { return m_dying; }

/**
* Returns true if the player is currently alive
* Returns true if the player is currently alive
* (not dying or dead)
*/
bool is_alive() const { return !is_dying() && !is_dead(); }

/**
* Returns true if the player can be controlled.
* (alive and not currently in a win sequence)
Expand Down Expand Up @@ -298,8 +298,8 @@ class Player final : public MovingObject

/**
* @scripting
* @description Set Tux visible or invisible.
* @param bool $visible
* @description Set Tux safe or invisible.
Copy link
Member

@tobbi tobbi Aug 30, 2024

Choose a reason for hiding this comment

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

This seems very much wrong from what I can tell. At the very least the parameter below should match the name of the actual parameter.

* @param bool $safe
*/
void set_visible(bool visible);
/**
Expand All @@ -308,6 +308,18 @@ class Player final : public MovingObject
*/
bool get_visible() const;

/**
* @scripting
* @description Set Tux visible or invisible.
* @param bool $visible
*/
void set_is_intentionally_safe(bool safe);
/**
* @scripting
* @description Returns ""true"" if Tux is currently visible (has not been set invisible by the ""set_visible()"" method).
*/
bool get_is_intentionally_safe() const;

bool on_ground() const;
void set_on_ground(bool flag);

Expand Down Expand Up @@ -535,7 +547,13 @@ class Player final : public MovingObject
private:
Timer m_skidding_timer;
Timer m_safe_timer;

/**
* @scripting
* @description Determines whether Tux is invincible.
*/
bool m_is_intentionally_safe;

Timer m_kick_timer;
Timer m_buttjump_timer;

Expand Down
Loading