Skip to content

Commit

Permalink
latest game
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahShomette committed Apr 8, 2023
1 parent ec716c1 commit a097230
Show file tree
Hide file tree
Showing 15 changed files with 595 additions and 246 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "clrs"
version = "0.1.0"
publish = false
authors = ["Noah Shomette <git@noahshomette.me>"]
authors = ["Noah Shomette <git@noahshomette.me>", "Kolbe Shomette"]
edition = "2021"
exclude = ["dist", "build", "assets", "credits"]

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Tiles of Color</title>
<title>CLRS</title>
<link data-trunk rel="copy-dir" href="assets"/>
<link data-trunk rel="copy-dir" href="credits"/>
<link data-trunk rel="copy-file" href="build/windows/icon.ico"/>
Expand Down
90 changes: 87 additions & 3 deletions src/abilities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,95 @@
mod nuke;

use bevy::prelude::{FromReflect, Reflect};
use crate::buildings::Activate;
use bevy::prelude::{
Commands, Component, Entity, FromReflect, Query, Reflect, Res, ResMut, Time, Timer, TimerMode,
With, Without,
};
use bevy_ecs_tilemap::prelude::TileStorage;
use bevy_ggf::game_core::state::{Changed, DespawnedObjects};
use bevy_ggf::mapping::tiles::Tile;
use bevy_ggf::mapping::MapId;
use bevy_ggf::object::{Object, ObjectGridPosition, ObjectId};
use bevy_ggf::player::PlayerMarker;

pub fn destroy_buildings(
abilities: Query<
(
Entity,
&PlayerMarker,
&ObjectId,
&ObjectGridPosition,
&AbilityMarker,
),
(With<Object>, With<DestroyAbility>),
>,
mut tiles: Query<(Entity, &PlayerMarker), (Without<Object>, With<Tile>)>,
mut tile_storage_query: Query<(&MapId, &TileStorage)>,
mut commands: Commands,
mut despawn_objects: ResMut<DespawnedObjects>,
) {
for (building_entity, player_marker, object_id, object_grid_pos, ability) in abilities.iter() {
let Some((_, tile_storage)) = tile_storage_query
.iter_mut()
.find(|(id, _)| id == &&MapId{ id: 1 })else {
continue;
};

let tile_entity = tile_storage.get(&object_grid_pos.tile_position).unwrap();

let Ok((entity, tile_marker)) = tiles.get_mut(tile_entity) else {
continue;
};

if player_marker != tile_marker && ability.requires_player_territory {
println!("killing abilities");
despawn_objects
.despawned_objects
.insert(*object_id, Changed::default());
commands.entity(building_entity).despawn();
}
}
}

pub fn update_ability_timers(
mut timers: Query<(Entity, &mut AbilityCooldown), Without<Activate>>,
mut commands: Commands,
time: Res<Time>,
) {
for (entity, mut timer) in timers.iter_mut() {
timer.timer.tick(time.delta());
if timer.timer.finished() {
commands.entity(entity).insert(Activate);
timer.timer = Timer::from_seconds(timer.timer_reset, TimerMode::Once);
timer.timer_ticks = timer.timer_ticks.saturating_sub(1);
}
}
}

#[derive(Default, Clone, Eq, Hash, Debug, PartialEq, Component, Reflect, FromReflect)]
pub struct DestroyAbility;

#[derive(Default, Clone, Copy, Eq, Hash, Debug, PartialEq, Reflect, FromReflect)]
pub enum Abilities{
pub enum Abilities {
#[default]
Nuke,
Sacrifice,
Boost,
}
}

#[derive(Default, Clone, Eq, Hash, Debug, PartialEq, Component, Reflect, FromReflect)]
pub struct AbilityMarker {
pub requires_player_territory: bool,
}

#[derive(Default, Clone, Eq, Hash, Debug, PartialEq, Component, Reflect, FromReflect)]
pub struct Ability<T> {
pub ability_type: T,
}

#[derive(Default, Clone, Debug, Component, Reflect, FromReflect)]
pub struct AbilityCooldown {
pub timer: Timer,
pub timer_ticks: u32,
pub timer_reset: f32,
}
4 changes: 2 additions & 2 deletions src/actions/game_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ pub fn place_building(
},
},
BuildingCooldown {
timer: Timer::from_seconds(0.1, TimerMode::Once),
timer_reset: 0.1,
timer: Timer::from_seconds(0.2, TimerMode::Once),
timer_reset: 0.2,
},
BuildingMarker::default(),
),
Expand Down
86 changes: 84 additions & 2 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::abilities::Abilities;
use crate::actions::game_control::{place_building};
use crate::actions::game_control::place_building;
use bevy::prelude::KeyCode::Pause;
use bevy::prelude::*;
use bevy_ascii_terminal::TileFormatter;
use bevy_ascii_terminal::Terminal;
use bevy_ecs_tilemap::prelude::TilePos;
use bevy_ggf::game_core::Game;
use bevy_ggf::mapping::tiles::Tile;
use bevy_ggf::object::Object;
use bevy_ggf::player::{Player, PlayerMarker};
use ns_defaults::camera::CursorWorldPos;

