Implement a proper gun fire-rate mechanism
There is now a `Weapon` component which is just a timer for the gun's fire rate. It is ticked every frame, clamping at the "ready" state (0 time remaining). The ship spawns with this thing, and the `input_ship_shoot` system has been updated to use it.
This commit is contained in:
@@ -22,7 +22,7 @@ use bevy_rapier2d::prelude::{ActiveCollisionTypes, ActiveEvents, Collider, Senso
|
||||
|
||||
use crate::{
|
||||
AngularVelocity, GameAssets, GameState, Lives,
|
||||
config::ASTEROID_LIFETIME,
|
||||
config::{ASTEROID_LIFETIME, SHIP_FIRE_RATE},
|
||||
events::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
machinery::Lifetime,
|
||||
physics::{Velocity, Wrapping},
|
||||
@@ -55,6 +55,10 @@ impl AsteroidSize {
|
||||
#[derive(Component)]
|
||||
pub struct Ship;
|
||||
|
||||
/// The ship's gun (is just a timer)
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
pub struct Weapon(Timer);
|
||||
|
||||
/// Marker component for bullets.
|
||||
#[derive(Component)]
|
||||
pub struct Bullet;
|
||||
@@ -144,6 +148,7 @@ pub fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
|
||||
ActiveEvents::COLLISION_EVENTS,
|
||||
ActiveCollisionTypes::STATIC_STATIC,
|
||||
Ship,
|
||||
Weapon(Timer::from_seconds(1.0 / SHIP_FIRE_RATE, TimerMode::Once)),
|
||||
Wrapping,
|
||||
Velocity(Vec2::ZERO),
|
||||
AngularVelocity(0.0),
|
||||
|
||||
Reference in New Issue
Block a user