mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 15:15:48 -06:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41affcd7ad | |||
| 4ecfded4ac | |||
| 25d5121a28 | |||
| 91095ed2cc | |||
| cbf52bb994 | |||
| d763b9646f | |||
| d7a9e0a304 | |||
| db720edeef | |||
| f241e85d8f |
@@ -5,6 +5,7 @@ rustflags = [
|
||||
"-C", "link-args=-sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_SDL_MIXER=2 -sUSE_OGG=1 -sUSE_SDL_GFX=2 -sUSE_SDL_TTF=2 -sSDL2_IMAGE_FORMATS=['png']",
|
||||
"-C", "link-args=--preload-file assets/game/",
|
||||
]
|
||||
runner = "node"
|
||||
|
||||
[target.'cfg(target_os = "linux")']
|
||||
rustflags = [
|
||||
@@ -13,4 +14,4 @@ rustflags = [
|
||||
# By adding `-lz` here, we ensure it's passed to the linker after `libpng`,
|
||||
# which is required for the linker to correctly resolve symbols.
|
||||
"-C", "link-arg=-lz",
|
||||
]
|
||||
]
|
||||
|
||||
2
.github/workflows/audit.yaml
vendored
2
.github/workflows/audit.yaml
vendored
@@ -4,7 +4,7 @@ on: ["push", "pull_request"]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUST_TOOLCHAIN: 1.86.0
|
||||
RUST_TOOLCHAIN: 1.88.0
|
||||
|
||||
jobs:
|
||||
audit:
|
||||
|
||||
13
.github/workflows/build.yaml
vendored
13
.github/workflows/build.yaml
vendored
@@ -5,9 +5,6 @@ on: ["push", "pull_request"]
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
RUST_TOOLCHAIN: 1.86.0
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build (${{ matrix.target }})
|
||||
@@ -18,15 +15,19 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
artifact_name: pacman
|
||||
toolchain: 1.88.0
|
||||
- os: macos-13
|
||||
target: x86_64-apple-darwin
|
||||
artifact_name: pacman
|
||||
toolchain: 1.88.0
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
artifact_name: pacman
|
||||
toolchain: 1.88.0
|
||||
- os: windows-latest
|
||||
target: x86_64-pc-windows-gnu
|
||||
artifact_name: pacman.exe
|
||||
toolchain: 1.88.0
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -36,7 +37,7 @@ jobs:
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
target: ${{ matrix.target }}
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
@@ -92,13 +93,13 @@ jobs:
|
||||
uses: pyodide/setup-emsdk@v15
|
||||
with:
|
||||
version: 3.1.43
|
||||
actions-cache-folder: "emsdk-cache"
|
||||
actions-cache-folder: "emsdk-cache-b"
|
||||
|
||||
- name: Setup Rust (WASM32 Emscripten)
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
target: wasm32-unknown-emscripten
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
toolchain: 1.86.0 # we are unfortunately pinned to 1.86.0 for some reason, bulk-memory-opt related issues
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
|
||||
10
.github/workflows/coverage.yaml
vendored
10
.github/workflows/coverage.yaml
vendored
@@ -43,11 +43,17 @@ jobs:
|
||||
- name: Install cargo-tarpaulin
|
||||
run: cargo install cargo-tarpaulin
|
||||
|
||||
# Note: We manually link zlib. This should be synchronized with the flags set for Linux in .cargo/config.toml.
|
||||
- name: Generate coverage report
|
||||
run: cargo tarpaulin --out Html --output-dir coverage
|
||||
run: |
|
||||
cargo tarpaulin \
|
||||
--out Lcov \
|
||||
--output-dir coverage \
|
||||
--rustflags="-C link-arg=-lz"
|
||||
|
||||
- name: Upload coverage to Coveralls
|
||||
uses: coverallsapp/github-action@v2
|
||||
with:
|
||||
files: ./coverage/tarpaulin-report.html
|
||||
files: ./coverage/lcov.info
|
||||
format: lcov
|
||||
allow-empty: false
|
||||
|
||||
4
.github/workflows/test.yaml
vendored
4
.github/workflows/test.yaml
vendored
@@ -4,7 +4,7 @@ on: ["push", "pull_request"]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUST_TOOLCHAIN: 1.86.0
|
||||
RUST_TOOLCHAIN: 1.88.0
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
components: clippy
|
||||
components: clippy, rustfmt
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use glam::Vec2;
|
||||
use glam::{UVec2, Vec2};
|
||||
|
||||
use crate::constants::BOARD_PIXEL_OFFSET;
|
||||
use crate::entity::direction::Direction;
|
||||
use crate::entity::graph::{Graph, NodeId, Position, Traverser};
|
||||
use crate::helpers::centered_with_size;
|
||||
use crate::texture::animated::AnimatedTexture;
|
||||
use crate::texture::directional::DirectionalAnimatedTexture;
|
||||
use crate::texture::sprite::SpriteAtlas;
|
||||
use sdl2::keyboard::Keycode;
|
||||
use sdl2::rect::Rect;
|
||||
use sdl2::render::{Canvas, RenderTarget};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -71,15 +71,14 @@ impl Pacman {
|
||||
Position::BetweenNodes { from, to, traversed } => {
|
||||
let from_pos = graph.get_node(from).unwrap().position;
|
||||
let to_pos = graph.get_node(to).unwrap().position;
|
||||
let weight = from_pos.distance(to_pos);
|
||||
from_pos.lerp(to_pos, traversed / weight)
|
||||
from_pos.lerp(to_pos, traversed / from_pos.distance(to_pos))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render<T: RenderTarget>(&self, canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, graph: &Graph) {
|
||||
let pixel_pos = self.get_pixel_pos(graph).round().as_ivec2() + BOARD_PIXEL_OFFSET.as_ivec2();
|
||||
let dest = Rect::new(pixel_pos.x - 8, pixel_pos.y - 8, 16, 16);
|
||||
let dest = centered_with_size(pixel_pos, UVec2::new(16, 16));
|
||||
let is_stopped = self.traverser.position.is_stopped();
|
||||
|
||||
if is_stopped {
|
||||
|
||||
51
src/helpers.rs
Normal file
51
src/helpers.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use glam::{IVec2, UVec2};
|
||||
use sdl2::rect::Rect;
|
||||
|
||||
pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect {
|
||||
Rect::new(
|
||||
pixel_pos.x - size.x as i32 / 2,
|
||||
pixel_pos.y - size.y as i32 / 2,
|
||||
size.x,
|
||||
size.y,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_centered_with_size_basic() {
|
||||
let rect = centered_with_size(IVec2::new(100, 100), UVec2::new(50, 30));
|
||||
assert_eq!(rect.origin(), (75, 85));
|
||||
assert_eq!(rect.size(), (50, 30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_centered_with_size_odd_dimensions() {
|
||||
let rect = centered_with_size(IVec2::new(50, 50), UVec2::new(51, 31));
|
||||
assert_eq!(rect.origin(), (25, 35));
|
||||
assert_eq!(rect.size(), (51, 31));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_centered_with_size_zero_position() {
|
||||
let rect = centered_with_size(IVec2::new(0, 0), UVec2::new(100, 100));
|
||||
assert_eq!(rect.origin(), (-50, -50));
|
||||
assert_eq!(rect.size(), (100, 100));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_centered_with_size_negative_position() {
|
||||
let rect = centered_with_size(IVec2::new(-100, -50), UVec2::new(80, 40));
|
||||
assert_eq!(rect.origin(), (-140, -70));
|
||||
assert_eq!(rect.size(), (80, 40));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_centered_with_size_large_dimensions() {
|
||||
let rect = centered_with_size(IVec2::new(1000, 1000), UVec2::new(1000, 1000));
|
||||
assert_eq!(rect.origin(), (500, 500));
|
||||
assert_eq!(rect.size(), (1000, 1000));
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@ pub mod constants;
|
||||
pub mod emscripten;
|
||||
pub mod entity;
|
||||
pub mod game;
|
||||
pub mod helpers;
|
||||
pub mod map;
|
||||
pub mod texture;
|
||||
|
||||
@@ -56,6 +56,7 @@ mod constants;
|
||||
mod emscripten;
|
||||
mod entity;
|
||||
mod game;
|
||||
mod helpers;
|
||||
mod map;
|
||||
mod texture;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user