Added in various comfort features, animated deaths, camera smooth scrolling.
This commit is contained in:
parent
60e043e812
commit
7103aba274
7 changed files with 69 additions and 18 deletions
File diff suppressed because one or more lines are too long
|
|
@ -14,7 +14,5 @@ texture = ExtResource("2_6t5aa")
|
||||||
hframes = 2
|
hframes = 2
|
||||||
vframes = 2
|
vframes = 2
|
||||||
|
|
||||||
[node name="Camera" type="Camera2D" parent="."]
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("RectangleShape2D_jjgbg")
|
shape = SubResource("RectangleShape2D_jjgbg")
|
||||||
|
|
|
||||||
4
Scripts/Levels/main.gd
Normal file
4
Scripts/Levels/main.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var startPosX : int = 40
|
||||||
|
var startPosY : int = 328
|
||||||
1
Scripts/Levels/main.gd.uid
Normal file
1
Scripts/Levels/main.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://b228yv3gle864
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
@onready var tile_layer : TileMapLayer = $"../TileMapLayer"
|
@onready var tile_layer : TileMapLayer = $"../TileMapLayer"
|
||||||
|
@onready var level : Node2D = $".."
|
||||||
|
|
||||||
@export_category("Movement")
|
@export_category("Movement")
|
||||||
@export var acceleration : float = 50
|
@export var acceleration : float = 50
|
||||||
|
|
@ -8,21 +9,26 @@ extends CharacterBody2D
|
||||||
@export var move_speed : float = 100
|
@export var move_speed : float = 100
|
||||||
|
|
||||||
var move_input : float
|
var move_input : float
|
||||||
|
var dead : bool
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
respawn()
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
|
||||||
#Horizontal movement.
|
if dead == false:
|
||||||
move_input = Input.get_axis("move_left", "move_right")
|
#Horizontal movement.
|
||||||
if move_input != 0:
|
move_input = Input.get_axis("move_left", "move_right")
|
||||||
velocity.x = lerp(velocity.x, move_input * move_speed, acceleration * delta)
|
if move_input != 0:
|
||||||
else:
|
velocity.x = lerp(velocity.x, move_input * move_speed, acceleration * delta)
|
||||||
velocity.x = lerp(velocity.x, 0.0, braking * delta)
|
else:
|
||||||
|
velocity.x = lerp(velocity.x, 0.0, braking * delta)
|
||||||
|
|
||||||
|
#Vertical movement.
|
||||||
|
velocity.y += al_globals.gravity * delta
|
||||||
|
|
||||||
#Vertical movement.
|
if Input.is_action_just_pressed("flip") and (is_on_floor() or is_on_ceiling()):
|
||||||
velocity.y += al_globals.gravity * delta
|
al_globals.gravity *= -1
|
||||||
|
|
||||||
if Input.is_action_just_pressed("flip") and (is_on_floor() or is_on_ceiling()):
|
|
||||||
al_globals.gravity *= -1
|
|
||||||
|
|
||||||
move_and_slide() #Allow physics control.
|
move_and_slide() #Allow physics control.
|
||||||
spike_detection() #Checks for tiles with the "Spike" custom data enabled.
|
spike_detection() #Checks for tiles with the "Spike" custom data enabled.
|
||||||
|
|
@ -38,6 +44,25 @@ func spike_detection() -> void:
|
||||||
if tile_data:
|
if tile_data:
|
||||||
var custom_data = tile_data.get_custom_data("spike")
|
var custom_data = tile_data.get_custom_data("spike")
|
||||||
if custom_data == true:
|
if custom_data == true:
|
||||||
if al_globals.gravity < 0:
|
death()
|
||||||
al_globals.gravity *= -1
|
await get_tree().create_timer(1).timeout
|
||||||
get_tree().change_scene_to_file("res://Scenes/main.tscn")
|
respawn()
|
||||||
|
|
||||||
|
|
||||||
|
func death() -> void:
|
||||||
|
dead = true
|
||||||
|
velocity.x = 0
|
||||||
|
velocity.y = 0
|
||||||
|
scale.x = lerp(scale.x, 0.0, 0.1)
|
||||||
|
scale.y = lerp(scale.y, 0.0, 0.1)
|
||||||
|
if al_globals.gravity < 0:
|
||||||
|
al_globals.gravity *= -1
|
||||||
|
|
||||||
|
func respawn() -> void:
|
||||||
|
dead = false
|
||||||
|
scale.x = lerp(scale.x, 1.0, 0.1)
|
||||||
|
scale.y = lerp(scale.y, 1.0, 0.1)
|
||||||
|
position.x = level.startPosX
|
||||||
|
position.y = level.startPosY
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
14
Scripts/player_camera.gd
Normal file
14
Scripts/player_camera.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
extends Camera2D
|
||||||
|
|
||||||
|
@onready var player : CharacterBody2D = $"../Player"
|
||||||
|
|
||||||
|
@export var camera_speed : float = 6.0
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
position.x = lerp(position.x, player.position.x, camera_speed * delta)
|
||||||
|
position.y = lerp(position.y, player.position.y, camera_speed * delta)
|
||||||
1
Scripts/player_camera.gd.uid
Normal file
1
Scripts/player_camera.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://de1fdvk35epdt
|
||||||
Loading…
Add table
Reference in a new issue