|
|
|
|
Reply From: |
SnapCracklins |
Already solved it. I was referencing my global variables wrong.
They were messing up my signals.
The ENEMY object:
extends Area2D
ready sprite, timer, set a duration to adjust in editor
onready var anim = $AnimatedSprite
onready var timer = $Timer
export var duration = 2
bools to register hits and determine spawn status for animation control
var canHit = false
var isSpawned = false
signal emitted to current score to update total
signal hasPoints
signal loadMole
spawn animation on ready then spawn bool changes
timer begins for mole to “escape”
func _ready():
anim.play(‘spawn’)
yield(anim, “animation_finished”)
isSpawned = true
anim.play(‘idle’)
timer.wait_time = duration
timer.start()
this function emits a signal to the Score node
changes animation then frees itself and flips isSpawned state
func _dizzy_mole():
emit_signal(“hasPoints”)
emit_signal(“loadMole”)
anim.play(‘dizzy’)
yield(anim, “animation_finished”)
anim.play(‘drop’)
yield(anim, “animation_finished”)
isSpawned = false
queue_free()
if hammer is in area and swung, this signal fires
if it is not in area, it passes
func _on_Hammer_hammerTime():
if canHit == true:
canHit = false
anim.play(‘hit’)
yield(anim,“animation_finished”)
_dizzy_mole()
else:
pass
registers if hammer is in the area, validating hits
func _on_Moles_area_entered(area):
if area.name == “Hammer”:
canHit = true
register if hammer is not in the area, not validating hits
func _on_Moles_area_exited(area):
if area.name == “Hammer”:
canHit = false
“escape” function, hitbox deactivates, animation change, freed.
func _on_Timer_timeout():
$CollisionShape2D.disabled
emit_signal(“loadMole”)
anim.play(‘drop’)
yield(anim,“animation_finished”)
queue_free()
function to switch from spawn to idle animation
waits for spawn animation to finish and reads bool to change animation
func _on_AnimatedSprite_animation_finished():
if isSpawned == true:
anim.play(‘idle’)
else:
pass
THE PLAYER OBJECT:
extends Area2D
export move speed, default vector, prep sprite and signal
export var speed = 1000
var vec = Vector2(0,0)
onready var hammer = $Sprite
this signal will call when the hammer swings
and the enemy will observe it
signal hammerTime
movement command code, per frame
func _process(delta):
# hard code mouse location for no stutter
self.position.x = get_global_mouse_position().x # set position to x of mouse
self.position.y = get_global_mouse_position().y # set position to y of mouse
vec = vec.normalized() * delta * speed # normalize it and multiply by time and speed
position += vec # move by that vector
# on accept button, swing the hammer, emit swing signal and then return
func _input(event):
if Input.is_action_just_pressed(“ui_accept”):
hammer.set_rotation(200)
emit_signal(“hammerTime”)
if Input.is_action_just_released(“ui_accept”):
hammer.set_rotation(0)