Compare commits
No commits in common. "a7195b9c3dd48010d903f87969b02faba320b2ba" and "32fffd492df11233c8bc6544599271357ffbd4c7" have entirely different histories.
a7195b9c3d
...
32fffd492d
|
@ -199,13 +199,11 @@ impl Game {
|
|||
}
|
||||
}
|
||||
/// updates the player's current level. This will remove collected artifacts and dead monsters.
|
||||
/// ticks is measuring the progress of the game even if the player is not moving, player_moved
|
||||
/// indicates the player moved
|
||||
pub fn update_level(&mut self, ticks: u128, player_moved: bool) {
|
||||
pub fn update_level(&mut self, ticks: u128) {
|
||||
let player_pos = &self.player.get_immutable_position();
|
||||
let player_level = player_pos.get_level();
|
||||
let level = &mut self.levels[player_level];
|
||||
level.update(ticks, player_moved, &mut self.player, &mut self.messages);
|
||||
level.update(ticks, &mut self.player, &mut self.messages);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ impl Level {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, ticks: u128, player_moved: bool, player: &mut Player, messages: &mut Vec<String>) {
|
||||
pub fn update(&mut self, ticks: u128, player: &mut Player, messages: &mut Vec<String>) {
|
||||
for (index, a) in &mut self.artifacts.iter().enumerate() {
|
||||
if a.was_collected() {
|
||||
self.artifacts.remove(index);
|
||||
|
@ -120,8 +120,7 @@ impl Level {
|
|||
if self.monsters[index].is_dead() {
|
||||
continue;
|
||||
}
|
||||
// if the player moved, the monsters move as well all the time
|
||||
if !player_moved && ticks % self.monsters[index].get_ticks_between_steps() != 0 {
|
||||
if ticks % self.monsters[index].get_ticks_between_steps() != 0 {
|
||||
continue;
|
||||
}
|
||||
loop {
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -132,7 +132,6 @@ fn main() -> Result<()> {
|
|||
messages_area,
|
||||
);
|
||||
})?;
|
||||
let mut player_moved = false;
|
||||
if event::poll(std::time::Duration::from_millis(FRAME_LENGTH))? {
|
||||
if let event::Event::Key(key) = event::read()? {
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('v') {
|
||||
|
@ -150,22 +149,10 @@ fn main() -> Result<()> {
|
|||
}
|
||||
if key.kind == KeyEventKind::Press {
|
||||
let new_pos = match key.code {
|
||||
KeyCode::Left => {
|
||||
player_moved = true;
|
||||
game.move_player(-1, 0)
|
||||
}
|
||||
KeyCode::Right => {
|
||||
player_moved = true;
|
||||
game.move_player(1, 0)
|
||||
}
|
||||
KeyCode::Up => {
|
||||
player_moved = true;
|
||||
game.move_player(0, -1)
|
||||
}
|
||||
KeyCode::Down => {
|
||||
player_moved = true;
|
||||
game.move_player(0, 1)
|
||||
}
|
||||
KeyCode::Left => { game.move_player(-1, 0) }
|
||||
KeyCode::Right => { game.move_player(1, 0) }
|
||||
KeyCode::Up => { game.move_player(0, -1) }
|
||||
KeyCode::Down => { game.move_player(0, 1) }
|
||||
_ => { (0, 0) }
|
||||
};
|
||||
if !game.player_fights_monster() {
|
||||
|
@ -176,7 +163,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
}
|
||||
game.update_level(ticks, player_moved);
|
||||
game.update_level(ticks);
|
||||
if game.get_game_state() != GameState::RUNNING {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ impl crate::monster::LowerDaemon {
|
|||
symbol: String::from("d"),
|
||||
color: Color::Black,
|
||||
experience_gain: 104,
|
||||
ticks_between_steps: 30,
|
||||
ticks_between_steps: 5,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ impl Rat {
|
|||
symbol: String::from("R"),
|
||||
color: Color::Black,
|
||||
experience_gain: 26,
|
||||
ticks_between_steps: 25,
|
||||
ticks_between_steps: 5,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ impl Orc {
|
|||
symbol: String::from("O"),
|
||||
color: Color::DarkGray,
|
||||
experience_gain: 63,
|
||||
ticks_between_steps: 50,
|
||||
ticks_between_steps: 10,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue