forked from team-sg/hero-mark-2
first commit
This commit is contained in:
commit
096ebe5aa4
275 changed files with 3937 additions and 0 deletions
52
objects/enemy/enemy_move_sidesideupdown.gd
Normal file
52
objects/enemy/enemy_move_sidesideupdown.gd
Normal file
|
@ -0,0 +1,52 @@
|
|||
extends Node2D
|
||||
|
||||
#How far to move
|
||||
export var left_up_boundry = 0.0
|
||||
export var right_down_boundry = 0.0
|
||||
#Start direction
|
||||
export var direction = 1
|
||||
export var speed = 50
|
||||
#Move horizontal or vertical
|
||||
export(int, "Horizontal", "Vertical") var move_direction
|
||||
export var flip_sprite = true
|
||||
export var can_be_killed_by_sword = true
|
||||
#Onreadys
|
||||
onready var startpos = position
|
||||
onready var sprite = $AnimatedSprite
|
||||
|
||||
func _physics_process(delta):
|
||||
if move_direction == 0:
|
||||
move_side_to_side(delta)
|
||||
else: move_up_and_down(delta)
|
||||
|
||||
func move_side_to_side(delta):
|
||||
#Move
|
||||
position.x += direction * (speed * delta)
|
||||
#Switch dir
|
||||
if position.x >= startpos.x + (right_down_boundry * 8):
|
||||
direction = -1
|
||||
if flip_sprite == true: sprite.scale.x = -1
|
||||
if position.x <= startpos.x + (-left_up_boundry * 8):
|
||||
direction = 1
|
||||
if flip_sprite == true: sprite.scale.x = 1
|
||||
|
||||
func move_up_and_down(delta):
|
||||
#Move
|
||||
position.y += direction * (speed * delta)
|
||||
#Switch dir
|
||||
if position.y >= startpos.y + (right_down_boundry * 8):
|
||||
direction = -1
|
||||
if flip_sprite == true: sprite.scale.y = 1
|
||||
if position.y <= startpos.y + (-left_up_boundry * 8):
|
||||
direction = 1
|
||||
if flip_sprite == true: sprite.scale.y = -1
|
||||
|
||||
|
||||
func _on_Area2D_area_entered(area):
|
||||
#Kill player
|
||||
if area.is_in_group("player"):
|
||||
area.get_parent().die()
|
||||
#Die from sword
|
||||
if area.is_in_group("sword"):
|
||||
if can_be_killed_by_sword:
|
||||
queue_free()
|
Loading…
Add table
Add a link
Reference in a new issue