Compare commits

..

2 commits
main ... add-ui

Author SHA1 Message Date
CoCo_Sol 26acb61a9f add docs
All checks were successful
Rust Checks / checks (push) Successful in 3m14s
2024-04-05 21:49:32 +02:00
CoCo_Sol 9307223a13 save
Some checks failed
Rust Checks / checks (push) Failing after 3m30s
2024-04-05 20:53:58 +02:00
7 changed files with 60 additions and 94 deletions

View file

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

View file

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

View file

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

View file

@ -1,52 +0,0 @@
//! 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

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