Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8fc9e682cc | |||
| be83be1a7b | |||
| 3639122e54 | |||
| 97e0313c23 | |||
| de79ca0258 | |||
| 1edbd3e78c | |||
| 5af59863a1 | |||
| 84d93d496a | |||
| 4a9d252691 | |||
| 3c9a9a7d9d | |||
| 010cbd6d4b | |||
| 918992702f | |||
| c8c64e4d22 |
6008
Cargo.lock
generated
Normal file
6008
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@@ -1,14 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "asteroids"
|
name = "asteroids"
|
||||||
version = "0.3.0"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "AGPL-3.0-only"
|
license = "AGPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.16"
|
bevy = "0.16"
|
||||||
bevy-inspector-egui = "0.32.0"
|
bevy-inspector-egui = "0.32"
|
||||||
bevy_rapier2d = "0.31.0"
|
bevy_rapier2d = "0.31"
|
||||||
rand = "0.9.2"
|
rand = "0.9"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["dynamic_linking"]
|
default = ["dynamic_linking"]
|
||||||
@@ -16,7 +16,7 @@ dynamic_linking = ["bevy/dynamic_linking"]
|
|||||||
debug_ui = ["bevy_rapier2d/debug-render-2d"]
|
debug_ui = ["bevy_rapier2d/debug-render-2d"]
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
getrandom = { version = "0.3.3", features = ["wasm_js"] }
|
getrandom = { version = "0.3", features = ["wasm_js"] }
|
||||||
|
|
||||||
[profile.speedy]
|
[profile.speedy]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
|
|||||||
15
Dockerfile
15
Dockerfile
@@ -1,22 +1,11 @@
|
|||||||
FROM rust:1.89 AS builder
|
FROM rust:1.89 AS builder
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y --no-install-recommends libasound2-dev libudev-dev
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
RUN cargo install --locked wasm-bindgen-cli
|
RUN cargo install --locked wasm-bindgen-cli
|
||||||
|
|
||||||
# Copy in only the parts we care about. This is to prevent Docker from re-
|
COPY . .
|
||||||
# running some steps because unimportant files changed (e.g.: the .git/ folder)
|
|
||||||
COPY src/ ./src
|
|
||||||
COPY Cargo.toml ./Cargo.toml
|
|
||||||
# WARN: The lockfile doesn't exist in the repo. You will have to create it
|
|
||||||
# before building the Docker image (i.e.: run `cargo update` first)
|
|
||||||
COPY Cargo.lock ./Cargo.lock
|
|
||||||
COPY www/ ./www
|
|
||||||
COPY Makefile ./Makefile
|
|
||||||
|
|
||||||
# Oops. There's no text output in the Docker build command line (it still works, though)
|
RUN make -j
|
||||||
RUN make
|
|
||||||
|
|
||||||
FROM busybox:musl
|
FROM busybox:musl
|
||||||
RUN mkdir -p /var/www
|
RUN mkdir -p /var/www
|
||||||
|
|||||||
42
Makefile
42
Makefile
@@ -3,22 +3,32 @@
|
|||||||
## Do not use it if that isn't your goal!
|
## Do not use it if that isn't your goal!
|
||||||
##
|
##
|
||||||
|
|
||||||
SRC_DIR = ./src
|
|
||||||
SRCS := $(wildcard $(SRC_DIR)/**)
|
|
||||||
|
|
||||||
# Patch these to select a different build profile or target
|
# Patch these to select a different build profile or target
|
||||||
# The target shouldn't change any time soon. WASM64, I guess. Other targets
|
# The target shouldn't change any time soon. WASM64, I guess. Other targets
|
||||||
# aren't aimed at the web, so you shouldn't be using this makefile.
|
# aren't aimed at the web, so you shouldn't be using this makefile.
|
||||||
CARGO_TARGET := wasm32-unknown-unknown
|
CARGO_TARGET := wasm32-unknown-unknown
|
||||||
CARGO_PROFILE := tiny
|
CARGO_PROFILE := tiny
|
||||||
|
|
||||||
.PHONY: clean full-clean web tarball
|
SRC_DIR = ./src
|
||||||
|
SRCS := $(wildcard $(SRC_DIR)/**)
|
||||||
|
|
||||||
web: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
.PHONY: clean full-clean tarball tarball-standalone web web-standalone
|
||||||
|
|
||||||
|
# "Standalone" version. It includes an index.html to serve as-is
|
||||||
|
web-standalone: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html
|
||||||
|
|
||||||
|
# "Bundle-able" version. It has a page, but no index.html. Consumers are
|
||||||
|
# expected to provide their own index.html and link to this page.
|
||||||
|
web: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html
|
||||||
|
|
||||||
tarball: asteroids_web_root.tar
|
tarball: asteroids_web_root.tar
|
||||||
|
|
||||||
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
tarball_standalone: asteroids_web_root_standalone.tar
|
||||||
|
|
||||||
|
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html
|
||||||
|
tar -caf $@ $^
|
||||||
|
|
||||||
|
asteroids_web_root_standalone.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html
|
||||||
tar -caf $@ $^
|
tar -caf $@ $^
|
||||||
|
|
||||||
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo.toml
|
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo.toml
|
||||||
@@ -29,18 +39,34 @@ out:
|
|||||||
|
|
||||||
# Both the JS and WASM files are generated by the wasm-bindgen call, so both
|
# Both the JS and WASM files are generated by the wasm-bindgen call, so both
|
||||||
# get to be on the target half of this recipe.
|
# get to be on the target half of this recipe.
|
||||||
out/asteroids.js out/asteroids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out
|
out/asteroids.js out/asteroids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out
|
||||||
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name asteroids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm
|
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name asteroids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm
|
||||||
|
gzip -9 -f out/asteroids_bg.wasm
|
||||||
|
|
||||||
|
# Copies the index page to the output dir.
|
||||||
out/index.html: www/index.html
|
out/index.html: www/index.html
|
||||||
cp -a $< $@
|
cp -a $< $@
|
||||||
|
rm -f out/asteroids.html
|
||||||
|
|
||||||
|
# Like `out/index.html`, but renames the page for use in a larger site.
|
||||||
|
out/asteroids.html: www/index.html
|
||||||
|
cp -a $< $@
|
||||||
|
rm -f out/index.html
|
||||||
|
|
||||||
# Clean the web build, but not the Cargo cache. Cargo handles it's own caching
|
# Clean the web build, but not the Cargo cache. Cargo handles it's own caching
|
||||||
# and I don't want to obliterate it all the time.
|
# and I don't want to obliterate it all the time.
|
||||||
clean:
|
clean:
|
||||||
rm -rf out/ asteroids_web_root.tar
|
rm -rf out/ asteroids_web_root.tar asteroids_web_root_standalone.tar
|
||||||
|
|
||||||
# Delete everything, including the Cargo build cache. In case someone needs
|
# Delete everything, including the Cargo build cache. In case someone needs
|
||||||
# this, I guess.
|
# this, I guess.
|
||||||
full-clean: clean
|
full-clean: clean
|
||||||
cargo clean
|
cargo clean
|
||||||
|
|
||||||
|
# Installation goal. It's meant to be a helper utility for moving the built
|
||||||
|
# output into the web root. Only supports the "bundle-able" mode.
|
||||||
|
install: web
|
||||||
|
install -dm0755 $(DESTDIR)
|
||||||
|
install -m0644 out/asteroids.js $(DESTDIR)/
|
||||||
|
install -m0644 out/asteroids_bg.wasm.gz $(DESTDIR)/
|
||||||
|
install -m0644 out/asteroids.html $(DESTDIR)/
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ impl Plugin for AsteroidPlugin {
|
|||||||
objects::ship_impact_listener,
|
objects::ship_impact_listener,
|
||||||
physics::collision_listener,
|
physics::collision_listener,
|
||||||
machinery::tick_lifetimes,
|
machinery::tick_lifetimes,
|
||||||
|
machinery::update_scoreboard,
|
||||||
)
|
)
|
||||||
.run_if(in_state(GameState::Playing)),
|
.run_if(in_state(GameState::Playing)),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{WorldSize, events::SpawnAsteroid, objects::AsteroidSize};
|
use crate::{WorldSize, events::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
|
||||||
|
|
||||||
/// Asteroid spawning parameters and state.
|
/// Asteroid spawning parameters and state.
|
||||||
///
|
///
|
||||||
@@ -135,3 +135,15 @@ pub fn operate_sparklers(sparklers: Query<(&mut Visibility, &mut Sparkler)>, tim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Event listener for adding score after an asteroid was destroyed
|
||||||
|
///
|
||||||
|
/// Refreshing the HUD element is done by [crate::widgets::operate_ui] (a private function)
|
||||||
|
pub fn update_scoreboard(
|
||||||
|
mut destroy_events: EventReader<AsteroidDestroy>,
|
||||||
|
mut scoreboard: ResMut<Score>,
|
||||||
|
) {
|
||||||
|
for _event in destroy_events.read() {
|
||||||
|
scoreboard.0 += 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
ecs::{
|
ecs::{
|
||||||
bundle::Bundle,
|
|
||||||
component::Component,
|
component::Component,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
event::{EventReader, EventWriter},
|
event::{EventReader, EventWriter},
|
||||||
|
|||||||
@@ -2,15 +2,25 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: hsl(200, 3%, 65%);
|
||||||
|
}
|
||||||
h1 {
|
h1 {
|
||||||
|
color: hsl(200, 3%, 90%);
|
||||||
|
background-color: hsl(195, 5%, 17%);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
margin: auto;
|
||||||
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
canvas {
|
canvas {
|
||||||
padding-left: 0;
|
margin-top: 1em;
|
||||||
padding-right: 0;
|
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
display: block;
|
display: block;
|
||||||
|
outline-color: hsl(200, 7%, 50%);
|
||||||
|
outline-style: outset;
|
||||||
|
border-radius: 8px;
|
||||||
|
background-color: rgb(40%, 40%, 40%);
|
||||||
}
|
}
|
||||||
main {
|
main {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
@@ -18,11 +28,12 @@
|
|||||||
width: 70%;
|
width: 70%;
|
||||||
}
|
}
|
||||||
table {
|
table {
|
||||||
|
margin-bottom: 10px;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
th, td {
|
th, td {
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
padding: 2px 4px;
|
padding: 0.1em 0.3em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -79,7 +90,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Program Version</td>
|
<td>Program Version</td>
|
||||||
<!-- This version text is completely unchecked. I'll need to do something about that. -->
|
<!-- This version text is completely unchecked. I'll need to do something about that. -->
|
||||||
<td><code>v0.3.0</code></td>
|
<td><code>v0.5.0</code></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</article>
|
</article>
|
||||||
@@ -87,7 +98,11 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
import init from './asteroids.js'
|
import init from './asteroids.js'
|
||||||
|
|
||||||
init().catch((error) => {
|
let compressed = await fetch("./asteroids_bg.wasm.gz")
|
||||||
|
let wasm_stream = compressed.body.pipeThrough(new DecompressionStream("gzip"))
|
||||||
|
let blob = await new Response(wasm_stream).blob();
|
||||||
|
|
||||||
|
init(await blob.arrayBuffer()).catch((error) => {
|
||||||
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
|
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user