survivor

graphical action game for the linux terminal
git clone https://git.ce9e.org/survivor.git

commit
bd6433ad0224f492220a4ed40d51c0d7664feaba
parent
01fa1215294d50107c05384862befabcad4eac23
Author
Viktor Bahr <viktorbahr@posteo.net>
Date
2023-03-26 15:33
feat: add projectile weapons structs

Diffstat

M src/game.rs 3 +++
M src/main.rs 1 +
A src/weapons.rs 22 ++++++++++++++++++++++

3 files changed, 26 insertions, 0 deletions


diff --git a/src/game.rs b/src/game.rs

@@ -1,6 +1,7 @@
    1     1 use crate::enemies;
    2     2 use crate::random;
    3     3 use crate::sprites;
   -1     4 use crate::weapons;
    4     5 use crate::win;
    5     6 
    6     7 const MAX_ENEMIES: usize = 200;
@@ -96,6 +97,7 @@ pub struct Game {
   96    97     pub player: Player,
   97    98     pub diamonds: Vec<Pos>,
   98    99     pub enemies: Vec<enemies::Enemy>,
   -1   100     pub projectiles: Vec<weapons::Projectile>,
   99   101     pub i_enemy: usize,
  100   102     rng: random::Rng,
  101   103 }
@@ -104,6 +106,7 @@ impl Game {
  104   106     pub fn new() -> Self {
  105   107         return Self {
  106   108             enemies: vec![],
   -1   109             projectiles: vec![],
  107   110             diamonds: vec![],
  108   111             i_enemy: 0,
  109   112             player: Player::new(),

diff --git a/src/main.rs b/src/main.rs

@@ -6,6 +6,7 @@ mod input;
    6     6 mod random;
    7     7 mod sprites;
    8     8 mod term;
   -1     9 mod weapons;
    9    10 mod win;
   10    11 
   11    12 use std::sync::atomic::{AtomicBool, Ordering};

diff --git a/src/weapons.rs b/src/weapons.rs

@@ -0,0 +1,22 @@
   -1     1 use crate::game::{Dir, Pos};
   -1     2 use crate::sprites;
   -1     3 
   -1     4 pub struct ProjectileType {
   -1     5     pub speed: f32,
   -1     6     pub size: f32,
   -1     7     pub power: f32,
   -1     8     pub sprite: &'static sprites::Sprite,
   -1     9 }
   -1    10 
   -1    11 pub struct Projectile {
   -1    12     pub p: Pos,
   -1    13     pub dir: Dir,
   -1    14     pub t: &'static ProjectileType,
   -1    15 }
   -1    16 
   -1    17 pub const KNIFE: ProjectileType = ProjectileType {
   -1    18     speed: 200.0,
   -1    19     size: 6.0,
   -1    20     power: 300.0,
   -1    21     sprite: &sprites::KNIFE,
   -1    22 };