Merge remote-tracking branch 'origin/main' into attack-human
Some checks failed
Rust / rustfmt (pull_request) Successful in 27s
Rust / clippy (pull_request) Failing after 2m31s
Rust / build (pull_request) Successful in 3m13s

This commit is contained in:
Glaeder 2024-07-07 18:23:44 +02:00
commit a9aceaf65a
5 changed files with 56 additions and 14 deletions

View file

@ -128,7 +128,11 @@ impl AssetsWriter {
writeln!(file, "{indent}\t\t_ctx.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?; writeln!(file, "{indent}\t\t_ctx.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?;
} }
for asset_const_name in root.sound_assets.values() { for asset_const_name in root.sound_assets.values() {
writeln!(file, "{indent}\t\tcomfy::load_sound_from_bytes({asset_const_name:?}, {asset_const_name}, Default::default());")?; writeln!(file, "{indent}\t\tcomfy::load_sound_from_bytes({asset_const_name:?}, {asset_const_name},")?;
writeln!(
file,
"{indent}\t\t\tcomfy::StaticSoundSettings::new().loop_region(..));"
)?;
} }
for group_name in root.groups.keys() { for group_name in root.groups.keys() {
writeln!(file, "{indent}\t\t{group_name}::Assets::load(_ctx);")?; writeln!(file, "{indent}\t\t{group_name}::Assets::load(_ctx);")?;

View file

@ -3,7 +3,11 @@ mod grid;
mod player; mod player;
mod room; mod room;
use comfy::{delta, main_camera_mut, random_i32, vec2, EngineContext, RandomRange as _}; use crate::assets::ASSETS;
use comfy::{
delta, main_camera_mut, play_sound_id, random_i32, stop_sound_id, vec2,
EngineContext, RandomRange as _
};
use grid::Grid; use grid::Grid;
use indexmap::IndexSet; use indexmap::IndexSet;
use log::error; use log::error;
@ -29,7 +33,9 @@ pub struct HouseState {
/// The energy level remaining in the house. Should decrease by itself, and much /// The energy level remaining in the house. Should decrease by itself, and much
/// faster when inhabited by the ghost. /// faster when inhabited by the ghost.
pub charge: f32, pub charge: f32,
pub max_charge: f32 pub max_charge: f32,
pub sound_playing: bool
} }
impl HouseState { impl HouseState {
@ -65,12 +71,14 @@ impl HouseState {
exit_time: 0.0, exit_time: 0.0,
// TODO this should be lower depending on the time elapsed // TODO this should be lower depending on the time elapsed
charge: max_charge, charge: max_charge,
max_charge max_charge,
sound_playing: false
} }
} }
} }
pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) { pub fn draw(state: &crate::State, _ctx: &EngineContext<'_>) {
let Some(house) = state.house() else { let Some(house) = state.house() else {
error!("How can I render a house when I'm not in one?!?"); error!("How can I render a house when I'm not in one?!?");
return; return;
@ -90,15 +98,28 @@ pub fn draw(state: &crate::State, _ctx: &comfy::EngineContext<'_>) {
house.player.draw(); house.player.draw();
} }
pub fn update(state: &mut crate::State, ctx: &mut comfy::EngineContext<'_>) { pub fn update(state: &mut crate::State, ctx: &mut EngineContext<'_>) {
if state.overworld.sound_playing {
stop_sound_id(ASSETS.music.galactic_rap_speedup);
state.overworld.sound_playing = false;
}
let mut camera = main_camera_mut(); let mut camera = main_camera_mut();
camera.center = vec2(0.0, 0.0); camera.center = vec2(0.0, 0.0);
drop(camera); drop(camera);
let house = state.house_mut(ctx); let Some(house) = state.house_mut(ctx) else {
error!("WTF I cannot update a house without a house");
return;
};
let current_room = house.rooms.get(house.current_room_id).unwrap(); let current_room = house.rooms.get(house.current_room_id).unwrap();
house.player.update(&current_room); house.player.update(&current_room);
if !house.sound_playing {
play_sound_id(ASSETS.music.mesmerizing_galaxy_loop);
house.sound_playing = true;
}
if house.player.is_moving_to_right_room(current_room) { if house.player.is_moving_to_right_room(current_room) {
if house.current_room_id < (house.room_count - 1) { if house.current_room_id < (house.room_count - 1) {
house.current_room_id += 1; house.current_room_id += 1;

View file

@ -1,11 +1,13 @@
use crate::{ use crate::{
activities::Activity, activities::Activity,
assets::ASSETS,
game::{ZLayer, GHOST_DISCHARGE_RATE, GHOST_DISCHARGE_RATE_MOVEMENT}, game::{ZLayer, GHOST_DISCHARGE_RATE, GHOST_DISCHARGE_RATE_MOVEMENT},
State State
}; };
use comfy::{ use comfy::{
draw_rect_outline, draw_sprite, error, info, is_key_down, main_camera_mut, draw_rect_outline, draw_sprite, error, info, is_key_down, main_camera_mut,
texture_id, vec2, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE play_sound_id, stop_sound_id, texture_id, vec2, EngineContext, IVec2, KeyCode, Vec2,
RED, WHITE
}; };
use std::time::Instant; use std::time::Instant;
use worldgen::MovementCost; use worldgen::MovementCost;
@ -50,9 +52,20 @@ pub fn draw(state: &State, _ctx: &EngineContext<'_>) {
); );
} }
fn update_move_player(state: &mut State, _ctx: &mut EngineContext<'_>) { fn update_move_player(state: &mut State, ctx: &mut EngineContext<'_>) {
let now = Instant::now(); let now = Instant::now();
if !state.overworld.sound_playing {
if let Some(house) = state.house_mut(ctx) {
if house.sound_playing {
stop_sound_id(ASSETS.music.mesmerizing_galaxy_loop);
house.sound_playing = false;
}
}
play_sound_id(ASSETS.music.galactic_rap_speedup);
state.overworld.sound_playing = true;
}
// Are there any pending position updates? If so, we ignore all user input and execute // Are there any pending position updates? If so, we ignore all user input and execute
// the pending updates. // the pending updates.
if state.ghost.overworld_movement_pending != Vec2::ZERO { if state.ghost.overworld_movement_pending != Vec2::ZERO {

View file

@ -422,7 +422,9 @@ impl Chunk {
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Overworld { pub struct Overworld {
chunks: HashMap<IVec2, Chunk> chunks: HashMap<IVec2, Chunk>,
pub sound_playing: bool
} }
fn world_to_chunk_and_local_coords(world_coords: IVec2) -> (IVec2, UVec2) { fn world_to_chunk_and_local_coords(world_coords: IVec2) -> (IVec2, UVec2) {

View file

@ -59,10 +59,12 @@ impl State {
self.houses.get(&self.get_house_pos()?) self.houses.get(&self.get_house_pos()?)
} }
fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> &mut HouseState { fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> Option<&mut HouseState> {
Some(
self.houses self.houses
.entry(self.get_house_pos().unwrap()) .entry(self.get_house_pos()?)
.or_insert_with(|| HouseState::generate_new_house(ctx)) .or_insert_with(|| HouseState::generate_new_house(ctx))
)
} }
} }