mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-14 19:55:02 +01:00
Add cave music
This commit is contained in:
parent
0a345aae5e
commit
9e9f44b5e5
4 changed files with 41 additions and 8 deletions
BIN
res/cave.ogg
Normal file
BIN
res/cave.ogg
Normal file
Binary file not shown.
32
src/app.rs
32
src/app.rs
|
|
@ -10,7 +10,7 @@ use sfml::{
|
|||
|
||||
use crate::{
|
||||
debug::DebugState,
|
||||
game::{for_each_tile_on_screen, GameState},
|
||||
game::{for_each_tile_on_screen, Biome, GameState},
|
||||
graphics::{self, NATIVE_RESOLUTION},
|
||||
input::Input,
|
||||
math::{wp_to_tp, WorldPos, TILE_SIZE},
|
||||
|
|
@ -34,9 +34,9 @@ impl App {
|
|||
let rw = graphics::make_window();
|
||||
let sf_egui = SfEgui::new(&rw);
|
||||
let mut res = Res::load()?;
|
||||
res.music.set_looping(true);
|
||||
res.music.set_volume(10.0);
|
||||
res.music.play();
|
||||
res.surf_music.set_looping(true);
|
||||
res.surf_music.set_volume(10.0);
|
||||
res.surf_music.play();
|
||||
Ok(Self {
|
||||
rw,
|
||||
should_quit: false,
|
||||
|
|
@ -170,6 +170,26 @@ impl App {
|
|||
t.bg = self.game.tile_to_place;
|
||||
}
|
||||
}
|
||||
if self.game.camera_offset.y > 163800 {
|
||||
self.game.current_biome = Biome::Underground;
|
||||
} else {
|
||||
self.game.current_biome = Biome::Surface;
|
||||
}
|
||||
if self.game.current_biome != self.game.prev_biome {
|
||||
self.game.prev_biome = self.game.current_biome;
|
||||
match self.game.current_biome {
|
||||
Biome::Surface => {
|
||||
self.res.und_music.stop();
|
||||
self.res.surf_music.play();
|
||||
}
|
||||
Biome::Underground => {
|
||||
self.res.surf_music.stop();
|
||||
self.res.und_music.set_volume(self.res.surf_music.volume());
|
||||
self.res.und_music.set_looping(true);
|
||||
self.res.und_music.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn do_freecam(&mut self) {
|
||||
|
|
@ -254,9 +274,9 @@ fn debug_panel_ui(
|
|||
ui.label("Tile to place");
|
||||
ui.add(egui::DragValue::new(&mut game.tile_to_place));
|
||||
ui.label("Music volume");
|
||||
let mut vol = res.music.volume();
|
||||
let mut vol = res.surf_music.volume();
|
||||
ui.add(egui::DragValue::new(&mut vol));
|
||||
res.music.set_volume(vol);
|
||||
res.surf_music.set_volume(vol);
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
gamedebug_core::for_each_imm(|info| match info {
|
||||
|
|
|
|||
11
src/game.rs
11
src/game.rs
|
|
@ -17,7 +17,16 @@ pub struct GameState {
|
|||
pub player: Player,
|
||||
pub gravity: f32,
|
||||
pub tile_to_place: TileId,
|
||||
pub current_biome: Biome,
|
||||
pub prev_biome: Biome,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Biome {
|
||||
Surface,
|
||||
Underground,
|
||||
}
|
||||
|
||||
impl GameState {
|
||||
pub(crate) fn draw_world(&mut self, rw: &mut RenderWindow, res: &Res) {
|
||||
let mut s = Sprite::with_texture(&res.tile_atlas);
|
||||
|
|
@ -77,6 +86,8 @@ impl Default for GameState {
|
|||
player: Player::new_at(spawn_point),
|
||||
gravity: 0.7,
|
||||
tile_to_place: 1,
|
||||
current_biome: Biome::Surface,
|
||||
prev_biome: Biome::Surface,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@ use sfml::{audio::Music, graphics::Texture, SfBox};
|
|||
|
||||
pub struct Res {
|
||||
pub tile_atlas: SfBox<Texture>,
|
||||
pub music: Music<'static>,
|
||||
pub surf_music: Music<'static>,
|
||||
pub und_music: Music<'static>,
|
||||
}
|
||||
|
||||
impl Res {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
tile_atlas: Texture::from_file("res/tiles.png")?,
|
||||
music: Music::from_file("res/music.ogg").unwrap(),
|
||||
surf_music: Music::from_file("res/music.ogg").unwrap(),
|
||||
und_music: Music::from_file("res/cave.ogg").unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue