diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index bb677b3..5b8c5b8 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -3,14 +3,9 @@ extends EnemyClass var velocity = Vector2.ZERO var speed = 64 -onready var player = $"../../Player" - func _ready(): hp = 15 - -func _process(delta): - $Sprite.flip_h = true if player.global_position.x > self.global_position.x else false - + func _physics_process(_delta): var player_position = player.global_position + Vector2(12, 12) var angle = get_angle_to(player_position) diff --git a/src/models/enemies/ghost/Ghost.tscn b/src/models/enemies/ghost/Ghost.tscn index df33a2d..3dd4272 100644 --- a/src/models/enemies/ghost/Ghost.tscn +++ b/src/models/enemies/ghost/Ghost.tscn @@ -25,7 +25,7 @@ flip_h = true use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 1 +frame = 2 playing = true centered = false diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd index ec83f80..ef78a18 100644 --- a/src/models/enemies/ghost/ghost.gd +++ b/src/models/enemies/ghost/ghost.gd @@ -1,6 +1,5 @@ extends EnemyClass -onready var player = $"../../Player" var dash_target = Vector2.ZERO var afterdash_timer = .0 var afterdash = false diff --git a/src/models/enemies/rat/rat.gd b/src/models/enemies/rat/rat.gd index 2c71200..1e2ba26 100644 --- a/src/models/enemies/rat/rat.gd +++ b/src/models/enemies/rat/rat.gd @@ -1,14 +1,10 @@ extends EnemyClass -onready var player = $"../../Player" var velocity = Vector2.ZERO var speed = 24 func _ready(): hp = 15 -func _process(delta): - $Sprite.flip_h = true if player.global_position.x > self.global_position.x else false - func _physics_process(delta): global_position = global_position.move_toward(player.global_position + Vector2(8, 8), speed * delta * speed_multiplier) diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd index 685a880..d86a330 100644 --- a/src/scenes/game/game.gd +++ b/src/scenes/game/game.gd @@ -12,6 +12,7 @@ var mob_timers = [.0, .0, .0, .0] var mob_threshold = [5, 7, 10, 7] func _ready(): + Global.playing = true Global.play_time = .0 Global.health = 3 Global.add_health(0) diff --git a/src/scripts/enemy_class.gd b/src/scripts/enemy_class.gd index 424fbb1..83fdcc6 100644 --- a/src/scripts/enemy_class.gd +++ b/src/scripts/enemy_class.gd @@ -1,5 +1,6 @@ extends KinematicBody2D +onready var player = $"../../Player" var empty_material = load("res://res/shaders/empty_material.tscn") var hp var dead = false @@ -21,6 +22,11 @@ func deal_damage(amount): if hp <= 0: death() +func _process(delta): + if Global.playing and not dead and is_in_group("enemy"): + player = get_tree().get_root().get_node("Game/View/Player") + $Sprite.flip_h = true if player.global_position.x > self.global_position.x else false + func death(): dead = true $Sprite.playing = false @@ -34,8 +40,8 @@ func _physics_process(delta): if dead: self.global_position = death_position dead_timer += delta - $Sprite.modulate.a = 1 - (dead_timer / 2) - if dead_timer >= 2.0: + $Sprite.modulate.a = 1 - (dead_timer * 2) + if dead_timer >= 0.5: self.call_deferred("free") if poisoned: diff --git a/src/scripts/global.gd b/src/scripts/global.gd index f7e617a..b46bfd2 100644 --- a/src/scripts/global.gd +++ b/src/scripts/global.gd @@ -3,12 +3,11 @@ extends Node var GAME_SCENE = preload("res://src/scenes/game/Game.tscn") var MENU_SCENE = preload("res://src/scenes/menu/Menu.tscn") -var playing = true +var playing = false var play_time = .0 var health = 2 func game_start(): - playing = true get_tree().change_scene_to(GAME_SCENE) func return_to_menu():