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

Item Pocket #3070

Merged
merged 37 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4b772da
aeiou
MatusGuy Sep 22, 2024
80c7d09
add item pocket input
MatusGuy Sep 24, 2024
49a12bb
item pocket workie
MatusGuy Sep 24, 2024
479dfd7
item pocket hud
MatusGuy Sep 25, 2024
4364d9b
lifesaver texture
MatusGuy Sep 25, 2024
5c4e09a
item pocket bare minimum
MatusGuy Sep 25, 2024
22264d0
god fujjgking damngit
MatusGuy Oct 5, 2024
4f1b9d7
THINGS
MatusGuy Oct 5, 2024
f9c6afc
pepsi pocket
MatusGuy Oct 5, 2024
fe93770
this is for the good of the item economy
MatusGuy Oct 5, 2024
04348f8
more bugs fickesed
MatusGuy Oct 6, 2024
336ea97
powerup stacking is gone
MatusGuy Oct 6, 2024
03b4ad2
editor
MatusGuy Oct 6, 2024
f1d3310
fix ci
MatusGuy Oct 12, 2024
ffea8b4
Merge branch 'SuperTux:master' into item-pocket
MatusGuy Oct 13, 2024
80b15fa
setting wip
MatusGuy Oct 19, 2024
ca870a7
item pocket setting complete
MatusGuy Oct 23, 2024
2bffb8d
Merge branch 'master' into item-pocket
MatusGuy Oct 23, 2024
e240d75
agjhag
MatusGuy Oct 23, 2024
6f6eb0f
tdjyfjgfjgf
MatusGuy Oct 24, 2024
8df8b8f
bitch
MatusGuy Oct 24, 2024
4cfa69a
the anticheat mechanism
MatusGuy Oct 25, 2024
86e324e
omfg
MatusGuy Oct 27, 2024
edb5457
wip [ci skip]
MatusGuy Nov 1, 2024
83bddf1
wip again [ci skip]
MatusGuy Nov 1, 2024
28ae4ce
script
MatusGuy Nov 1, 2024
f339d63
augh squirrel thing
MatusGuy Nov 2, 2024
0535250
Apply suggestions from code review
MatusGuy Nov 2, 2024
935de91
Fix being unable to spawn player [ci skip]
Vankata453 Nov 2, 2024
f8c3e8a
Remove code duplication in `MultiplayerPlayerMenu`, do not remove pla…
Vankata453 Nov 2, 2024
6e18d69
Fix scripting documentation consistency with function
Vankata453 Nov 2, 2024
babdd6d
wip script item pocket
MatusGuy Nov 2, 2024
d8639a8
chagne docs
MatusGuy Nov 3, 2024
460f906
Merge branch 'master' into item-pocket
MatusGuy Nov 7, 2024
4ccfadf
fix duo player bug weird strange weird
MatusGuy Nov 17, 2024
2aca43e
Scripting docs: Full stops
Vankata453 Nov 20, 2024
ec5160b
Fix `BonusType` enum descriptions for scripting documentation
Vankata453 Nov 20, 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
Binary file added data/images/engine/hud/item_pocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ HitResponse
BadGuy::collision_bullet(Bullet& bullet, const CollisionHit& hit)
{
if (is_frozen()) {
if (bullet.get_type() == FIRE_BONUS) {
if (bullet.get_type() == BONUS_FIRE) {
// Fire bullet thaws frozen badguys.
unfreeze();
bullet.remove_me();
Expand All @@ -629,7 +629,7 @@ BadGuy::collision_bullet(Bullet& bullet, const CollisionHit& hit)
}
}
else if (is_ignited()) {
if (bullet.get_type() == ICE_BONUS) {
if (bullet.get_type() == BONUS_ICE) {
// Ice bullets extinguish ignited badguys.
extinguish();
bullet.remove_me();
Expand All @@ -640,13 +640,13 @@ BadGuy::collision_bullet(Bullet& bullet, const CollisionHit& hit)
return FORCE_MOVE;
}
}
else if (bullet.get_type() == FIRE_BONUS && is_flammable()) {
else if (bullet.get_type() == BONUS_FIRE && is_flammable()) {
// Fire bullets ignite flammable badguys.
ignite();
bullet.remove_me();
return ABORT_MOVE;
}
else if (bullet.get_type() == ICE_BONUS && is_freezable()) {
else if (bullet.get_type() == BONUS_ICE && is_freezable()) {
// Ice bullets freeze freezable badguys.
freeze();
bullet.remove_me();
Expand Down
21 changes: 14 additions & 7 deletions src/badguy/boss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ namespace
Boss::Boss(const ReaderMapping& reader, const std::string& sprite_name, int layer) :
BadGuy(reader, sprite_name, layer),
m_lives(),
m_max_lives(),
m_pinch_lives(),
m_hud_head(),
m_hud_icon(),
m_pinch_mode(),
m_pinch_activation_script()
{
reader.get("lives", m_lives, DEFAULT_LIVES);
reader.get("pinch-lives", m_pinch_lives, DEFAULT_PINCH_LIVES);
m_max_lives = m_lives;

m_countMe = true;

reader.get("pinch-lives", m_pinch_lives, DEFAULT_PINCH_LIVES);
reader.get("pinch-activation-script", m_pinch_activation_script, "");
}

Expand Down Expand Up @@ -70,9 +73,13 @@ Boss::draw_hit_points(DrawingContext& context)
context.set_translation(Vector(0, 0));
context.transform().scale = 1.f;

float startpos = (context.get_width() - static_cast<float>((m_hud_head->get_width() * m_max_lives))) / 2;
for (int i = 0; i < m_lives; ++i)
{
context.color().draw_surface(m_hud_head, Vector(BORDER_X + (static_cast<float>(i * m_hud_head->get_width())), BORDER_Y + 1), LAYER_HUD);
context.color().draw_surface(m_hud_head,
Vector(BORDER_X + (startpos + static_cast<float>(i * m_hud_head->get_width())),
BORDER_Y + 1),
LAYER_HUD);
}

context.pop_transform();
Expand All @@ -86,15 +93,15 @@ Boss::get_settings()

result.add_text("hud-icon", &m_hud_icon, "hud-icon", "images/creatures/yeti/hudlife.png", OPTION_HIDDEN);
result.add_int(_("Lives"), &m_lives, "lives", DEFAULT_LIVES);
/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.

/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.
This setting specifies how many lives need to be spent until pinch
mode is activated. */
result.add_int(_("Lives to Pinch Mode"), &m_pinch_lives, "pinch-lives", DEFAULT_PINCH_LIVES);

/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.
/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.
This setting specifies the squirrel script that gets run to activate boss mode. */
result.add_script(_("Pinch Mode Activation Script"), &m_pinch_activation_script, "pinch-activation-script");

Expand Down
1 change: 1 addition & 0 deletions src/badguy/boss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Boss : public BadGuy

protected:
int m_lives;
int m_max_lives;
int m_pinch_lives;
SurfacePtr m_hud_head;
std::string m_hud_icon;
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/snowman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Snowman::loose_head()
HitResponse
Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit)
{
if (bullet.get_type() == FIRE_BONUS) {
if (bullet.get_type() == BONUS_FIRE) {
// Fire bullets destroy snowman's body.
Vector snowball_pos = get_pos();
// Hard-coded values from sprites.
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/stalactite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Stalactite::collision_bullet(Bullet& bullet, const CollisionHit& hit)
timer.start(SHAKE_TIME);
state = STALACTITE_SHAKING;
bullet.remove_me();
if (bullet.get_type() == FIRE_BONUS)
if (bullet.get_type() == BONUS_FIRE)
SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
SoundManager::current()->play("sounds/cracking.wav", get_pos());
}
Expand Down
1 change: 1 addition & 0 deletions src/control/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const char* g_control_names[] = {
"down",
"jump",
"action",
"item",
"start",
"escape",
"menu-select",
Expand Down
1 change: 1 addition & 0 deletions src/control/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class Control {

JUMP,
ACTION,
ITEM,

START,
ESCAPE,
Expand Down
35 changes: 8 additions & 27 deletions src/control/game_controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "supertux/globals.hpp"
#include "supertux/game_session.hpp"
#include "supertux/savegame.hpp"
#include "supertux/sector.hpp"
#include "util/log.hpp"

GameControllerManager::GameControllerManager(InputManager* parent) :
Expand Down Expand Up @@ -84,7 +83,7 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev)
break;

case SDL_CONTROLLER_BUTTON_BACK:
set_control(Control::CONSOLE, ev.state);
set_control(Control::ITEM, ev.state);
break;

case SDL_CONTROLLER_BUTTON_GUIDE:
Expand Down Expand Up @@ -205,6 +204,9 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev)
void
GameControllerManager::on_controller_added(int joystick_index)
{
if (!m_parent->can_add_user())
return;

if (!SDL_IsGameController(joystick_index))
{
log_warning << "joystick is not a game controller, ignoring: " << joystick_index << std::endl;
Expand Down Expand Up @@ -240,16 +242,7 @@ GameControllerManager::on_controller_added(int joystick_index)

if (GameSession::current() && !GameSession::current()->get_savegame().is_title_screen() && id != 0)
{
auto& sector = GameSession::current()->get_current_sector();
auto& player_status = GameSession::current()->get_savegame().get_player_status();

if (player_status.m_num_players <= id)
player_status.add_player();

// ID = 0 is impossible, so no need to write `(id == 0) ? "" : ...`
auto& player = sector.add<Player>(player_status, "Tux" + std::to_string(id + 1), id);

player.multiplayer_prepare_spawn();
GameSession::current()->on_player_added(id);
}
}
}
Expand All @@ -272,22 +265,10 @@ GameControllerManager::on_controller_removed(int instance_id)
m_game_controllers.erase(it);

if (m_parent->m_use_game_controller && g_config->multiplayer_auto_manage_players
&& deleted_player_id != 0 && !m_parent->m_uses_keyboard[deleted_player_id])
&& deleted_player_id != 0 && !m_parent->m_uses_keyboard[deleted_player_id] &&
GameSession::current())
{
// Sectors in worldmaps have no Player's of that class.
if (Sector::current() && Sector::current()->get_object_count<Player>() > 0)
{
auto players = Sector::current()->get_objects_by_type<Player>();
auto it_players = players.begin();

while (it_players != players.end())
{
if (it_players->get_id() == deleted_player_id)
it_players->remove_me();

it_players++;
}
}
GameSession::current()->on_player_removed(deleted_player_id);
}
}
else
Expand Down
11 changes: 11 additions & 0 deletions src/control/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "control/keyboard_manager.hpp"
#include "util/log.hpp"

static constexpr int MAX_PLAYERS = 4;

InputManager::InputManager(KeyboardConfig& keyboard_config,
JoystickConfig& joystick_config) :
m_controllers(),
Expand Down Expand Up @@ -51,6 +53,12 @@ InputManager::get_controller(int player_id)
return *m_controllers[player_id];
}

bool
InputManager::can_add_user() const
{
return get_num_users() < MAX_PLAYERS;
}

void
InputManager::use_game_controller(bool v)
{
Expand Down Expand Up @@ -139,6 +147,9 @@ InputManager::process_event(const SDL_Event& event)
void
InputManager::push_user()
{
if (!can_add_user())
return;

m_controllers.push_back(std::make_unique<Controller>());
}

Expand Down
2 changes: 1 addition & 1 deletion src/control/input_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class InputManager final : public Currenton<InputManager>
Controller& get_controller(int player_id = 0);

int get_num_users() const { return static_cast<int>(m_controllers.size()); }

bool can_add_user() const;
void push_user();
void pop_user();

Expand Down
1 change: 1 addition & 0 deletions src/control/joystick_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JoystickConfig::JoystickConfig() :
bind_joybutton(0, 4, Control::PEEK_LEFT);
bind_joybutton(0, 5, Control::PEEK_RIGHT);
bind_joybutton(0, 6, Control::START);
bind_joybutton(0, 7, Control::ITEM);

// Default joystick axis configuration
bind_joyaxis(0, -1, Control::LEFT);
Expand Down
34 changes: 8 additions & 26 deletions src/control/joystick_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "supertux/globals.hpp"
#include "supertux/game_session.hpp"
#include "supertux/savegame.hpp"
#include "supertux/sector.hpp"
#include "util/log.hpp"

JoystickManager::JoystickManager(InputManager* parent_,
Expand Down Expand Up @@ -55,6 +54,10 @@ void
JoystickManager::on_joystick_added(int joystick_index)
{
log_debug << "on_joystick_added(): " << joystick_index << std::endl;

if (!parent->can_add_user())
return;

SDL_Joystick* joystick = SDL_JoystickOpen(joystick_index);
if (!joystick)
{
Expand Down Expand Up @@ -96,16 +99,7 @@ JoystickManager::on_joystick_added(int joystick_index)

if (GameSession::current() && !GameSession::current()->get_savegame().is_title_screen() && id != 0)
{
auto& sector = GameSession::current()->get_current_sector();
auto& player_status = GameSession::current()->get_savegame().get_player_status();

if (player_status.m_num_players <= id)
player_status.add_player();

// ID = 0 is impossible, so no need to write `(id == 0) ? "" : ...`
auto& player = sector.add<Player>(player_status, "Tux" + std::to_string(id + 1), id);

player.multiplayer_prepare_spawn();
GameSession::current()->on_player_added(id);
}
}
}
Expand All @@ -129,22 +123,10 @@ JoystickManager::on_joystick_removed(int instance_id)
joysticks.erase(it);

if (!parent->m_use_game_controller && g_config->multiplayer_auto_manage_players
&& deleted_player_id != 0 && !parent->m_uses_keyboard[deleted_player_id])
&& deleted_player_id != 0 && !parent->m_uses_keyboard[deleted_player_id] &&
GameSession::current())
{
// Sectors in worldmaps have no Player's of that class
if (Sector::current() && Sector::current()->get_object_count<Player>() > 0)
{
auto players = Sector::current()->get_objects_by_type<Player>();
auto it_players = players.begin();

while (it_players != players.end())
{
if (it_players->get_id() == deleted_player_id)
it_players->remove_me();

it_players++;
}
}
GameSession::current()->on_player_removed(deleted_player_id);
}
}
else
Expand Down
16 changes: 2 additions & 14 deletions src/control/keyboard_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ KeyboardConfig::KeyboardConfig() :
Control::RIGHT,
Control::JUMP,
Control::ACTION,
Control::ITEM,
Control::PEEK_LEFT,
Control::PEEK_RIGHT,
Control::PEEK_UP,
Expand All @@ -51,6 +52,7 @@ KeyboardConfig::KeyboardConfig() :
m_keymap[SDLK_DOWN] = {0, Control::DOWN};
m_keymap[SDLK_SPACE] = {0, Control::JUMP};
m_keymap[SDLK_LCTRL] = {0, Control::ACTION};
m_keymap[SDLK_LSHIFT] = {0, Control::ITEM};
m_keymap[SDLK_ESCAPE] = {0, Control::ESCAPE};
m_keymap[SDLK_p] = {0, Control::START};
m_keymap[SDLK_PAUSE] = {0, Control::START};
Expand All @@ -64,20 +66,6 @@ KeyboardConfig::KeyboardConfig() :
m_keymap[SDLK_F1] = {0, Control::CHEAT_MENU};
m_keymap[SDLK_F2] = {0, Control::DEBUG_MENU};
m_keymap[SDLK_BACKSPACE] = {0, Control::REMOVE};

m_keymap[SDLK_a] = {1, Control::LEFT};
m_keymap[SDLK_d] = {1, Control::RIGHT};
m_keymap[SDLK_w] = {1, Control::UP};
m_keymap[SDLK_s] = {1, Control::DOWN};
m_keymap[SDLK_e] = {1, Control::JUMP};
m_keymap[SDLK_q] = {1, Control::ACTION};

m_keymap[SDLK_j] = {2, Control::LEFT};
m_keymap[SDLK_l] = {2, Control::RIGHT};
m_keymap[SDLK_i] = {2, Control::UP};
m_keymap[SDLK_k] = {2, Control::DOWN};
m_keymap[SDLK_o] = {2, Control::JUMP};
m_keymap[SDLK_u] = {2, Control::ACTION};
Vankata453 marked this conversation as resolved.
Show resolved Hide resolved
}

void
Expand Down
Loading