-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
physics upgrade & unit collision (#70)
- Loading branch information
1 parent
fa1a94e
commit ecb36ea
Showing
26 changed files
with
153 additions
and
169 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Component } from "@piggo-legends/core"; | ||
|
||
export type ColliderProps = { | ||
x: number; | ||
y: number; | ||
radius: number | ||
mass?: number | ||
} | ||
|
||
export class Collider implements Component<"collider"> { | ||
type: "collider"; | ||
|
||
x: number; | ||
y: number; | ||
radius: number; | ||
mass: number; | ||
|
||
constructor(props: ColliderProps) { | ||
this.x = props.x; | ||
this.y = props.y; | ||
this.radius = props.radius; | ||
this.mass = props.mass ?? 0.001; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
modules/contrib/src/components/actions/CharacterMovement.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ActionMap, Position } from "@piggo-legends/contrib"; | ||
import { Entity } from "@piggo-legends/core"; | ||
|
||
const TURN_SPEED = 0.1; | ||
const SLIDE_FACTOR = 1.5; | ||
|
||
const SPEED = 2; | ||
|
||
export type VehicleMovementCommands = "up" | "down" | "left" | "right" | "skidleft" | "skidright"; | ||
|
||
export const VehicleMovement: ActionMap<VehicleMovementCommands> = { | ||
"up": (entity: Entity<Position>) => { | ||
const x = Math.cos(entity.components.position.rotation.rads - Math.PI / 1.35) * SPEED; | ||
const y = Math.sin(entity.components.position.rotation.rads - Math.PI / 1.35) * SPEED; | ||
entity.components.position?.setVelocity({ x, y }); | ||
}, | ||
"down": (entity: Entity) => entity.components.position?.setVelocity({ x: 0, y: 0 }), | ||
"left": (entity: Entity) => entity.components.position?.rotation.minus(TURN_SPEED), | ||
"right": (entity: Entity) => entity.components.position?.rotation.plus(TURN_SPEED), | ||
"skidleft": (entity: Entity) => entity.components.position?.rotation.minus(TURN_SPEED * SLIDE_FACTOR), | ||
"skidright": (entity: Entity) => entity.components.position?.rotation.plus(TURN_SPEED * SLIDE_FACTOR), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ActionMap, AnimationKeys, Character, Position } from "@piggo-legends/contrib" | ||
import { Entity } from "@piggo-legends/core"; | ||
|
||
const speed = 2; | ||
const speedDiagonal = speed / Math.sqrt(2); | ||
const speedHorizontal = speed / 2; | ||
|
||
export type WASDMovementCommands = "" | "up" | "down" | "left" | "right" | "upleft" | "upright" | "downleft" | "downright"; | ||
|
||
export const WASDMovementPhysics: ActionMap<WASDMovementCommands> = { | ||
"up": (entity: Entity<Position>) => setAV(entity, "u", { x: -speedDiagonal, y: -speedDiagonal }), | ||
"down": (entity: Entity<Position>) => setAV(entity, "d", { x: speedDiagonal, y: speedDiagonal }), | ||
"left": (entity: Entity<Position>) => setAV(entity, "l", { x: -speedHorizontal, y: speedHorizontal }), | ||
"right": (entity: Entity<Position>) => setAV(entity, "r", { x: speedHorizontal, y: -speedHorizontal }), | ||
"upleft": (entity: Entity<Position>) => setAV(entity, "ul", { x: -speed, y: 0 }), | ||
"upright": (entity: Entity<Position>) => setAV(entity, "ur", { x: 0, y: -speed }), | ||
"downleft": (entity: Entity<Position>) => setAV(entity, "dl", { x: 0, y: speed }), | ||
"downright": (entity: Entity<Position>) => setAV(entity, "dr", { x: speed, y: 0 }), | ||
"": (entity: Entity<Position>) => setAV(entity, undefined, { x: 0, y: 0 }) | ||
} | ||
|
||
const setAV = (entity: Entity<Position>, animation: AnimationKeys | undefined, velocity: { x: number, y: number }) => { | ||
const { position, renderable } = entity.components; | ||
position.setVelocity(velocity); | ||
|
||
const character = renderable?.r as Character; | ||
if (character && animation) character.setAnimation(animation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.