Skip to content

Commit

Permalink
Merge branch 'master' into custom-linked-sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 authored Nov 22, 2024
2 parents 87e89cf + 82bca54 commit 4fddd07
Show file tree
Hide file tree
Showing 53 changed files with 782 additions and 537 deletions.
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 @@ -620,7 +620,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 @@ -632,7 +632,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 @@ -643,13 +643,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/haywire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Haywire::draw(DrawingContext& context)
{
m_exploding_sprite->set_blend(Blend::ADD);
m_exploding_sprite->draw(context.light(),
get_pos()+Vector(get_bbox().get_width()/2, get_bbox().get_height()/2), m_layer, m_flip);
get_pos() + (get_bbox().get_size().as_vector() / 2.0f), m_layer, m_flip);
}
WalkingBadguy::draw(context);
}
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};
}

void
Expand Down
Loading

0 comments on commit 4fddd07

Please sign in to comment.