Fix bullets miss continuously

This commit is contained in:
Moe Poi ~ 2023-10-17 00:12:44 +07:00
parent b8c0b6acac
commit 5503473e48
9 changed files with 55 additions and 43 deletions

View file

@ -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()

View file

@ -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():

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()