Added Objects

This commit is contained in:
Exobyt 2024-09-09 19:36:34 +02:00
parent eb11047456
commit 78dcaac886
11 changed files with 148 additions and 35 deletions

View file

@ -5,6 +5,8 @@ extends "res://scenes/game/entities/entity.gd"
@onready var animatedSprite = $AnimatedSprite2D
@onready var pickupArea = $PickupArea
var rollSpeed = maxSpeed * 5
const rollCooldown = 5.0
@ -14,6 +16,9 @@ var rolling = false
var canRoll = true
var carrying = false
var object = null
var lastDirection : Vector2
var lastdirectionVector : Vector2
@ -31,6 +36,17 @@ func _physics_process(delta: float) -> void:
lastdirectionVector = directionVector
if Input.is_action_just_pressed("ROLL") and lastDirection != Vector2.ZERO:
roll()
if Input.is_action_just_pressed("INTERACT"):
match carrying:
false:
if pickupArea.get_overlapping_areas() != []:
pickup(pickupArea.get_overlapping_areas()[0])
true:
dropObject()
#pickupArea.get_overlapping_areas()[0].pickup(self)
#print(pickupArea.get_overlapping_areas())
if rolling:
move(lastdirectionVector * speed, acceleration)
else:
@ -48,21 +64,12 @@ func move(newVelocity : Vector2, acc):
func roll():
if not rolling and canRoll:
dropObject()
canRoll = false
setSpeed(rollSpeed)
invincible = true
rolling = true
rollTimer.start(rollTime)
func _on_roll_timeout() -> void:
resetSpeed()
invincible = false
rolling = false
rollCooldownTimer.start(rollCooldown)
func _on_roll_cooldown_timer_timeout() -> void:
canRoll = true
func setAnimation():
if not rolling:
@ -76,3 +83,28 @@ func setAnimation():
animatedSprite.play("DOWN")
elif not (Input.is_action_pressed("MOVE_UP") or Input.is_action_pressed("MOVE_RIGHT") or Input.is_action_pressed("MOVE_DOWN") or Input.is_action_pressed("MOVE_LEFT")):
animatedSprite.play("IDLE")
func _on_roll_timeout() -> void:
resetSpeed()
invincible = false
rolling = false
rollCooldownTimer.start(rollCooldown)
func _on_roll_cooldown_timer_timeout() -> void:
canRoll = true
func pickup(newObject):
if newObject.player == null and not rolling:
carrying = true
object = newObject
speed -= object.getWeight()
object.pickup(self)
func dropObject():
if carrying:
carrying = false
object.drop()
object = null
resetSpeed()