Skip to content

Commit

Permalink
Merge pull request #192 from cdsupina/character-selection
Browse files Browse the repository at this point in the history
Improved Character Selection UI
  • Loading branch information
varoonp123 authored Jun 4, 2024
2 parents b32ded5 + 31298f9 commit 51dd8f3
Show file tree
Hide file tree
Showing 34 changed files with 1,898 additions and 1,009 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ runner = "wasm-server-runner"
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
#[profile.dev]
#debug = 1

# This is sometimes required while we pull a library directly from git. Requires the system used for build to have git
# installed. See https://docs.shipyard.rs/configuration/git-fetch-with-cli.html
[net]
git-fetch-with-cli = true
10 changes: 10 additions & 0 deletions assets/data/ability_descriptions.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(
slot_one: {
StandardBlast: "Fires energy blasts.",
StandardBullet: "Fires lead bullets.",
},
slot_two: {
Charge: "Charge in a direction.",
MegaBlast: "Fires large, high damage, blasts.",
}
)
4 changes: 2 additions & 2 deletions assets/data/characters.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(
characters: {
Captain: (
name: "Captain",
acceleration: (25.0, 25.0),
deceleration: (10.0, 10.0),
speed: (300.0, 300.0),
Expand All @@ -15,7 +16,6 @@
attraction_acceleration: 15.0,
money: 0,
weapon_damage: 12,
ability_period: 5.0,
ability_type: MegaBlast(5.0),
projectile_speed: 800.0,
projectile_spawn_position: Local((0.0, 40.0)),
Expand All @@ -27,6 +27,7 @@
slot_2_ability: Some(MegaBlast),
),
Juggernaut: (
name: "Juggernaut",
acceleration: (25.0, 25.0),
deceleration: (10.0, 10.0),
speed: (250.0, 250.0),
Expand All @@ -41,7 +42,6 @@
attraction_acceleration: 15.0,
money: 0,
weapon_damage: 10,
ability_period: 2.0,
ability_type: Charge(0.5),
projectile_speed: 650.0,
projectile_spawn_position: Local((0.0, 45.0)),
Expand Down
1 change: 1 addition & 0 deletions assets/data/game_parameters.ron
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
scan_range: 100.0,
sprite_scale: 3.0,
stop_threshold: 0.1,
max_players: 2, // should be between 1 and 4
)
41 changes: 41 additions & 0 deletions assets/ui_assets.assets.ron
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,45 @@
"ability_slot.right": File ( path: "texture/ability_square_right.png"),
"warning_gradient": File( path: "texture/warning_gradient.png"),
"defense_gradient": File( path: "texture/defense_gradient.png"),
"arrow_right.layout": TextureAtlasLayout (
tile_size_x: 37.,
tile_size_y: 16.,
columns: 1,
rows: 6,
),
"arrow_right.image": File(path: "texture/arrow_right_spritesheet.png"),
"arrow_left.layout": TextureAtlasLayout (
tile_size_x: 37.,
tile_size_y: 16.,
columns: 1,
rows: 6,
),
"arrow_left.image": File(path: "texture/arrow_left_spritesheet.png"),
"large_menu_button.layout": TextureAtlasLayout (
tile_size_x: 160.,
tile_size_y: 77.,
columns: 1,
rows: 2,
),
"large_menu_button.image": File(path: "texture/large_menu_button_spritesheet.png"),
"gamepad_button_a.layout": TextureAtlasLayout (
tile_size_x: 20.,
tile_size_y: 25.,
columns: 1,
rows: 2,
),
"gamepad_button_a.image": File(path: "texture/gamepad_button_a.png"),
"keyboard_key_return.layout": TextureAtlasLayout (
tile_size_x: 34.,
tile_size_y: 33.,
columns: 1,
rows: 2,
),
"keyboard_key_return.image": File(path: "texture/keyboard_key_return.png"),
"stat_icon.damage": File( path: "texture/damage_icon.png"),
"stat_icon.health": File( path: "texture/health_icon.png"),
"stat_icon.size": File( path: "texture/size_icon.png"),
"stat_icon.range": File( path: "texture/range_icon.png"),
"stat_icon.fire_rate": File( path: "texture/fire_rate_icon.png"),
"stat_icon.speed": File( path: "texture/speed_icon.png"),
})
4 changes: 2 additions & 2 deletions crates/thetawave_arcade/src/arduino.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ fn character_selection_button_leds_system(
mut player_join_event: EventReader<PlayerJoinEvent>,
) {
for event in player_join_event.read() {
if event.0 == 0 {
if event.player_idx == 0 {
serial_resource.send_message(&(*arduino_port), ButtonLEDByte::player_one_joined());
} else if event.0 == 1 {
} else if event.player_idx == 1 {
serial_resource.send_message(&(*arduino_port), ButtonLEDByte::player_two_joined());
}
}
Expand Down
14 changes: 12 additions & 2 deletions crates/thetawave_interface/src/abilities.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use bevy_ecs::{bundle::Bundle, component::Component, event::Event, system::Resource};
use bevy_time::{Timer, TimerMode};
use serde::Deserialize;
Expand All @@ -9,20 +11,28 @@ use crate::{

/// Identifier for slot one abilities
/// One for each unique ability
#[derive(Clone, Deserialize)]
#[derive(Clone, Deserialize, PartialEq, Eq, Hash)]
pub enum SlotOneAbilityType {
StandardBlast,
StandardBullet,
}

/// Identifier for slot two abilities
/// One for each unique ability
#[derive(Clone, Deserialize)]
#[derive(Clone, Deserialize, PartialEq, Eq, Hash)]
pub enum SlotTwoAbilityType {
Charge,
MegaBlast,
}

/// Hashmaps of ability types to descriptions
/// Used for providing information to user on character selection screen
#[derive(Resource, Deserialize)]
pub struct AbilityDescriptionsResource {
pub slot_one: HashMap<SlotOneAbilityType, String>,
pub slot_two: HashMap<SlotTwoAbilityType, String>,
}

/// Event for triggering ability systems to fire when criteria like inputs and cooldowns are met
#[derive(Event, Debug)]
pub struct ActivateAbilityEvent {
Expand Down
17 changes: 16 additions & 1 deletion crates/thetawave_interface/src/character.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy_math::Vec2;
use serde::Deserialize;
use strum_macros::EnumIter;

use crate::{
abilities::{SlotOneAbilityType, SlotTwoAbilityType},
Expand All @@ -8,18 +9,32 @@ use crate::{
};

/// The playable character types. To a player, these will have different appearances and abilities.
#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq, EnumIter, Default, Copy)]
pub enum CharacterType {
#[default]
Captain,
Juggernaut,
}

// Stats used to give the player a rough idea of the strengths and weaknesses of the character
#[derive(EnumIter)]
pub enum CharacterStatType {
Health,
Damage,
Speed,
FireRate,
Range,
Size,
}

/// Contains data necessary to create a player entity.
/// A character is chosen at the beginning of the game.
/// The base stats of the player are provided from the character.
/// Other data such as sprite sheets are also included with the character.
#[derive(Deserialize, Clone)]
pub struct Character {
/// Name of the character
pub name: String,
/// Base acceleration
pub acceleration: Vec2,
/// Base deceleration
Expand Down
7 changes: 6 additions & 1 deletion crates/thetawave_interface/src/character_selection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use bevy_ecs_macros::Event;

use crate::player::PlayerInput;

/// Stores the index (likely 0 or 1) of the player that joined an n-player game.
#[derive(Event)]
pub struct PlayerJoinEvent(pub usize);
pub struct PlayerJoinEvent {
pub player_idx: u8,
pub input: PlayerInput,
}
1 change: 1 addition & 0 deletions crates/thetawave_interface/src/game/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub const DEFAULT_OPTIONS_PROFILE_ID: usize = 0;
pub struct GameOptions {
pub bloom_enabled: bool,
pub bloom_intensity: f32,
pub tutorials_enabled: bool,
}
23 changes: 17 additions & 6 deletions crates/thetawave_interface/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@ use bevy_reflect::Reflect;
use leafwing_input_manager::{prelude::InputMap, Actionlike};
use serde::Deserialize;

/// Used by players to access their matching menu ui
/// has a u8 index matching the player (0-3) for a 4 player game
#[derive(Component)]
pub struct MenuExplorer;
pub struct MenuExplorer(pub u8);

/// Shared between all players to access shared ui such as the main and pause menus
#[derive(Component)]
pub struct MainMenuExplorer;

/// The input behaviors from the controller/gamepad available while in the menus.
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect, Deserialize)]
pub enum MenuAction {
Confirm,
JoinKeyboard,
ChangeCharacterKeyboard,
JoinGamepad,
ChangeCharacterGamepad,
Back,
Reset,
ExitPauseMenu,
PauseGame,
ToggleTutorial,
NavigateUp,
NavigateDown,
NavigateUpKeyboard,
NavigateDownKeyboard,
NavigateUpGamepad,
NavigateDownGamepad,
NavigateLeftKeyboard,
NavigateRightKeyboard,
NavigateLeftGamepad,
NavigateRightGamepad,
PlayerReadyKeyboard,
PlayerReadyGamepad,
}

/// Player actions during the main game/while fighting mobs. Many of these can be simultaneously
Expand Down
13 changes: 2 additions & 11 deletions crates/thetawave_interface/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct InputRestrictions {
}

/// Stores all available player slots
#[derive(Resource, Debug)]
#[derive(Resource, Debug, Default)]
pub struct PlayersResource {
/// Vec of Optional players, an index is Some if a player has joined for that slot
pub player_data: Vec<Option<PlayerData>>,
Expand All @@ -34,21 +34,12 @@ pub struct PlayerData {

/// Input method for a player
/// Gamepad has a usize identifier
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Debug, Copy)]
pub enum PlayerInput {
Keyboard,
Gamepad(usize),
}

/// Defaults to all player slots being empty
impl Default for PlayersResource {
fn default() -> Self {
PlayersResource {
player_data: vec![None, None, None, None],
}
}
}

impl PlayersResource {
/// A method to get a vector of all used inputs
pub fn get_used_inputs(&self) -> Vec<PlayerInput> {
Expand Down
3 changes: 2 additions & 1 deletion crates/thetawave_storage/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub(super) fn setup_db(conn: Connection) -> rusqlite::Result<()> {
"CREATE TABLE IF NOT EXISTS {OPTIONS_TABLE_NAME} (
optionsProfileId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
bloomEnabled BOOLEAN NOT NULL DEFAULT TRUE,
bloomIntensity REAL NOT NULL DEFAULT 1.0
bloomIntensity REAL NOT NULL DEFAULT 1.0,
tutorialsEnabled BOOLEAN NOT NULL DEFAULT FALSE
)"
);

Expand Down
4 changes: 3 additions & 1 deletion crates/thetawave_storage/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn _get_game_options(options_profile_id: usize) -> Result<Option<GameOptions>, O
let conn = get_db()?;
let stmt_raw = format!(
"
SELECT bloomEnabled, bloomIntensity FROM {OPTIONS_TABLE_NAME}
SELECT bloomEnabled, bloomIntensity, tutorialsEnabled FROM {OPTIONS_TABLE_NAME}
WHERE optionsProfileId=?1
"
);
Expand All @@ -18,9 +18,11 @@ fn _get_game_options(options_profile_id: usize) -> Result<Option<GameOptions>, O
Some(r) => {
let bloom_enabled = r.get(0)?;
let bloom_intensity = r.get(1)?;
let tutorials_enabled = r.get(2)?;
Ok(Some(GameOptions {
bloom_enabled,
bloom_intensity,
tutorials_enabled,
}))
}

Expand Down
48 changes: 47 additions & 1 deletion src/assets/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use bevy::{
text::Font,
};
use bevy_asset_loader::prelude::AssetCollection;
use thetawave_interface::abilities::{SlotOneAbilityType, SlotTwoAbilityType};
use thetawave_interface::{
abilities::{SlotOneAbilityType, SlotTwoAbilityType},
character::CharacterStatType,
};

#[derive(AssetCollection, Resource)]
pub struct UiAssets {
Expand All @@ -18,6 +21,26 @@ pub struct UiAssets {
pub thetawave_menu_button_layout: Handle<TextureAtlasLayout>,
#[asset(key = "thetawave_menu_button.image")]
pub thetawave_menu_button_image: Handle<Image>,
#[asset(key = "large_menu_button.layout")]
pub large_menu_button_layout: Handle<TextureAtlasLayout>,
#[asset(key = "large_menu_button.image")]
pub large_menu_button_image: Handle<Image>,
#[asset(key = "gamepad_button_a.layout")]
pub gamepad_button_a_layout: Handle<TextureAtlasLayout>,
#[asset(key = "gamepad_button_a.image")]
pub gamepad_button_a_image: Handle<Image>,
#[asset(key = "keyboard_key_return.layout")]
pub keyboard_key_return_layout: Handle<TextureAtlasLayout>,
#[asset(key = "keyboard_key_return.image")]
pub keyboard_key_return_image: Handle<Image>,
#[asset(key = "arrow_right.layout")]
pub arrow_right_layout: Handle<TextureAtlasLayout>,
#[asset(key = "arrow_right.image")]
pub arrow_right_image: Handle<Image>,
#[asset(key = "arrow_left.layout")]
pub arrow_left_layout: Handle<TextureAtlasLayout>,
#[asset(key = "arrow_left.image")]
pub arrow_left_image: Handle<Image>,
#[asset(key = "ability_icon.mega_blast")]
pub mega_blast_ability: Handle<Image>,
#[asset(key = "ability_icon.charge")]
Expand All @@ -34,6 +57,18 @@ pub struct UiAssets {
pub warning_gradient: Handle<Image>,
#[asset(key = "defense_gradient")]
pub defense_gradient: Handle<Image>,
#[asset(key = "stat_icon.damage")]
pub damage_icon: Handle<Image>,
#[asset(key = "stat_icon.speed")]
pub speed_icon: Handle<Image>,
#[asset(key = "stat_icon.range")]
pub range_icon: Handle<Image>,
#[asset(key = "stat_icon.size")]
pub size_icon: Handle<Image>,
#[asset(key = "stat_icon.fire_rate")]
pub fire_rate_icon: Handle<Image>,
#[asset(key = "stat_icon.health")]
pub health_icon: Handle<Image>,
}

impl UiAssets {
Expand All @@ -58,4 +93,15 @@ impl UiAssets {
self.left_ability_slot.clone()
}
}

pub fn get_stat_icon(&self, stat: &CharacterStatType) -> Handle<Image> {
match stat {
CharacterStatType::Damage => self.damage_icon.clone(),
CharacterStatType::Health => self.health_icon.clone(),
CharacterStatType::Range => self.range_icon.clone(),
CharacterStatType::FireRate => self.fire_rate_icon.clone(),
CharacterStatType::Size => self.size_icon.clone(),
CharacterStatType::Speed => self.speed_icon.clone(),
}
}
}
Loading

0 comments on commit 51dd8f3

Please sign in to comment.