Skip to content

Commit

Permalink
Attempt to make mult buttons switch to matching gameplay mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Elsklivet authored and cmgo412 committed Dec 1, 2022
1 parent 711e2eb commit 663a6ce
Show file tree
Hide file tree
Showing 15 changed files with 703 additions and 420 deletions.
81 changes: 43 additions & 38 deletions src/battle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::monster::{
PartyMonster, SelectedMonster, Strength,
};
use crate::player::Player;
use crate::{quests::*};
use crate::quests::*;
use crate::world::{GameProgress, PooledText, TextBuffer, TypeSystem, SPECIALS_PER_BATTLE};
use crate::GameState;
use bevy::prelude::*;
Expand Down Expand Up @@ -49,28 +49,27 @@ pub(crate) struct SwitchMonsterEvent(Entity);

impl Plugin for BattlePlugin {
fn build(&self, app: &mut App) {
app
.add_event::<SwitchMonsterEvent>()
.add_enter_system_set(
GameState::Battle,
SystemSet::new()
.with_system(setup_battle)
.with_system(setup_battle_stats)
.with_system(spawn_player_monster)
.with_system(spawn_enemy_monster)
)
.add_system_set(
ConditionSet::new()
// TODO: Use events and system ordering
// Run these systems only when in Battle state
.run_in_state(GameState::Battle)
// addl systems go here
.with_system(update_battle_stats)
.with_system(key_press_handler)
.with_system(update_player_monster)
.into(),
)
.add_exit_system(GameState::Battle, despawn_battle);
app.add_event::<SwitchMonsterEvent>()
.add_enter_system_set(
GameState::Battle,
SystemSet::new()
.with_system(setup_battle)
.with_system(setup_battle_stats)
.with_system(spawn_player_monster)
.with_system(spawn_enemy_monster),
)
.add_system_set(
ConditionSet::new()
// TODO: Use events and system ordering
// Run these systems only when in Battle state
.run_in_state(GameState::Battle)
// addl systems go here
.with_system(update_battle_stats)
.with_system(key_press_handler)
.with_system(update_player_monster)
.into(),
)
.add_exit_system(GameState::Battle, despawn_battle);
}
}

