Compare commits

..

3 commits

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
6 changed files with 93 additions and 98 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

@ -1,90 +0,0 @@
//! All programs related to the actions that you can do with all tiles.
use bevy::prelude::*;
use crate::map::Tile;
/// A number of action points. This is decreased when you do an action.
pub struct ActionPoint(pub u32);
/// The action that you can do with a tile.
pub enum Action {
/// Build something on the tile.
Build(Entity),
/// Destroy something on the tile.
Destroy(Entity),
/// Recolt something on the tile.
Recolt(Entity),
/// Upgrade the tile.
Upgrade(Entity),
/// Manage the villages.
VillageManagement,
/// Manage the troops.
TroopManagement,
/// Teleport management.
TeleportManagement(Entity),
}
impl Tile {
/// Get the actions that you can do with the tile.
pub fn get_action(&self, tile_entity: Entity) -> Vec<Action> {
let mut actions = vec![];
if let Self::Breeding
| Self::Casern
| Self::Castle
| Self::Mine
| Self::Sawmill
| Self::Tower = *self
{
actions.push(Action::Upgrade(tile_entity));
}
if let Self::Breeding | Self::Casern | Self::Mine | Self::Outpost | Self::Sawmill = *self {
actions.push(Action::Destroy(tile_entity));
}
if matches!(*self, Self::Casern) {
actions.push(Action::TroopManagement);
}
if let Self::Forest | Self::Hill = *self {
actions.push(Action::Recolt(tile_entity));
}
if matches!(*self, Self::Castle) {
actions.push(Action::VillageManagement);
}
if matches!(*self, Self::Grass) {
actions.push(Action::Build(tile_entity));
}
if matches!(*self, Self::Outpost) {
actions.push(Action::TeleportManagement(tile_entity));
}
actions
}
}
impl Action {
/// Get the cost of an action.
pub const fn point_cost(&self) -> ActionPoint {
ActionPoint(match *self {
Self::Build(_) => 50,
Self::Destroy(_) => 10,
Self::Recolt(_) => 10,
Self::Upgrade(_) => 25,
Self::VillageManagement => 0,
Self::TroopManagement => 0,
Self::TeleportManagement(_) => 0,
})
}
}

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

@ -5,10 +5,10 @@ use bevy::prelude::*;
use networking::PlayerRank;
use serde::{Deserialize, Serialize};
pub mod actions;
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();
}
}