Compare commits
No commits in common. "cfea34861fcded3287dcb7b6db1820c8ac0b6e09" and "bec85cefe3f255031cd239e5c3dba01d920b4f4b" have entirely different histories.
cfea34861f
...
bec85cefe3
5 changed files with 113 additions and 131 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.2 KiB |
|
|
@ -1,43 +0,0 @@
|
|||
[gd_resource type="SpriteFrames" format=3 uid="uid://d0suj5i5kalpp"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://c3v26u2wh4it4" path="res://Assets/Player.png" id="1_qkju4"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_65ufv"]
|
||||
atlas = ExtResource("1_qkju4")
|
||||
region = Rect2(0, 0, 38, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vhg5s"]
|
||||
atlas = ExtResource("1_qkju4")
|
||||
region = Rect2(39, 0, 38, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_lrw40"]
|
||||
atlas = ExtResource("1_qkju4")
|
||||
region = Rect2(78, 0, 38, 32)
|
||||
|
||||
[resource]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_65ufv")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"Idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_65ufv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vhg5s")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_lrw40")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vhg5s")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"Moving",
|
||||
"speed": 7.0
|
||||
}]
|
||||
|
|
@ -1,12 +1,22 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
# The slime crawls on floors, walls and ceilings and sticks to them.
|
||||
# Generally the player press away from a surface while holding still to unstick.
|
||||
# - Let go: hold away from a wall or ceiling for HOLD_TIME.
|
||||
# - Edge hold: crawling to an edge stops there until you've held towards it for HOLD_TIME.
|
||||
# - Edge wrap: near an edge, press into the surface to swing around the corner.
|
||||
# - Hop: standing still, hold away from the surface for HOLD_TIME to hop to one within a tile.
|
||||
#
|
||||
# Terms:
|
||||
# - Godot's y axis points DOWN, so up is negative y (Vector2.UP is (0, -1)).
|
||||
# - Normal: arrow pointing straight out of a surface.
|
||||
# - Tangent: arrow pointing along a surface.
|
||||
# - a.dot(b): how much two arrows point the same way (1 same, 0 sideways, -1 opposite).
|
||||
|
||||
###############
|
||||
## Constants ##
|
||||
###############
|
||||
const GROUND_SPEED = 150.0
|
||||
|
||||
# ---- Settings ----
|
||||
|
||||
# Speeds are positive; the direction is applied where they're used.
|
||||
const GROUND_SPEED = 150.0 # Crawling on floors, walls and ceilings (pixels per second).
|
||||
const AIR_SPEED = 75.0
|
||||
const CLIMB_SPEED = 150.0
|
||||
|
||||
|
|
@ -28,11 +38,11 @@ const SURFACE_SNAP_DISTANCE = 4.0 # Drift off a wall/ceiling by up to this and w
|
|||
const HOLD_TIME = 0.5
|
||||
|
||||
# How close an edge must be (from our center) for an edge wrap.
|
||||
const EDGE_SENSOR_RANGE := 12.0
|
||||
@export var edgeSensorRange := 12.0
|
||||
const EDGE_SENSOR_DEPTH = 4.0 # How far past our radius the sensors reach into the surface.
|
||||
const WRAP_MARGIN = 0.5 # Extra gap from the corner so we don't clip into it.
|
||||
|
||||
const HOP_REACH = 32.0
|
||||
const HOP_REACH = 32.0 # One tile.
|
||||
const HOP_NO_CEILING_HEIGHT = 16.0 # Floor hop with nothing in reach, so you can tell it worked.
|
||||
const HOP_OVERSHOOT = 2.0 # Aim slightly past the surface so we arrive with some speed and stick.
|
||||
|
||||
|
|
@ -41,7 +51,10 @@ const MIN_LAND_SPEED = 60.0 # Slower landings don't splat.
|
|||
const LAND_PITCH_MIN = 0.87
|
||||
const LAND_PITCH_MAX = 1.15
|
||||
|
||||
|
||||
# ---- State ----
|
||||
|
||||
# For the floor we use Godot's is_on_floor().
|
||||
var isStickingToWall := false
|
||||
var wallNormalX := 0.0 # -1 if the wall faces left, 1 if it faces right.
|
||||
var isStickingToCeiling := false
|
||||
|
|
@ -80,7 +93,8 @@ var wrapDistanceTravelled := 0.0
|
|||
|
||||
# ---- Nodes ----
|
||||
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
# Temp for now, need to use AnimatedSprite2D later on.
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@onready var collisionShape: CollisionShape2D = $CollisionShape2D
|
||||
# Edge-finding raycasts, one each side, under a pivot we turn to face the surface we're on.
|
||||
@onready var edgeSensors: Node2D = $EdgeSensors
|
||||
|
|
@ -99,18 +113,20 @@ func _ready() -> void:
|
|||
floor_snap_length = SURFACE_SNAP_DISTANCE
|
||||
|
||||
var sensorLength := _get_radius() + EDGE_SENSOR_DEPTH
|
||||
leftEdgeSensor.position = Vector2(-EDGE_SENSOR_RANGE, 0)
|
||||
leftEdgeSensor.position = Vector2(-edgeSensorRange, 0)
|
||||
leftEdgeSensor.target_position = Vector2(0, sensorLength)
|
||||
rightEdgeSensor.position = Vector2(EDGE_SENSOR_RANGE, 0)
|
||||
rightEdgeSensor.position = Vector2(edgeSensorRange, 0)
|
||||
rightEdgeSensor.target_position = Vector2(0, sensorLength)
|
||||
|
||||
# Raycasts only ignore their parent, which is the EdgeSensors pivot, not us.
|
||||
leftEdgeSensor.add_exception(self)
|
||||
rightEdgeSensor.add_exception(self)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var xInput := Input.get_axis("moveLeft", "moveRight")
|
||||
var yInput := Input.get_axis("moveDown", "moveUp")
|
||||
# -1 is left/down, 1 is right/up.
|
||||
var horizontalInput := Input.get_axis("moveLeft", "moveRight")
|
||||
var verticalInput := Input.get_axis("moveDown", "moveUp")
|
||||
|
||||
if isWrapping:
|
||||
_update_wrap(delta)
|
||||
|
|
@ -120,18 +136,15 @@ func _physics_process(delta: float) -> void:
|
|||
if not wasInAir:
|
||||
isHoppingAcross = false
|
||||
|
||||
if isStickingToWall and yInput != 0.0:
|
||||
wallFacingY = -signf(yInput)
|
||||
if _start_edge_wrap(xInput, yInput):
|
||||
if isStickingToWall and verticalInput != 0.0:
|
||||
wallFacingY = -signf(verticalInput)
|
||||
if _start_edge_wrap(horizontalInput, verticalInput):
|
||||
return
|
||||
|
||||
# Animated Sprite
|
||||
_update_facing(xInput, yInput)
|
||||
_update_animation(xInput, yInput)
|
||||
|
||||
_update_vertical_movement(delta, xInput, yInput)
|
||||
_update_floor_hop(delta, xInput, yInput)
|
||||
_update_horizontal_movement(delta, xInput, yInput)
|
||||
_update_facing(horizontalInput)
|
||||
_update_vertical_movement(delta, horizontalInput, verticalInput)
|
||||
_update_floor_hop(delta, horizontalInput, verticalInput)
|
||||
_update_horizontal_movement(delta, horizontalInput, verticalInput)
|
||||
_hold_at_edge(delta)
|
||||
|
||||
var wasOnWall := isStickingToWall and not is_on_floor()
|
||||
|
|
@ -141,7 +154,7 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
_update_wall_sticking(wasOnWall)
|
||||
|
||||
var climbedPastWallTop := wasOnWall and not isStickingToWall and yInput > 0
|
||||
var climbedPastWallTop := wasOnWall and not isStickingToWall and verticalInput > 0
|
||||
var tryingToLetGo := timeSpentUnstickingWall >= HOLD_TIME
|
||||
if climbedPastWallTop and not tryingToLetGo and _start_wall_top_wrap():
|
||||
return
|
||||
|
|
@ -150,7 +163,7 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
# In a corner, stick to the ceiling if pressing up, otherwise the wall.
|
||||
if isStickingToWall and isStickingToCeiling:
|
||||
if yInput > 0:
|
||||
if verticalInput > 0:
|
||||
isStickingToWall = false
|
||||
else:
|
||||
isStickingToCeiling = false
|
||||
|
|
@ -164,47 +177,35 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
_update_sprite_rotation(delta)
|
||||
|
||||
|
||||
# ---- Movement steps (in the order _physics_process runs them) ----
|
||||
|
||||
func _update_facing(xInput: float, yInput: float) -> void:
|
||||
if xInput == 0.0 and yInput == 0.0:
|
||||
func _update_facing(horizontalInput: float) -> void:
|
||||
if horizontalInput == 0.0:
|
||||
return
|
||||
|
||||
if isStickingToCeiling:
|
||||
sprite.flip_h = xInput > 0 # Upside down, so flipped the other way.
|
||||
elif isStickingToWall:
|
||||
if wallNormalX < 0:
|
||||
sprite.flip_h = yInput < 0
|
||||
sprite.flip_h = horizontalInput > 0 # Upside down, so flipped the other way.
|
||||
else:
|
||||
sprite.flip_h = yInput > 0
|
||||
else:
|
||||
sprite.flip_h = xInput < 0
|
||||
sprite.flip_h = horizontalInput < 0
|
||||
|
||||
|
||||
func _update_animation(xInput:float, yInput:float):
|
||||
if xInput and (isStickingToCeiling or is_on_floor()):
|
||||
sprite.play("Moving")
|
||||
elif yInput and isStickingToWall:
|
||||
sprite.play("Moving")
|
||||
else:
|
||||
sprite.play("Idle")
|
||||
|
||||
func _update_vertical_movement(delta: float, xInput: float, yInput: float) -> void:
|
||||
func _update_vertical_movement(delta: float, horizontalInput: float, verticalInput: float) -> void:
|
||||
if isStickingToCeiling:
|
||||
_update_ceiling_letting_go(delta, xInput, yInput)
|
||||
_update_ceiling_letting_go(delta, horizontalInput, verticalInput)
|
||||
elif isStickingToWall:
|
||||
var targetSpeed := -CLIMB_SPEED * yInput
|
||||
var targetSpeed := -CLIMB_SPEED * verticalInput
|
||||
velocity.y = _accelerate(velocity.y, targetSpeed, delta)
|
||||
elif not is_on_floor():
|
||||
velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED)
|
||||
|
||||
|
||||
# Holding down (not moving) for HOLD_TIME lets go, hopping onto a floor if one's in reach.
|
||||
func _update_ceiling_letting_go(delta: float, xInput: float, yInput: float) -> void:
|
||||
if yInput >= 0:
|
||||
func _update_ceiling_letting_go(delta: float, horizontalInput: float, verticalInput: float) -> void:
|
||||
if verticalInput >= 0:
|
||||
ignoreCeilingUnstickUntilRelease = false
|
||||
|
||||
var holdingDown := yInput < 0
|
||||
var standingStill := xInput == 0.0
|
||||
var holdingDown := verticalInput < 0
|
||||
var standingStill := horizontalInput == 0.0
|
||||
if holdingDown and standingStill and not ignoreCeilingUnstickUntilRelease:
|
||||
timeSpentUnstickingCeiling += delta
|
||||
else:
|
||||
|
|
@ -221,9 +222,13 @@ func _update_ceiling_letting_go(delta: float, xInput: float, yInput: float) -> v
|
|||
else:
|
||||
velocity.y = get_gravity().y * delta
|
||||
|
||||
# Hopping from the floop while holding still.
|
||||
func _update_floor_hop(delta: float, xInput: float, yInput: float) -> void:
|
||||
if is_on_floor() and not isStickingToWall and xInput == 0.0 and yInput > 0:
|
||||
|
||||
# Holding up (not moving) for HOLD_TIME hops to the ceiling. Not against a wall,
|
||||
# where up climbs it instead.
|
||||
func _update_floor_hop(delta: float, horizontalInput: float, verticalInput: float) -> void:
|
||||
var holdingUp := verticalInput > 0
|
||||
var standingStill := horizontalInput == 0.0
|
||||
if is_on_floor() and not isStickingToWall and holdingUp and standingStill:
|
||||
timeSpentHoldingUpOnFloor += delta
|
||||
else:
|
||||
timeSpentHoldingUpOnFloor = 0.0
|
||||
|
|
@ -232,25 +237,27 @@ func _update_floor_hop(delta: float, xInput: float, yInput: float) -> void:
|
|||
timeSpentHoldingUpOnFloor = 0.0
|
||||
velocity.y = -_get_hop_speed(_get_hop_height())
|
||||
|
||||
func _update_horizontal_movement(delta: float, xInput: float, yInput: float) -> void:
|
||||
|
||||
func _update_horizontal_movement(delta: float, horizontalInput: float, verticalInput: float) -> void:
|
||||
if isStickingToWall and not is_on_floor():
|
||||
_update_wall_letting_go(delta, xInput, yInput)
|
||||
_update_wall_letting_go(delta, horizontalInput, verticalInput)
|
||||
return
|
||||
|
||||
timeSpentUnstickingWall = 0.0
|
||||
if is_on_floor() or isStickingToCeiling:
|
||||
velocity.x = _accelerate(velocity.x, xInput * GROUND_SPEED, delta)
|
||||
velocity.x = _accelerate(velocity.x, horizontalInput * GROUND_SPEED, delta)
|
||||
elif not isHoppingAcross:
|
||||
velocity.x = _air_steer(velocity.x, xInput, delta)
|
||||
velocity.x = _air_steer(velocity.x, horizontalInput, delta)
|
||||
|
||||
|
||||
# Holding away (not climbing) for HOLD_TIME hops to the opposite wall if one's
|
||||
# in reach, otherwise lets go.
|
||||
func _update_wall_letting_go(delta: float, xInput: float, yInput: float) -> void:
|
||||
var pressingAwayFromWall := xInput * wallNormalX > 0
|
||||
func _update_wall_letting_go(delta: float, horizontalInput: float, verticalInput: float) -> void:
|
||||
var pressingAwayFromWall := horizontalInput * wallNormalX > 0
|
||||
if not pressingAwayFromWall:
|
||||
ignoreWallUnstickUntilRelease = false
|
||||
|
||||
var standingStill := yInput == 0.0
|
||||
var standingStill := verticalInput == 0.0
|
||||
if pressingAwayFromWall and standingStill and not ignoreWallUnstickUntilRelease:
|
||||
timeSpentUnstickingWall += delta
|
||||
else:
|
||||
|
|
@ -264,7 +271,8 @@ func _update_wall_letting_go(delta: float, xInput: float, yInput: float) -> void
|
|||
if wallDistance >= 0.0:
|
||||
_hop_across(wallDistance)
|
||||
else:
|
||||
velocity.x = xInput * GROUND_SPEED
|
||||
velocity.x = horizontalInput * GROUND_SPEED
|
||||
|
||||
|
||||
func _update_wall_sticking(wasOnWall: bool) -> void:
|
||||
var meantToLetGo := timeSpentUnstickingWall >= HOLD_TIME
|
||||
|
|
@ -276,6 +284,7 @@ func _update_wall_sticking(wasOnWall: bool) -> void:
|
|||
if isStickingToWall:
|
||||
wallNormalX = get_wall_normal().x
|
||||
|
||||
|
||||
func _update_ceiling_sticking() -> void:
|
||||
var wasOnCeiling := isStickingToCeiling
|
||||
var driftedBackOn := false
|
||||
|
|
@ -283,6 +292,7 @@ func _update_ceiling_sticking() -> void:
|
|||
driftedBackOn = _snap_to_surface(Vector2.DOWN)
|
||||
isStickingToCeiling = is_on_ceiling() or driftedBackOn
|
||||
|
||||
|
||||
func _update_sprite_rotation(delta: float) -> void:
|
||||
var targetRotation := 0.0
|
||||
if isStickingToWall and not is_on_floor():
|
||||
|
|
@ -294,6 +304,7 @@ func _update_sprite_rotation(delta: float) -> void:
|
|||
var turnAmount := 1.0 - exp(-ROTATE_TO_SURFACE_SPEED * delta)
|
||||
sprite.rotation = lerp_angle(sprite.rotation, targetRotation, turnAmount)
|
||||
|
||||
|
||||
# ---- Movement helpers ----
|
||||
|
||||
# GROUND_ACCEL when speeding up, GROUND_FRICTION when slowing, stopping or turning.
|
||||
|
|
@ -303,15 +314,17 @@ func _accelerate(speed: float, targetSpeed: float, delta: float) -> float:
|
|||
var rate := GROUND_ACCEL if speedingUp else GROUND_FRICTION
|
||||
return move_toward(speed, targetSpeed, rate * delta)
|
||||
|
||||
|
||||
# Extra speed from leaving a surface fades slowly unless we steer against it.
|
||||
func _air_steer(speed: float, xInput: float, delta: float) -> float:
|
||||
var targetSpeed := xInput * AIR_SPEED
|
||||
var steeringSameWay := xInput == 0.0 or signf(xInput) == signf(speed)
|
||||
func _air_steer(speed: float, horizontalInput: float, delta: float) -> float:
|
||||
var targetSpeed := horizontalInput * AIR_SPEED
|
||||
var steeringSameWay := horizontalInput == 0.0 or signf(horizontalInput) == signf(speed)
|
||||
var hasExtraSpeed := absf(speed) > AIR_SPEED
|
||||
if (hasExtraSpeed and steeringSameWay) or xInput == 0.0:
|
||||
if (hasExtraSpeed and steeringSameWay) or horizontalInput == 0.0:
|
||||
return move_toward(speed, targetSpeed, AIR_DRAG * delta)
|
||||
return move_toward(speed, targetSpeed, AIR_ACCEL * delta)
|
||||
|
||||
|
||||
# Moves flush against the surface with this normal if it's within SURFACE_SNAP_DISTANCE.
|
||||
func _snap_to_surface(normal: Vector2) -> bool:
|
||||
var hit := move_and_collide(-normal * SURFACE_SNAP_DISTANCE, true) # true = test only, don't move.
|
||||
|
|
@ -324,12 +337,18 @@ func _snap_to_surface(normal: Vector2) -> bool:
|
|||
global_position += hit.get_travel()
|
||||
return true
|
||||
|
||||
|
||||
# The normal of the surface we're stuck to, or zero in the air.
|
||||
func _get_surface_normal() -> Vector2:
|
||||
if is_on_floor(): return Vector2.UP
|
||||
if isStickingToCeiling: return Vector2.DOWN
|
||||
if isStickingToWall: return Vector2(wallNormalX, 0)
|
||||
if is_on_floor():
|
||||
return Vector2.UP
|
||||
if isStickingToCeiling:
|
||||
return Vector2.DOWN
|
||||
if isStickingToWall:
|
||||
return Vector2(wallNormalX, 0)
|
||||
return Vector2.ZERO
|
||||
|
||||
|
||||
func _get_facing() -> Vector2:
|
||||
if is_on_floor():
|
||||
if sprite.flip_h:
|
||||
|
|
@ -341,13 +360,16 @@ func _get_facing() -> Vector2:
|
|||
return Vector2.LEFT
|
||||
return Vector2(0, wallFacingY)
|
||||
|
||||
|
||||
# ---- Hops ----
|
||||
|
||||
func _get_hop_height() -> float:
|
||||
var ceilingDistance := _get_hop_distance(Vector2.UP)
|
||||
if ceilingDistance >= 0.0:
|
||||
return ceilingDistance
|
||||
return HOP_NO_CEILING_HEIGHT
|
||||
|
||||
|
||||
# Distance to a surface facing us within HOP_REACH (plus HOP_OVERSHOOT), or -1 if none.
|
||||
func _get_hop_distance(direction: Vector2) -> float:
|
||||
var hit := move_and_collide(direction * HOP_REACH, true)
|
||||
|
|
@ -378,12 +400,12 @@ func _hop_across(distance: float) -> void:
|
|||
# Pressing into the surface near an edge starts wrapping around it. A direction
|
||||
# along the surface picks the side, otherwise facing does (or the other side if
|
||||
# only it has an edge).
|
||||
func _start_edge_wrap(xInput: float, yInput: float) -> bool:
|
||||
func _start_edge_wrap(horizontalInput: float, verticalInput: float) -> bool:
|
||||
var normal := _get_surface_normal()
|
||||
if normal == Vector2.ZERO:
|
||||
return false
|
||||
|
||||
var inputDirection := Vector2(xInput, -yInput) # Up is negative y.
|
||||
var inputDirection := Vector2(horizontalInput, -verticalInput) # Up is negative y.
|
||||
var pressingIntoSurface := inputDirection.dot(-normal) >= 0.5
|
||||
if not pressingIntoSurface:
|
||||
return false
|
||||
|
|
@ -417,7 +439,7 @@ func _try_edge_wrap(normal: Vector2, tangent: Vector2, side: float) -> bool:
|
|||
return false # Starts inside something: an inside corner, not an edge.
|
||||
|
||||
var direction := tangent * side
|
||||
var corner = _find_edge_corner(normal, direction, EDGE_SENSOR_RANGE + 2)
|
||||
var corner = _find_edge_corner(normal, direction, edgeSensorRange + 2)
|
||||
if corner == null:
|
||||
return false
|
||||
|
||||
|
|
@ -488,6 +510,7 @@ func _hold_at_edge(delta: float) -> void:
|
|||
var speedToReachEdge := maxf(distanceToEdge, 0.0) / delta
|
||||
velocity += direction * (speedToReachEdge - absf(speedAlongSurface))
|
||||
|
||||
|
||||
# We've just climbed past a wall's top corner, so _find_edge_corner (which looks
|
||||
# from the surface we're on) can't see it. Find it with our own raycasts.
|
||||
func _start_wall_top_wrap() -> bool:
|
||||
|
|
@ -524,7 +547,7 @@ func _begin_wrap(corner: Vector2, arcEndAngle: float, exitOffset: Vector2, ontoN
|
|||
|
||||
wrapCorner = corner
|
||||
wrapEntryStart = global_position
|
||||
if is_nan(arcStartAngle):
|
||||
if is_nan(arcStartAngle): # NAN ("not a number") means it wasn't given.
|
||||
var fromCorner := global_position - corner
|
||||
wrapFromAngle = fromCorner.angle()
|
||||
wrapFromDistance = fromCorner.length()
|
||||
|
|
@ -582,6 +605,7 @@ func _update_wrap(delta: float) -> void:
|
|||
if wrapDistanceTravelled >= totalLength:
|
||||
_finish_wrap(delta)
|
||||
|
||||
|
||||
func _finish_wrap(delta: float) -> void:
|
||||
# Close the WRAP_MARGIN gap with move_and_slide() so is_on_floor()/is_on_wall()
|
||||
# describe where we are now, not where we were before the wrap.
|
||||
|
|
@ -616,6 +640,7 @@ func _finish_wrap(delta: float) -> void:
|
|||
ignoreWallUnstickUntilRelease = true
|
||||
ignoreCeilingUnstickUntilRelease = isStickingToCeiling
|
||||
|
||||
|
||||
# ---- Effects ----
|
||||
|
||||
func _splat(normal: Vector2) -> void:
|
||||
|
|
@ -629,16 +654,19 @@ func _splat(normal: Vector2) -> void:
|
|||
landSound.pitch_scale = randf_range(LAND_PITCH_MIN, LAND_PITCH_MAX)
|
||||
landSound.play()
|
||||
|
||||
|
||||
# ---- Physics queries (all ignore the slime itself) ----
|
||||
|
||||
func _get_radius() -> float:
|
||||
return (collisionShape.shape as CircleShape2D).radius
|
||||
|
||||
|
||||
# Returns the hit (.position, .normal), or an empty Dictionary if nothing.
|
||||
func _cast_ray(from: Vector2, to: Vector2) -> Dictionary:
|
||||
var query := PhysicsRayQueryParameters2D.create(from, to, collision_mask, [get_rid()])
|
||||
return get_world_2d().direct_space_state.intersect_ray(query)
|
||||
|
||||
|
||||
func _is_point_free(point: Vector2) -> bool:
|
||||
var query := PhysicsPointQueryParameters2D.new()
|
||||
query.position = point
|
||||
|
|
@ -646,6 +674,7 @@ func _is_point_free(point: Vector2) -> bool:
|
|||
query.exclude = [get_rid()]
|
||||
return get_world_2d().direct_space_state.intersect_point(query, 1).is_empty()
|
||||
|
||||
|
||||
# Whether our whole shape fits at this spot.
|
||||
func _is_spot_free(spot: Vector2) -> bool:
|
||||
var query := PhysicsShapeQueryParameters2D.new()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
[gd_scene format=3 uid="uid://uaxviwb40nn8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://drxbt88sjb1y4" path="res://Characters/player.gd" id="1_eovys"]
|
||||
[ext_resource type="Texture2D" uid="uid://c3v26u2wh4it4" path="res://Assets/Player.png" id="2_eovys"]
|
||||
[ext_resource type="AudioStream" uid="uid://b06e7ntjhc4dp" path="res://Assets/Sounds/slime_land_1.ogg" id="3_land1"]
|
||||
[ext_resource type="AudioStream" uid="uid://bpa664tsd4kwn" path="res://Assets/Sounds/slime_land_2.ogg" id="4_land2"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://d0suj5i5kalpp" path="res://Assets/slime_player.tres" id="5_4m0gv"]
|
||||
[ext_resource type="AudioStream" uid="uid://ceyykao0r6u7g" path="res://Assets/Sounds/slime_land_3.ogg" id="5_land3"]
|
||||
[ext_resource type="AudioStream" uid="uid://1dmf4p7x4y3b" path="res://Assets/Sounds/slime_wrap.ogg" id="6_wrap"]
|
||||
|
||||
|
|
@ -16,28 +16,27 @@ colors = PackedColorArray(0, 0.6666667, 0, 1, 0, 1, 0.50980395, 1)
|
|||
script = ExtResource("1_eovys")
|
||||
landSounds = Array[AudioStream]([ExtResource("3_land1"), ExtResource("4_land2"), ExtResource("5_land3")])
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=402647784]
|
||||
sprite_frames = ExtResource("5_4m0gv")
|
||||
animation = &"Moving"
|
||||
frame_progress = 0.92610025
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1511454314]
|
||||
texture = ExtResource("2_eovys")
|
||||
offset = Vector2(0, -6)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1379572123]
|
||||
shape = SubResource("CircleShape2D_eovys")
|
||||
|
||||
[node name="EdgeSensors" type="Node2D" parent="." unique_id=94721438]
|
||||
[node name="EdgeSensors" type="Node2D" parent="."]
|
||||
|
||||
[node name="LeftEdgeSensor" type="RayCast2D" parent="EdgeSensors" unique_id=1317329635]
|
||||
[node name="LeftEdgeSensor" type="RayCast2D" parent="EdgeSensors"]
|
||||
position = Vector2(-12, 0)
|
||||
target_position = Vector2(0, 14)
|
||||
|
||||
[node name="RightEdgeSensor" type="RayCast2D" parent="EdgeSensors" unique_id=655411504]
|
||||
[node name="RightEdgeSensor" type="RayCast2D" parent="EdgeSensors"]
|
||||
position = Vector2(12, 0)
|
||||
target_position = Vector2(0, 14)
|
||||
|
||||
[node name="SplatParticles" type="CPUParticles2D" parent="." unique_id=1885906440]
|
||||
[node name="SplatParticles" type="CPUParticles2D" parent="."]
|
||||
top_level = true
|
||||
emitting = false
|
||||
amount = 8
|
||||
lifetime = 0.4
|
||||
one_shot = true
|
||||
explosiveness = 1.0
|
||||
|
|
@ -46,14 +45,15 @@ spread = 55.0
|
|||
gravity = Vector2(0, 500)
|
||||
initial_velocity_min = 40.0
|
||||
initial_velocity_max = 90.0
|
||||
scale_amount_min = 1.0
|
||||
scale_amount_max = 2.0
|
||||
color_initial_ramp = SubResource("Gradient_splat")
|
||||
|
||||
[node name="LandSound" type="AudioStreamPlayer" parent="." unique_id=1069784417]
|
||||
[node name="LandSound" type="AudioStreamPlayer" parent="."]
|
||||
volume_db = -6.0
|
||||
bus = &"SFX"
|
||||
|
||||
[node name="WrapSound" type="AudioStreamPlayer" parent="." unique_id=89143697]
|
||||
[node name="WrapSound" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource("6_wrap")
|
||||
volume_db = -10.0
|
||||
bus = &"SFX"
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@
|
|||
position = Vector2(329, 266)
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="." unique_id=459516426]
|
||||
tile_map_data = PackedByteArray("AAABAA4AAAAEAAQAAAACAA4AAAAEAAQAAAADAA4AAAAEAAQAAAAEAA4AAAAEAAQAAAAFAA4AAAAEAAQAAAAGAA4AAAAEAAQAAAAHAA4AAAAEAAQAAAAIAA4AAAAEAAQAAAAJAA4AAAAEAAQAAAAKAA4AAAAEAAQAAAALAA4AAAAEAAQAAAAMAA4AAAAEAAQAAAANAA4AAAAEAAQAAAAOAA4AAAAEAAQAAAAPAA4AAAAEAAQAAAAQAA4AAAAEAAQAAAARAA4AAAAEAAQAAAAAAA4AAAAEAAQAAAASAA4AAAAEAAQAAAATAA4AAAAEAAQAAAATAA0AAAAEAAQAAAATAAwAAAAEAAQAAAATAAsAAAAEAAQAAAATAAoAAAAEAAQAAAATAAkAAAAEAAQAAAATAAgAAAAEAAQAAAATAAcAAAAEAAQAAAATAAYAAAAEAAQAAAATAAUAAAAEAAQAAAATAAQAAAAEAAQAAAATAAM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AAQAAAACAAkAAAAEAAQAAAADAAkAAAAEAAQAAAABAAYAAAAEAAQAAAACAAYAAAAEAAQAAAAFAAEAAAAEAAQAAAAFAAIAAAAEAAQAAAAFAAMAAAAEAAQAAAAFAAQAAAAEAAQAAAAEAAYAAAAEAAQAAAAFAAYAAAAEAAQAAAAGAAYAAAAEAAQAAAAHAAYAAAAEAAQAAAAKAAUAAAAEAAQAAAALAAUAAAAEAAQAAAAMAAUAAAAEAAQAAAANAAUAAAAEAAQAAAASAAMAAAAEAAQAAAARAAMAAAAEAAQAAAAQAAMAAAAEAAQAAAAPAAMAAAAEAAQAAAA=")
|
||||
tile_set = ExtResource("2_00vsl")
|
||||
|
||||
[node name="PauseMenu" parent="." unique_id=904032161 instance=ExtResource("3_pause")]
|
||||
visible = false
|
||||
|
||||
[node name="MusicPlayer" type="AudioStreamPlayer" parent="." unique_id=1203733461]
|
||||
volume_db = -20.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue