Skip to content

Commit

Permalink
cleanuo
Browse files Browse the repository at this point in the history
  • Loading branch information
bayou-brogrammer committed Oct 13, 2022
1 parent 44f9753 commit d081bc3
Show file tree
Hide file tree
Showing 45 changed files with 691 additions and 264 deletions.
1 change: 1 addition & 0 deletions app/src/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl AudioTable {
Audio::Explosion => audio_player.load_sound(&EXPLOSION),
Audio::SoundEffect(SoundEffect::Die) => audio_player.load_sound(&DIE),
Audio::SoundEffect(SoundEffect::Heal) => audio_player.load_sound(&HEAL),
Audio::SoundEffect(SoundEffect::Pickup) => audio_player.load_sound(&PICKUP),
Audio::SoundEffect(SoundEffect::DoorOpen) => audio_player.load_sound(&DOOR_OPEN),
Audio::SoundEffect(SoundEffect::DoorClose) => audio_player.load_sound(&DOOR_CLOSE),

Expand Down
2 changes: 1 addition & 1 deletion app/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl Default for Controls {
// Action Keys
KeyboardInput::Char('g') => AppInput::Get,
KeyboardInput::Char(' ') => AppInput::Wait,
KeyboardInput::Char('x') => AppInput::Examine,
KeyboardInput::Char('.') => AppInput::Descend,
KeyboardInput::Char('x') => AppInput::Examine,

// Movement Keys
KeyboardInput::Up => AppInput::Direction(CardinalDirection::North),
Expand Down
4 changes: 0 additions & 4 deletions app/src/game_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ impl GameInstance {
pub fn render(&self, ctx: Ctx, fb: &mut FrameBuffer) {
self.render_hud(ctx, fb);
self.render_message_log(ctx, fb);

let offset = self.scope.player_coord() - (GAME_VIEW_SIZE / 2);
let ctx = ctx.add_offset(GAME_VIEW_OFFSET);
crate::render::render_game_with_visibility(&self.scope, offset, GAME_VIEW_SIZE, ctx, fb);
}

pub fn render_message_log(&self, ctx: Ctx, fb: &mut FrameBuffer) {
Expand Down
9 changes: 4 additions & 5 deletions app/src/game_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl GameLoopData {

let instance = self.instance.as_ref().unwrap();
instance.render(ctx, fb);
self.render_game_with_visibility(ctx, fb);

if let Some(cursor) = self.cursor {
if cursor.is_valid(GAME_VIEW_SIZE + Size::new_u16(1, 1)) {
Expand Down Expand Up @@ -235,10 +236,7 @@ impl GameLoopData {
}

pub fn update_examine_text(&mut self) {
self.examine_message = self.cursor.and_then(|coord| {
let world_coord = self.scope().player_coord() - (GAME_VIEW_SIZE / 2) + coord;
examine(self.scope(), world_coord)
});
self.examine_message = self.cursor.and_then(|coord| examine(self.scope(), coord));
}
}

Expand Down Expand Up @@ -266,7 +264,7 @@ pub fn game_loop_component(initial_state: GameLoopState) -> AppCF<()> {
}
}),
Playing(witness) => match witness {
GameState::Win => todo!(),
GameState::Win => win().map_val(|| MainMenu).continue_(),
GameState::GameOver => game_over().map_val(|| MainMenu).continue_(),
GameState::Prompt(prompt_witness) => prompt(prompt_witness).map(Playing).continue_(),
GameState::Running(running) => game_instance_component(running).continue_(),
Expand All @@ -277,6 +275,7 @@ pub fn game_loop_component(initial_state: GameLoopState) -> AppCF<()> {
try_get_melee_weapon(melee_witness).map(Playing).continue_()
}
GameState::FireWeapon(fire_witness) => fire_weapon(fire_witness).map(Playing).continue_(),
GameState::Upgrade(upgrade) => try_upgrade_component(upgrade).map(Playing).continue_(),
},
Examine(running) => {
game_examine_component().map_val(|| Playing(running.into_witness())).continue_()
Expand Down
2 changes: 2 additions & 0 deletions app/src/instances/menus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ mod options;
mod paused;
mod prologue;
mod prompt;
mod upgrade;

pub use main_menu::*;
pub use options::*;
pub use paused::*;
pub use prologue::*;
pub use prompt::*;
pub use upgrade::*;

fn _menu_style<T: 'static>(menu: AppCF<T>) -> AppCF<T> {
menu.border(BorderStyle::default()).fill(color::MENU_BACKGROUND).centre().overlay_tint(
Expand Down
120 changes: 120 additions & 0 deletions app/src/instances/menus/upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use gridbugs::chargrid::{
menu::{self, Menu},
text::StyledString,
};

use super::menu_style;
use crate::{instances::popup, prelude::*};

fn upgrade_identifier(upgrade: Upgrade) -> String {
let name = match upgrade.typ {
UpgradeType::Toughness => "Toughness",
};
let level = match upgrade.level {
UpgradeLevel::Level1 => "1",
UpgradeLevel::Level2 => "2",
UpgradeLevel::Level3 => "3",
};
let price = upgrade.level.cost();
format!("{} {} (${})", name, level, price)
}

fn upgrade_description(upgrade: &Upgrade) -> &'static str {
use {UpgradeLevel::*, UpgradeType::*};
match upgrade {
Upgrade { typ: Toughness, level: Level1 } => {
"Toughness 1: Strong Back\nGain a third ranged weapon slot."
}
Upgrade { typ: Toughness, level: Level2 } => "Toughness 2: Hardy\nDouble your maximum health.",
Upgrade { typ: Toughness, level: Level3 } => {
"Toughness 3: Immune to Explosions + Explosive Rounds ;)"
}
}
}

struct UpgradeMenuDecorated {
menu: Menu<Upgrade>,
}
impl UpgradeMenuDecorated {
const MENU_Y_OFFSET: i32 = 4;
const TEXT_STYLE: Style = Style::new().with_bold(false).with_foreground(Rgba32::new_grey(255));
const SIZE: Size = Size::new_u16(33, 13);

fn text(ctx: Ctx, fb: &mut FrameBuffer, string: String) {
StyledString { string, style: Self::TEXT_STYLE }.render(&(), ctx, fb);
}
}

impl Component for UpgradeMenuDecorated {
type Output = Option<Upgrade>;
type State = GameLoopData;

fn render(&self, state: &Self::State, ctx: Ctx, fb: &mut FrameBuffer) {
let instance = state.instance.as_ref().unwrap();
let balance = instance.scope.player().credit;

Self::text(ctx, fb, "Buy an Upgrade (escape cancels)".to_string());
Self::text(ctx.add_y(2), fb, format!("Your balance: ${}", balance));
self.menu.render(&(), ctx.add_y(Self::MENU_Y_OFFSET), fb);
let description = upgrade_description(self.menu.selected());

StyledString { string: description.to_string(), style: Self::TEXT_STYLE }
.wrap_word()
.cf()
.bound_width(Self::SIZE.width())
.render(&(), ctx.add_y(9), fb);
}

fn update(&mut self, _state: &mut Self::State, ctx: Ctx, event: Event) -> Self::Output {
self.menu.update(&mut (), ctx.add_y(Self::MENU_Y_OFFSET), event)
}

fn size(&self, _state: &Self::State, _ctx: Ctx) -> Size {
Self::SIZE
}
}

fn upgrade_menu() -> AppCF<Upgrade> {
on_state_then(|state: &mut State| {
let instance = state.instance.as_ref().unwrap();
let upgrades = instance.scope.available_upgrades();

use menu::builder::*;
let mut builder = menu_builder().vi_keys();
for upgrade in upgrades {
let name = upgrade_identifier(upgrade);
let identifier = MENU_FADE_SPEC.identifier(move |b| write!(b, "{}", name).unwrap());
builder = builder.add_item(item(upgrade, identifier));
}
let menu = builder.build();
UpgradeMenuDecorated { menu }
})
}

fn upgrade_component(upgrade_witness: UpgradeState) -> AppCF<GameState> {
menu_style(upgrade_menu()).menu_harness().and_then(|result| {
on_state_then(move |state: &mut State| match result {
Err(Close) => val_once(upgrade_witness.cancel()),
Ok(upgrade) => {
let instance = state.instance.as_mut().unwrap();
if upgrade.level.cost() > instance.scope.player().credit {
popup("You can't afford that!".to_string()).map_val(|| upgrade_witness.cancel())
} else {
val_once(upgrade_witness.commit(&mut instance.scope, upgrade))
}
}
})
})
}

pub fn try_upgrade_component(upgrade_witness: UpgradeState) -> AppCF<GameState> {
on_state_then(move |state: &mut State| {
let instance = state.instance.as_ref().unwrap();
let upgrades = instance.scope.available_upgrades();
if upgrades.is_empty() {
popup("No remaining upgrades!".to_string()).map_val(|| upgrade_witness.cancel())
} else {
upgrade_component(upgrade_witness)
}
})
}
2 changes: 2 additions & 0 deletions app/src/instances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ mod gameover;
mod menus;
mod playing;
mod weapon;
mod win;

pub use examine::*;
pub use gameover::*;
pub use menus::*;
pub use playing::*;
pub use weapon::*;
pub use win::*;

pub fn _popup_delay(string: String) -> AppCF<()> {
popup_style(
Expand Down
12 changes: 12 additions & 0 deletions app/src/instances/win.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::prelude::*;

pub fn win() -> AppCF<()> {
on_state_then(move |state: &mut State| {
state.clear_saved_game();
state.config.won = true;
state.save_config();
state.audio_state.loop_music(Audio::EndTextHappy, state.config.music_volume);
text::epilogue1(MAIN_MENU_TEXT_WIDTH)
})
.centre()
}
2 changes: 1 addition & 1 deletion app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod prelude {
pub use crate::AppConfig;

pub const GAME_VIEW_SIZE: Size = Size::new_u16(40, 33);
pub const GAME_VIEW_OFFSET: Coord = Coord::new(0, 2);
pub const GAME_VIEW_OFFSET: Coord = Coord::new(0, 3);
pub const GAME_UI_OFFSET: Coord = Coord::new(42, 0);
pub const LAUNCHER_TITLE: &str = "F.o.r.g.o.t.t.e.n";
}
Expand Down
90 changes: 55 additions & 35 deletions app/src/render/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,7 @@ pub fn npc_renderable(tile: Tile, remembered: bool) -> RenderCell {
RenderCell::BLANK.with_character('Œ').with_foreground(DOOMBOT).with_bold(true)
}
},
Tile::Weapon(weapon_type) => match weapon_type {
forgotten_game::WeaponType::BareHands => RenderCell::BLANK,
forgotten_game::WeaponType::CattleProd => {
RenderCell::BLANK.with_character('Δ').with_foreground(YELLOW).with_bold(true)
}
forgotten_game::WeaponType::Chainsaw => {
RenderCell::BLANK.with_character('Э').with_foreground(CHAINSAW).with_bold(true)
}
forgotten_game::WeaponType::Railgun => {
RenderCell::BLANK.with_character('Я').with_foreground(PLASMA).with_bold(true)
}
forgotten_game::WeaponType::Leecher => {
RenderCell::BLANK.with_character('ł').with_foreground(LEECH).with_bold(true)
}
forgotten_game::WeaponType::FiftyCal => {
RenderCell::BLANK.with_character('£').with_foreground(GAUS).with_bold(true)
}
forgotten_game::WeaponType::Pistol => {
RenderCell::BLANK.with_character('√').with_foreground(OXYGEN).with_bold(true)
}
forgotten_game::WeaponType::Rifle => {
RenderCell::BLANK.with_character('∕').with_foreground(LASER).with_bold(true)
}
},

Tile::Medkit => RenderCell::BLANK
.with_character('†')
.with_foreground(HEALTH)
.with_background(LIGHT_RED)
.with_bold(true),
_ => unreachable!("npc_renderable called with non-npc tile"),
}
}
Expand All @@ -76,10 +47,8 @@ pub fn terrain_renderable(scope: &StateScope, tile: Tile, coord: Coord) -> Rende
Tile::Reactor => {
RenderCell::BLANK.with_character('₪').with_background(LIGHT_GREY).with_foreground(REACTOR)
}
Tile::Stairs => {
RenderCell::BLANK.with_character('>').with_foreground(STAIRS).with_background(BLUE_VIOLET)
}
_ => unreachable!("Tried to render a non-terrain tile as terrain"),
Tile::Stairs => RenderCell::BLANK.with_character('>').with_foreground(STAIRS),
_ => unreachable!("Tried to render a non-terrain tile as terrain: {:?}", tile),
}
}

Expand All @@ -102,7 +71,7 @@ pub fn wall_renderable(tile: Tile, is_wall_below: bool) -> RenderCell {
.with_foreground(CAVE_WALL_FG)
}
}
_ => unreachable!("wall_character called on non-wall tile"),
_ => unreachable!("wall_renderable called on non-wall tile"),
}
}

Expand All @@ -115,6 +84,57 @@ pub fn floor_renderable(tile: Tile) -> RenderCell {
Tile::Water => {
RenderCell::BLANK.with_character('≈').with_foreground(WATER_FG).with_background(WATER_BG)
}
_ => unreachable!("wall_character called on non-wall tile"),
_ => unreachable!("floor_renderable called on non-wall tile"),
}
}

pub fn item_renderable(tile: Tile) -> RenderCell {
match tile {
Tile::Weapon(weapon_type) => match weapon_type {
forgotten_game::WeaponType::BareHands => RenderCell::BLANK,
forgotten_game::WeaponType::CattleProd => {
RenderCell::BLANK.with_character('Δ').with_foreground(YELLOW).with_bold(true)
}
forgotten_game::WeaponType::Chainsaw => {
RenderCell::BLANK.with_character('Э').with_foreground(CHAINSAW).with_bold(true)
}
forgotten_game::WeaponType::Railgun => {
RenderCell::BLANK.with_character('Я').with_foreground(PLASMA).with_bold(true)
}
forgotten_game::WeaponType::Leecher => {
RenderCell::BLANK.with_character('ł').with_foreground(LEECH).with_bold(true)
}
forgotten_game::WeaponType::FiftyCal => {
RenderCell::BLANK.with_character('ξ').with_foreground(GAUS).with_bold(true)
}
forgotten_game::WeaponType::Pistol => {
RenderCell::BLANK.with_character('┌').with_foreground(OXYGEN).with_bold(true)
}
forgotten_game::WeaponType::Rifle => {
RenderCell::BLANK.with_character('√').with_foreground(LASER).with_bold(true)
}
},

Tile::Medkit => RenderCell::BLANK
.with_character('†')
.with_foreground(HEALTH)
.with_background(MEDKIT_TOP)
.with_bold(true),
Tile::Upgrade => RenderCell::BLANK
.with_character('Ū')
.with_foreground(UPGRADE_FOREGROUND)
.with_background(UPGRADE_BACKGROUND)
.with_bold(true),
Tile::Credit1 => {
RenderCell::BLANK.with_character('1').with_foreground(CREDIT_FOREGROUND).with_bold(true)
}
Tile::Credit2 => {
RenderCell::BLANK.with_character('2').with_foreground(CREDIT_FOREGROUND).with_bold(true)
}
Tile::Credit3 => {
RenderCell::BLANK.with_character('3').with_foreground(CREDIT_FOREGROUND).with_bold(true)
}

_ => unreachable!("item_renderable called on non-wall tile"),
}
}
11 changes: 6 additions & 5 deletions app/src/render/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ pub const BULLET: Rgba32 = Rgba32::new_grey(0);
pub const GAUS: Rgba32 = Rgba32::new_rgb(127, 0, 255);
pub const PLASMA: Rgba32 = Rgba32::new_rgb(0x00, 0xFF, 0xFF);
pub const CHAINSAW: Rgba32 = Rgba32::new_rgb(0x7a, 0x6a, 0x00);
pub const CREDIT_FOREGROUND: Rgba32 = Rgba32::new_rgb(0, 127, 127);

