Skip to content

Commit

Permalink
feat: fullscreen 🌊
Browse files Browse the repository at this point in the history
fix: entities lost when the path to their end was destroyed
  • Loading branch information
eerii committed Dec 11, 2023
1 parent d88deab commit 8062e2e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 28 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ a game for the bevy jam 4
- [x] end screen (win/lose)
- [x] restart game
- [x] main menu with image
- [ ] sound and music
- [x] music
- [ ] tutorial text
- [x] fullscreen
- [ ] sounds (ui, entities)
- [ ] other river types + bridges
- [ ] other spirit behaviour

- [ ] playtesting and bugfixing (lun)
- [ ] review settings menu
- [x] review settings menu
- [ ] profiling and optimization

- [ ] presentation (lun)
Expand Down
Binary file added assets/music/background_music.ogg
Binary file not shown.
Binary file removed assets/music/soundscape.ogg
Binary file not shown.
20 changes: 10 additions & 10 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{load::GameAssets, GameState};
use bevy::prelude::*;
use bevy_kira_audio::prelude::AudioPlugin as KiraAudioPlugin;
use bevy_kira_audio::{prelude::AudioPlugin as KiraAudioPlugin, prelude::*};

// ······
// Plugin
Expand All @@ -10,8 +11,8 @@ pub struct AudioPlugin;
impl Plugin for AudioPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(KiraAudioPlugin)
/*.add_systems(OnEnter(GameState::Play), init_music)
.add_systems(OnExit(GameState::Play), pause_music)*/
.add_systems(OnEnter(GameState::Play), init_music)
.add_systems(OnExit(GameState::Play), pause_music)
.init_resource::<MusicHandles>();
}
}
Expand All @@ -22,15 +23,15 @@ impl Plugin for AudioPlugin {

#[derive(Resource, Default)]
struct MusicHandles {
//ambient_music: Option<Handle<AudioInstance>>,
ambient_music: Option<Handle<AudioInstance>>,
}

// ·······
// Systems
// ·······

/*fn init_music(
assets: Res<SampleAssets>,
fn init_music(
assets: Res<GameAssets>,
audio: Res<Audio>,
mut handles: ResMut<MusicHandles>,
mut instances: ResMut<Assets<AudioInstance>>,
Expand All @@ -44,12 +45,11 @@ struct MusicHandles {
None => {
handles.ambient_music = Some(
audio
.play(assets.ambient_music.clone())
.play(assets.music.clone())
.looped()
.with_volume(0.05)
.with_volume(0.1)
.handle(),
);
audio.stop(); // [CHANGE]: Ambient music is disabled by default
}
}
}
Expand All @@ -60,4 +60,4 @@ fn pause_music(handles: Res<MusicHandles>, mut instances: ResMut<Assets<AudioIns
inst.pause(default());
}
}
}*/
}
24 changes: 20 additions & 4 deletions src/game.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::too_many_arguments)]

use bevy::{prelude::*, render::view::RenderLayers};
use bevy::{prelude::*, render::view::RenderLayers, window::WindowResized};
use bevy_ecs_tilemap::prelude::*;
use bevy_persistent::Persistent;
use rand::Rng;
Expand All @@ -11,7 +11,7 @@ use crate::{
play_to_real_size, EndTile, ForegroundTile, LevelSize, PathTile, StartTile, TilemapLayer,
TilesAvailable, MAP_SIZE,
},
GameState,
GameState, INITIAL_RESOLUTION,
};

//0, 1, 2, 3, 4, 5, 130, 160, 250, 300, 400, 500, 700, 900, 1200, 1500, 2000, 2500, 3500,
Expand Down Expand Up @@ -232,9 +232,25 @@ fn spawn_start_end(
}
}

