Skip to content

Commit

Permalink
fix(enemy): properly position enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
tversteeg committed Nov 24, 2024
1 parent 45a79f0 commit aed5c64
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 59 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ jobs:
command: fmt
args: --all -- --check

# Run test check on Linux, macOS, and Windows
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
# Checkout the branch being tested
- uses: actions/checkout@v4

# Install rust stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable

# Cache the built dependencies
- uses: Swatinem/[email protected]
with:
save-if: ${{ github.event_name == 'push' }}

# Install cargo-hack
- uses: taiki-e/install-action@cargo-hack

# Test all feature combinations on the target platform
- name: Test
run: cargo hack --feature-powerset test

# Build the WASM target & push it to GitHub pages
wasm:
name: WASM test & build
Expand Down
Binary file modified assets/level/grass-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/settings.ron
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distance from the edge at which the camera will pan
pan_edge_offset: 80,
// How many pixels per second the camera will pan
pan_speed: 100,
pan_speed: 300,

// Interval in seconds for when a unit spawns
unit_spawn_interval: 3,
Expand Down
17 changes: 4 additions & 13 deletions assets/unit/enemy-spear.ron
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,17 @@
// Interval in seconds for when a new projectile is thrown
projectile_spawn_interval: 10,
// Don't let the projectile spawn in the ground
projectile_spawn_offset: (0, -20),
projectile_spawn_offset: (-10, -20),
// How fast a projectile is thrown
projectile_velocity: Static(70),
// How long the hands are hidden after launching a projectile in seconds
hide_hands_delay: 2,

// Where the hands are placed
hands_offset: (13, 1),

// Size of the healthbar
healthbar_size: (20, 3),
// Where above the unit it floats
healthbar_offset: (-1, -8),

// physics: (
// // Handle all collisions manually
// is_kinematic: true,
// ),

// // Collider shape for collisions with projectile
// collider: (
// shape: "rectangle",
// width: 10,
// height: 30,
// ),
)
3 changes: 3 additions & 0 deletions assets/unit/spear.ron
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// How long the hands are hidden after launching a projectile in seconds
hide_hands_delay: 2,

// Where the hands are placed
hands_offset: (-1, -1),

// Size of the healthbar
healthbar_size: (20, 3),
// Where above the unit it floats
Expand Down
2 changes: 1 addition & 1 deletion run-wasm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
cargo_run_wasm::run_wasm_cli_with_css("body { margin: 0px; }");
}
32 changes: 17 additions & 15 deletions src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

/// All unit types.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnitType {
PlayerSpear,
EnemySpear,
Expand Down Expand Up @@ -116,23 +116,18 @@ impl Unit {

Some(Projectile::new(
self.pos + Vector2::from_tuple(projectile_spawn_offset),
Vector2::new(velocity, -velocity),
Vector2::new(
if self.r#type == UnitType::PlayerSpear {
velocity
} else {
-velocity
},
-velocity,
),
))
} else {
None
}

/*
// Draw the healthbar
crate::graphics::healthbar::healthbar(
self.health,
settings.health,
self.pos + settings.healthbar_offset,
settings.healthbar_size,
canvas,
camera,
);
*/
}

/// Draw the unit.
Expand All @@ -157,7 +152,12 @@ impl Unit {
if let Some(hands_asset_path) = &settings.hands_asset_path {
if self.hide_hands_delay <= 0.0 {
ctx.sprite(hands_asset_path)
.translate(draw_pos - Vector2::splat(1.0))
.translate(draw_pos + Vector2::from_tuple(settings.hands_offset))
.scale_x(if self.r#type == UnitType::PlayerSpear {
1.0
} else {
-1.0
})
.draw();
}
}
Expand Down Expand Up @@ -199,6 +199,8 @@ pub struct Settings {
pub projectile_velocity: RandomRange,
/// How long the hands are hidden after launching a projectile.
pub hide_hands_delay: f32,
/// Position offset of the hands.
pub hands_offset: (f32, f32),
/// Size of the healthbar.
pub healthbar_size: (f32, f32),
/// Position offset of the healthbar.
Expand Down

0 comments on commit aed5c64

Please sign in to comment.