Compare commits

..

3 commits
add-ui ... main

Author SHA1 Message Date
CoCo_Sol 106cabe951 Add resources system (#111)
All checks were successful
Rust Checks / checks (push) Successful in 3m5s
closes: #71
Reviewed-on: #111
Reviewed-by: Raphaël <r.lauray@outlook.fr>
Co-authored-by: CoCo_Sol007 <solois.corentin@gmail.com>
Co-committed-by: CoCo_Sol007 <solois.corentin@gmail.com>
2024-04-06 11:24:32 +00:00
CoCo_Sol 129f219401 Add license for tiles assets (#113)
Some checks failed
Rust Checks / checks (push) Has been cancelled
Reviewed-on: #113
Reviewed-by: Raphaël <r.lauray@outlook.fr>
2024-04-06 11:23:41 +00:00
CoCo_Sol 0b750da56b Fix speed movement of camera by adding delta time (#114)
Some checks failed
Rust Checks / checks (push) Has been cancelled
Reviewed-on: #114
Reviewed-by: Raphaël <r.lauray@outlook.fr>
2024-04-06 11:23:07 +00:00
7 changed files with 94 additions and 60 deletions

View file

@ -0,0 +1,28 @@
Hexagon Kit (2.0)
Created/distributed by Kenney (www.kenney.nl)
Creation date: 23-01-2024 11:58
------------------------------
License: (Creative Commons Zero, CC0)
http://creativecommons.org/publicdomain/zero/1.0/
You can use this content for personal, educational, and commercial purposes.
Support by crediting 'Kenney' or 'www.kenney.nl' (this is not a requirement)
------------------------------
• Website : www.kenney.nl
• Donate : www.kenney.nl/donate
• Patreon : patreon.com/kenney
Follow on social media for updates:
• Twitter: twitter.com/KenneyNL
• Instagram: instagram.com/kenney_nl
• Mastodon: mastodon.gamedev.place/@kenney

View file

@ -75,7 +75,7 @@ fn init_resources_for_camera(mut commands: Commands) {
left: KeyCode::Q,
});
commands.insert_resource(CameraSpeedMouvement(10.0));
commands.insert_resource(CameraSpeedMouvement(400.0));
commands.insert_resource(CameraSpeedScale(0.1));
commands.insert_resource(MinimumScale(0.1));
commands.insert_resource(MaximumScale(10.0));
@ -87,20 +87,23 @@ fn keyboard_movement_system(
keys: Res<Input<KeyCode>>,
keys_settings: Res<KeysMovementSettings>,
movement_speed: Res<CameraSpeedMouvement>,
delta_time: Res<Time>,
) {
for mut transform in query.iter_mut() {
let mut target = Vec3::ZERO;
let mut dx = 0.0;
let mut dy = 0.0;
for key in keys.get_pressed() {
match *key {
value if value == keys_settings.up => target.y += movement_speed.0,
value if value == keys_settings.down => target.y -= movement_speed.0,
value if value == keys_settings.right => target.x += movement_speed.0,
value if value == keys_settings.left => target.x -= movement_speed.0,
up if up == keys_settings.up => dy += movement_speed.0,
down if down == keys_settings.down => dy -= movement_speed.0,
right if right == keys_settings.right => dx += movement_speed.0,
left if left == keys_settings.left => dx -= movement_speed.0,
_ => continue,
}
}
transform.translation += target;
transform.translation.x += dx * delta_time.delta_seconds();
transform.translation.y += dy * delta_time.delta_seconds();
}
}

View file

@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub mod camera;
pub mod map;
pub mod networking;
pub mod resources;
pub mod scenes;
pub mod ui;

View file

@ -7,6 +7,7 @@ use border_wars::map::ownership::OwnershipPlugin;
use border_wars::map::renderer::RendererPlugin;
use border_wars::map::selected_tile::SelectTilePlugin;
use border_wars::networking::NetworkingPlugin;
use border_wars::resources::ResourcesPlugin;
use border_wars::scenes::ScenesPlugin;
use border_wars::ui::UiPlugin;
@ -21,5 +22,6 @@ fn main() {
.add_plugins(MapGenerationPlugin)
.add_plugins(UiPlugin)
.add_plugins(OwnershipPlugin)
.add_plugins(ResourcesPlugin)
.run();
}

View file

@ -0,0 +1,52 @@
//! All program related to the resources of the game.
use bevy::prelude::*;
/// The plugin that manage the resources.
pub struct ResourcesPlugin;
impl Plugin for ResourcesPlugin {
fn build(&self, app: &mut App) {
app.add_event::<ResetResources>()
.insert_resource(Resources::initial())
.add_systems(Update, handle_reset_resources);
}
}
/// The resources of the game.
#[derive(Resource, Default)]
pub struct Resources {
/// The stone resource.
pub stone: u32,
/// The wood resource.
pub wood: u32,
/// The food resource.
pub food: u32,
}
impl Resources {
/// Returns the initial resources of the game.
const fn initial() -> Self {
Self {
stone: 100,
wood: 100,
food: 100,
}
}
}
/// An event send to reset the resources of the game.
#[derive(Event)]
pub struct ResetResources;
/// Handles the reset resources event.
fn handle_reset_resources(
mut reset_resources_event: EventReader<ResetResources>,
mut resources: ResMut<Resources>,
) {
for _ in reset_resources_event.read() {
*resources = Resources::initial();
}
}

View file

@ -1,49 +0,0 @@
//! ToDo
use bevy::prelude::*;
use crate::CurrentScene;
/// The plugin that sets up the UI for the game.
pub struct GameUiPlugin;
impl Plugin for GameUiPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(CurrentScene::Game), setup_ui);
}
}
/// Sets up the UI for the game.
fn setup_ui(mut commands: Commands) {
commands.spawn(NodeBundle {
style: Style {
margin: UiRect {
left: Val::Auto,
right: Val::Auto,
top: Val::Auto,
bottom: Val::Px(25.),
},
width: Val::Px(1000.),
height: Val::Px(150.),
..Default::default()
},
background_color: Color::BLUE.into(),
..Default::default()
});
commands.spawn(NodeBundle {
style: Style {
margin: UiRect {
left: Val::Px(10.),
right: Val::Auto,
top: Val::Px(10.),
bottom: Val::Auto,
},
width: Val::Px(200.),
height: Val::Px(200.),
..Default::default()
},
background_color: Color::BLUE.into(),
..Default::default()
});
}

View file

@ -1,12 +1,10 @@
//! The file that contains the UI logic.
pub mod game_ui;
pub mod hover;
pub mod responsive_scale;
use bevy::prelude::*;
use self::game_ui::GameUiPlugin;
use self::hover::HoverPlugin;
use self::responsive_scale::ResponsiveScalingPlugin;
@ -16,7 +14,6 @@ pub struct UiPlugin;
impl Plugin for UiPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(HoverPlugin)
.add_plugins(ResponsiveScalingPlugin)
.add_plugins(GameUiPlugin);
.add_plugins(ResponsiveScalingPlugin);
}
}