Skip to content
Snippets Groups Projects
Verified Commit 89ed6e93 authored by Louis's avatar Louis :fire:
Browse files

Add basic assets

- Include dawnbringer sprites
- Create basic spawner, spawn player
- Fix splash screen scaling for virtual pixel sizes
parent f3bdcfcd
No related branches found
No related tags found
No related merge requests found
Pipeline #170 passed with stages
in 8 minutes and 53 seconds
Showing
with 172 additions and 24 deletions
...@@ -7,4 +7,6 @@ ...@@ -7,4 +7,6 @@
.idea/ .idea/
.vscode/ .vscode/
dist/ dist/
\ No newline at end of file
*.tiled-session
\ No newline at end of file
[fonts]
Kaph - GGBotNet - https://ggbot.itch.io/kaph-font
[sprites]
Dawnlike - DragonDePlatino / Dawnbringer - https://opengameart.org/content/dawnlike-16x16-universal-rogue-like-tileset-v181
\ No newline at end of file
...@@ -52,5 +52,7 @@ The code source files found in this repository are covered by the license found ...@@ -52,5 +52,7 @@ The code source files found in this repository are covered by the license found
The logo found in `assets/splash.png` is licensed under the following license for use only within the context of this project. The logo found in `assets/splash.png` is licensed under the following license for use only within the context of this project.
Asset creators are listed in CREDITS with any relevant licenses
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><span property="dct:title">Microhacks Logo</span> by <span property="cc:attributionName">Microhacks Ltd</span> is licensed under <a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0</a></p> <p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><span property="dct:title">Microhacks Logo</span> by <span property="cc:attributionName">Microhacks Ltd</span> is licensed under <a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0</a></p>
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1"> <img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1">
File added
assets/sprites/creatures.png

130 B

assets/sprites/environs.png

131 B

