moved enemy direction control and y axis to game controller, converted enemies to be staticBodies and made many of them
This commit is contained in:
1 parent
a563c0c93d
commit
3bf4b60989
3 files changed
+284
-14
No files matched your search
+11
-4
@@ -1,12 +1,19 @@
|
||||
class_name Enemy extends RigidBody2D
|
||||
class_name Enemy extends StaticBody2D
|
||||
# used StaticBody to get around gravity, probably a better way
|
||||
|
||||
# there is probably a better built-in to use here
|
||||
# there is probably a better built-in to use here, maybe not for static body
|
||||
@export var direction:int = 1
|
||||
const SPEED = 1
|
||||
var drop = false
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
pass
|
||||
|
||||
func go_down():
|
||||
drop = true
|
||||
|
||||
func _process(_delta):
|
||||
var x = get_transform().get_origin().x
|
||||
move_local_x(SPEED * direction)
|
||||
if drop:
|
||||
move_local_y(SPEED * 5)
|
||||
drop = false
|
||||
@@ -11,13 +11,15 @@ func _process(_delta):
|
||||
# detect when one enemy goes too far
|
||||
var change_dir = false
|
||||
for child in game_node.get_children():
|
||||
if child is RigidBody2D:
|
||||
if child is Enemy:
|
||||
var x = child.transform.get_origin().x
|
||||
if x < 0 or x > 300: # not using collision detection properly
|
||||
if x < 0 or x > 600: # not using collision detection properly
|
||||
change_dir = true
|
||||
break
|
||||
|
||||
# change directions of all enemies
|
||||
if change_dir:
|
||||
for child in game_node.get_children():
|
||||
if child is RigidBody2D:
|
||||
child.mydirection *= -1
|
||||
if child is Enemy:
|
||||
child.direction *= -1
|
||||
child.go_down()
|
||||
Reference in new issue
Block a user