survivor

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

commit
29dfbf1b86f163354bb6310a8b4dad63b5c224c4
parent
176d27d5370b6f57835bd2a1126f7b2fa62b64be
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-03-29 06:31
add perk to reduce weapon cooldown

Diffstat

M README.md 1 +
M src/game.rs 18 +++++++++++-------

2 files changed, 12 insertions, 7 deletions


diff --git a/README.md b/README.md

@@ -16,6 +16,7 @@ the player receives a random perk:
   16    16 -	Damage radius is increased by 10%
   17    17 -	Pickup radius is increased by 10%
   18    18 -	Experience from diamonds is increased by 10%
   -1    19 -	Weapon cooldown is decreased by 10%
   19    20 -	Full health is restored
   20    21 -	The player recovers +0.2HP per second
   21    22 -	Get an additional axe

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

@@ -14,10 +14,11 @@ const PERK_HEAL: usize = 4;
   14    14 const PERK_RECOVER: usize = 5;
   15    15 const PERK_ATTRACT: usize = 6;
   16    16 const PERK_XP: usize = 7;
   17    -1 const PERK_AXE: usize = 8;
   18    -1 const PERK_KNIFE: usize = 9;
   19    -1 const PERK_STAR: usize = 10;
   20    -1 const PERK_WIND: usize = 11;
   -1    17 const PERK_COOLDOWN: usize = 8;
   -1    18 const PERK_AXE: usize = 9;
   -1    19 const PERK_KNIFE: usize = 10;
   -1    20 const PERK_STAR: usize = 11;
   -1    21 const PERK_WIND: usize = 12;
   21    22 
   22    23 #[derive(PartialEq, Clone, Copy)]
   23    24 pub enum Dir {
@@ -56,6 +57,7 @@ pub struct Player {
   56    57     pub diamond_radius: f32,
   57    58     pub xp: f32,
   58    59     pub xp_factor: f32,
   -1    60     pub cooldown_factor: f32,
   59    61     pub last_level: f32,
   60    62     pub next_level: f32,
   61    63 }
@@ -77,6 +79,7 @@ impl Player {
   77    79             diamond_radius: 15.0,
   78    80             xp: 0.0,
   79    81             xp_factor: 1.0,
   -1    82             cooldown_factor: 1.0,
   80    83             last_level: 0.0,
   81    84             next_level: 10.0,
   82    85         };
@@ -93,7 +96,7 @@ impl Player {
   93    96             self.last_level = self.next_level;
   94    97             self.next_level *= 1.3;
   95    98 
   96    -1             match rng.gen_range(0, 12) {
   -1    99             match rng.gen_range(0, 13) {
   97   100                 PERK_POWER => self.power *= 1.1,
   98   101                 PERK_HEALTH => self.health_max *= 1.1,
   99   102                 PERK_SPEED => self.speed *= 1.1,
@@ -102,6 +105,7 @@ impl Player {
  102   105                 PERK_RECOVER => self.health_recover += 0.2,
  103   106                 PERK_ATTRACT => self.diamond_radius *= 1.1,
  104   107                 PERK_XP => self.xp_factor *= 1.1,
   -1   108                 PERK_COOLDOWN => self.cooldown_factor *= 0.9,
  105   109                 PERK_AXE => self.weapons[0].amount += 1,
  106   110                 PERK_KNIFE => self.weapons[1].amount += 1,
  107   111                 PERK_STAR => self.weapons[2].amount += 1,
@@ -219,8 +223,8 @@ impl Game {
  219   223     fn spawn_projectiles(&mut self, dt: f32) {
  220   224         for weapon in self.player.weapons.iter_mut() {
  221   225             weapon.last += dt;
  222    -1             if weapon.last > weapon.cooldown {
  223    -1                 weapon.last -= weapon.cooldown;
   -1   226             if weapon.last > weapon.cooldown * self.player.cooldown_factor {
   -1   227                 weapon.last -= weapon.cooldown * self.player.cooldown_factor;
  224   228                 for _ in 0..weapon.amount {
  225   229                     weapon.projectiles.push(weapons::Projectile {
  226   230                         p: Pos {