fn zoom_camera(mut cam: Query<(&mut OrthographicProjection, &GameCam)>) {
fn zoom_camera(
mut cam: Query<(&mut OrthographicProjection, &GameCam)>,
mut win: Query<&mut Window>,
mut on_resize: EventReader<WindowResized>,
mut base_scale: Local<f32>,
) {
if *base_scale == 0. {
*base_scale = 0.9;
}

for e in on_resize.read() {
*base_scale = (INITIAL_RESOLUTION.x / e.width) * 0.9;
if let Ok(mut win) = win.get_single_mut() {
win.resolution.set(e.width, e.height);
}
}

if let Ok((mut proj, cam)) = cam.get_single_mut() {
proj.scale = lerp(proj.scale, 0.9 + cam.target_zoom, 0.01);
proj.scale = lerp(proj.scale, *base_scale + cam.target_zoom, 0.01);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mod ui;

use bevy::prelude::*;

pub const INITIAL_RESOLUTION: Vec2 = Vec2::new(1080., 720.);

// Game state
#[derive(States, Debug, Default, Clone, Eq, PartialEq, Hash)]
pub enum GameState {
Expand Down
4 changes: 4 additions & 0 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{config::GameOptions, ui::*, GameState};
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;
use bevy_kira_audio::AudioSource;
use bevy_persistent::Persistent;
use iyes_progress::prelude::*;

Expand Down Expand Up @@ -64,6 +65,9 @@ pub struct GameAssets {

#[asset(path = "sprites/river.png")]
pub river_icon: Handle<Image>,

#[asset(path = "music/background_music.ogg")]
pub music: Handle<AudioSource>,
}

#[derive(AssetCollection, Resource)]
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{asset::AssetMetaCheck, prelude::*, window::WindowResolution};
use bevy::{asset::AssetMetaCheck, prelude::*};
use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode};
use charon::GamePlugin;
use charon::{GamePlugin, INITIAL_RESOLUTION};

fn main() {
App::new()
Expand All @@ -12,8 +12,9 @@ fn main() {
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Charon".to_string(),
resolution: WindowResolution::new(1080., 720.),
resizable: false, // Or use fit_canvas_to_parent: true for resizing on the web
resolution: INITIAL_RESOLUTION.into(),
resizable: true,
fit_canvas_to_parent: true,
canvas: Some("#bevy".to_string()),
prevent_default_event_handling: false,
..default()
Expand Down
2 changes: 0 additions & 2 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ fn layout_main(
},
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
position_type: PositionType::Absolute,
top: Val::Px(0.),
left: Val::Px(0.),
..default()
},
Expand Down
21 changes: 17 additions & 4 deletions src/spirits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,25 @@ fn next_tile_spirit(
map_type,
map_trans,
) {
if spirit.next_tile.is_some() && spirit.curr_tile == tile_pos {
continue;
// Check if selected end tile is reachable
if let Some(selected_end) = spirit.selected_end {
if let Some(entity) = storage.get(&tile_pos) {
if let Ok((_, path)) = paths.get(entity) {
if !path.distance.contains_key(&selected_end) {
spirit.selected_end = None;
spirit.next_tile = None;
spirit.curr_distance = std::f32::MAX;
}
}
}
}

// TODO: Move this so it updates for other spirits

if spirit.next_tile.is_some()
&& spirit.selected_end.is_some()
&& spirit.curr_tile == tile_pos
{
continue;
}
spirit.curr_tile = tile_pos;

// If it arrived at the next tile (or if there is no next tile)
Expand Down
8 changes: 6 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{prelude::*, render::view::RenderLayers, sprite::MaterialMesh2dBundle};
use bevy_persistent::Persistent;

use crate::{config::GameOptions, load::StartAssets, GameState};
use crate::{config::GameOptions, load::StartAssets, GameState, INITIAL_RESOLUTION};

pub const UI_LAYER: RenderLayers = RenderLayers::layer(1);
const MENU_WIDTH: Val = Val::Px(300.);
Expand Down Expand Up @@ -79,7 +79,11 @@ pub fn init_ui(
cmd.spawn((
MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(shape::Quad::default())).into(),
transform: Transform::from_xyz(0., 0., -10.).with_scale(Vec3::new(1080., 720., 1.)),
transform: Transform::from_xyz(0., 0., -10.).with_scale(Vec3::new(
INITIAL_RESOLUTION.x * 2.,
INITIAL_RESOLUTION.y * 2.,
1.,
)),
material: materials.add(ColorMaterial::from(opts.color.dark)),
..default()
},
Expand Down

0 comments on commit 8062e2e

Please sign in to comment.