mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-08 12:07:52 -06:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41affcd7ad | |||
| 4ecfded4ac | |||
| 25d5121a28 | |||
| 91095ed2cc |
7
.github/workflows/build.yaml
vendored
7
.github/workflows/build.yaml
vendored
@@ -11,20 +11,23 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
toolchain: [1.88.0]
|
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: x86_64-unknown-linux-gnu
|
target: x86_64-unknown-linux-gnu
|
||||||
artifact_name: pacman
|
artifact_name: pacman
|
||||||
|
toolchain: 1.88.0
|
||||||
- os: macos-13
|
- os: macos-13
|
||||||
target: x86_64-apple-darwin
|
target: x86_64-apple-darwin
|
||||||
artifact_name: pacman
|
artifact_name: pacman
|
||||||
|
toolchain: 1.88.0
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
artifact_name: pacman
|
artifact_name: pacman
|
||||||
|
toolchain: 1.88.0
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: x86_64-pc-windows-gnu
|
target: x86_64-pc-windows-gnu
|
||||||
artifact_name: pacman.exe
|
artifact_name: pacman.exe
|
||||||
|
toolchain: 1.88.0
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -90,7 +93,7 @@ jobs:
|
|||||||
uses: pyodide/setup-emsdk@v15
|
uses: pyodide/setup-emsdk@v15
|
||||||
with:
|
with:
|
||||||
version: 3.1.43
|
version: 3.1.43
|
||||||
actions-cache-folder: "emsdk-cache"
|
actions-cache-folder: "emsdk-cache-b"
|
||||||
|
|
||||||
- name: Setup Rust (WASM32 Emscripten)
|
- name: Setup Rust (WASM32 Emscripten)
|
||||||
uses: dtolnay/rust-toolchain@master
|
uses: dtolnay/rust-toolchain@master
|
||||||
|
|||||||
5
.github/workflows/coverage.yaml
vendored
5
.github/workflows/coverage.yaml
vendored
@@ -47,12 +47,13 @@ jobs:
|
|||||||
- name: Generate coverage report
|
- name: Generate coverage report
|
||||||
run: |
|
run: |
|
||||||
cargo tarpaulin \
|
cargo tarpaulin \
|
||||||
--out Html \
|
--out Lcov \
|
||||||
--output-dir coverage \
|
--output-dir coverage \
|
||||||
--rustflags="-C link-arg=-lz"
|
--rustflags="-C link-arg=-lz"
|
||||||
|
|
||||||
- name: Upload coverage to Coveralls
|
- name: Upload coverage to Coveralls
|
||||||
uses: coverallsapp/github-action@v2
|
uses: coverallsapp/github-action@v2
|
||||||
with:
|
with:
|
||||||
files: ./coverage/tarpaulin-report.html
|
files: ./coverage/lcov.info
|
||||||
|
format: lcov
|
||||||
allow-empty: false
|
allow-empty: false
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use glam::Vec2;
|
use glam::{UVec2, Vec2};
|
||||||
|
|
||||||
use crate::constants::BOARD_PIXEL_OFFSET;
|
use crate::constants::BOARD_PIXEL_OFFSET;
|
||||||
use crate::entity::direction::Direction;
|
use crate::entity::direction::Direction;
|
||||||
use crate::entity::graph::{Graph, NodeId, Position, Traverser};
|
use crate::entity::graph::{Graph, NodeId, Position, Traverser};
|
||||||
|
use crate::helpers::centered_with_size;
|
||||||
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 sdl2::keyboard::Keycode;
|
||||||
use sdl2::rect::Rect;
|
|
||||||
use sdl2::render::{Canvas, RenderTarget};
|
use sdl2::render::{Canvas, RenderTarget};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -71,15 +71,14 @@ impl Pacman {
|
|||||||
Position::BetweenNodes { from, to, traversed } => {
|
Position::BetweenNodes { from, to, traversed } => {
|
||||||
let from_pos = graph.get_node(from).unwrap().position;
|
let from_pos = graph.get_node(from).unwrap().position;
|
||||||
let to_pos = graph.get_node(to).unwrap().position;
|
let to_pos = graph.get_node(to).unwrap().position;
|
||||||
let weight = from_pos.distance(to_pos);
|
from_pos.lerp(to_pos, traversed / from_pos.distance(to_pos))
|
||||||
from_pos.lerp(to_pos, traversed / weight)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<T: RenderTarget>(&self, canvas: &mut Canvas<T>, atlas: &mut SpriteAtlas, graph: &Graph) {
|
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 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();
|
let is_stopped = self.traverser.position.is_stopped();
|
||||||
|
|
||||||
if 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 emscripten;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
|
pub mod helpers;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod texture;
|
pub mod texture;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ mod constants;
|
|||||||
mod emscripten;
|
mod emscripten;
|
||||||
mod entity;
|
mod entity;
|
||||||
mod game;
|
mod game;
|
||||||
|
mod helpers;
|
||||||
mod map;
|
mod map;
|
||||||
mod texture;
|
mod texture;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user