Compare commits
4 Commits
32fffd492d
...
implement_
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c6e5d26d0 | |||
| 4a31994ac9 | |||
| a7195b9c3d | |||
| 970904c411 |
193
Cargo.lock
generated
193
Cargo.lock
generated
@@ -20,6 +20,54 @@ version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@@ -56,6 +104,52 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.38",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.27.0"
|
||||
@@ -91,6 +185,7 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||
name = "el_diabolo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"crossterm",
|
||||
"petgraph",
|
||||
"rand",
|
||||
@@ -211,7 +306,7 @@ dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi",
|
||||
"windows-sys",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -240,7 +335,7 @@ dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-targets",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -399,6 +494,12 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.25.0"
|
||||
@@ -461,6 +562,12 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
@@ -575,7 +682,16 @@ version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -584,13 +700,28 @@ version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.0",
|
||||
"windows_aarch64_msvc 0.52.0",
|
||||
"windows_i686_gnu 0.52.0",
|
||||
"windows_i686_msvc 0.52.0",
|
||||
"windows_x86_64_gnu 0.52.0",
|
||||
"windows_x86_64_gnullvm 0.52.0",
|
||||
"windows_x86_64_msvc 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -599,42 +730,84 @@ version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.19"
|
||||
|
||||
@@ -11,3 +11,4 @@ crossterm = "0.27.0"
|
||||
rand = "0.8.5"
|
||||
petgraph = "0.6.4"
|
||||
whoami = "1.4.1"
|
||||
clap = { version = "4.4.11", features = ["derive"] }
|
||||
@@ -199,11 +199,13 @@ impl Game {
|
||||
}
|
||||
}
|
||||
/// updates the player's current level. This will remove collected artifacts and dead monsters.
|
||||
pub fn update_level(&mut self, ticks: u128) {
|
||||
/// 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) {
|
||||
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, &mut self.player, &mut self.messages);
|
||||
level.update(ticks, player_moved, &mut self.player, &mut self.messages);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ impl Level {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, ticks: u128, player: &mut Player, messages: &mut Vec<String>) {
|
||||
pub fn update(&mut self, ticks: u128, player_moved: bool, 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,7 +120,8 @@ impl Level {
|
||||
if self.monsters[index].is_dead() {
|
||||
continue;
|
||||
}
|
||||
if ticks % self.monsters[index].get_ticks_between_steps() != 0 {
|
||||
// if the player moved, the monsters move as well all the time
|
||||
if !player_moved && ticks % self.monsters[index].get_ticks_between_steps() != 0 {
|
||||
continue;
|
||||
}
|
||||
loop {
|
||||
|
||||
101
src/main.rs
101
src/main.rs
@@ -1,7 +1,10 @@
|
||||
use std::io::Result;
|
||||
use std::cmp::min;
|
||||
use std::io::{Result, Stdout};
|
||||
use std::io::stdout;
|
||||
use std::string::ToString;
|
||||
use std::time::Instant;
|
||||
|
||||
use clap::Parser;
|
||||
use crossterm::{
|
||||
event::{self, KeyCode, KeyEventKind},
|
||||
ExecutableCommand,
|
||||
@@ -35,16 +38,37 @@ mod dungeon_slayer;
|
||||
/// length of a game frame in ms
|
||||
pub const FRAME_LENGTH: u64 = 100;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about = "A small game in the tradition of rogue.", long_about = None)]
|
||||
struct CliOptions {
|
||||
#[arg(short, long, action)]
|
||||
manual: bool,
|
||||
}
|
||||
|
||||
//
|
||||
fn main() -> Result<()> {
|
||||
let player_stats = PlayerStats::create_random();
|
||||
let mut game = Game::new(Player::new(realname().as_str(), player_stats));
|
||||
let cli_options = CliOptions::parse();
|
||||
|
||||
stdout().execute(EnterAlternateScreen)?;
|
||||
enable_raw_mode()?;
|
||||
let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?;
|
||||
terminal.clear()?;
|
||||
|
||||
if cli_options.manual {
|
||||
show_manual(&mut terminal);
|
||||
} else {
|
||||
play_game(&mut terminal)?;
|
||||
}
|
||||
|
||||
stdout().execute(LeaveAlternateScreen)?;
|
||||
disable_raw_mode()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// play the game ;)
|
||||
fn play_game(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> Result<()> {
|
||||
let player_stats = PlayerStats::create_random();
|
||||
let mut game = Game::new(Player::new(realname().as_str(), player_stats));
|
||||
let start_time = Instant::now();
|
||||
let mut ticks = 0;
|
||||
loop {
|
||||
@@ -132,6 +156,7 @@ 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') {
|
||||
@@ -149,10 +174,22 @@ fn main() -> Result<()> {
|
||||
}
|
||||
if key.kind == KeyEventKind::Press {
|
||||
let new_pos = match key.code {
|
||||
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) }
|
||||
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)
|
||||
}
|
||||
_ => { (0, 0) }
|
||||
};
|
||||
if !game.player_fights_monster() {
|
||||
@@ -163,7 +200,7 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
game.update_level(ticks);
|
||||
game.update_level(ticks, player_moved);
|
||||
if game.get_game_state() != GameState::RUNNING {
|
||||
break;
|
||||
}
|
||||
@@ -211,7 +248,51 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
stdout().execute(LeaveAlternateScreen)?;
|
||||
disable_raw_mode()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// this function shows some manual text
|
||||
fn show_manual(terminal: &mut Terminal<CrosstermBackend<Stdout>>) {
|
||||
let mut page = 0;
|
||||
let pages = [
|
||||
"Background story\n\n\
|
||||
You are a traveller and on your journey....
|
||||
".to_string(),
|
||||
"To control your character (depicted by the 8) you can use the cursor keys (←, ↑, →, ↓). \n\n\
|
||||
To interact simply walk into the entity to interact with. Possible entities are creates \
|
||||
(depicted by C), potions (depicted by P) or enemies.".to_string(),
|
||||
];
|
||||
loop {
|
||||
let _ = terminal.draw(|frame| {
|
||||
let mut area = frame.size();
|
||||
let w = area.width / 2;
|
||||
let h = area.height / 2;
|
||||
area.x += w - 20;
|
||||
area.y += h - 10;
|
||||
area.width = 40;
|
||||
area.height = 20;
|
||||
let block = Block::default()
|
||||
.title(Title::from(format!(" Manual ({}/{})", page + 1, pages.len())).alignment(Alignment::Center).position(Position::Top))
|
||||
.title(Title::from("`q` to quit, `↑` and `↓` to scroll.").position(Position::Bottom))
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::White))
|
||||
.border_type(BorderType::Rounded)
|
||||
.style(Style::default().bg(Color::Black));
|
||||
let paragraph = Paragraph::new(pages[page].as_str()).block(block).wrap(Wrap { trim: true });
|
||||
frame.render_widget(paragraph, area);
|
||||
});
|
||||
if event::poll(std::time::Duration::from_millis(16)).unwrap_or(false) {
|
||||
if let event::Event::Key(key) = event::read().unwrap() {
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') {
|
||||
break;
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Up {
|
||||
page = page.saturating_sub(1);
|
||||
}
|
||||
if key.kind == KeyEventKind::Press && key.code == KeyCode::Down {
|
||||
page = min(pages.len() - 1, page + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl crate::monster::LowerDaemon {
|
||||
symbol: String::from("d"),
|
||||
color: Color::Black,
|
||||
experience_gain: 104,
|
||||
ticks_between_steps: 5,
|
||||
ticks_between_steps: 30,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ impl Rat {
|
||||
symbol: String::from("R"),
|
||||
color: Color::Black,
|
||||
experience_gain: 26,
|
||||
ticks_between_steps: 5,
|
||||
ticks_between_steps: 25,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ impl Orc {
|
||||
symbol: String::from("O"),
|
||||
color: Color::DarkGray,
|
||||
experience_gain: 63,
|
||||
ticks_between_steps: 10,
|
||||
ticks_between_steps: 50,
|
||||
monster_stats,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user