Skip to content

Commit

Permalink
this is for the good of the item economy
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed Oct 5, 2024
1 parent f9c6afc commit fe93770
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/control/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ InputManager::get_controller(int player_id)
return *m_controllers[player_id];
}

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

void
Expand Down
1 change: 1 addition & 0 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ GameSession::update(float dt_sec, const Controller& controller)
}

m_currentsector->update(dt_sec);

} else {
bool are_all_stopped = true;

Expand Down
11 changes: 8 additions & 3 deletions src/supertux/player_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static const int MAX_COINS = 9999;

PlayerStatus::PlayerStatus(int num_players) :
m_num_players(num_players),
m_item_pockets(num_players),
coins(START_COINS),
bonus(num_players),
m_item_pockets(num_players),
max_fire_bullets(num_players),
max_ice_bullets(num_players),
max_air_time(num_players),
Expand Down Expand Up @@ -64,7 +64,8 @@ PlayerStatus::take_checkpoint_coins()
coins = 0;
}

void PlayerStatus::reset(int num_players)
void
PlayerStatus::reset(int num_players)
{
coins = START_COINS;

Expand Down Expand Up @@ -265,15 +266,19 @@ void
PlayerStatus::give_item_from_pocket(Player* player)
{
BonusType bonustype = m_item_pockets[player->get_id()];
if (bonustype == NO_BONUS)
return;

m_item_pockets[player->get_id()] = NO_BONUS;

Vector pos;
auto& powerup = Sector::get().add<PowerUp>(pos, PowerUp::get_type_from_bonustype(bonustype));
pos.x = player->get_bbox().get_left();
pos.y = player->get_bbox().get_top() - powerup.get_bbox().get_height() - 5;
pos.y = player->get_bbox().get_top() + player->get_collision_object()->get_movement().y - powerup.get_bbox().get_height() - 15;

powerup.physic.set_velocity_y(-200);
powerup.physic.set_gravity_modifier(0.4f);
powerup.get_collision_object()->m_group = COLGROUP_TOUCHABLE;
powerup.set_pos(pos);
}

Expand Down
21 changes: 13 additions & 8 deletions src/supertux/player_status_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "video/surface.hpp"
#include "editor/editor.hpp"

#include <iostream>

static const int DISPLAYED_COINS_UNSET = -1;

PlayerStatusHUD::PlayerStatusHUD(PlayerStatus& player_status) :
Expand Down Expand Up @@ -151,15 +153,18 @@ PlayerStatusHUD::draw(DrawingContext& context)
PlayerStatusHUD::text_color);
}

std::cout << m_player_status.m_num_players << std::endl;
for (int i = 0; i < m_player_status.m_num_players; i++) {
float ypos = static_cast<float>(m_item_pocket_border->get_height() * i);
Vector pos(BORDER_X, BORDER_Y + ypos);
context.color().draw_surface(m_item_pocket_border, pos, LAYER_HUD);

Vector pos(BORDER_X, BORDER_Y);
context.color().draw_surface(m_item_pocket_border, pos, LAYER_HUD);

Sprite* sprite = m_bonus_sprites[m_player_status.m_item_pockets.front()].get();
if (m_player_status.m_item_pockets.size() > 0 && sprite)
{
pos += 20;
sprite->draw(context.color(), pos, LAYER_HUD);
if (m_bonus_sprites.find(m_player_status.m_item_pockets[i]) != m_bonus_sprites.end())
{
pos += 20;
Sprite* sprite = m_bonus_sprites[m_player_status.m_item_pockets.front()].get();
sprite->draw(context.color(), pos, LAYER_HUD);
}
}

context.pop_transform();
Expand Down

0 comments on commit fe93770

Please sign in to comment.