66 lines
1.4 KiB
GDScript
66 lines
1.4 KiB
GDScript
extends CharacterBody2D
|
|
|
|
@export var Speed = 2500
|
|
@export var FrictionMult = 5
|
|
|
|
@export var GUI : CanvasLayer
|
|
|
|
@onready var Sprite : Sprite2D = $Sprite2D
|
|
var SpriteTurningSpeed = 5
|
|
|
|
var ActiveContract : Node2D
|
|
|
|
@export var Money : int = 0
|
|
|
|
var Frozen = true
|
|
|
|
@onready var PackageSprite = $PackageSprite
|
|
|
|
@onready var Camera = $Camera2D
|
|
|
|
# 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:
|
|
|
|
if not Frozen:
|
|
|
|
var direction = Vector2(0,0)
|
|
|
|
if Input.is_action_pressed("up"):
|
|
direction.y -= 1
|
|
if Input.is_action_pressed("down"):
|
|
direction.y += 1
|
|
if Input.is_action_pressed("left"):
|
|
direction.x -= 1
|
|
if Input.is_action_pressed("right"):
|
|
direction.x += 1
|
|
|
|
direction = direction.normalized()
|
|
|
|
velocity += direction * Speed * delta
|
|
|
|
velocity = velocity.move_toward(Vector2(0,0), delta * clamp(velocity.length() * FrictionMult, 1000, 100000))
|
|
|
|
if velocity.length() > 0.1:
|
|
rotation = rotate_toward(rotation,velocity.angle(),delta*SpriteTurningSpeed)
|
|
|
|
if ActiveContract:
|
|
PackageSprite.show()
|
|
else:
|
|
PackageSprite.hide()
|
|
|
|
move_and_slide()
|
|
|
|
|
|
func _on_hitbox_body_entered(body: Node2D) -> void:
|
|
if body.is_in_group("hurt"):
|
|
kill()
|
|
|
|
func kill():
|
|
Money -= 2000
|
|
position = Vector2(0,0)
|