Pls test Jas
This commit is contained in:
42
snowmen_enemy_blue.gd
Normal file
42
snowmen_enemy_blue.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
onready var SNOWBALL_BLUE_SCENE = preload("res://snowball_blue.tscn")
|
||||
|
||||
var player = null
|
||||
var move = Vector2.ZERO
|
||||
var speed = 1
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
move = Vector2.ZERO
|
||||
|
||||
if player != null:
|
||||
move = position.direction_to(player.position) * speed
|
||||
else:
|
||||
move = Vector2.ZERO
|
||||
|
||||
move = move.normalized()
|
||||
move = move_and_collide(move)
|
||||
|
||||
|
||||
|
||||
func _on_Area2D_body_entered(body: Node) -> void:
|
||||
if body != self && !(body.name.begins_with("tree")) && !(body.name.begins_with("snowmen_enemy")):
|
||||
player = body
|
||||
|
||||
|
||||
func _on_Area2D_body_exited(body: Node) -> void:
|
||||
if !(body.name.begins_with("tree")) && !(body.name.begins_with("snowmen_enemy")):
|
||||
player = null
|
||||
|
||||
|
||||
func fire():
|
||||
var snowball = SNOWBALL_BLUE_SCENE.instance()
|
||||
snowball.position = get_global_position()
|
||||
snowball.player = player
|
||||
get_parent().add_child(snowball)
|
||||
$Timer.set_wait_time(1)
|
||||
|
||||
|
||||
func _on_Timer_timeout() -> void:
|
||||
if player != null:
|
||||
fire()
|
Reference in New Issue
Block a user