Implemented win/lose scenes and added fire spinner trap
This commit is contained in:
55
Levels/Traps/Fire Spinner.gd
Normal file
55
Levels/Traps/Fire Spinner.gd
Normal file
@@ -0,0 +1,55 @@
|
||||
extends StaticBody2D
|
||||
|
||||
export var glowing_fireball: PackedScene
|
||||
|
||||
var player: KinematicBody2D = null
|
||||
var center: Vector2
|
||||
var shoot_directions: Array
|
||||
var rotated_shoot_directions: Array
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
center = $Sprite.global_position
|
||||
shoot_directions = [
|
||||
Vector2(center.x - 1, center.y),
|
||||
Vector2(center.x + 1, center.y),
|
||||
Vector2(center.x, center.y - 1),
|
||||
Vector2(center.x, center.y + 1)]
|
||||
rotated_shoot_directions = [
|
||||
Vector2(center.x - 1, center.y - 1),
|
||||
Vector2(center.x + 1, center.y + 1),
|
||||
Vector2(center.x + 1, center.y - 1),
|
||||
Vector2(center.x - 1, center.y + 1)]
|
||||
return
|
||||
|
||||
|
||||
func _on_spinner_timeout():
|
||||
$Sprite.set_rotation_degrees($Sprite.get_rotation_degrees() + 45)
|
||||
return
|
||||
|
||||
|
||||
func _on_shoot_timeout():
|
||||
if player:
|
||||
var shoot_array: Array
|
||||
if int($Sprite.get_rotation_degrees()) % 90 == 0:
|
||||
shoot_array = shoot_directions
|
||||
else:
|
||||
shoot_array = rotated_shoot_directions
|
||||
|
||||
for itr in shoot_array:
|
||||
var projectile: Node = glowing_fireball.instance()
|
||||
projectile.init(center, itr)
|
||||
get_tree().get_current_scene().get_node('Projectiles').add_child(projectile)
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_body_entered(body: Node) -> void:
|
||||
if body.is_in_group('player'):
|
||||
player = body
|
||||
return
|
||||
|
||||
|
||||
func _on_player_detector_body_exited(body: Node) -> void:
|
||||
if body.is_in_group('player'):
|
||||
player = null
|
||||
return
|
Reference in New Issue
Block a user