Skip to content

Commit

Permalink
fix: Adjust score system and tweak player values
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Jan 19, 2024
1 parent 6e31d82 commit b2805ac
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/audio/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod bgm;
mod sound;

#[allow(unused_imports)]
pub use sound::PlaySound;

use bevy::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions src/enemy/archer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bevy_trickfilm::prelude::*;

use crate::{GameAssets, GameState};

const SCORE: u32 = 200;
const MOVE_SPEED: f32 = 80.0;
const SHOOT_RANGE: f32 = 500.0;
/// How long should the archer idle after shooting before moving again
Expand Down
7 changes: 5 additions & 2 deletions src/enemy/archer/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
GameAssets, GameState,
};

use super::{ArcherState, Enemy, EnemyArcher};
use super::{ArcherState, Enemy, EnemyArcher, SCORE};

#[derive(Resource)]
struct EnemySpawnCooldown {
Expand Down Expand Up @@ -68,7 +68,10 @@ fn spawn_enemies(

commands
.spawn((
Enemy::default(),
Enemy {
score: SCORE,
..default()
},
EnemyArcher::default(),
YSort(0.0),
animator,
Expand Down
1 change: 1 addition & 0 deletions src/enemy/bat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod spawn;

use bevy::prelude::*;

const SCORE: u32 = 100;
const MOVE_SPEED: f32 = 120.0;

pub use super::Enemy;
Expand Down
7 changes: 5 additions & 2 deletions src/enemy/bat/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
enemy::spawn::SPAWN_OFFSET, player::Player, world::camera::YSort, GameAssets, GameState,
};

use super::{Enemy, EnemyBat};
use super::{Enemy, EnemyBat, SCORE};

#[derive(Resource)]
struct EnemySpawnCooldown {
Expand Down Expand Up @@ -64,7 +64,10 @@ fn spawn_enemies(

commands
.spawn((
Enemy::default(),
Enemy {
score: SCORE,
..default()
},
EnemyBat,
YSort(0.0),
animator,
Expand Down
25 changes: 16 additions & 9 deletions src/enemy/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
utils::FixedRotation,
};

use super::{Enemy, EnemyProjectile};
use super::{Enemy, EnemyProjectile, DASH_SCORE_MULTIPLIYER, REFLECTION_PROJECTILE_SCORE_ADDITION};

fn player_strike_collisions(
q_strikes: Query<&Strike>,
Expand Down Expand Up @@ -51,7 +51,6 @@ fn player_strike_collisions(
};

enemy.disabled = true;
enemy.score = 100;
}
}

Expand Down Expand Up @@ -105,9 +104,16 @@ fn projectile_strike_collisions(
}

fn player_reflection_projectiles_collisions(
q_projectiles: Query<&ReflectionProjectile>,
mut q_projectiles: Query<&mut ReflectionProjectile>,
mut q_enemies: Query<&mut Enemy>,
q_colliders: Query<&Parent, (With<Collider>, Without<Enemy>, Without<DashLanding>)>,
q_colliders: Query<
&Parent,
(
With<Collider>,
Without<Enemy>,
Without<ReflectionProjectile>,
),
>,
mut ev_collision_events: EventReader<CollisionEvent>,
) {
for ev in ev_collision_events.read() {
Expand All @@ -133,16 +139,17 @@ fn player_reflection_projectiles_collisions(
continue;
};

let _ = if let Ok(r) = q_projectiles.get(source_parent) {
let mut projectile = if let Ok(r) = q_projectiles.get_mut(source_parent) {
r
} else if let Ok(r) = q_projectiles.get(target_parent) {
} else if let Ok(r) = q_projectiles.get_mut(target_parent) {
r
} else {
continue;
};

projectile.increase_counter();
enemy.disabled = true;
enemy.score = 200;
enemy.score += REFLECTION_PROJECTILE_SCORE_ADDITION * projectile.enemy_counter();
}
}

Expand Down Expand Up @@ -191,7 +198,7 @@ fn player_dash_collisions(
};

enemy.disabled = true;
enemy.score = 50;
enemy.score = (enemy.score as f32 * DASH_SCORE_MULTIPLIYER) as u32;
}
}

Expand Down Expand Up @@ -233,7 +240,7 @@ fn player_dash_landing_collisions(
};

enemy.disabled = true;
enemy.score = 25;
enemy.score = (enemy.score as f32 * DASH_SCORE_MULTIPLIYER) as u32;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/enemy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ mod spawn;

use bevy::prelude::*;

const REFLECTION_PROJECTILE_SCORE_ADDITION: u32 = 100;
const DASH_SCORE_MULTIPLIYER: f32 = 0.35;

pub struct EnemyPlugin;

impl Plugin for EnemyPlugin {
Expand Down
11 changes: 11 additions & 0 deletions src/player/reflection_projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const PROJECTILE_SPEED: f32 = 800.0;
#[derive(Component, Default)]
pub struct ReflectionProjectile {
disabled: bool,
enemy_counter: u32,
}

#[derive(Event)]
Expand All @@ -17,6 +18,16 @@ pub struct SpawnReflectionProjectile {
pub dir: Vec2,
}

impl ReflectionProjectile {
pub fn enemy_counter(&self) -> u32 {
self.enemy_counter
}

pub fn increase_counter(&mut self) {
self.enemy_counter += 1;
}
}

fn spawn_reflection_projectiles(
mut commands: Commands,
assets: Res<GameAssets>,
Expand Down
9 changes: 5 additions & 4 deletions src/player/strike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::{

const OFFSET: Vec3 = Vec3::new(0.0, -10.0, 0.0);
const CHAIN_COOLDOWN: f32 = 0.35;
const STRIKE_COOLDOWN: f32 = 0.2;
const STRIKE_COOLDOWN: f32 = 0.4;
const STRIKE_CHAIN_COUNT: usize = 3;

#[derive(Resource, Default)]
Expand Down Expand Up @@ -64,10 +64,10 @@ fn spawn_strikes(
animator.play(assets.player_strike_animations[0].clone());

let flip_y = ev.strike_index % 2 == 1;
let scale = if ev.strike_index == STRIKE_CHAIN_COUNT - 1 {
Vec3::splat(2.0)
let (scale, color) = if ev.strike_index == STRIKE_CHAIN_COUNT - 1 {
(Vec3::splat(2.0), Color::rgb(0.8, 0.8, 0.8))
} else {
Vec3::splat(1.5)
(Vec3::splat(1.5), Color::WHITE)
};

let collider = commands
Expand Down Expand Up @@ -96,6 +96,7 @@ fn spawn_strikes(
texture_atlas: assets.player_strike.clone(),
sprite: TextureAtlasSprite {
flip_y,
color,
..default()
},
..default()
Expand Down

0 comments on commit b2805ac

Please sign in to comment.