Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bevy = { version = "0.17.2", default-features = false, features = [
"bevy_window",
"bevy_winit",
"bevy_state",
"multi_threaded",
"png",
"std",
"webgl2",
Expand All @@ -25,7 +26,6 @@ bevy = { version = "0.17.2", default-features = false, features = [
bevy_embedded_assets = "0.14.0"
leafwing-input-manager = "0.18.0"
log = { version = "*", features = [
"max_level_debug",
"release_max_level_warn",
] }
rand = "0.9.2"
Expand All @@ -37,12 +37,11 @@ getrandom = { version = "0.3", features = ["wasm_js"] }
# Default to a native dev build.
default = ["dev_native"]
dev = [
# Improve compile times for dev builds by linking Bevy as a dynamic library.
"bevy/dynamic_linking",
"bevy/bevy_dev_tools",
"bevy/bevy_ui_debug",
# Improve error messages coming from Bevy
"bevy/track_location",
"bevy/trace",
]
dev_native = [
"dev",
Expand Down
46 changes: 46 additions & 0 deletions assets/palette.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
172038
253a5e
3c5e8b
4f8fba
73bed3
a4dddb
19332d
25562e
468232
75a743
a8ca58
d0da91
4d2b32
7a4841
ad7757
c09473
d7b594
e7d5b3
341c27
602c2c
884b2b
be772b
de9e41
e8c170
241527
411d31
752438
a53030
cf573c
da863e
1e1d39
402751
7a367b
a23e8c
c65197
df84a5
090a14
10141f
151d28
202e37
394a50
577277
819796
a8b5b2
c7cfcc
ebede9
Binary file added assets/palette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/asteroids/asteroid3.aseprite
Binary file not shown.
Binary file added assets/sprites/asteroids/asteroid3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/asteroids/asteroid4.aseprite
Binary file not shown.
Binary file added assets/sprites/asteroids/asteroid4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/projectiles/projectile1.aseprite
Binary file not shown.
Binary file added assets/sprites/projectiles/projectile1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/ships/ship3.aseprite
Binary file not shown.
Binary file added assets/sprites/ships/ship3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 76 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use bevy::{
asset::AssetMetaCheck,
camera::{RenderTarget, visibility::RenderLayers},
prelude::*,
window::{WindowMode, WindowResolution},
render::render_resource::{
Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
},
window::{WindowMode, WindowResized, WindowResolution},
};
use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode};

Expand All @@ -10,6 +14,21 @@ use crate::input::InputPlugin;
mod input;
mod screens;

const RES_WIDTH: u32 = 853;
const RES_HEIGHT: u32 = 480;

const PIXEL_PERFECT_LAYERS: RenderLayers = RenderLayers::layer(0);
const HIGH_RES_LAYERS: RenderLayers = RenderLayers::layer(1);

#[derive(Component)]
struct Canvas;

#[derive(Component)]
struct InGameCamera;

#[derive(Component)]
struct OuterCamera;

fn main() -> AppExit {
App::new().add_plugins(AppPlugin).run()
}
Expand Down Expand Up @@ -50,8 +69,9 @@ impl Plugin for AppPlugin {
app.init_state::<Pause>();
app.configure_sets(Update, PausableSystems.run_if(in_state(Pause(false))));

app.insert_resource(ClearColor(Color::srgb_u8(49, 54, 56)));
app.insert_resource(ClearColor(Color::srgb_u8(9, 10, 20)));
app.add_systems(Startup, spawn_camera);
app.add_systems(Update, fit_canvas.run_if(on_message::<WindowResized>));
}
}

Expand All @@ -61,6 +81,58 @@ struct Pause(pub bool);
#[derive(SystemSet, Copy, Clone, Eq, PartialEq, Hash, Debug)]
struct PausableSystems;

fn spawn_camera(mut commands: Commands) {
commands.spawn((Name::new("Camera"), Camera2d));
fn spawn_camera(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let canvas_size = Extent3d {
width: RES_WIDTH,
height: RES_HEIGHT,
..default()
};
let mut canvas = Image {
texture_descriptor: TextureDescriptor {
label: Some("Canvas Texture"),
size: canvas_size,
dimension: TextureDimension::D2,
format: TextureFormat::Rgba8UnormSrgb,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::COPY_DST
| TextureUsages::TEXTURE_BINDING
| TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
},
..default()
};
canvas.resize(canvas_size);
let image_handle = images.add(canvas);
commands.spawn((
Camera2d,
Camera {
order: -1,
target: RenderTarget::Image(image_handle.clone().into()),
clear_color: ClearColorConfig::Custom(Color::srgb_u8(9, 10, 20)),
..default()
},
Msaa::Off,
InGameCamera,
PIXEL_PERFECT_LAYERS,
));

commands.spawn((Sprite::from_image(image_handle), Canvas, HIGH_RES_LAYERS));

commands.spawn((Camera2d, Msaa::Off, OuterCamera, HIGH_RES_LAYERS));
}

fn fit_canvas(
mut resize_messages: MessageReader<WindowResized>,
mut projection: Single<&mut Projection, With<OuterCamera>>,
) {
let Projection::Orthographic(proj) = &mut **projection else {
return;
};

for msg in resize_messages.read() {
let h_scale = msg.width / RES_WIDTH as f32;
let v_scale = msg.height / RES_HEIGHT as f32;
proj.scale = 1. / h_scale.min(v_scale);
}
}
Loading