Better lava
This commit is contained in:
parent
4f70414ed9
commit
d0d7899340
82 changed files with 1747 additions and 738 deletions
|
@ -1,172 +1,8 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://c4x2fbs6bvxpp"]
|
||||
|
||||
[ext_resource type="Script" path="res://Player/BasicCharacter/CharacterController.gd" id="1_n3rkw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bl4g0ao3b8b6p" path="res://Player/BasicCharacter/sprite.tscn" id="2_mjdr3"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_nkjkv"]
|
||||
script/source = "extends CharacterBody2D
|
||||
|
||||
const SPEED = 400.0
|
||||
const ACCEL = 7.0
|
||||
var direction = 0
|
||||
var addedveloc = 0
|
||||
|
||||
const JUMP_VELOCITY = -450.0
|
||||
const MAX_JUMPS = 2
|
||||
var jumps = MAX_JUMPS
|
||||
|
||||
var wallKayote = 0
|
||||
|
||||
const FALL_SPEED = -JUMP_VELOCITY
|
||||
var falling = false
|
||||
|
||||
var floorTime = 0
|
||||
|
||||
var gravity = ProjectSettings.get_setting(\"physics/2d/default_gravity\")
|
||||
|
||||
func isWallSliding():
|
||||
return is_on_wall_only() and direction
|
||||
|
||||
func getGravMulti():
|
||||
var axis = (gen.boolToNumb(ghostInputHeld(\"up\"), 1))
|
||||
if velocity.y < 0:
|
||||
return axis
|
||||
return 1
|
||||
|
||||
func launch(veloc):
|
||||
addedveloc = veloc
|
||||
velocity.x = veloc
|
||||
|
||||
signal Jumped
|
||||
|
||||
func die():
|
||||
position = Vector2.ZERO
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
var ghostFrame = 0
|
||||
var startPos = Vector2.ZERO
|
||||
|
||||
@export var savedInputsPath : String
|
||||
var savedInputsRef = load(savedInputsPath)
|
||||
|
||||
var savedInputs = []
|
||||
|
||||
func ghostInputJustPressed(action):
|
||||
if action in savedInputs[ghostFrame] and not action in savedInputs[ghostFrame - 1]:
|
||||
return true
|
||||
return false
|
||||
func ghostInputHeld(action):
|
||||
if action in savedInputs[ghostFrame]:
|
||||
return true
|
||||
return false
|
||||
|
||||
func _ready():
|
||||
startPos = global_position
|
||||
var rc = load(savedInputsPath)
|
||||
|
||||
for x in rc:
|
||||
var dict = {}
|
||||
for y in x:
|
||||
dict[y] = x[y]
|
||||
savedInputs.append(dict)
|
||||
|
||||
|
||||
@onready var trail = $\"Sprite/Trail\"
|
||||
|
||||
var ghosting = true
|
||||
|
||||
func _physics_process(delta):
|
||||
if ghostFrame + 1 >= savedInputs.size():
|
||||
ghostFrame = 0
|
||||
global_position = startPos
|
||||
trail.points = []
|
||||
$Sprite.visible = false
|
||||
ghosting = false
|
||||
$SpawnParticles.emitting = true
|
||||
await get_tree().create_timer(3).timeout
|
||||
ghosting = true
|
||||
$Sprite.visible = true
|
||||
|
||||
if ghosting:
|
||||
if ghostFrame == 0:
|
||||
$SpawnParticles.emitting = true
|
||||
ghostFrame += 1
|
||||
direction = 0
|
||||
if ghostInputHeld(\"left\"):
|
||||
direction -= 1
|
||||
if ghostInputHeld(\"right\"):
|
||||
direction += 1
|
||||
|
||||
wallKayote -= delta
|
||||
|
||||
if not is_on_floor():
|
||||
if velocity.y < 2000:
|
||||
velocity.y += gravity * delta / getGravMulti()
|
||||
|
||||
floorTime = 0
|
||||
else:
|
||||
floorTime += delta
|
||||
jumps = MAX_JUMPS
|
||||
falling = false
|
||||
|
||||
if isWallSliding():
|
||||
wallKayote = 0.2
|
||||
falling = false
|
||||
|
||||
if ghostInputJustPressed(\"respawn\") or position.y > 5000:
|
||||
die()
|
||||
|
||||
if ghostInputJustPressed(\"jump\"):
|
||||
if wallKayote > 0 and not is_on_floor():
|
||||
wallKayote /= 2
|
||||
if ghostInputHeld(\"down\"):
|
||||
launch(get_wall_normal().x * SPEED * 2)
|
||||
velocity.y = JUMP_VELOCITY / 1.8
|
||||
else:
|
||||
launch(get_wall_normal().x * SPEED * 1.5)
|
||||
velocity.y = clamp(velocity.y + JUMP_VELOCITY, -INF, JUMP_VELOCITY)
|
||||
elif jumps > 0:
|
||||
Jumped.emit()
|
||||
velocity.y = clamp(velocity.y + JUMP_VELOCITY, -INF, JUMP_VELOCITY)
|
||||
jumps -= 1
|
||||
falling = false
|
||||
|
||||
if ghostInputJustPressed(\"down\") and not falling and not isWallSliding():
|
||||
falling = true
|
||||
velocity.y = clamp(velocity.y + FALL_SPEED, FALL_SPEED, INF)
|
||||
|
||||
if isWallSliding():
|
||||
var upDown = 0
|
||||
if ghostInputHeld(\"up\"):
|
||||
upDown -= 0.5
|
||||
if ghostInputHeld(\"down\"):
|
||||
upDown += 1
|
||||
var holdMulti = (upDown * 2) + 1
|
||||
velocity.y = lerpf(velocity.y, clamp(velocity.y, JUMP_VELOCITY, 100 * holdMulti), delta * 10)
|
||||
|
||||
var finalSpeed = clamp(abs(velocity.x), SPEED, INF)
|
||||
if floorTime > 0.05:
|
||||
finalSpeed = clamp(lerp(finalSpeed, SPEED, delta * 20), SPEED, INF)
|
||||
|
||||
velocity.x = lerp(velocity.x, direction * finalSpeed, delta * ACCEL)
|
||||
|
||||
if abs(velocity.x) < abs(addedveloc):
|
||||
addedveloc = lerp(addedveloc, velocity.x, ACCEL * 2 * delta)
|
||||
velocity.x += addedveloc * delta * 15
|
||||
|
||||
addedveloc = lerpf(addedveloc, 0, delta * 5)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func _process(delta):
|
||||
if velocity.length() > 5:
|
||||
trail.add_point(global_position)
|
||||
elif trail.get_point_count() > 0:
|
||||
trail.remove_point(0)
|
||||
|
||||
if trail.get_point_count() > 100:
|
||||
trail.remove_point(0)
|
||||
"
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_jbiem"]
|
||||
radius = 8.0
|
||||
|
||||
|
@ -207,7 +43,7 @@ scale_curve = SubResource("CurveTexture_ibtln")
|
|||
collision_layer = 3
|
||||
floor_stop_on_slope = false
|
||||
floor_snap_length = 3.0
|
||||
script = SubResource("GDScript_nkjkv")
|
||||
script = ExtResource("1_n3rkw")
|
||||
|
||||
[node name="BoxCollider" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_jbiem")
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue