Compare commits
No commits in common. "fe7eef77704f095377ffb35e2c331f3af6a484e8" and "ecaf448e90a261ccbd28289f719dad5e1fcfe762" have entirely different histories.
fe7eef7770
...
ecaf448e90
14 changed files with 45 additions and 261 deletions
|
@ -2,7 +2,6 @@
|
||||||
/// Fast PC mode at 400 cycles/ms.
|
/// Fast PC mode at 400 cycles/ms.
|
||||||
pub const CLOCK_PERIOD: f32 = 0.184;
|
pub const CLOCK_PERIOD: f32 = 0.184;
|
||||||
pub const PLAYER_STEP_PERIOD: f32 = 1.0 / 7.5;
|
pub const PLAYER_STEP_PERIOD: f32 = 1.0 / 7.5;
|
||||||
pub const FLASHING_PERIOD: f32 = 0.02;
|
|
||||||
|
|
||||||
pub const SIDEBAR_POS_X: i32 = 66;
|
pub const SIDEBAR_POS_X: i32 = 66;
|
||||||
pub const SIDEBAR_POS_Y: i32 = 0;
|
pub const SIDEBAR_POS_Y: i32 = 0;
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
use crate::constants::*;
|
|
||||||
use crate::graphics::vga_color as vga;
|
|
||||||
use crate::resources::Resources;
|
|
||||||
use bracket_lib::prelude::*;
|
|
||||||
|
|
||||||
pub fn draw(resources: &mut Resources, bterm: &mut BTerm) {
|
|
||||||
if let Some(flashing_message) = &mut resources.flashing_message {
|
|
||||||
flashing_message.next_color();
|
|
||||||
|
|
||||||
bterm.print_color_centered_at(
|
|
||||||
MAP_X + (MAP_WIDTH / 2),
|
|
||||||
MAP_Y + MAP_HEIGHT,
|
|
||||||
RGB::named(vga::get_by_index(flashing_message.color)),
|
|
||||||
RGB::named(vga::BLACK),
|
|
||||||
flashing_message.message.to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,17 +4,15 @@ use hecs::World;
|
||||||
use crate::resources::Resources;
|
use crate::resources::Resources;
|
||||||
|
|
||||||
mod entities;
|
mod entities;
|
||||||
mod flashing_message;
|
|
||||||
mod map;
|
mod map;
|
||||||
mod sidebar;
|
mod sidebar;
|
||||||
pub mod vga_color;
|
pub mod vga_color;
|
||||||
mod whip;
|
mod whip;
|
||||||
|
|
||||||
pub fn draw(world: &World, resources: &mut Resources, bterm: &mut BTerm) {
|
pub fn draw(world: &World, resources: &Resources, bterm: &mut BTerm) {
|
||||||
bterm.cls();
|
bterm.cls();
|
||||||
map::draw(resources, bterm);
|
map::draw(resources, bterm);
|
||||||
entities::draw(world, bterm);
|
entities::draw(world, bterm);
|
||||||
whip::draw(world, resources, bterm);
|
whip::draw(world, resources, bterm);
|
||||||
flashing_message::draw(resources, bterm);
|
|
||||||
sidebar::draw(resources, bterm);
|
sidebar::draw(resources, bterm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,11 @@
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::World;
|
use hecs::World;
|
||||||
|
|
||||||
use crate::resources::{flashing_message::FlashingMessageIntent, *};
|
use crate::resources::*;
|
||||||
|
|
||||||
mod player;
|
mod player;
|
||||||
|
|
||||||
pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Resources) {
|
|
||||||
if let Some(key) = bterm.key {
|
|
||||||
if let Some(flashing_message) = &resources.flashing_message {
|
|
||||||
if let Some(intent) = &flashing_message.intent {
|
|
||||||
match intent {
|
|
||||||
FlashingMessageIntent::Quit => {
|
|
||||||
if key == VirtualKeyCode::Y {
|
|
||||||
bterm.quit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FlashingMessageIntent::Save => todo!(),
|
|
||||||
FlashingMessageIntent::Restore => todo!(),
|
|
||||||
FlashingMessageIntent::Restart => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||||
if resources.flashing_message.is_some() && bterm.key.is_some() {
|
|
||||||
handle_intent(bterm, world, resources);
|
|
||||||
resources.flashing_message = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
match bterm.key {
|
match bterm.key {
|
||||||
None => {}
|
None => {}
|
||||||
Some(key) => match key {
|
Some(key) => match key {
|
||||||
|
@ -58,17 +34,7 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||||
resources.show_debug_info = !resources.show_debug_info;
|
resources.show_debug_info = !resources.show_debug_info;
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
|
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
|
||||||
resources.flashing_message = Some(FlashingMessage::new(
|
bterm.quit();
|
||||||
" Are you sure you want to quit (Y/N)? ",
|
|
||||||
Some(FlashingMessageIntent::Quit),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
VirtualKeyCode::P => {
|
|
||||||
resources
|
|
||||||
.sound_output
|
|
||||||
.play_sound(resources.sound_effects.pause.clone());
|
|
||||||
resources.flashing_message =
|
|
||||||
Some(FlashingMessage::from(" Press any key to resume game. "));
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
resources
|
resources
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Stairs => {
|
crate::tile_data::TileType::Stairs => {
|
||||||
resources.should_advance_level = true;
|
// TODO: Go to next level
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Chest => todo!(),
|
crate::tile_data::TileType::Chest => todo!(),
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn main() -> BError {
|
||||||
|
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
|
|
||||||
let mut map = Map::from(levels::get_level(starting_level));
|
let mut map = Map::from_level(levels::get_level(starting_level));
|
||||||
map.spawn_entities(&mut world);
|
map.spawn_entities(&mut world);
|
||||||
|
|
||||||
let resources = Resources {
|
let resources = Resources {
|
||||||
|
@ -57,8 +57,6 @@ fn main() -> BError {
|
||||||
sound_effects,
|
sound_effects,
|
||||||
sound_output,
|
sound_output,
|
||||||
selected_difficulty: Some(selected_difficulty),
|
selected_difficulty: Some(selected_difficulty),
|
||||||
flashing_message: Some(FlashingMessage::from("Press any key to begin this level.")),
|
|
||||||
should_advance_level: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// let descent_sounds: Vec<Sound> = (20..100)
|
// let descent_sounds: Vec<Sound> = (20..100)
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use crate::constants::*;
|
|
||||||
|
|
||||||
pub enum FlashingMessageIntent {
|
|
||||||
Quit,
|
|
||||||
Save,
|
|
||||||
Restore,
|
|
||||||
Restart,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FlashingMessage {
|
|
||||||
pub message: String,
|
|
||||||
pub color: usize,
|
|
||||||
pub last_changed_color: Instant,
|
|
||||||
pub intent: Option<FlashingMessageIntent>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlashingMessage {
|
|
||||||
pub fn new(message: &str, intent: Option<FlashingMessageIntent>) -> Self {
|
|
||||||
Self {
|
|
||||||
message: message.to_string(),
|
|
||||||
color: 14,
|
|
||||||
last_changed_color: Instant::now(),
|
|
||||||
intent,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_color(&mut self) {
|
|
||||||
let now = Instant::now();
|
|
||||||
if now - self.last_changed_color > Duration::from_secs_f32(FLASHING_PERIOD) {
|
|
||||||
self.color += 1;
|
|
||||||
if self.color > 15 {
|
|
||||||
self.color = 13
|
|
||||||
}
|
|
||||||
self.last_changed_color = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for FlashingMessage {
|
|
||||||
fn from(message: &str) -> Self {
|
|
||||||
Self::new(message, None)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -44,6 +44,42 @@ impl Map {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_level(level: Level) -> Self {
|
||||||
|
match level {
|
||||||
|
Level::Normal(_data) => todo!(),
|
||||||
|
Level::Randomized(data) => {
|
||||||
|
let mut rng = RandomNumberGenerator::new();
|
||||||
|
let mut map = Self::new();
|
||||||
|
for (tile, count) in data {
|
||||||
|
for _ in 0..count {
|
||||||
|
loop {
|
||||||
|
let point = Point {
|
||||||
|
x: rng.range(0, MAP_WIDTH as i32),
|
||||||
|
y: rng.range(0, MAP_HEIGHT as i32),
|
||||||
|
};
|
||||||
|
if map.get_tile_at(point) == TileType::Floor {
|
||||||
|
map.set_tile_at(point, tile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loop {
|
||||||
|
let point = Point {
|
||||||
|
x: rng.range(0, MAP_WIDTH as i32),
|
||||||
|
y: rng.range(0, MAP_HEIGHT as i32),
|
||||||
|
};
|
||||||
|
if map.get_tile_at(point) == TileType::Floor {
|
||||||
|
map.set_tile_at(point, TileType::Player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map
|
||||||
|
}
|
||||||
|
Level::End => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn spawn_entities(&mut self, world: &mut World) {
|
pub fn spawn_entities(&mut self, world: &mut World) {
|
||||||
for (index, tile) in self
|
for (index, tile) in self
|
||||||
.tiles
|
.tiles
|
||||||
|
@ -210,58 +246,3 @@ impl Map {
|
||||||
self.tiles[index] = tile;
|
self.tiles[index] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Level> for Map {
|
|
||||||
fn from(level: Level) -> Self {
|
|
||||||
match level {
|
|
||||||
Level::Normal(data) => {
|
|
||||||
assert_eq!(data.len(), MAP_HEIGHT, "Level data is incorrect height!");
|
|
||||||
|
|
||||||
let mut map = Self::new();
|
|
||||||
for (y, line) in data.iter().enumerate() {
|
|
||||||
assert_eq!(line.len(), MAP_WIDTH, "Level data is incorrect width!");
|
|
||||||
for (x, c) in line.chars().enumerate() {
|
|
||||||
map.set_tile_at(
|
|
||||||
Point {
|
|
||||||
x: x as i32,
|
|
||||||
y: y as i32,
|
|
||||||
},
|
|
||||||
TileType::from(c),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
|
||||||
Level::Randomized(data) => {
|
|
||||||
let mut rng = RandomNumberGenerator::new();
|
|
||||||
let mut map = Self::new();
|
|
||||||
for (tile, count) in data {
|
|
||||||
for _ in 0..count {
|
|
||||||
loop {
|
|
||||||
let point = Point {
|
|
||||||
x: rng.range(0, MAP_WIDTH as i32),
|
|
||||||
y: rng.range(0, MAP_HEIGHT as i32),
|
|
||||||
};
|
|
||||||
if map.get_tile_at(point) == TileType::Floor {
|
|
||||||
map.set_tile_at(point, tile);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop {
|
|
||||||
let point = Point {
|
|
||||||
x: rng.range(0, MAP_WIDTH as i32),
|
|
||||||
y: rng.range(0, MAP_HEIGHT as i32),
|
|
||||||
};
|
|
||||||
if map.get_tile_at(point) == TileType::Floor {
|
|
||||||
map.set_tile_at(point, TileType::Player);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
|
||||||
Level::End => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod clock;
|
pub mod clock;
|
||||||
pub mod difficulty;
|
pub mod difficulty;
|
||||||
pub mod flashing_message;
|
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod sound_effects;
|
pub mod sound_effects;
|
||||||
pub mod sound_output;
|
pub mod sound_output;
|
||||||
|
@ -9,7 +8,6 @@ pub mod stats;
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
pub use clock::{Clock, StopClock};
|
pub use clock::{Clock, StopClock};
|
||||||
pub use difficulty::Difficulty;
|
pub use difficulty::Difficulty;
|
||||||
pub use flashing_message::FlashingMessage;
|
|
||||||
pub use map::Map;
|
pub use map::Map;
|
||||||
pub use sound_effects::SoundEffects;
|
pub use sound_effects::SoundEffects;
|
||||||
pub use sound_output::SoundOutput;
|
pub use sound_output::SoundOutput;
|
||||||
|
@ -26,6 +24,4 @@ pub struct Resources {
|
||||||
pub selected_difficulty: Option<Difficulty>,
|
pub selected_difficulty: Option<Difficulty>,
|
||||||
pub sound_effects: SoundEffects,
|
pub sound_effects: SoundEffects,
|
||||||
pub sound_output: SoundOutput,
|
pub sound_output: SoundOutput,
|
||||||
pub flashing_message: Option<FlashingMessage>,
|
|
||||||
pub should_advance_level: bool,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ pub struct SoundEffects {
|
||||||
pub slow_hit: SoundSamples,
|
pub slow_hit: SoundSamples,
|
||||||
pub medium_hit: SoundSamples,
|
pub medium_hit: SoundSamples,
|
||||||
pub fast_hit: SoundSamples,
|
pub fast_hit: SoundSamples,
|
||||||
pub pause: SoundSamples,
|
|
||||||
rng: RandomNumberGenerator,
|
rng: RandomNumberGenerator,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,19 +153,6 @@ impl SoundEffects {
|
||||||
duration: Duration::from_millis(25),
|
duration: Duration::from_millis(25),
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
pause: sound_output.render_sound_effect(&SoundEffect {
|
|
||||||
sounds: {
|
|
||||||
let mut sounds = vec![Sound {
|
|
||||||
sound_type: SoundType::Tone(500),
|
|
||||||
duration: Duration::from_millis(100),
|
|
||||||
}];
|
|
||||||
sounds.extend((100..=200).rev().step_by(10).map(|x| Sound {
|
|
||||||
sound_type: SoundType::Tone(x),
|
|
||||||
duration: Duration::from_millis(20),
|
|
||||||
}));
|
|
||||||
sounds
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
rng: RandomNumberGenerator::new(),
|
rng: RandomNumberGenerator::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
24
src/state.rs
24
src/state.rs
|
@ -1,6 +1,5 @@
|
||||||
use crate::resources::flashing_message::FlashingMessage;
|
use crate::resources::Resources;
|
||||||
use crate::resources::{Map, Resources};
|
use crate::{graphics, input, systems};
|
||||||
use crate::{graphics, input, levels, systems};
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::World;
|
use hecs::World;
|
||||||
|
|
||||||
|
@ -13,11 +12,7 @@ impl GameState for State {
|
||||||
fn tick(&mut self, bterm: &mut BTerm) {
|
fn tick(&mut self, bterm: &mut BTerm) {
|
||||||
input::handle(&mut self.world, &mut self.resources, bterm);
|
input::handle(&mut self.world, &mut self.resources, bterm);
|
||||||
systems::run(&mut self.world, &mut self.resources);
|
systems::run(&mut self.world, &mut self.resources);
|
||||||
graphics::draw(&self.world, &mut self.resources, bterm);
|
graphics::draw(&self.world, &self.resources, bterm);
|
||||||
|
|
||||||
if self.resources.should_advance_level {
|
|
||||||
self.next_level();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,17 +20,4 @@ impl State {
|
||||||
pub fn new(world: World, resources: Resources) -> Self {
|
pub fn new(world: World, resources: Resources) -> Self {
|
||||||
State { world, resources }
|
State { world, resources }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_level(&mut self) {
|
|
||||||
self.resources.level_number += 1;
|
|
||||||
|
|
||||||
self.world.clear();
|
|
||||||
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
|
|
||||||
self.resources.map.spawn_entities(&mut self.world);
|
|
||||||
|
|
||||||
self.resources.flashing_message =
|
|
||||||
Some(FlashingMessage::from("Press any key to begin this level."));
|
|
||||||
|
|
||||||
self.resources.should_advance_level = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,6 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
resources.stats.add_score(1);
|
resources.stats.add_score(1);
|
||||||
*tile = TileType::Floor;
|
*tile = TileType::Floor;
|
||||||
to_kill.push(entity);
|
to_kill.push(entity);
|
||||||
resources.map.clear_tile_content_at(Point::from(*position));
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
resources.map.clear_tile_content_at(Point::from(*position));
|
resources.map.clear_tile_content_at(Point::from(*position));
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::constants::CLOCK_PERIOD;
|
||||||
use crate::resources::{Clock, Resources};
|
use crate::resources::{Clock, Resources};
|
||||||
|
|
||||||
pub fn run(resources: &mut Resources) {
|
pub fn run(resources: &mut Resources) {
|
||||||
if !resources.stop_clock && resources.flashing_message.is_none() {
|
if !resources.stop_clock {
|
||||||
try_tick(&mut resources.clock);
|
try_tick(&mut resources.clock);
|
||||||
} else {
|
} else {
|
||||||
reset(&mut resources.clock);
|
reset(&mut resources.clock);
|
||||||
|
|
|
@ -375,61 +375,3 @@ pub fn tile_data(tile: TileType) -> TileData {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<char> for TileType {
|
|
||||||
fn from(c: char) -> Self {
|
|
||||||
match c {
|
|
||||||
' ' => TileType::Floor,
|
|
||||||
'1' => TileType::Slow,
|
|
||||||
'2' => TileType::Medium,
|
|
||||||
'3' => TileType::Fast,
|
|
||||||
'X' => TileType::Block,
|
|
||||||
'W' => TileType::Whip,
|
|
||||||
'L' => TileType::Stairs,
|
|
||||||
'C' => TileType::Chest,
|
|
||||||
'S' => TileType::SlowTime,
|
|
||||||
'+' => TileType::Gem,
|
|
||||||
'I' => TileType::Invisible,
|
|
||||||
'T' => TileType::Teleport,
|
|
||||||
'K' => TileType::Key,
|
|
||||||
'D' => TileType::Door,
|
|
||||||
'#' => TileType::Wall,
|
|
||||||
'F' => TileType::SpeedTime,
|
|
||||||
'.' => TileType::Trap,
|
|
||||||
'R' => TileType::River,
|
|
||||||
'Q' => TileType::Power,
|
|
||||||
'/' => TileType::Forest,
|
|
||||||
'\\' => TileType::Tree,
|
|
||||||
'B' => TileType::Bomb,
|
|
||||||
'V' => TileType::Lava,
|
|
||||||
'=' => TileType::Pit,
|
|
||||||
'A' => TileType::Tome,
|
|
||||||
'U' => TileType::Tunnel,
|
|
||||||
'Z' => TileType::Freeze,
|
|
||||||
'*' => TileType::Nugget,
|
|
||||||
'E' => TileType::Quake,
|
|
||||||
';' => TileType::InvisibleBlock,
|
|
||||||
':' => TileType::InvisibleWall,
|
|
||||||
'`' => TileType::InvisibleDoor,
|
|
||||||
'-' => TileType::Stop,
|
|
||||||
'%' => TileType::Zap,
|
|
||||||
']' => TileType::Create,
|
|
||||||
'G' => TileType::Generator,
|
|
||||||
'@' => TileType::Trap2,
|
|
||||||
')' => TileType::Trap3,
|
|
||||||
'(' => TileType::Trap4,
|
|
||||||
'$' => TileType::Trap5,
|
|
||||||
'α' => TileType::Trap6,
|
|
||||||
'ß' => TileType::Trap7,
|
|
||||||
'Γ' => TileType::Trap8,
|
|
||||||
'π' => TileType::Trap9,
|
|
||||||
'Σ' => TileType::Trap10,
|
|
||||||
'σ' => TileType::Trap11,
|
|
||||||
'µ' => TileType::Trap12,
|
|
||||||
'τ' => TileType::Trap13,
|
|
||||||
'P' => TileType::Player,
|
|
||||||
'!' => TileType::Punctuation,
|
|
||||||
_ => TileType::Letter(c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue