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 3 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: 17 additions & 2 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,18 @@ Player::set_bonus(BonusType type, bool animate)
return true;
}

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 @@ -2375,7 +2387,7 @@ Player::collision(MovingObject& 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 @@ -2421,7 +2433,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 @@ -3071,6 +3083,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 @@ -3096,6 +3110,7 @@ Player::register_class(ssq::VM& vm)
cls.addFunc("set_item_pocket", &Player::set_item_pocket);

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

/* EOF */
18 changes: 18 additions & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ class Player final : public MovingObject
*/
inline bool get_visible() const { return m_visible; }

/**
* @scripting
* @description Make tux invincible without the star effect.
* @param bool $safe
*/
void set_is_intentionally_safe(bool safe);
/**
* @scripting
* @description Returns ""true"" if Tux is currently intentionally safe.
*/
bool get_is_intentionally_safe() const;

inline bool on_ground() const { return m_on_ground_flag; }
inline void set_on_ground(bool flag) { m_on_ground_flag = flag; }

Expand Down Expand Up @@ -556,7 +568,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