use crate::buildings::BuildingTypes;
use crate::game::GameBuildSettings;
use crate::GameState;

mod game_control;
Expand All @@ -18,6 +23,9 @@ pub struct ActionsPlugin;
impl Plugin for ActionsPlugin {
fn build(&self, app: &mut App) {
app.add_system(update_actions.in_set(OnUpdate(GameState::Playing)));
app.add_system(paused_controls.in_set(OnUpdate(GameState::Paused)));
app.add_system(ended_controls.in_set(OnUpdate(GameState::Ended)));
app.add_system(handle_pause);
app.add_system(
place_building
.in_set(OnUpdate(GameState::Playing))
Expand All @@ -37,11 +45,85 @@ pub struct Actions {
pub tile_pos: Option<TilePos>,
}

#[derive(Default, Resource)]
pub struct PauseGame;

#[derive(Default, Resource)]
pub struct UnPauseGame;

fn handle_pause(
mut current_state: ResMut<State<GameState>>,
mut next_state: ResMut<NextState<GameState>>,
mut commands: Commands,
pause_game: Option<Res<PauseGame>>,
unpause_game: Option<Res<UnPauseGame>>,
) {
match current_state.0 {
GameState::Loading => {}
GameState::Playing => {
if let Some(pause_game) = pause_game {
next_state.set(GameState::Paused);
commands.remove_resource::<PauseGame>();
}
}
GameState::Paused => {
if let Some(unpause_game) = unpause_game {
next_state.set(GameState::Playing);
commands.remove_resource::<UnPauseGame>();
}
}
GameState::Menu => {}
GameState::Ended => {}
}
}

pub fn paused_controls(mut commands: Commands, keyboard_input: Res<Input<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::Escape) {
commands.insert_resource(UnPauseGame);
}
}

pub fn ended_controls(
mut commands: Commands,
mut next_state: ResMut<NextState<GameState>>,
keyboard_input: Res<Input<KeyCode>>,
tiles: Query<Entity, With<Tile>>,
objects: Query<Entity, With<Object>>,
players: Query<Entity, With<Player>>,
player_marker: Query<Entity, With<PlayerMarker>>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
next_state.set(GameState::Menu);

for entity in tiles.iter(){
commands.entity(entity).despawn();
}
for entity in objects.iter(){
commands.entity(entity).despawn();
}
for entity in players.iter(){
commands.entity(entity).despawn();
}
for entity in player_marker.iter(){
commands.entity(entity).despawn();
}

commands.remove_resource::<Game>();
commands.init_resource::<GameBuildSettings>();
}

}

pub fn update_actions(
mouse: Res<Input<MouseButton>>,
mut actions: Query<(&PlayerMarker, &mut Actions)>,
keyboard_input: Res<Input<KeyCode>>,
mut commands: Commands,
) {
if keyboard_input.just_pressed(KeyCode::Escape) {
commands.insert_resource(PauseGame);
}

for (player, mut actions) in actions.iter_mut() {
if player.id() == 0 {
if mouse.just_pressed(MouseButton::Left) {
Expand Down
7 changes: 5 additions & 2 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ impl Plugin for InternalAudioPlugin {
#[derive(Resource)]
struct FlyingAudio(Handle<AudioInstance>);

fn start_audio(mut commands: Commands, audio_assets: Res<AudioAssets>, audio: Res<Audio>) {
fn start_audio(mut commands: Commands, audio_assets: Res<AudioAssets>, audio: Res<Audio>) {
/*
audio.pause();
let handle = audio
.play(audio_assets.flying.clone())
.looped()
.with_volume(0.3)
.handle();
commands.insert_resource(FlyingAudio(handle));
*/
}

fn control_flying_sound(
actions: Query<&Actions>,
audio: Res<FlyingAudio>,
//audio: Res<FlyingAudio>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
) {
/*
Expand Down
1 change: 1 addition & 0 deletions src/buildings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn destroy_buildings(
&BuildingMarker,
),
With<Object>,

>,
mut tiles: Query<(Entity, &PlayerMarker), (Without<Object>, With<Tile>)>,
mut tile_storage_query: Query<(&MapId, &TileStorage)>,
Expand Down
Loading

0 comments on commit a097230

Please sign in to comment.