From b42673076aaa4cd57a1bfd7c748341ab06cdad09 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Tue, 19 Mar 2024 21:50:03 +0000 Subject: [PATCH] feat: mana --- src/main.rs | 10 ++++++---- src/player.rs | 16 +++++++++++----- src/ui.rs | 17 +++++++++++++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index a7b9e8d..fdf1f09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,7 +66,7 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(SpriteBundle { texture: asset_server.load("player/player-4x.png"), transform: Transform { - scale: Vec3::splat(0.2), + scale: Vec3::splat(0.25), ..default() }, ..default() @@ -87,7 +87,7 @@ fn setup(mut commands: Commands, asset_server: Res) { .spawn(SpriteBundle { texture: asset_server.load("player/player-4x.png"), transform: Transform { - scale: Vec3::splat(0.2), + scale: Vec3::splat(0.25), ..default() }, ..default() @@ -96,9 +96,11 @@ fn setup(mut commands: Commands, asset_server: Res) { movement_speed: 512., rotation_speed: f32::to_radians(360.), - health: 1., + health: 10., health_max: 10., - stamina: 1., + stamina: 10., stamina_max: 10., + mana: 100., + mana_max: 100., }); } diff --git a/src/player.rs b/src/player.rs index 4737f1f..0c8ed18 100644 --- a/src/player.rs +++ b/src/player.rs @@ -10,6 +10,8 @@ pub struct Player { pub health_max: f32, pub stamina: f32, pub stamina_max: f32, + pub mana: f32, + pub mana_max: f32, } // Define the attacking component @@ -47,9 +49,9 @@ pub fn movement( let mut is_dashing = false; // Dash on space key press if the player has the stamina - if keys.just_pressed(KeyCode::Space) && player.stamina >= 0.3 { + if keys.just_pressed(KeyCode::Space) && player.stamina >= 1. { is_dashing = true; - player.stamina -= 0.3; + player.stamina -= 1.; movement_distance = 256.; } @@ -72,19 +74,21 @@ pub fn attack( Query<&mut Transform, With>, Query<&Transform, With> )>, + mut player_query: Query<&mut Player>, mut commands: Commands, asset_server: Res, ) { + let mut player = player_query.single_mut(); for player_transform in set.p1().iter_mut() { - let attack_position = player_transform.translation + ((player_transform.rotation * Vec3::Y) * 50.); + let attack_position = player_transform.translation + ((player_transform.rotation * Vec3::Y) * 100.); if keys.just_pressed(KeyCode::Enter) { commands .spawn(SpriteBundle { texture: asset_server.load("attacks/stone_cannon.png"), transform: Transform { - scale: Vec3::splat(0.2), + scale: Vec3::splat(0.3), translation: attack_position, rotation: player_transform.rotation, }, @@ -94,6 +98,8 @@ pub fn attack( velocity: 10., damage: 20., }); + + player.mana -= 1.; } } @@ -119,7 +125,7 @@ pub fn camera_follow( pub fn player_regen(mut player_query: Query<&mut Player, With>, time: Res