
rogerkoehler
Hands-on Rust: Game Over (175)
I had to use DrawBatch to get the game over screen to display:
fn game_over(&mut self, ctx: &mut BTerm) {
let mut draw_batch = DrawBatch::new();
draw_batch.target(2);
draw_batch.print_color_centered(2,
“Your quest has ended.”,
ColorPair::new(RED, BLACK));
draw_batch.print_color_centered(4,
“Slain by a monster, your hero’s journey has come to a premature end.”,
ColorPair::new(WHITE, BLACK));
draw_batch.print_color_centered(5,
“The Amulet of Yala remains unclaimed, and your home town is not saved.”,
ColorPair::new(WHITE, BLACK));
draw_batch.print_color_centered(8,
“Don’t worry, you can always try again with a new hero.”,
ColorPair::new(YELLOW, BLACK));
draw_batch.print_color_centered(9,
“Press 1 to play agin.”,
ColorPair::new(GREEN, BLACK));
draw_batch.submit(12000).expect(“Batch error”);
if let Some(VirtualKeyCode::Key1) = ctx.key {
self.ecs = World::default();
self.resources = Resources::default();
let mut rng = RandomNumberGenerator::new();
let map_builder = MapBuilder::new(&mut rng);
spawn_player(&mut self.ecs, map_builder.player_start);
map_builder.rooms
.iter()
.skip(1)
.map(|r| r.center())
.for_each(|pos| spawn_monster(&mut self.ecs, &mut rng, pos));
self.resources.insert(map_builder.map);
self.resources.insert(Camera::new(map_builder.player_start));
self.resources.insert(TurnState::AwaitingInput);
}
}
Popular Pragmatic Bookshelf topics









Modern front-end development for Rails, second edition - Struggling to get the first chapter to work

Other popular topics










Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /ash
- /vscode
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /sublime-text
- /textmate
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /c
- /julia
- /slackware
- /neovim