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