// pub const MEDKIT: Rgba32 = Rgba32::new_grey(200);
// pub const MEDKIT_TOP: Rgba32 = Rgba32::new_grey(150);
// pub const MAP_FOREGROUND: Rgba32 = Rgba32::new_rgb(0, 63, 0);
// pub const MAP_BACKGROUND: Rgba32 = Rgba32::new_rgb(0, 255, 0);
// Items
pub const CREDIT_FOREGROUND: Rgba32 = Rgba32::new_rgb(0, 127, 127);
pub const UPGRADE_FOREGROUND: Rgba32 = Rgba32::new_rgb(0, 187, 0);
pub const UPGRADE_BACKGROUND: Rgba32 = Rgba32::new_rgb(0, 0, 0);
pub const MEDKIT: Rgba32 = Rgba32::new_grey(200);
pub const MEDKIT_TOP: Rgba32 = Rgba32::new_grey(150);
9 changes: 9 additions & 0 deletions app/src/render/examine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ fn tile_str(tile: Tile) -> Option<TileLabel> {
| Tile::Grass
| Tile::GrassCrushed
| Tile::Water
| Tile::Upgrade
| Tile::Credit1
| Tile::Credit2
| Tile::Credit3
)
.then(|| TileLabel::Name(desc.clone()))
.or_else(|| {
Expand All @@ -84,6 +88,11 @@ fn default_tile_str(tile: Tile) -> Option<&'static str> {
Tile::Reactor => "core reactor that powers all robots",
Tile::Stairs => "an elevator down...",
Tile::Medkit => "a medkit",
Tile::Upgrade => "an upgrade store",

Tile::Credit1 => "a $1 credit chip",
Tile::Credit2 => "a $2 credit chip",
Tile::Credit3 => "a $3 credit chip",

Tile::Weapon(wpn) => match wpn {
WeaponType::BareHands => return None,
Expand Down
Loading

0 comments on commit d081bc3

Please sign in to comment.