generated from tipragot/rust
Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
CoCo_Sol | 106cabe951 | ||
CoCo_Sol | 129f219401 | ||
CoCo_Sol | 0b750da56b |
28
crates/border-wars/assets/tiles/License.txt
Normal file
28
crates/border-wars/assets/tiles/License.txt
Normal 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
|
|
@ -75,7 +75,7 @@ fn init_resources_for_camera(mut commands: Commands) {
|
||||||
left: KeyCode::Q,
|
left: KeyCode::Q,
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.insert_resource(CameraSpeedMouvement(10.0));
|
commands.insert_resource(CameraSpeedMouvement(400.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,20 +87,23 @@ 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 target = Vec3::ZERO;
|
let mut dx = 0.0;
|
||||||
|
let mut dy = 0.0;
|
||||||
for key in keys.get_pressed() {
|
for key in keys.get_pressed() {
|
||||||
match *key {
|
match *key {
|
||||||
value if value == keys_settings.up => target.y += movement_speed.0,
|
up if up == keys_settings.up => dy += movement_speed.0,
|
||||||
value if value == keys_settings.down => target.y -= movement_speed.0,
|
down if down == keys_settings.down => dy -= movement_speed.0,
|
||||||
value if value == keys_settings.right => target.x += movement_speed.0,
|
right if right == keys_settings.right => dx += movement_speed.0,
|
||||||
value if value == keys_settings.left => target.x -= movement_speed.0,
|
left if left == keys_settings.left => dx -= movement_speed.0,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transform.translation += target;
|
transform.translation.x += dx * delta_time.delta_seconds();
|
||||||
|
transform.translation.y += dy * delta_time.delta_seconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||||
|
|
||||||
|
@ -21,5 +22,6 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
52
crates/border-wars/src/resources.rs
Normal file
52
crates/border-wars/src/resources.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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()
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,12 +1,10 @@
|
||||||
//! 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;
|
||||||
|
|
||||||
|
@ -16,7 +14,6 @@ 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue