Base game template

This commit is contained in:
Jeremy Kaplan 2026-08-09 13:08:28 -04:00
commit f83c7c0781
7 changed files with 6158 additions and 0 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
/build/*
!/build/index.html
/target

6045
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,27 @@ version = "0.1.0"
edition = "2024"
[dependencies]
bevy = "0.19.0"
chacha20 = { version = "0.10.1", default-features = false, features = ["rng"] }
getrandom = "0.4.3"
rand = "0.10.2"
[features]
default = ["debug"]
debug = ["bevy/debug"]
wasm = ["getrandom/wasm_js"]
# Enable some optimization in development so the game runs well.
# Enable more optimization for dependencies because they change less often.
[profile.dev]
opt-level = 1
package."*".opt-level = 3
[profile.release]
codegen-units = 1
lto = "thin"
[profile.wasm-release]
inherits = "release"
opt-level = "s" # TODO: compare with "z"
strip = "debuginfo"

16
Makefile Normal file
View file

@ -0,0 +1,16 @@
.DEFAULT_GOAL := help
.PHONY: help
help: ## List targets in this Makefile
@awk 'BEGIN { FS = ":|:.*?## "; OFS="\t" }; /^[0-9a-zA-Z_-]+?:/ { print $$1, $$2 }' $(MAKEFILE_LIST) \
| column --separator $$'\t' --table --table-wrap 2 --output-separator ' ' \
| sort --dictionary-order
.PHONY: build
build:
cargo build --release --target wasm32-unknown-unknown --no-default-features --features wasm
wasm-bindgen --target web --out-dir build target/wasm32-unknown-unknown/release/breakout.wasm
.PHONY: publish
publish:
rsync --verbose --checksum --recursive --safe-links --delete --progress build/ root@lab:/www/games/breakout

23
build/index.html Normal file
View file

@ -0,0 +1,23 @@
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body {
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
background-color: #aaaaaa;
}
canvas {
background-color: black;
}
</style>
<title>Pong</title>
</head>
<script type="module">
import init from './breakout.js';
init();
</script>
</html>

5
clippy.toml Normal file
View file

@ -0,0 +1,5 @@
# Bevy query types can get a bit more complicated than usual Rust code.
type-complexity-threshold = 1000
# Bevy systems sometimes rely on a lot of different entities.
too-many-arguments-threshold = 10

View file

@ -1,3 +1,45 @@
use bevy::camera::ScalingMode;
use bevy::prelude::*;
pub const WORLD_SIZE: Vec2 = Vec2::new(480., 640.);
fn main() {
App::new()
.insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins.set(WindowPlugin {
// Until there's a reliable way to hint that a game window should
// float on tiling window managers, the most reliable way to achieve
// that is to define a fixed non-resizable window.
//
// https://github.com/rust-windowing/winit/issues/862#issuecomment-2047791401
primary_window: Some(Window {
resize_constraints: WindowResizeConstraints {
min_width: WORLD_SIZE.x,
min_height: WORLD_SIZE.y,
max_width: WORLD_SIZE.x,
max_height: WORLD_SIZE.y,
},
..default()
}),
..default()
}))
.add_systems(Startup, (setup, greet).chain())
.run();
}
fn setup(mut commands: Commands) {
commands.spawn((
Camera2d,
Projection::Orthographic(OrthographicProjection {
scaling_mode: ScalingMode::Fixed {
width: WORLD_SIZE.x,
height: WORLD_SIZE.y,
},
..OrthographicProjection::default_2d()
}),
));
}
fn greet() {
println!("Hello, world!");
}