Expand Down Expand Up @@ -360,7 +359,7 @@ pub(crate) fn spawn_player_monster(
let (selected_type, _selected_monster) = selected_monster_query.single();

commands
.spawn_bundle(SpriteBundle {
.spawn_bundle(SpriteBundle {
sprite: Sprite {
flip_y: false, // flips our little buddy, you guessed it, in the y direction
flip_x: true, // guess what this does
Expand All @@ -378,8 +377,9 @@ pub(crate) fn update_player_monster(
mut commands: Commands,
asset_server: Res<AssetServer>,
cameras: Query<
(&Transform, Entity),
(With<Camera2d>, Without<MenuCamera>, Without<SlidesCamera>,)>,
(&Transform, Entity),
(With<Camera2d>, Without<MenuCamera>, Without<SlidesCamera>),
>,
mut switch_event: EventReader<SwitchMonsterEvent>,
game_progress: ResMut<GameProgress>,
player_monster_sprites: Query<Entity, With<PlayerMonster>>,
Expand All @@ -392,8 +392,8 @@ pub(crate) fn update_player_monster(
let mut new_entity: Option<Entity> = None;
for event in switch_event.iter() {
info!("Event fired");
// Despawn
for pm in player_monster_sprites.iter(){
// Despawn
for pm in player_monster_sprites.iter() {
commands.entity(pm).despawn_recursive();
}

Expand All @@ -402,14 +402,18 @@ pub(crate) fn update_player_monster(

if new_entity.is_none() {
return;
}
let new_type = game_progress.monster_entity_to_stats.get(&new_entity.unwrap()).unwrap().typing;
}
let new_type = game_progress
.monster_entity_to_stats
.get(&new_entity.unwrap())
.unwrap()
.typing;
info!("got type {:?}", new_type);

let (ct, _) = cameras.single();

commands.
spawn_bundle(SpriteBundle {
commands
.spawn_bundle(SpriteBundle {
sprite: Sprite {
flip_y: false, // flips our little buddy, you guessed it, in the y direction
flip_x: true, // guess what this does
Expand All @@ -421,7 +425,6 @@ pub(crate) fn update_player_monster(
})
.insert(PlayerMonster)
.insert(Monster);

}

pub(crate) fn spawn_enemy_monster(
Expand Down Expand Up @@ -929,7 +932,7 @@ pub(crate) fn key_press_handler(
format!("Enemy special!")
};

if game_progress.spec_moves_left[0] == 0 {
if game_progress.spec_moves_left[0] == 0 {
// No special moves left
let text = PooledText {
text: format!("Special move not allowed!"),
Expand All @@ -940,7 +943,7 @@ pub(crate) fn key_press_handler(
}

game_progress.spec_moves_left[0] -= 1;

let text = PooledText {
text: format!("{:?} multi-move! {}", player_type, enemy_act_string),
pooled: false,
Expand Down Expand Up @@ -1398,7 +1401,8 @@ fn calculate_turn(
enemy_type,
enemy_action,
type_system,
).0 as usize;
)
.0 as usize;
// Then simulate elemental
result.0 = (type_system.type_modifier[*player_type as usize][*enemy_type as usize]
* result.0 as f32)
Expand All @@ -1422,12 +1426,13 @@ fn calculate_turn(
enemy_type,
0,
type_system,
).1 as usize;
)
.1 as usize;
// Then simulate elemental
result.1 = (type_system.type_modifier[*player_type as usize][*enemy_type as usize]
* result.1 as f32)
.trunc() as usize;
}

(result.0 as isize, result.1 as isize)
}
}
2 changes: 1 addition & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) struct MultWaitingCamera;
pub(crate) struct SlidesCamera;

#[derive(Component)]
pub(crate) struct PauseCamera;
pub(crate) struct PauseCamera;

#[derive(Component)]
pub(crate) struct HelpCamera;
Expand Down
9 changes: 6 additions & 3 deletions src/game_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rand::seq::SliceRandom;
use std::fmt;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use rand::seq::SliceRandom;

const SIZE: usize = 50;

Expand Down Expand Up @@ -49,12 +49,15 @@ impl fmt::Display for Package {

/// Choose a random port of the known, normally open UDP ports
pub(crate) fn get_randomized_port() -> i32 {
let port_list = vec![9800, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090];
let port_list = vec![
9800, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090,
];
*port_list.choose(&mut rand::thread_rng()).unwrap()
}

/// Get the local address to bind a socket to
pub(crate) fn get_addr() -> SocketAddr {
let ip_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let socket_addr = SocketAddr::new(ip_addr, get_randomized_port() as u16);
let socket_addr = SocketAddr::new(ip_addr, 0 as u16);
socket_addr
}
2 changes: 1 addition & 1 deletion src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ fn handle_exit_help(mut commands: Commands, input: Res<Input<KeyCode>>) {
// Change back to start menu state
commands.insert_resource(NextState(GameState::Start));
}
}
}
32 changes: 17 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ pub(crate) enum GameState {
Help,
MultiplayerMenu,
MultiplayerWaiting,
MultiplayerBattle,
MultiplayerPvPBattle,
MultiplayerPvEBattle,
}

pub(crate) const TITLE: &str = "Waste";
Expand All @@ -30,40 +31,40 @@ mod backgrounds;
mod battle;
mod camera;
mod credits;
mod game_client;
mod help;
mod monster;
mod multiplayer_menu;
mod multiplayer_pve;
mod multiplayer_pvp;
mod multiplayer_waiting;
mod networking;
mod pause;
mod player;
mod quests;
mod start_menu;
mod wfc;
mod world;
mod multiplayer_menu;
mod multiplayer_battle;
mod game_client;
mod quests;
mod networking;
mod multiplayer_waiting;


//use statements:
use backgrounds::*;
use battle::*;
use camera::*;
use credits::*;
use game_client::*;
use help::*;
use monster::*;
use multiplayer_menu::*;
use multiplayer_pve::*;
use multiplayer_pvp::*;
use multiplayer_waiting::*;
use networking::*;
use pause::*;
use player::*;
use quests::*;
use start_menu::*;
use wfc::*;
use world::*;
use multiplayer_menu::*;
use multiplayer_battle::*;
use game_client::*;
use multiplayer_waiting::*;



// END CUSTOM MODULES

Expand All @@ -88,6 +89,7 @@ fn main() {
.init_resource::<GameProgress>()
.init_resource::<TypeSystem>()
.init_resource::<ProcGen>()
.init_resource::<MultiplayerModeSelected>()
.add_event::<AttackEvent>()
.add_event::<DefendEvent>()
.add_event::<HealEvent>()
Expand All @@ -103,7 +105,7 @@ fn main() {
.add_plugin(BattlePlugin)
.add_plugin(MultMenuPlugin)
.add_plugin(MultiplayerWaitingPlugin)
.add_plugin(MultBattlePlugin)
.add_plugin(MultPvPPlugin)
.add_enter_system_set(
GameState::StartPlaying,
// This system set is unconditional, as it is being added in an enter helper
Expand Down
2 changes: 1 addition & 1 deletion src/monster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::prelude::*;
use rand::distributions::{Distribution, Standard};
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};

// Elemental types
#[derive(Component, Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 663a6ce

Please sign in to comment.