Skip to content

Commit

Permalink
If no rotation specified, point in the direction of movement
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Feb 2, 2025
1 parent c72227f commit 65e80a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Shooter {

camera.follow(player)

var mapFile = resourceManager.loadFile('scg01ea.ini', IniFile)
var mapFile = resourceManager.loadFile('scm01ea.ini', IniFile)
var map = new Map(mapFile as MapFile, resourceManager)
scene << map
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Player extends Node<Player> implements Rotatable, Temporal {
private Vector2f velocity = new Vector2f()
private Vector2f direction = new Vector2f()
private Vector2f movement = new Vector2f()
private float movementHeading
private Vector2f lookAt = new Vector2f()
private Vector2f lastLookAt = new Vector2f()
private Vector2f relativeLookAt = new Vector2f()
Expand Down Expand Up @@ -158,6 +159,7 @@ class Player extends Node<Player> implements Rotatable, Temporal {
Math.clamp(movement.x, MOVEMENT_RANGE.minX, MOVEMENT_RANGE.maxX),
Math.clamp(movement.y, MOVEMENT_RANGE.minY, MOVEMENT_RANGE.maxY)
)
movementHeading = Math.toDegrees(velocity.angle(up)) as float
}
else {
stop.execute()
Expand All @@ -180,6 +182,9 @@ class Player extends Node<Player> implements Rotatable, Temporal {
else if (direction.length()) {
heading = Math.toDegrees(direction.angle(up)) as float
}
else {
heading = movementHeading
}

// Gamepad firing
if (firing) {
Expand Down Expand Up @@ -267,11 +272,17 @@ class Player extends Node<Player> implements Rotatable, Temporal {
if (value < -MOVEMENT_THRESHOLD || value > MOVEMENT_THRESHOLD) {
direction.x = value
}
else {
direction.x = 0
}
}),
new GamepadControl(GLFW_GAMEPAD_AXIS_RIGHT_Y, 'Heading along the Y axis', { value ->
if (value < -MOVEMENT_THRESHOLD || value > MOVEMENT_THRESHOLD) {
direction.y = -value
}
else {
direction.y = 0
}
}),
new GamepadControl(GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 'Fire', { value ->
firing = value > -1f
Expand Down

0 comments on commit 65e80a6

Please sign in to comment.