Second Prototype; Added Player Animations
This commit is contained in:
parent
51774f485b
commit
e82438139f
13 changed files with 332 additions and 73 deletions
|
|
@ -7,6 +7,11 @@ extends "res://scenes/game/entities/entity.gd"
|
|||
|
||||
@onready var pickupArea = $PickupArea
|
||||
|
||||
@onready var healthBar = $Camera2D/CanvasLayer/Control/VBoxContainer/HealthBar
|
||||
@onready var rollCooldownBar = $Camera2D/CanvasLayer/Control/VBoxContainer/RollCooldownBar
|
||||
@onready var moneyValueLabel = $Camera2D/CanvasLayer/Control/HBoxContainer/MoneyValue
|
||||
|
||||
|
||||
var rollSpeed = maxSpeed * 5
|
||||
|
||||
const rollCooldown = 5.0
|
||||
|
|
@ -22,7 +27,17 @@ var object = null
|
|||
var lastDirection : Vector2
|
||||
var lastdirectionVector : Vector2
|
||||
|
||||
func _ready():
|
||||
rollCooldownBar.min_value = 0
|
||||
rollCooldownBar.max_value = rollCooldown
|
||||
healthBar.min_value = 0
|
||||
healthBar.max_value = health
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
rollCooldownBar.value = rollCooldownTimer.time_left
|
||||
healthBar.value = health
|
||||
moneyValueLabel.text = str(G.money)
|
||||
|
||||
var direction : Vector2 = Input.get_vector("MOVE_LEFT", "MOVE_RIGHT", "MOVE_UP", "MOVE_DOWN").normalized()
|
||||
#var direction : Vector2 = Vector2(
|
||||
|
|
@ -39,8 +54,9 @@ func _physics_process(delta: float) -> void:
|
|||
if Input.is_action_just_pressed("INTERACT"):
|
||||
match carrying:
|
||||
false:
|
||||
if pickupArea.get_overlapping_areas() != []:
|
||||
pickup(pickupArea.get_overlapping_areas()[0])
|
||||
|
||||
|
||||
pickup(getNearestObject(pickupArea.get_overlapping_areas()))
|
||||
true:
|
||||
dropObject()
|
||||
#pickupArea.get_overlapping_areas()[0].pickup(self)
|
||||
|
|
@ -74,33 +90,40 @@ func roll():
|
|||
func setAnimation():
|
||||
if not rolling:
|
||||
if Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT") and animatedSprite.animation != "LEFT":
|
||||
animatedSprite.play("LEFT")
|
||||
animatedSprite.play("SIDE")
|
||||
animatedSprite.flip_h = true
|
||||
elif Input.is_action_pressed("MOVE_RIGHT") and not Input.is_action_pressed("MOVE_LEFT") and animatedSprite.animation != "RIGHT":
|
||||
animatedSprite.play("RIGHT")
|
||||
elif Input.is_action_pressed("MOVE_UP") and animatedSprite.animation != "UP" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
|
||||
animatedSprite.play("SIDE")
|
||||
animatedSprite.flip_h = false
|
||||
elif Input.is_action_pressed("MOVE_UP") and not Input.is_action_pressed("MOVE_DOWN") and animatedSprite.animation != "UP" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
|
||||
animatedSprite.play("UP")
|
||||
elif Input.is_action_pressed("MOVE_DOWN") and animatedSprite.animation != "DOWN" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
|
||||
elif Input.is_action_pressed("MOVE_DOWN") and not Input.is_action_pressed("MOVE_UP") and animatedSprite.animation != "DOWN" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
|
||||
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")):
|
||||
elif not animatedSprite.animation == "Ball" and 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")
|
||||
|
||||
animatedSprite.flip_h = false
|
||||
elif animatedSprite.animation != "Ball":
|
||||
animatedSprite.play("Ball")
|
||||
|
||||
func _on_roll_timeout() -> void:
|
||||
animatedSprite.play_backwards("Ball")
|
||||
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)
|
||||
if newObject != null:
|
||||
if newObject.player == null and not rolling:
|
||||
carrying = true
|
||||
object = newObject
|
||||
speed -= object.getWeight()
|
||||
object.pickup(self)
|
||||
|
||||
func dropObject():
|
||||
if carrying:
|
||||
|
|
@ -108,3 +131,16 @@ func dropObject():
|
|||
object.drop()
|
||||
object = null
|
||||
resetSpeed()
|
||||
|
||||
func getNearestObject(list):
|
||||
var nearestObject = null
|
||||
var shortestDistance = 0
|
||||
if list != []:
|
||||
for i in list:
|
||||
if nearestObject == null:
|
||||
shortestDistance = global_position.distance_to(i.global_position)
|
||||
nearestObject = i
|
||||
elif shortestDistance > global_position.distance_to(i.global_position):
|
||||
shortestDistance = global_position.distance_to(i.global_position)
|
||||
nearestObject = i
|
||||
return nearestObject
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue