Compare commits
19 Commits
v0.34.4
...
2f1ff85d8f
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f1ff85d8f | |||
| b7429cd9ec | |||
| 12a63374a8 | |||
| d80d7061e7 | |||
| abdefe0af0 | |||
| 4f76de7c9f | |||
| db8cd6220a | |||
| ced4e87d41 | |||
| 09e3d85821 | |||
| c1e421bbbb | |||
| 3a9381a56c | |||
| 90bdfbd2ae | |||
| a230d15ffc | |||
| 60bbd1f5d6 | |||
| 43ce8a4e01 | |||
| 1529a64588 | |||
| be5eec64c9 | |||
| 780a33f657 | |||
| c1c5dae6f2 |
@@ -1,2 +1,5 @@
|
|||||||
[profile.default]
|
[profile.default]
|
||||||
fail-fast = false
|
fail-fast = false
|
||||||
|
|
||||||
|
[profile.coverage]
|
||||||
|
status-level = "none"
|
||||||
|
|||||||
38
.github/workflows/coverage.yaml
vendored
@@ -42,15 +42,39 @@ jobs:
|
|||||||
|
|
||||||
- uses: taiki-e/install-action@cargo-llvm-cov
|
- uses: taiki-e/install-action@cargo-llvm-cov
|
||||||
- uses: taiki-e/install-action@nextest
|
- uses: taiki-e/install-action@nextest
|
||||||
|
- uses: taiki-e/install-action@just
|
||||||
|
|
||||||
# Note: We manually link zlib. This should be synchronized with the flags set for Linux in .cargo/config.toml.
|
|
||||||
- name: Generate coverage report
|
- name: Generate coverage report
|
||||||
run: |
|
run: |
|
||||||
cargo llvm-cov --no-fail-fast --lcov --output-path lcov.info nextest
|
just coverage
|
||||||
|
|
||||||
|
- name: Download Coveralls CLI
|
||||||
|
run: |
|
||||||
|
# use GitHub Releases URL instead of coveralls.io because they can't maintain their own files; it 404s
|
||||||
|
curl -L https://github.com/coverallsapp/coverage-reporter/releases/download/v0.6.15/coveralls-linux-x86_64.tar.gz | tar -xz -C /usr/local/bin
|
||||||
|
|
||||||
- name: Upload coverage to Coveralls
|
- name: Upload coverage to Coveralls
|
||||||
uses: coverallsapp/github-action@v2
|
env:
|
||||||
with:
|
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
||||||
files: ./lcov.info
|
run: |
|
||||||
format: lcov
|
if [ ! -f "lcov.info" ]; then
|
||||||
allow-empty: false
|
echo "Error: lcov.info file not found. Coverage generation may have failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in {1..10}; do
|
||||||
|
echo "Attempt $i: Uploading coverage to Coveralls..."
|
||||||
|
if coveralls -n report lcov.info; then
|
||||||
|
echo "Successfully uploaded coverage report."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $i -lt 10 ]; then
|
||||||
|
delay=$((2**i))
|
||||||
|
echo "Attempt $i failed. Retrying in $delay seconds..."
|
||||||
|
sleep $delay
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Failed to upload coverage report after 10 attempts."
|
||||||
|
exit 1
|
||||||
|
|||||||
15
.gitignore
vendored
@@ -1,8 +1,17 @@
|
|||||||
|
# IDE, Other files
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
rust-sdl2-emscripten/
|
||||||
|
|
||||||
|
# Build files
|
||||||
target/
|
target/
|
||||||
dist/
|
dist/
|
||||||
emsdk/
|
emsdk/
|
||||||
.idea
|
|
||||||
rust-sdl2-emscripten/
|
# Site build f iles
|
||||||
assets/site/build.css
|
|
||||||
tailwindcss-*
|
tailwindcss-*
|
||||||
|
assets/site/build.css
|
||||||
|
|
||||||
|
# Coverage reports
|
||||||
lcov.info
|
lcov.info
|
||||||
|
coverage.html
|
||||||
|
|||||||
68
Cargo.lock
generated
@@ -194,7 +194,8 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pathfinding",
|
"pathfinding",
|
||||||
"rand",
|
"phf",
|
||||||
|
"rand 0.9.2",
|
||||||
"sdl2",
|
"sdl2",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -223,6 +224,48 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
|
||||||
|
dependencies = [
|
||||||
|
"phf_macros",
|
||||||
|
"phf_shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_generator"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||||
|
dependencies = [
|
||||||
|
"phf_shared",
|
||||||
|
"rand 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_macros"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
|
||||||
|
dependencies = [
|
||||||
|
"phf_generator",
|
||||||
|
"phf_shared",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "phf_shared"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
|
||||||
|
dependencies = [
|
||||||
|
"siphasher",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-lite"
|
name = "pin-project-lite"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
@@ -253,15 +296,30 @@ version = "5.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core 0.6.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core",
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
@@ -399,6 +457,12 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "siphasher"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.15.1"
|
version = "1.15.1"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ serde_json = "1.0.142"
|
|||||||
smallvec = "1.15.1"
|
smallvec = "1.15.1"
|
||||||
strum = "0.27.2"
|
strum = "0.27.2"
|
||||||
strum_macros = "0.27.2"
|
strum_macros = "0.27.2"
|
||||||
|
phf = { version = "0.11", features = ["macros"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
@@ -57,3 +58,8 @@ aarch64-apple-darwin = { triplet = "arm64-osx" }
|
|||||||
|
|
||||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||||
libc = "0.2.175"
|
libc = "0.2.175"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
phf = { version = "0.11", features = ["macros"] }
|
||||||
|
|||||||
33
Justfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
set shell := ["bash", "-c"]
|
||||||
|
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
|
||||||
|
|
||||||
|
# Regex to exclude files from coverage report, double escapes for Justfile + CLI
|
||||||
|
# You can use src\\\\..., but the filename alone is acceptable too
|
||||||
|
coverage_exclude_pattern := "src\\\\app.rs|audio.rs|src\\\\error.rs|platform\\\\emscripten.rs"
|
||||||
|
|
||||||
|
# !!! --ignore-filename-regex should be used on both reports & coverage testing
|
||||||
|
# !!! --remap-path-prefix prevents the absolute path from being used in the generated report
|
||||||
|
|
||||||
|
# Generate HTML report (for humans, source line inspection)
|
||||||
|
html: coverage
|
||||||
|
cargo llvm-cov report \
|
||||||
|
--remap-path-prefix \
|
||||||
|
--ignore-filename-regex "{{ coverage_exclude_pattern }}" \
|
||||||
|
--html \
|
||||||
|
--open
|
||||||
|
|
||||||
|
# Display report (for humans)
|
||||||
|
report-coverage: coverage
|
||||||
|
cargo llvm-cov report \
|
||||||
|
--remap-path-prefix \
|
||||||
|
--ignore-filename-regex "{{ coverage_exclude_pattern }}"
|
||||||
|
|
||||||
|
# Run & generate report (for CI)
|
||||||
|
coverage:
|
||||||
|
cargo llvm-cov \
|
||||||
|
--lcov \
|
||||||
|
--remap-path-prefix \
|
||||||
|
--ignore-filename-regex "{{ coverage_exclude_pattern }}" \
|
||||||
|
--output-path lcov.info \
|
||||||
|
--profile coverage \
|
||||||
|
--no-fail-fast nextest
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Pac-Man
|
# Pac-Man
|
||||||
|
|
||||||
[![Tests Status][badge-test]][test] [![Build Status][badge-build]][build] [![Code Coverage][badge-coverage]][coverage] [![Online Demo][badge-online-demo]][demo] [![Last Commit][badge-last-commit]][commits]
|
[![Tests Status][badge-test]][test] [![Build Status][badge-build]][build] [![If you're seeing this, Coveralls.io is broken again and it's not my fault.][badge-coverage]][coverage] [![Online Demo][badge-online-demo]][demo] [![Last Commit][badge-last-commit]][commits]
|
||||||
|
|
||||||
[badge-test]: https://github.com/Xevion/Pac-Man/actions/workflows/tests.yaml/badge.svg
|
[badge-test]: https://github.com/Xevion/Pac-Man/actions/workflows/tests.yaml/badge.svg
|
||||||
[badge-build]: https://github.com/Xevion/Pac-Man/actions/workflows/build.yaml/badge.svg
|
[badge-build]: https://github.com/Xevion/Pac-Man/actions/workflows/build.yaml/badge.svg
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
BIN
assets/unpacked/maze/tiles/0.png
Normal file
|
After Width: | Height: | Size: 102 B |
BIN
assets/unpacked/maze/tiles/1.png
Normal file
|
After Width: | Height: | Size: 79 B |
BIN
assets/unpacked/maze/tiles/10.png
Normal file
|
After Width: | Height: | Size: 84 B |
BIN
assets/unpacked/maze/tiles/11.png
Normal file
|
After Width: | Height: | Size: 77 B |
BIN
assets/unpacked/maze/tiles/12.png
Normal file
|
After Width: | Height: | Size: 80 B |
BIN
assets/unpacked/maze/tiles/13.png
Normal file
|
After Width: | Height: | Size: 87 B |
BIN
assets/unpacked/maze/tiles/14.png
Normal file
|
After Width: | Height: | Size: 79 B |
BIN
assets/unpacked/maze/tiles/15.png
Normal file
|
After Width: | Height: | Size: 89 B |
BIN
assets/unpacked/maze/tiles/16.png
Normal file
|
After Width: | Height: | Size: 91 B |
BIN
assets/unpacked/maze/tiles/17.png
Normal file
|
After Width: | Height: | Size: 87 B |
BIN
assets/unpacked/maze/tiles/18.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
assets/unpacked/maze/tiles/19.png
Normal file
|
After Width: | Height: | Size: 77 B |
BIN
assets/unpacked/maze/tiles/2.png
Normal file
|
After Width: | Height: | Size: 93 B |
BIN
assets/unpacked/maze/tiles/20.png
Normal file
|
After Width: | Height: | Size: 91 B |
BIN
assets/unpacked/maze/tiles/21.png
Normal file
|
After Width: | Height: | Size: 97 B |
BIN
assets/unpacked/maze/tiles/22.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
assets/unpacked/maze/tiles/23.png
Normal file
|
After Width: | Height: | Size: 88 B |
BIN
assets/unpacked/maze/tiles/24.png
Normal file
|
After Width: | Height: | Size: 82 B |
BIN
assets/unpacked/maze/tiles/25.png
Normal file
|
After Width: | Height: | Size: 80 B |
BIN
assets/unpacked/maze/tiles/26.png
Normal file
|
After Width: | Height: | Size: 82 B |
BIN
assets/unpacked/maze/tiles/27.png
Normal file
|
After Width: | Height: | Size: 93 B |
BIN
assets/unpacked/maze/tiles/28.png
Normal file
|
After Width: | Height: | Size: 89 B |
BIN
assets/unpacked/maze/tiles/29.png
Normal file
|
After Width: | Height: | Size: 90 B |
BIN
assets/unpacked/maze/tiles/3.png
Normal file
|
After Width: | Height: | Size: 87 B |
BIN
assets/unpacked/maze/tiles/30.png
Normal file
|
After Width: | Height: | Size: 79 B |
BIN
assets/unpacked/maze/tiles/31.png
Normal file
|
After Width: | Height: | Size: 100 B |
BIN
assets/unpacked/maze/tiles/32.png
Normal file
|
After Width: | Height: | Size: 98 B |
BIN
assets/unpacked/maze/tiles/33.png
Normal file
|
After Width: | Height: | Size: 96 B |
BIN
assets/unpacked/maze/tiles/34.png
Normal file
|
After Width: | Height: | Size: 100 B |
BIN
assets/unpacked/maze/tiles/4.png
Normal file
|
After Width: | Height: | Size: 105 B |
BIN
assets/unpacked/maze/tiles/5.png
Normal file
|
After Width: | Height: | Size: 82 B |
BIN
assets/unpacked/maze/tiles/6.png
Normal file
|
After Width: | Height: | Size: 71 B |
BIN
assets/unpacked/maze/tiles/7.png
Normal file
|
After Width: | Height: | Size: 82 B |
BIN
assets/unpacked/maze/tiles/8.png
Normal file
|
After Width: | Height: | Size: 82 B |
BIN
assets/unpacked/maze/tiles/9.png
Normal file
|
After Width: | Height: | Size: 82 B |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
25
bacon.toml
@@ -34,6 +34,30 @@ command = [
|
|||||||
need_stdout = true
|
need_stdout = true
|
||||||
analyzer = "nextest"
|
analyzer = "nextest"
|
||||||
|
|
||||||
|
[jobs.coverage]
|
||||||
|
command = [
|
||||||
|
"just", "report-coverage"
|
||||||
|
]
|
||||||
|
need_stdout = true
|
||||||
|
ignored_lines = [
|
||||||
|
"info:",
|
||||||
|
"\\s+Compiling",
|
||||||
|
"test result: ok",
|
||||||
|
"^\\s*$",
|
||||||
|
"running \\d+ test",
|
||||||
|
"Nextest run ID",
|
||||||
|
"[─]+",
|
||||||
|
"test.+ok",
|
||||||
|
"PASS|START",
|
||||||
|
"Starting \\d+ test",
|
||||||
|
"\\s*#",
|
||||||
|
"\\s*Finished.+in \\d+",
|
||||||
|
"\\s*Summary\\s+\\[",
|
||||||
|
"\\s*Blocking",
|
||||||
|
"Finished report saved to"
|
||||||
|
]
|
||||||
|
on_change_strategy = "wait_then_restart"
|
||||||
|
|
||||||
[jobs.doc]
|
[jobs.doc]
|
||||||
command = ["cargo", "doc", "--no-deps"]
|
command = ["cargo", "doc", "--no-deps"]
|
||||||
need_stdout = false
|
need_stdout = false
|
||||||
@@ -59,3 +83,4 @@ c = "job:clippy"
|
|||||||
alt-c = "job:check"
|
alt-c = "job:check"
|
||||||
ctrl-alt-c = "job:check-all"
|
ctrl-alt-c = "job:check-all"
|
||||||
shift-c = "job:clippy-all"
|
shift-c = "job:clippy-all"
|
||||||
|
f = "job:coverage"
|
||||||
|
|||||||
50
build.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufWriter, Write};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct AtlasMapper {
|
||||||
|
frames: HashMap<String, MapperFrame>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Deserialize)]
|
||||||
|
struct MapperFrame {
|
||||||
|
x: u16,
|
||||||
|
y: u16,
|
||||||
|
width: u16,
|
||||||
|
height: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("atlas_data.rs");
|
||||||
|
let mut file = BufWriter::new(File::create(&path).unwrap());
|
||||||
|
|
||||||
|
let atlas_json = include_str!("./assets/game/atlas.json");
|
||||||
|
let atlas_mapper: AtlasMapper = serde_json::from_str(atlas_json).unwrap();
|
||||||
|
|
||||||
|
writeln!(&mut file, "use phf::phf_map;").unwrap();
|
||||||
|
|
||||||
|
writeln!(&mut file, "use crate::texture::sprite::MapperFrame;").unwrap();
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
&mut file,
|
||||||
|
"pub static ATLAS_FRAMES: phf::Map<&'static str, MapperFrame> = phf_map! {{"
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
for (name, frame) in atlas_mapper.frames {
|
||||||
|
writeln!(
|
||||||
|
&mut file,
|
||||||
|
" \"{}\" => MapperFrame {{ x: {}, y: {}, width: {}, height: {} }},",
|
||||||
|
name, frame.x, frame.y, frame.width, frame.height
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(&mut file, "}};").unwrap();
|
||||||
|
println!("cargo:rerun-if-changed=assets/game/atlas.json");
|
||||||
|
}
|
||||||
107
src/app.rs
@@ -2,26 +2,29 @@ use std::time::{Duration, Instant};
|
|||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use sdl2::event::{Event, WindowEvent};
|
use sdl2::event::{Event, WindowEvent};
|
||||||
use sdl2::keyboard::Keycode;
|
|
||||||
use sdl2::render::{Canvas, ScaleMode, Texture, TextureCreator};
|
use sdl2::render::{Canvas, ScaleMode, Texture, TextureCreator};
|
||||||
use sdl2::ttf::Sdl2TtfContext;
|
use sdl2::ttf::Sdl2TtfContext;
|
||||||
use sdl2::video::{Window, WindowContext};
|
use sdl2::video::{Window, WindowContext};
|
||||||
use sdl2::{AudioSubsystem, EventPump, Sdl, VideoSubsystem};
|
use sdl2::{AudioSubsystem, EventPump, Sdl, VideoSubsystem};
|
||||||
use tracing::{error, event};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use crate::error::{GameError, GameResult};
|
use crate::error::{GameError, GameResult};
|
||||||
|
|
||||||
use crate::constants::{CANVAS_SIZE, LOOP_TIME, SCALE};
|
use crate::constants::{CANVAS_SIZE, LOOP_TIME, SCALE};
|
||||||
use crate::game::Game;
|
use crate::game::Game;
|
||||||
|
use crate::input::commands::GameCommand;
|
||||||
|
use crate::input::InputSystem;
|
||||||
use crate::platform::get_platform;
|
use crate::platform::get_platform;
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
game: Game,
|
game: Game,
|
||||||
|
input_system: InputSystem,
|
||||||
canvas: Canvas<Window>,
|
canvas: Canvas<Window>,
|
||||||
event_pump: &'static mut EventPump,
|
|
||||||
backbuffer: Texture<'static>,
|
backbuffer: Texture<'static>,
|
||||||
paused: bool,
|
event_pump: &'static mut EventPump,
|
||||||
|
|
||||||
last_tick: Instant,
|
last_tick: Instant,
|
||||||
|
focused: bool,
|
||||||
cursor_pos: Vec2,
|
cursor_pos: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,9 +33,9 @@ impl App {
|
|||||||
let sdl_context: &'static Sdl = Box::leak(Box::new(sdl2::init().map_err(|e| GameError::Sdl(e.to_string()))?));
|
let sdl_context: &'static Sdl = Box::leak(Box::new(sdl2::init().map_err(|e| GameError::Sdl(e.to_string()))?));
|
||||||
let video_subsystem: &'static VideoSubsystem =
|
let video_subsystem: &'static VideoSubsystem =
|
||||||
Box::leak(Box::new(sdl_context.video().map_err(|e| GameError::Sdl(e.to_string()))?));
|
Box::leak(Box::new(sdl_context.video().map_err(|e| GameError::Sdl(e.to_string()))?));
|
||||||
let audio_subsystem: &'static AudioSubsystem =
|
let _audio_subsystem: &'static AudioSubsystem =
|
||||||
Box::leak(Box::new(sdl_context.audio().map_err(|e| GameError::Sdl(e.to_string()))?));
|
Box::leak(Box::new(sdl_context.audio().map_err(|e| GameError::Sdl(e.to_string()))?));
|
||||||
let ttf_context: &'static Sdl2TtfContext =
|
let _ttf_context: &'static Sdl2TtfContext =
|
||||||
Box::leak(Box::new(sdl2::ttf::init().map_err(|e| GameError::Sdl(e.to_string()))?));
|
Box::leak(Box::new(sdl2::ttf::init().map_err(|e| GameError::Sdl(e.to_string()))?));
|
||||||
let event_pump: &'static mut EventPump =
|
let event_pump: &'static mut EventPump =
|
||||||
Box::leak(Box::new(sdl_context.event_pump().map_err(|e| GameError::Sdl(e.to_string()))?));
|
Box::leak(Box::new(sdl_context.event_pump().map_err(|e| GameError::Sdl(e.to_string()))?));
|
||||||
@@ -51,14 +54,20 @@ impl App {
|
|||||||
.build()
|
.build()
|
||||||
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
||||||
|
|
||||||
let mut canvas = window.into_canvas().build().map_err(|e| GameError::Sdl(e.to_string()))?;
|
let mut canvas = window
|
||||||
|
.into_canvas()
|
||||||
|
.accelerated()
|
||||||
|
.present_vsync()
|
||||||
|
.build()
|
||||||
|
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
||||||
|
|
||||||
canvas
|
canvas
|
||||||
.set_logical_size(CANVAS_SIZE.x, CANVAS_SIZE.y)
|
.set_logical_size(CANVAS_SIZE.x, CANVAS_SIZE.y)
|
||||||
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
||||||
|
|
||||||
let texture_creator: &'static TextureCreator<WindowContext> = Box::leak(Box::new(canvas.texture_creator()));
|
let texture_creator: &'static TextureCreator<WindowContext> = Box::leak(Box::new(canvas.texture_creator()));
|
||||||
|
|
||||||
let mut game = Game::new(texture_creator, ttf_context, audio_subsystem)?;
|
let mut game = Game::new(texture_creator)?;
|
||||||
// game.audio.set_mute(cfg!(debug_assertions));
|
// game.audio.set_mute(cfg!(debug_assertions));
|
||||||
|
|
||||||
let mut backbuffer = texture_creator
|
let mut backbuffer = texture_creator
|
||||||
@@ -72,12 +81,13 @@ impl App {
|
|||||||
game.present_backbuffer(&mut canvas, &backbuffer, glam::Vec2::ZERO)
|
game.present_backbuffer(&mut canvas, &backbuffer, glam::Vec2::ZERO)
|
||||||
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
.map_err(|e| GameError::Sdl(e.to_string()))?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(App {
|
||||||
game,
|
game,
|
||||||
|
input_system: InputSystem::new(),
|
||||||
canvas,
|
canvas,
|
||||||
event_pump,
|
event_pump,
|
||||||
backbuffer,
|
backbuffer,
|
||||||
paused: false,
|
focused: true,
|
||||||
last_tick: Instant::now(),
|
last_tick: Instant::now(),
|
||||||
cursor_pos: Vec2::ZERO,
|
cursor_pos: Vec2::ZERO,
|
||||||
})
|
})
|
||||||
@@ -90,75 +100,58 @@ impl App {
|
|||||||
for event in self.event_pump.poll_iter() {
|
for event in self.event_pump.poll_iter() {
|
||||||
match event {
|
match event {
|
||||||
Event::Window { win_event, .. } => match win_event {
|
Event::Window { win_event, .. } => match win_event {
|
||||||
WindowEvent::Hidden => {
|
WindowEvent::FocusGained => {
|
||||||
event!(tracing::Level::DEBUG, "Window hidden");
|
self.focused = true;
|
||||||
}
|
}
|
||||||
WindowEvent::Shown => {
|
WindowEvent::FocusLost => {
|
||||||
event!(tracing::Level::DEBUG, "Window shown");
|
self.focused = false;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
// It doesn't really make sense to have this available in the browser
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
Event::Quit { .. }
|
|
||||||
| Event::KeyDown {
|
|
||||||
keycode: Some(Keycode::Escape) | Some(Keycode::Q),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
event!(tracing::Level::INFO, "Exit requested. Exiting...");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Event::KeyDown {
|
|
||||||
keycode: Some(Keycode::P),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
self.paused = !self.paused;
|
|
||||||
event!(tracing::Level::INFO, "{}", if self.paused { "Paused" } else { "Unpaused" });
|
|
||||||
}
|
|
||||||
Event::KeyDown {
|
|
||||||
keycode: Some(Keycode::Space),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
self.game.debug_mode = !self.game.debug_mode;
|
|
||||||
}
|
|
||||||
Event::KeyDown { keycode: Some(key), .. } => {
|
|
||||||
self.game.keyboard_event(key);
|
|
||||||
}
|
|
||||||
Event::MouseMotion { x, y, .. } => {
|
Event::MouseMotion { x, y, .. } => {
|
||||||
// Convert window coordinates to logical coordinates
|
// Convert window coordinates to logical coordinates
|
||||||
self.cursor_pos = Vec2::new(x as f32, y as f32);
|
self.cursor_pos = Vec2::new(x as f32, y as f32);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(command) = self.input_system.handle_event(&event) {
|
||||||
|
match command {
|
||||||
|
GameCommand::Exit => {
|
||||||
|
info!("Exit requested. Exiting...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_ => self.game.post_event(command.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let dt = self.last_tick.elapsed().as_secs_f32();
|
let dt = self.last_tick.elapsed().as_secs_f32();
|
||||||
self.last_tick = Instant::now();
|
self.last_tick = Instant::now();
|
||||||
|
|
||||||
if !self.paused {
|
let exit = self.game.tick(dt);
|
||||||
self.game.tick(dt);
|
|
||||||
if let Err(e) = self.game.draw(&mut self.canvas, &mut self.backbuffer) {
|
if exit {
|
||||||
error!("Failed to draw game: {}", e);
|
return false;
|
||||||
}
|
}
|
||||||
if let Err(e) = self
|
|
||||||
.game
|
if let Err(e) = self.game.draw(&mut self.canvas, &mut self.backbuffer) {
|
||||||
.present_backbuffer(&mut self.canvas, &self.backbuffer, self.cursor_pos)
|
error!("Failed to draw game: {}", e);
|
||||||
{
|
}
|
||||||
error!("Failed to present backbuffer: {}", e);
|
if let Err(e) = self
|
||||||
}
|
.game
|
||||||
|
.present_backbuffer(&mut self.canvas, &self.backbuffer, self.cursor_pos)
|
||||||
|
{
|
||||||
|
error!("Failed to present backbuffer: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if start.elapsed() < LOOP_TIME {
|
if start.elapsed() < LOOP_TIME {
|
||||||
let time = LOOP_TIME.saturating_sub(start.elapsed());
|
let time = LOOP_TIME.saturating_sub(start.elapsed());
|
||||||
if time != Duration::ZERO {
|
if time != Duration::ZERO {
|
||||||
get_platform().sleep(time);
|
get_platform().sleep(time, self.focused);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event!(
|
warn!("Game loop behind schedule by: {:?}", start.elapsed() - LOOP_TIME);
|
||||||
tracing::Level::WARN,
|
|
||||||
"Game loop behind schedule by: {:?}",
|
|
||||||
start.elapsed() - LOOP_TIME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|||||||
20
src/asset.rs
@@ -3,28 +3,15 @@
|
|||||||
//! On desktop, assets are embedded using include_bytes!; on Emscripten, assets are loaded from the filesystem.
|
//! On desktop, assets are embedded using include_bytes!; on Emscripten, assets are loaded from the filesystem.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io;
|
use strum_macros::EnumIter;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||||
pub enum AssetError {
|
|
||||||
#[error("IO error: {0}")]
|
|
||||||
Io(#[from] io::Error),
|
|
||||||
#[error("Asset not found: {0}")]
|
|
||||||
NotFound(String),
|
|
||||||
#[error("Invalid asset format: {0}")]
|
|
||||||
InvalidFormat(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
||||||
pub enum Asset {
|
pub enum Asset {
|
||||||
Wav1,
|
Wav1,
|
||||||
Wav2,
|
Wav2,
|
||||||
Wav3,
|
Wav3,
|
||||||
Wav4,
|
Wav4,
|
||||||
Atlas,
|
Atlas,
|
||||||
AtlasJson,
|
|
||||||
// Add more as needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Asset {
|
impl Asset {
|
||||||
@@ -37,15 +24,16 @@ impl Asset {
|
|||||||
Wav3 => "sound/waka/3.ogg",
|
Wav3 => "sound/waka/3.ogg",
|
||||||
Wav4 => "sound/waka/4.ogg",
|
Wav4 => "sound/waka/4.ogg",
|
||||||
Atlas => "atlas.png",
|
Atlas => "atlas.png",
|
||||||
AtlasJson => "atlas.json",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::error::AssetError;
|
||||||
use crate::platform::get_platform;
|
use crate::platform::get_platform;
|
||||||
|
|
||||||
|
/// Returns the raw bytes of the given asset.
|
||||||
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
|
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
|
||||||
get_platform().get_asset_bytes(asset)
|
get_platform().get_asset_bytes(asset)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ pub const SCALE: f32 = 2.6;
|
|||||||
pub const BOARD_CELL_OFFSET: UVec2 = UVec2::new(0, 3);
|
pub const BOARD_CELL_OFFSET: UVec2 = UVec2::new(0, 3);
|
||||||
/// The offset of the game board from the top-left corner of the window, in pixels.
|
/// The offset of the game board from the top-left corner of the window, in pixels.
|
||||||
pub const BOARD_PIXEL_OFFSET: UVec2 = UVec2::new(BOARD_CELL_OFFSET.x * CELL_SIZE, BOARD_CELL_OFFSET.y * CELL_SIZE);
|
pub const BOARD_PIXEL_OFFSET: UVec2 = UVec2::new(BOARD_CELL_OFFSET.x * CELL_SIZE, BOARD_CELL_OFFSET.y * CELL_SIZE);
|
||||||
/// The size of the game board, in pixels.
|
|
||||||
pub const BOARD_PIXEL_SIZE: UVec2 = UVec2::new(BOARD_CELL_SIZE.x * CELL_SIZE, BOARD_CELL_SIZE.y * CELL_SIZE);
|
|
||||||
/// The size of the canvas, in pixels.
|
/// The size of the canvas, in pixels.
|
||||||
pub const CANVAS_SIZE: UVec2 = UVec2::new(
|
pub const CANVAS_SIZE: UVec2 = UVec2::new(
|
||||||
(BOARD_CELL_SIZE.x + BOARD_CELL_OFFSET.x) * CELL_SIZE,
|
(BOARD_CELL_SIZE.x + BOARD_CELL_OFFSET.x) * CELL_SIZE,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::entity::traversal::Position;
|
use crate::entity::{graph::NodeId, traversal::Position};
|
||||||
|
|
||||||
/// Trait for entities that can participate in collision detection.
|
/// Trait for entities that can participate in collision detection.
|
||||||
pub trait Collidable {
|
pub trait Collidable {
|
||||||
@@ -19,7 +19,7 @@ pub trait Collidable {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CollisionSystem {
|
pub struct CollisionSystem {
|
||||||
/// Maps node IDs to lists of entity IDs that are at that node
|
/// Maps node IDs to lists of entity IDs that are at that node
|
||||||
node_entities: HashMap<usize, Vec<EntityId>>,
|
node_entities: HashMap<NodeId, Vec<EntityId>>,
|
||||||
/// Maps entity IDs to their current positions
|
/// Maps entity IDs to their current positions
|
||||||
entity_positions: HashMap<EntityId, Position>,
|
entity_positions: HashMap<EntityId, Position>,
|
||||||
/// Next available entity ID
|
/// Next available entity ID
|
||||||
@@ -62,7 +62,7 @@ impl CollisionSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all entity IDs at a specific node
|
/// Gets all entity IDs at a specific node
|
||||||
pub fn entities_at_node(&self, node: usize) -> &[EntityId] {
|
pub fn entities_at_node(&self, node: NodeId) -> &[EntityId] {
|
||||||
self.node_entities.get(&node).map(|v| v.as_slice()).unwrap_or(&[])
|
self.node_entities.get(&node).map(|v| v.as_slice()).unwrap_or(&[])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ fn positions_overlap(a: &Position, b: &Position) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all nodes that an entity is currently at or between.
|
/// Gets all nodes that an entity is currently at or between.
|
||||||
fn get_nodes(pos: &Position) -> SmallVec<[usize; 2]> {
|
fn get_nodes(pos: &Position) -> SmallVec<[NodeId; 2]> {
|
||||||
let mut nodes = SmallVec::new();
|
let mut nodes = SmallVec::new();
|
||||||
match pos {
|
match pos {
|
||||||
Position::AtNode(node) => nodes.push(*node),
|
Position::AtNode(node) => nodes.push(*node),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use glam::IVec2;
|
use glam::IVec2;
|
||||||
|
|
||||||
/// The four cardinal directions.
|
/// The four cardinal directions.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
#[repr(usize)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
|
|||||||
@@ -164,10 +164,8 @@ impl Ghost {
|
|||||||
})?,
|
})?,
|
||||||
];
|
];
|
||||||
|
|
||||||
textures[direction.as_usize()] =
|
textures[direction.as_usize()] = Some(AnimatedTexture::new(moving_tiles, 0.2)?);
|
||||||
Some(AnimatedTexture::new(moving_tiles, 0.2).map_err(|e| GameError::Texture(TextureError::Animated(e)))?);
|
stopped_textures[direction.as_usize()] = Some(AnimatedTexture::new(stopped_tiles, 0.1)?);
|
||||||
stopped_textures[direction.as_usize()] =
|
|
||||||
Some(AnimatedTexture::new(stopped_tiles, 0.1).map_err(|e| GameError::Texture(TextureError::Animated(e)))?);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@@ -192,14 +192,15 @@ impl Graph {
|
|||||||
|
|
||||||
// Check if the edge already exists in this direction or to the same target
|
// Check if the edge already exists in this direction or to the same target
|
||||||
if let Some(err) = adjacency_list.edges().find_map(|e| {
|
if let Some(err) = adjacency_list.edges().find_map(|e| {
|
||||||
// If we're not replacing the edge, we don't want to replace an edge that already exists in this direction
|
if !replace {
|
||||||
if !replace && e.direction == direction {
|
// If we're not replacing the edge, we don't want to replace an edge that already exists in this direction
|
||||||
Some(Err("Edge already exists in this direction."))
|
if e.direction == direction {
|
||||||
} else if e.target == to {
|
return Some(Err("Edge already exists in this direction."));
|
||||||
Some(Err("Edge already exists."))
|
} else if e.target == to {
|
||||||
} else {
|
return Some(Err("Edge already exists."));
|
||||||
None
|
}
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}) {
|
}) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
constants,
|
||||||
entity::{collision::Collidable, graph::Graph},
|
entity::{collision::Collidable, graph::Graph},
|
||||||
error::EntityError,
|
error::{EntityError, GameResult},
|
||||||
texture::sprite::{Sprite, SpriteAtlas},
|
texture::sprite::{Sprite, SpriteAtlas},
|
||||||
};
|
};
|
||||||
use sdl2::render::{Canvas, RenderTarget};
|
use sdl2::render::{Canvas, RenderTarget};
|
||||||
@@ -95,16 +95,18 @@ impl Item {
|
|||||||
self.item_type.get_score()
|
self.item_type.get_score()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<T: RenderTarget>(&self, canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, graph: &Graph) -> anyhow::Result<()> {
|
pub fn render<T: RenderTarget>(&self, canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, graph: &Graph) -> GameResult<()> {
|
||||||
if !self.collected {
|
if self.collected {
|
||||||
let node = graph
|
return Ok(());
|
||||||
.get_node(self.node_index)
|
|
||||||
.ok_or(EntityError::NodeNotFound(self.node_index))?;
|
|
||||||
let position = node.position + constants::BOARD_PIXEL_OFFSET.as_vec2();
|
|
||||||
self.sprite.render(canvas, atlas, position)
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let node = graph
|
||||||
|
.get_node(self.node_index)
|
||||||
|
.ok_or(EntityError::NodeNotFound(self.node_index))?;
|
||||||
|
let position = node.position + constants::BOARD_PIXEL_OFFSET.as_vec2();
|
||||||
|
|
||||||
|
self.sprite.render(canvas, atlas, position)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use crate::entity::{
|
|||||||
use crate::texture::animated::AnimatedTexture;
|
use crate::texture::animated::AnimatedTexture;
|
||||||
use crate::texture::directional::DirectionalAnimatedTexture;
|
use crate::texture::directional::DirectionalAnimatedTexture;
|
||||||
use crate::texture::sprite::SpriteAtlas;
|
use crate::texture::sprite::SpriteAtlas;
|
||||||
use sdl2::keyboard::Keycode;
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::error::{GameError, GameResult, TextureError};
|
use crate::error::{GameError, GameResult, TextureError};
|
||||||
@@ -98,10 +97,8 @@ impl Pacman {
|
|||||||
let stopped_tiles = vec![SpriteAtlas::get_tile(atlas, &format!("{moving_prefix}_b.png"))
|
let stopped_tiles = vec![SpriteAtlas::get_tile(atlas, &format!("{moving_prefix}_b.png"))
|
||||||
.ok_or_else(|| GameError::Texture(TextureError::AtlasTileNotFound(format!("{moving_prefix}_b.png"))))?];
|
.ok_or_else(|| GameError::Texture(TextureError::AtlasTileNotFound(format!("{moving_prefix}_b.png"))))?];
|
||||||
|
|
||||||
textures[direction.as_usize()] =
|
textures[direction.as_usize()] = Some(AnimatedTexture::new(moving_tiles, 0.08)?);
|
||||||
Some(AnimatedTexture::new(moving_tiles, 0.08).map_err(|e| GameError::Texture(TextureError::Animated(e)))?);
|
stopped_textures[direction.as_usize()] = Some(AnimatedTexture::new(stopped_tiles, 0.1)?);
|
||||||
stopped_textures[direction.as_usize()] =
|
|
||||||
Some(AnimatedTexture::new(stopped_tiles, 0.1).map_err(|e| GameError::Texture(TextureError::Animated(e)))?);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@@ -109,24 +106,6 @@ impl Pacman {
|
|||||||
texture: DirectionalAnimatedTexture::new(textures, stopped_textures),
|
texture: DirectionalAnimatedTexture::new(textures, stopped_textures),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles keyboard input to change Pac-Man's direction.
|
|
||||||
///
|
|
||||||
/// Maps arrow keys to directions and queues the direction change
|
|
||||||
/// for the next valid intersection.
|
|
||||||
pub fn handle_key(&mut self, keycode: Keycode) {
|
|
||||||
let direction = match keycode {
|
|
||||||
Keycode::Up => Some(Direction::Up),
|
|
||||||
Keycode::Down => Some(Direction::Down),
|
|
||||||
Keycode::Left => Some(Direction::Left),
|
|
||||||
Keycode::Right => Some(Direction::Right),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(direction) = direction {
|
|
||||||
self.traverser.set_next_direction(direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collidable for Pacman {
|
impl Collidable for Pacman {
|
||||||
|
|||||||