aboutsummaryrefslogtreecommitdiff
path: root/entities/player/Player.gd
diff options
context:
space:
mode:
Diffstat (limited to 'entities/player/Player.gd')
-rw-r--r--entities/player/Player.gd35
1 files changed, 20 insertions, 15 deletions
diff --git a/entities/player/Player.gd b/entities/player/Player.gd
index 6087221..ff11b18 100644
--- a/entities/player/Player.gd
+++ b/entities/player/Player.gd
@@ -5,17 +5,18 @@ export (int) var jump_speed = -400
export (int) var gravity = 1200
export var entity_type = "PLAYER"
export (int) var health = 90
-var hurt = false
-
+export (int) var total_apples_need = 0
+var total_apples_collected = 0
var velocity = Vector2()
var jumping = false
onready var sprite = $AnimatedSprite
+onready var state_machine = $AnimationTree.get("parameters/playback")
var facing_right = true
func get_input():
velocity.x = 0
var right = Input.is_action_pressed('right')
var left = Input.is_action_pressed('left')
- var jump = Input.is_action_just_pressed('jump')
+ var jump = Input.is_action_pressed('jump')
if facing_right == true:
sprite.flip_h = false
@@ -29,33 +30,37 @@ func get_input():
if right:
velocity.x += run_speed
facing_right = true
- play_animation("run")
+ state_machine.travel("run")
elif left:
velocity.x -= run_speed
facing_right = false
- play_animation("run")
- else:
- play_animation("idle")
+ state_machine.travel("run")
+
+ if velocity.length() == 0:
+ state_machine.travel("idle")
if !jumping && !is_on_floor():
- play_animation("jump")
+ state_machine.travel("jump")
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
if jumping and is_on_floor():
jumping = false
+ if total_apples_collected==total_apples_need:
+ SignalBus.emit_signal("open_level_door",true)
velocity = move_and_slide(velocity, Vector2(0, -1))
+ print("Total Apples Needed",total_apples_need)
-func _on_enemyHit(health):
- hurt = true
- play_animation("hit")
+func _on_enemyHit(_health):
+ state_machine.travel("hit")
+
+func _on_apples_collected(apple_count):
+ total_apples_collected += apple_count
func _ready() -> void:
SignalBus.connect("on_hit", self, "_on_enemyHit")
+ SignalBus.connect("on_apples_collected", self, "_on_apples_collected")
func play_animation(animation_name):
- if $AnimatedSprite.get_animation()!=animation_name :
- #$AnimatedSprite.play(animation_name)
- #$AnimatedSprite/AnimationPlayer.stop()
- $AnimatedSprite/AnimationPlayer.play(animation_name)
+ pass