summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assets/introduction.pngbin972031 -> 972993 bytes
-rw-r--r--src/assets/introduction.xcfbin1593811 -> 1593413 bytes
-rw-r--r--src/gates.rs15
-rw-r--r--src/main.rs3
-rw-r--r--src/state.rs1
5 files changed, 14 insertions, 5 deletions
diff --git a/src/assets/introduction.png b/src/assets/introduction.png
index b087f26..5e14519 100644
--- a/src/assets/introduction.png
+++ b/src/assets/introduction.png
Binary files differ
diff --git a/src/assets/introduction.xcf b/src/assets/introduction.xcf
index 007bd6f..c12e25b 100644
--- a/src/assets/introduction.xcf
+++ b/src/assets/introduction.xcf
Binary files differ
diff --git a/src/gates.rs b/src/gates.rs
index 2c8da82..def618a 100644
--- a/src/gates.rs
+++ b/src/gates.rs
@@ -95,6 +95,14 @@ fn shorten(x: f64, y: f64, maxlen: f64) -> (f64, f64) {
}
}
+impl Gates {
+ fn choose_position(&mut self) {
+ let (x, y) = random_position();
+ self.target_x = x;
+ self.target_y = y;
+ }
+}
+
impl state::Enemy<GatesBullet> for Gates {
fn new() -> Gates {
Gates { x: 200., y: 40., v_x: 0., v_y: 0., a_x: 0., a_y: 0., target_x: 200., target_y: 40., health: 1. }
@@ -107,9 +115,7 @@ impl state::Enemy<GatesBullet> for Gates {
/* If we've arrived (close and stopped) */
if (dx*dx + dy*dy).sqrt() < max_velocity / max_accel && (self.v_x*self.v_x + self.v_y*self.v_y).sqrt() < 0.01 {
/* Then pick a new target */
- let (x, y) = random_position();
- self.target_x = x;
- self.target_y = y;
+ self.choose_position();
}
let dx = self.target_x - self.x;
@@ -170,6 +176,9 @@ impl state::Enemy<GatesBullet> for Gates {
fn set_health(&mut self, health: f64) {
self.health = health;
}
+ fn injure(&mut self, damage: f64) {
+ self.health -= damage;
+ }
}
impl state::Drawable for GatesBullet {
diff --git a/src/main.rs b/src/main.rs
index e2638b7..43c0c22 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,9 +53,8 @@ fn frame<T: state::Enemy<U>, U: state::Bullet>(canvas: &mut sdl2::render::Window
for enemy in state.enemies.iter_mut() {
for bullet in state.player_bullets.iter_mut() {
if enemy.overlaps(bullet) {
+ enemy.injure(state::PBullet::damage());
bullet.delete();
- let health = enemy.health();
- enemy.set_health(health - state::PBullet::damage());
}
}
}
diff --git a/src/state.rs b/src/state.rs
index 820c1e4..bf62f51 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -76,6 +76,7 @@ pub trait Enemy<T>: Drawable {
fn act(&mut self, count: u64) -> Vec<T>;
fn health(&self) -> f64;
fn set_health(&mut self, health: f64);
+ fn injure(&mut self, damage: f64);
}
pub struct State<T, U> {