35 lines
883 B
GDScript
35 lines
883 B
GDScript
extends CharacterBody2D
|
|
|
|
@export var gravity: float = 300
|
|
@export var move_speed: float = 120
|
|
@export var Hüpfen_inpuls: float = 340
|
|
|
|
func _physics_process(delta):
|
|
velocity.y = velocity.y + gravity *delta
|
|
velocity.y += gravity * delta
|
|
velocity.x = 0
|
|
if Input.is_action_pressed("move_left"):
|
|
velocity.x -= move_speed
|
|
if Input.is_action_pressed("move_right"):
|
|
velocity.x += move_speed
|
|
velocity.x += $"../Control/left/Joystick".posVector.x*move_speed
|
|
if Input.is_action_pressed("Hüpfen"):
|
|
jump()
|
|
move_and_slide()
|
|
|
|
|
|
|
|
func jump():
|
|
if is_on_floor():
|
|
velocity.y -= Hüpfen_inpuls
|
|
|
|
func die():
|
|
# sterben
|
|
$"../Charakter".global_position = $"../RespawnMarker".global_position
|
|
|
|
func _on_area_2d_area_entered(area: Area2D) -> void:
|
|
# Falls die Playerhitbox eine are betritt
|
|
if area.is_in_group("die"):
|
|
# Ist die Area in der "die" Gruppe?
|
|
# dann stirb!!!
|
|
die()
|