...@@ -2,7 +2,7 @@ use bevy::asset::LoadState; ...@@ -2,7 +2,7 @@ use bevy::asset::LoadState;
use bevy::prelude::*; use bevy::prelude::*;
use iyes_loopless::prelude::NextState; use iyes_loopless::prelude::NextState;
use crate::assets::AssetTypeLoader; use crate::assets::{AssetTypeLoader, SpriteSheetConfig};
use crate::system::flow::AppState; use crate::system::flow::AppState;
pub fn start_preload_resources(mut commands: Commands) { pub fn start_preload_resources(mut commands: Commands) {
...@@ -14,6 +14,15 @@ pub fn start_preload_resources(mut commands: Commands) { ...@@ -14,6 +14,15 @@ pub fn start_preload_resources(mut commands: Commands) {
pub fn start_load_resources(mut loader: AssetTypeLoader) { pub fn start_load_resources(mut loader: AssetTypeLoader) {
loader.load_images(&[("splash.png", "splash")]); loader.load_images(&[("splash.png", "splash")]);
loader.load_audio(&[("splash_sting.mp3", "splash_sting")]); loader.load_audio(&[("splash_sting.mp3", "splash_sting")]);
let sheet_config = SpriteSheetConfig::squares(16, 64, 64);
loader.load_spritesheet(
&sheet_config,
&[
("sprites/environs.png", "environs"),
("sprites/creatures.png", "creatures"),
],
);
} }
pub fn check_load_resources(mut commands: Commands, loader: AssetTypeLoader) { pub fn check_load_resources(mut commands: Commands, loader: AssetTypeLoader) {
......
use bevy::math::uvec2;
use bevy::prelude::*;
use iyes_loopless::prelude::AppLooplessStateExt;
use iyes_loopless::state::NextState;
use crate::entities::spawner::EntitySpawner;
use crate::system::flow::AppState;
pub fn spawn_player(mut spawner: EntitySpawner) {
log::info!("Spawning player");
spawner.spawn_player(uvec2(2, 2));
}
pub fn skip_menu(mut commands: Commands) {
commands.insert_resource(NextState(AppState::InGame));
}
pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
app.add_enter_system(AppState::Menu, skip_menu)
.add_enter_system(AppState::InGame, spawn_player);
}
}
use bevy::prelude::*;
#[derive(Debug, Clone, Copy, Component)]
pub struct GameEntity;
pub fn remove_game_entities(mut commands: Commands, query: Query<Entity, With<GameEntity>>) {
for entity in &query {
commands.entity(entity).despawn_recursive();
}
}
pub mod lifecycle;
pub mod spawner;
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use crate::assets::AssetHandles;
use crate::entities::lifecycle::GameEntity;
use crate::system::camera::ChaseCam;
use crate::system::graphics::LAYER_CREATURE;
const PLAYER_SPRITE: usize = 2;
#[derive(SystemParam)]
pub struct EntitySpawner<'w, 's> {
pub commands: Commands<'w, 's>,
pub handles: Res<'w, AssetHandles>,
}
impl<'w, 's> EntitySpawner<'w, 's> {
pub fn spawn_player(&mut self, grid_position: UVec2) {
let mut entity = self.commands.spawn();
entity.insert(ChaseCam).insert(GameEntity);
entity.insert_bundle(SpriteSheetBundle {
texture_atlas: self.handles.atlas("creatures"),
transform: Transform::from_translation(grid_position.as_vec2().extend(LAYER_CREATURE)),
sprite: TextureAtlasSprite {
index: PLAYER_SPRITE,
..Default::default()
},
..Default::default()
});
}
}
pub mod assets; pub mod assets;
pub mod debug;
pub mod entities;
pub mod multiplayer; pub mod multiplayer;
pub mod splash_screen; pub mod splash_screen;
pub mod system; pub mod system;
pub mod world;
use bevy::prelude::*; use bevy::prelude::*;
use game_core::assets::AssetHandles;
use game_core::system::flow::AppState; use game_core::system::flow::AppState;
use game_core::system::resources::DefaultResourcesPlugin; use game_core::system::resources::DefaultResourcesPlugin;
use iyes_loopless::prelude::AppLooplessStateExt; use iyes_loopless::prelude::AppLooplessStateExt;
use micro_musicbox::CombinedAudioPlugins; use micro_musicbox::CombinedAudioPlugins;
use remote_events::RemoteEventPlugin; use remote_events::RemoteEventPlugin;
use game_core::assets::AssetHandles;
fn main() { fn main() {
App::new() App::new()
...@@ -19,5 +19,6 @@ fn main() { ...@@ -19,5 +19,6 @@ fn main() {
game_core::multiplayer::OutgoingEvent, game_core::multiplayer::OutgoingEvent,
game_core::multiplayer::IncomingEvent, game_core::multiplayer::IncomingEvent,
>::new()) >::new())
.add_plugin(game_core::debug::DebugPlugin)
.run(); .run();
} }
...@@ -9,6 +9,7 @@ use crate::splash_screen::components::{ ...@@ -9,6 +9,7 @@ use crate::splash_screen::components::{
SplashAnimation, SplashAnimationBundle, SplashAnimationTimer, SplashAnimationType, SplashAnimation, SplashAnimationBundle, SplashAnimationTimer, SplashAnimationType,
}; };
use crate::system::flow::AppState; use crate::system::flow::AppState;
use crate::system::load_config::initial_size;
use crate::system::utilities::f32_min; use crate::system::utilities::f32_min;
use crate::system::window::WindowManager; use crate::system::window::WindowManager;
...@@ -36,14 +37,19 @@ pub fn setup_splash_screen( ...@@ -36,14 +37,19 @@ pub fn setup_splash_screen(
windows: WindowManager, windows: WindowManager,
mut music_box: MusicBox<AssetHandles>, mut music_box: MusicBox<AssetHandles>,
) { ) {
let window_size = match windows.get_primary_window() { // Changed window scaling to auto, so layout is based on virtual pixel units, not
Some(size) => size, // window units
None => { //
log::error!("Missing window for splash screen"); // let window_size = match windows.get_primary_window() {
commands.insert_resource(NextState(AppState::Menu)); // Some(size) => size,
return; // None => {
} // log::error!("Missing window for splash screen");
}; // commands.insert_resource(NextState(AppState::Menu));
// return;
// }
// };
let window_size = initial_size();
let handle = match handles.images.get("splash") { let handle = match handles.images.get("splash") {
Some(handle) => handle, Some(handle) => handle,
...@@ -59,11 +65,21 @@ pub fn setup_splash_screen( ...@@ -59,11 +65,21 @@ pub fn setup_splash_screen(
commands.insert_resource(ClearColor(Color::hex("001122").unwrap())); commands.insert_resource(ClearColor(Color::hex("001122").unwrap()));
let scale_factor = match window_size.width() > window_size.height() { let image_size = image_data.texture_descriptor.size;
true => window_size.height() / image_data.texture_descriptor.size.height as f32, let scale_factor = match window_size.0 > window_size.1 {
false => window_size.width() / image_data.texture_descriptor.size.width as f32, true => window_size.1 / image_size.height as f32,
false => window_size.0 / image_size.width as f32,
}; };
log::info!(
"Splash scaling: s{:.3}; i({}x{}); w({}x{})",
scale_factor,
image_size.width,
image_size.height,
window_size.0,
window_size.1
);
image_data.sampler_descriptor = ImageSampler::linear(); image_data.sampler_descriptor = ImageSampler::linear();
music_box.play_sfx("splash_sting"); music_box.play_sfx("splash_sting");
......
pub const LAYER_TILE: f32 = 50.0;
pub const LAYER_ITEM: f32 = 300.0;
pub const LAYER_CREATURE: f32 = 400.0;
...@@ -10,7 +10,7 @@ mod setup { ...@@ -10,7 +10,7 @@ mod setup {
} }
pub fn initial_size() -> (f32, f32) { pub fn initial_size() -> (f32, f32) {
(1280.0, 720.0) (16.0 * 32.0, 16.0 * 18.0)
} }
} }
...@@ -22,8 +22,8 @@ mod setup { ...@@ -22,8 +22,8 @@ mod setup {
#[cfg(feature = "no_aspect")] #[cfg(feature = "no_aspect")]
pub fn initial_size() -> (f32, f32) { pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0; static default_width: f32 = 16.0 * 32.0;
static default_height: f32 = 720.0; static default_height: f32 = 16.0 * 18.0;
web_sys::window() web_sys::window()
.and_then(|window: web_sys::Window| { .and_then(|window: web_sys::Window| {
...@@ -45,9 +45,9 @@ mod setup { ...@@ -45,9 +45,9 @@ mod setup {
#[cfg(not(feature = "no_aspect"))] #[cfg(not(feature = "no_aspect"))]
pub fn initial_size() -> (f32, f32) { pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0; static default_width: f32 = 16.0 * 32.0;
static default_height: f32 = 720.0; static default_height: f32 = 16.0 * 18.0;
static ratio: f32 = 1280.0 / 720.0; static ratio: f32 = default_width / default_height;
web_sys::window() web_sys::window()
.and_then(|window: web_sys::Window| { .and_then(|window: web_sys::Window| {
......
pub mod camera; pub mod camera;
pub mod flow; pub mod flow;
pub mod graphics;
pub mod load_config; pub mod load_config;
pub mod resources; pub mod resources;
pub mod utilities; pub mod utilities;
......
...@@ -3,7 +3,6 @@ use bevy::prelude::*; ...@@ -3,7 +3,6 @@ use bevy::prelude::*;
use bevy::render::texture::ImageSettings; use bevy::render::texture::ImageSettings;
use bevy::window::PresentMode; use bevy::window::PresentMode;
use crate::system::camera::spawn_orthographic_camera;
use crate::system::load_config::{get_asset_path_string, initial_size}; use crate::system::load_config::{get_asset_path_string, initial_size};
pub struct DefaultResourcesPlugin; pub struct DefaultResourcesPlugin;
...@@ -12,10 +11,10 @@ impl Plugin for DefaultResourcesPlugin { ...@@ -12,10 +11,10 @@ impl Plugin for DefaultResourcesPlugin {
let (width, height) = initial_size(); let (width, height) = initial_size();
app.insert_resource(WindowDescriptor { app.insert_resource(WindowDescriptor {
width, width: width * 3.0,
height, height: height * 3.0,
resizable: true, resizable: true,
title: String::from("Bevy 2D Template"), title: String::from("Ludum Dare 51"),
present_mode: PresentMode::AutoNoVsync, present_mode: PresentMode::AutoNoVsync,
..Default::default() ..Default::default()
}) })
......
use std::ops::Deref;
use bevy::math::UVec2;
use bevy::prelude::*;
pub const WORLD_TILE_SIZE: f32 = 16.0;
/// Track the location of an entity within a grid
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Component)]
#[repr(transparent)]
pub struct GridPosition(pub UVec2);
impl Deref for GridPosition {
type Target = UVec2;
fn deref(&self) -> &Self::Target {
&self.0
}
}
/// Take an entity's position on a grid, and sync it up to the transform used to render
/// the sprite
pub fn sync_grid_to_transform(mut query: Query<(&GridPosition, &mut Transform)>) {
for (position, mut transform) in &mut query {
transform.translation = ((position.as_vec2() * WORLD_TILE_SIZE) + (WORLD_TILE_SIZE / 2.0))
.extend(transform.translation.z);
}
}
pub mod level_map;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment