diff --git a/scripts/bullets/bullet_1.gd b/scripts/bullets/bullet_1.gd index 67ff7cc..5952d2e 100644 --- a/scripts/bullets/bullet_1.gd +++ b/scripts/bullets/bullet_1.gd @@ -1,12 +1,14 @@ extends Area2D + const right = Vector2.RIGHT var speed : int = 0 var damage : int = 0 - +var dir = 0 + func _physics_process(delta): - var movement = right.rotated(rotation) * speed * delta - global_position += movement + var move_dir = Vector2(1,0).rotated(dir) + global_position += (move_dir * speed) func _on_VisibilityNotifier2D_screen_exited(): queue_free() diff --git a/scripts/enemies/enemy.gd b/scripts/enemies/enemy.gd index 5d462e9..06ef115 100644 --- a/scripts/enemies/enemy.gd +++ b/scripts/enemies/enemy.gd @@ -9,6 +9,9 @@ var reward: int = 0 var direction_progress = [] var direction = [] +var enemy_vol = Vector2(1,1) +var old_enemy_pos + func set_config(config_path): config = load(config_path).new() @@ -25,6 +28,9 @@ func set_direction(type: int): direction_progress.append(x['progress']) direction.append(x['direction']) +func _ready(): + old_enemy_pos = global_position + func _process(delta): update_healthbar() change_direction(get_progress()) @@ -32,6 +38,8 @@ func _process(delta): get_tree().current_scene.on_enemy_reward(reward) queue_free() set_progress(get_progress() + speed * delta) + enemy_vol = global_position - old_enemy_pos + old_enemy_pos = global_position func change_direction(current_progress): if !direction_progress.is_empty(): diff --git a/scripts/stages/1/config.gd b/scripts/stages/1/config.gd index c0a903c..4dbdb4d 100644 --- a/scripts/stages/1/config.gd +++ b/scripts/stages/1/config.gd @@ -69,7 +69,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -79,7 +79,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -89,7 +89,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -99,7 +99,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -109,7 +109,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -119,7 +119,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/stages/2/config.gd b/scripts/stages/2/config.gd index cd1bb4a..913133c 100644 --- a/scripts/stages/2/config.gd +++ b/scripts/stages/2/config.gd @@ -99,7 +99,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -109,7 +109,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -119,7 +119,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -129,7 +129,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -139,7 +139,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -149,7 +149,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/stages/3/config.gd b/scripts/stages/3/config.gd index b62fe18..62a30d4 100644 --- a/scripts/stages/3/config.gd +++ b/scripts/stages/3/config.gd @@ -81,7 +81,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -91,7 +91,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -101,7 +101,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -111,7 +111,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -121,7 +121,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -131,7 +131,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/stages/4/config.gd b/scripts/stages/4/config.gd index 31c62e5..2562a62 100644 --- a/scripts/stages/4/config.gd +++ b/scripts/stages/4/config.gd @@ -87,7 +87,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -97,7 +97,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -107,7 +107,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -117,7 +117,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -127,7 +127,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -137,7 +137,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/stages/5/config.gd b/scripts/stages/5/config.gd index edb220f..6ed3426 100644 --- a/scripts/stages/5/config.gd +++ b/scripts/stages/5/config.gd @@ -87,7 +87,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -97,7 +97,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -107,7 +107,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -117,7 +117,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -127,7 +127,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -137,7 +137,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/stages/6/config.gd b/scripts/stages/6/config.gd index a3080e7..322455b 100644 --- a/scripts/stages/6/config.gd +++ b/scripts/stages/6/config.gd @@ -129,7 +129,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 30, "health": 100, "durability_reduction": 10 @@ -139,7 +139,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_1.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -149,7 +149,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -159,7 +159,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_2.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -169,7 +169,7 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 @@ -179,7 +179,7 @@ var tower = [ "asset": preload("res://scenes/towers/railgun_3.tscn"), "bullet": preload("res://scenes/bullets/bullet_1.tscn"), "timer": 1, - "speed": 200, + "speed": 3, "damage": 40, "health": 100, "durability_reduction": 10 diff --git a/scripts/towers/tower.gd b/scripts/towers/tower.gd index 7578411..68f09ad 100644 --- a/scripts/towers/tower.gd +++ b/scripts/towers/tower.gd @@ -48,7 +48,8 @@ func _physics_process(_delta): if enemies.is_empty(): $AnimatedSprite2D.stop() else: - _update_look_at(enemies[0].global_position) + var distance = global_position.distance_to(enemies[0].global_position) + _update_look_at(enemies[0].global_position + enemies[0].enemy_vol * (distance / speed)) if timer.is_stopped(): $AnimatedSprite2D.play("default") _shoot() @@ -56,11 +57,12 @@ func _physics_process(_delta): func _shoot(): if bullet: var bullet_instance: Node2D = bullet.instantiate() - get_tree().current_scene.add_child(bullet_instance) + bullet_instance.dir = rotation + bullet_instance.rotation = rotation + bullet_instance.global_position = global_position bullet_instance.speed = speed bullet_instance.damage = damage - bullet_instance.global_position = global_position - bullet_instance.global_rotation = rayCast.global_rotation + 0.1 + get_tree().current_scene.add_child(bullet_instance) health -= durability_reduction timer.start()