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
|
||||
vframes = 2
|
||||
|
||||
[node name="Camera" type="Camera2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
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
|
||||
|
||||
@onready var tile_layer : TileMapLayer = $"../TileMapLayer"
|
||||
@onready var level : Node2D = $".."
|
||||
|
||||
@export_category("Movement")
|
||||
@export var acceleration : float = 50
|
||||
|
|
@ -8,9 +9,14 @@ extends CharacterBody2D
|
|||
@export var move_speed : float = 100
|
||||
|
||||
var move_input : float
|
||||
var dead : bool
|
||||
|
||||
func _ready() -> void:
|
||||
respawn()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
||||
if dead == false:
|
||||
#Horizontal movement.
|
||||
move_input = Input.get_axis("move_left", "move_right")
|
||||
if move_input != 0:
|
||||
|
|
@ -38,6 +44,25 @@ func spike_detection() -> void:
|
|||
if tile_data:
|
||||
var custom_data = tile_data.get_custom_data("spike")
|
||||
if custom_data == true:
|
||||
death()
|
||||
await get_tree().create_timer(1).timeout
|
||||
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
|
||||
get_tree().change_scene_to_file("res://Scenes/main.tscn")
|
||||
|
||||
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