diff --git a/game/entities/ships/abstract_ship.gd b/game/entities/ships/abstract_ship.gd index 3f240e6..5b97581 100644 --- a/game/entities/ships/abstract_ship.gd +++ b/game/entities/ships/abstract_ship.gd @@ -2,15 +2,15 @@ class_name AbstractShip extends CharacterBody2D -const CANNON = preload("res://game/entities/weapons/cannon/cannon.tscn") -const GATLING = preload("res://game/entities/weapons/gatling/gatling.tscn") -const LASER = preload("res://game/entities/weapons/laser/laser.tscn") -const LAUNCHER = preload("res://game/entities/weapons/launcher/launcher.tscn") -const MINELAYER = preload("res://game/entities/weapons/minelayer/minelayer.tscn") -const PLASMA = preload("res://game/entities/weapons/plasma/plasma.tscn") -const RAILGUN = preload("res://game/entities/weapons/railgun/railgun.tscn") -const SHRAPNEL = preload("res://game/entities/weapons/shrapnel/shrapnel.tscn") -const TESLA = preload("res://game/entities/weapons/tesla/tesla.tscn") +const CANNON = preload("res://game/entities/weapons/cannon/cannon_weapon.tscn") +const GATLING = preload("res://game/entities/weapons/gatling/gatling_weapon.tscn") +const LASER = preload("res://game/entities/weapons/laser/laser_weapon.tscn") +const LAUNCHER = preload("res://game/entities/weapons/launcher/launcher_weapon.tscn") +const MINELAYER = preload("res://game/entities/weapons/minelayer/minelayer_weapon.tscn") +const PLASMA = preload("res://game/entities/weapons/plasma/plasma_weapon.tscn") +const RAILGUN = preload("res://game/entities/weapons/railgun/railgun_weapon.tscn") +const SHRAPNEL = preload("res://game/entities/weapons/shrapnel/shrapnel_weapon.tscn") +const TESLA = preload("res://game/entities/weapons/tesla/tesla_weapon.tscn") const WEAPONS := [ CANNON, GATLING, LASER, diff --git a/game/entities/weapons/abstract_projectile.gd b/game/entities/weapons/abstract_projectile.gd index cb5b98d..35c4082 100644 --- a/game/entities/weapons/abstract_projectile.gd +++ b/game/entities/weapons/abstract_projectile.gd @@ -78,7 +78,7 @@ func _process_hit_for_projectile(_collided_body: Node2D) -> void: queue_free() -func _get_nearest_foe(filter: Array[AbstractShip]) -> AbstractShip: +func _get_nearest_foe(filter: Array[AbstractShip] = []) -> AbstractShip: var nearest_foe : AbstractShip = null var minimal_distance := 1000000 @@ -91,7 +91,7 @@ func _get_nearest_foe(filter: Array[AbstractShip]) -> AbstractShip: return nearest_foe -func _get_foes(filter: Array[AbstractShip]) -> Array[AbstractShip]: +func _get_foes(filter: Array[AbstractShip] = []) -> Array[AbstractShip]: var foes : Array[AbstractShip] = [] var flags_by_group : Dictionary[String, bool] = { diff --git a/game/entities/weapons/cannon/cannon.gd b/game/entities/weapons/cannon/cannon_weapon.gd similarity index 100% rename from game/entities/weapons/cannon/cannon.gd rename to game/entities/weapons/cannon/cannon_weapon.gd diff --git a/game/entities/weapons/cannon/cannon.gd.uid b/game/entities/weapons/cannon/cannon_weapon.gd.uid similarity index 100% rename from game/entities/weapons/cannon/cannon.gd.uid rename to game/entities/weapons/cannon/cannon_weapon.gd.uid diff --git a/game/entities/weapons/cannon/cannon.tscn b/game/entities/weapons/cannon/cannon_weapon.tscn similarity index 94% rename from game/entities/weapons/cannon/cannon.tscn rename to game/entities/weapons/cannon/cannon_weapon.tscn index 187029d..bfca469 100644 --- a/game/entities/weapons/cannon/cannon.tscn +++ b/game/entities/weapons/cannon/cannon_weapon.tscn @@ -2,7 +2,7 @@ [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_xnbws"] [ext_resource type="PackedScene" uid="uid://cgi7wd84kjnyw" path="res://game/entities/weapons/cannon/cannon_projectile.tscn" id="2_2bjeu"] -[ext_resource type="Script" uid="uid://db24dm76b1am7" path="res://game/entities/weapons/cannon/cannon.gd" id="2_ew5um"] +[ext_resource type="Script" uid="uid://db24dm76b1am7" path="res://game/entities/weapons/cannon/cannon_weapon.gd" id="2_ew5um"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_7e2aj"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_bv8g1"] diff --git a/game/entities/weapons/gatling/gatling.gd b/game/entities/weapons/gatling/gatling_weapon.gd similarity index 100% rename from game/entities/weapons/gatling/gatling.gd rename to game/entities/weapons/gatling/gatling_weapon.gd diff --git a/game/entities/weapons/gatling/gatling.gd.uid b/game/entities/weapons/gatling/gatling_weapon.gd.uid similarity index 100% rename from game/entities/weapons/gatling/gatling.gd.uid rename to game/entities/weapons/gatling/gatling_weapon.gd.uid diff --git a/game/entities/weapons/gatling/gatling.tscn b/game/entities/weapons/gatling/gatling_weapon.tscn similarity index 95% rename from game/entities/weapons/gatling/gatling.tscn rename to game/entities/weapons/gatling/gatling_weapon.tscn index e130b4d..7a5fb45 100644 --- a/game/entities/weapons/gatling/gatling.tscn +++ b/game/entities/weapons/gatling/gatling_weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=9 format=3 uid="uid://c4mlppn5i55bp"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_gblx7"] -[ext_resource type="Script" uid="uid://c1bsvmj7xhnxe" path="res://game/entities/weapons/gatling/gatling.gd" id="1_kg6du"] +[ext_resource type="Script" uid="uid://c1bsvmj7xhnxe" path="res://game/entities/weapons/gatling/gatling_weapon.gd" id="1_kg6du"] [ext_resource type="PackedScene" uid="uid://yfvluap3uy1r" path="res://game/entities/weapons/gatling/gatling_projectile.tscn" id="2_ylc0n"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_uucc4"] [ext_resource type="Script" uid="uid://oslebeau3f4b" path="res://game/reloaders/gatling_reloader.gd" id="4_g81jq"] diff --git a/game/entities/weapons/laser/laser.gd b/game/entities/weapons/laser/laser_weapon.gd similarity index 100% rename from game/entities/weapons/laser/laser.gd rename to game/entities/weapons/laser/laser_weapon.gd diff --git a/game/entities/weapons/laser/laser.gd.uid b/game/entities/weapons/laser/laser_weapon.gd.uid similarity index 100% rename from game/entities/weapons/laser/laser.gd.uid rename to game/entities/weapons/laser/laser_weapon.gd.uid diff --git a/game/entities/weapons/laser/laser.tscn b/game/entities/weapons/laser/laser_weapon.tscn similarity index 95% rename from game/entities/weapons/laser/laser.tscn rename to game/entities/weapons/laser/laser_weapon.tscn index 45b40c7..ae5403b 100644 --- a/game/entities/weapons/laser/laser.tscn +++ b/game/entities/weapons/laser/laser_weapon.tscn @@ -2,7 +2,7 @@ [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_pki4x"] [ext_resource type="PackedScene" uid="uid://cmni0xrbbfcy5" path="res://game/entities/weapons/laser/laser_projectile.tscn" id="2_fecho"] -[ext_resource type="Script" uid="uid://bxr150at8ul2a" path="res://game/entities/weapons/laser/laser.gd" id="2_lbdvb"] +[ext_resource type="Script" uid="uid://bxr150at8ul2a" path="res://game/entities/weapons/laser/laser_weapon.gd" id="2_lbdvb"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_c1wcw"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_cl0br"] [ext_resource type="Script" uid="uid://dxk56xdihfw4m" path="res://game/reloaders/energy_reloader.gd" id="5_l3tgo"] diff --git a/game/entities/weapons/launcher/launcher_projectile.gd b/game/entities/weapons/launcher/launcher_projectile.gd index 786d126..34abdef 100644 --- a/game/entities/weapons/launcher/launcher_projectile.gd +++ b/game/entities/weapons/launcher/launcher_projectile.gd @@ -25,27 +25,30 @@ func _physics_process(delta: float) -> void: func _acquire_target() -> void: - target = _get_nearest_foe([]) + target = _get_nearest_foe() func _apply_homing_guidance(delta: float) -> void: if not target: return - var max_rotation_speed := deg_to_rad(rotation_speed) * delta + var max_angle_change := deg_to_rad(rotation_speed) * delta - var angle := (_velocity + position - target.position).angle() + var current_angle := _velocity.angle() + var target_angle := (target.position - position).angle() - _velocity = _velocity.rotated(angle) + var angle_diff := wrapf(target_angle - current_angle, -PI, PI) + var angle_change := clampf(angle_diff, -max_angle_change, max_angle_change) + _velocity = _velocity.rotated(angle_change) _update_sprite(_velocity) func _update_sprite(velocity: Vector2) -> void: - var sector := 360.0 / sprites.size() - var angle := rad_to_deg(velocity.angle()) - var bisector := floori(angle + sector * 0.5) + var sector := TAU / sprites.size() + var angle := velocity.angle() + var bisector := angle + sector * 0.5 - var index := floori(posmod(bisector, 360) / sector) + var index := floori(fposmod(bisector, TAU) / sector) for sprite in sprites: sprite.hide() diff --git a/game/entities/weapons/launcher/launcher.gd b/game/entities/weapons/launcher/launcher_weapon.gd similarity index 100% rename from game/entities/weapons/launcher/launcher.gd rename to game/entities/weapons/launcher/launcher_weapon.gd diff --git a/game/entities/weapons/launcher/launcher.gd.uid b/game/entities/weapons/launcher/launcher_weapon.gd.uid similarity index 100% rename from game/entities/weapons/launcher/launcher.gd.uid rename to game/entities/weapons/launcher/launcher_weapon.gd.uid diff --git a/game/entities/weapons/launcher/launcher.tscn b/game/entities/weapons/launcher/launcher_weapon.tscn similarity index 93% rename from game/entities/weapons/launcher/launcher.tscn rename to game/entities/weapons/launcher/launcher_weapon.tscn index e85304e..128507a 100644 --- a/game/entities/weapons/launcher/launcher.tscn +++ b/game/entities/weapons/launcher/launcher_weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=3 uid="uid://c3l866fdqt7pf"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_sk5u1"] -[ext_resource type="Script" uid="uid://lauvvj5xhbud" path="res://game/entities/weapons/launcher/launcher.gd" id="2_mxjpe"] +[ext_resource type="Script" uid="uid://lauvvj5xhbud" path="res://game/entities/weapons/launcher/launcher_weapon.gd" id="2_mxjpe"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_1rkeb"] [ext_resource type="PackedScene" uid="uid://dukgbg13ujkv2" path="res://game/entities/weapons/launcher/launcher_projectile.tscn" id="3_fsoo2"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_fsoo2"] diff --git a/game/entities/weapons/minelayer/minelayer.gd b/game/entities/weapons/minelayer/minelayer_weapon.gd similarity index 100% rename from game/entities/weapons/minelayer/minelayer.gd rename to game/entities/weapons/minelayer/minelayer_weapon.gd diff --git a/game/entities/weapons/minelayer/minelayer.gd.uid b/game/entities/weapons/minelayer/minelayer_weapon.gd.uid similarity index 100% rename from game/entities/weapons/minelayer/minelayer.gd.uid rename to game/entities/weapons/minelayer/minelayer_weapon.gd.uid diff --git a/game/entities/weapons/minelayer/minelayer.tscn b/game/entities/weapons/minelayer/minelayer_weapon.tscn similarity index 93% rename from game/entities/weapons/minelayer/minelayer.tscn rename to game/entities/weapons/minelayer/minelayer_weapon.tscn index f147eed..f237ef8 100644 --- a/game/entities/weapons/minelayer/minelayer.tscn +++ b/game/entities/weapons/minelayer/minelayer_weapon.tscn @@ -2,7 +2,7 @@ [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_12l3k"] [ext_resource type="PackedScene" uid="uid://4mkklqt1g14f" path="res://game/entities/weapons/minelayer/minelayer_projectile.tscn" id="2_7y446"] -[ext_resource type="Script" uid="uid://c3ckkpjaef5jn" path="res://game/entities/weapons/minelayer/minelayer.gd" id="2_mmhtn"] +[ext_resource type="Script" uid="uid://c3ckkpjaef5jn" path="res://game/entities/weapons/minelayer/minelayer_weapon.gd" id="2_mmhtn"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_uotj8"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_fbmxv"] diff --git a/game/entities/weapons/plasma/plasma.gd b/game/entities/weapons/plasma/plasma_weapon.gd similarity index 100% rename from game/entities/weapons/plasma/plasma.gd rename to game/entities/weapons/plasma/plasma_weapon.gd diff --git a/game/entities/weapons/plasma/plasma.gd.uid b/game/entities/weapons/plasma/plasma_weapon.gd.uid similarity index 100% rename from game/entities/weapons/plasma/plasma.gd.uid rename to game/entities/weapons/plasma/plasma_weapon.gd.uid diff --git a/game/entities/weapons/plasma/plasma.tscn b/game/entities/weapons/plasma/plasma_weapon.tscn similarity index 95% rename from game/entities/weapons/plasma/plasma.tscn rename to game/entities/weapons/plasma/plasma_weapon.tscn index 3e730b4..92e77fb 100644 --- a/game/entities/weapons/plasma/plasma.tscn +++ b/game/entities/weapons/plasma/plasma_weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=9 format=3 uid="uid://cj1jclfterepm"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_pkk8e"] -[ext_resource type="Script" uid="uid://cu6ck2oqqdem8" path="res://game/entities/weapons/plasma/plasma.gd" id="2_fnsb7"] +[ext_resource type="Script" uid="uid://cu6ck2oqqdem8" path="res://game/entities/weapons/plasma/plasma_weapon.gd" id="2_fnsb7"] [ext_resource type="PackedScene" uid="uid://cgvb0hjrl5h4s" path="res://game/entities/weapons/plasma/plasma_projectile.tscn" id="2_yluvp"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_fnsb7"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_gpth1"] diff --git a/game/entities/weapons/railgun/railgun.gd b/game/entities/weapons/railgun/railgun_weapon.gd similarity index 100% rename from game/entities/weapons/railgun/railgun.gd rename to game/entities/weapons/railgun/railgun_weapon.gd diff --git a/game/entities/weapons/railgun/railgun.gd.uid b/game/entities/weapons/railgun/railgun_weapon.gd.uid similarity index 100% rename from game/entities/weapons/railgun/railgun.gd.uid rename to game/entities/weapons/railgun/railgun_weapon.gd.uid diff --git a/game/entities/weapons/railgun/railgun.tscn b/game/entities/weapons/railgun/railgun_weapon.tscn similarity index 95% rename from game/entities/weapons/railgun/railgun.tscn rename to game/entities/weapons/railgun/railgun_weapon.tscn index 0fcb0f5..ce7e6d1 100644 --- a/game/entities/weapons/railgun/railgun.tscn +++ b/game/entities/weapons/railgun/railgun_weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=9 format=3 uid="uid://do6h77gmnreho"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_0nxvu"] -[ext_resource type="Script" uid="uid://drnofu4ium56e" path="res://game/entities/weapons/railgun/railgun.gd" id="1_5nhwg"] +[ext_resource type="Script" uid="uid://drnofu4ium56e" path="res://game/entities/weapons/railgun/railgun_weapon.gd" id="1_5nhwg"] [ext_resource type="PackedScene" uid="uid://bab3bopsw74cb" path="res://game/entities/weapons/railgun/railgun_projectile.tscn" id="2_cbsia"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_qxka8"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_igknv"] diff --git a/game/entities/weapons/shrapnel/shrapnel.gd b/game/entities/weapons/shrapnel/shrapnel_weapon.gd similarity index 100% rename from game/entities/weapons/shrapnel/shrapnel.gd rename to game/entities/weapons/shrapnel/shrapnel_weapon.gd diff --git a/game/entities/weapons/shrapnel/shrapnel.gd.uid b/game/entities/weapons/shrapnel/shrapnel_weapon.gd.uid similarity index 100% rename from game/entities/weapons/shrapnel/shrapnel.gd.uid rename to game/entities/weapons/shrapnel/shrapnel_weapon.gd.uid diff --git a/game/entities/weapons/shrapnel/shrapnel.tscn b/game/entities/weapons/shrapnel/shrapnel_weapon.tscn similarity index 95% rename from game/entities/weapons/shrapnel/shrapnel.tscn rename to game/entities/weapons/shrapnel/shrapnel_weapon.tscn index a1c4e23..e5b7a0d 100644 --- a/game/entities/weapons/shrapnel/shrapnel.tscn +++ b/game/entities/weapons/shrapnel/shrapnel_weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=9 format=3 uid="uid://r7wnk762jbfy"] [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_xk300"] -[ext_resource type="Script" uid="uid://gxwbsiicuqh5" path="res://game/entities/weapons/shrapnel/shrapnel.gd" id="2_1bd18"] +[ext_resource type="Script" uid="uid://gxwbsiicuqh5" path="res://game/entities/weapons/shrapnel/shrapnel_weapon.gd" id="2_1bd18"] [ext_resource type="PackedScene" uid="uid://bsx23u3a2obbj" path="res://game/entities/weapons/shrapnel/shrapnel_projectile.tscn" id="2_xvd4y"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_tyrw7"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_nfmol"] diff --git a/game/entities/weapons/tesla/tesla.gd b/game/entities/weapons/tesla/tesla_weapon.gd similarity index 100% rename from game/entities/weapons/tesla/tesla.gd rename to game/entities/weapons/tesla/tesla_weapon.gd diff --git a/game/entities/weapons/tesla/tesla.gd.uid b/game/entities/weapons/tesla/tesla_weapon.gd.uid similarity index 100% rename from game/entities/weapons/tesla/tesla.gd.uid rename to game/entities/weapons/tesla/tesla_weapon.gd.uid diff --git a/game/entities/weapons/tesla/tesla.tscn b/game/entities/weapons/tesla/tesla_weapon.tscn similarity index 95% rename from game/entities/weapons/tesla/tesla.tscn rename to game/entities/weapons/tesla/tesla_weapon.tscn index 0222c75..7538906 100644 --- a/game/entities/weapons/tesla/tesla.tscn +++ b/game/entities/weapons/tesla/tesla_weapon.tscn @@ -2,7 +2,7 @@ [ext_resource type="PackedScene" uid="uid://1o2ta17yc5bp" path="res://game/entities/weapons/abstract_weapon.tscn" id="1_rpud7"] [ext_resource type="PackedScene" uid="uid://bi64687wtxi4d" path="res://game/entities/weapons/tesla/tesla_projectile.tscn" id="2_1rrdy"] -[ext_resource type="Script" uid="uid://ctv408wdwvttc" path="res://game/entities/weapons/tesla/tesla.gd" id="2_08si3"] +[ext_resource type="Script" uid="uid://ctv408wdwvttc" path="res://game/entities/weapons/tesla/tesla_weapon.gd" id="2_08si3"] [ext_resource type="Script" uid="uid://ccpriilfr3kme" path="res://game/reloaders/abstract_reloader.gd" id="3_08si3"] [ext_resource type="Script" uid="uid://b255rb32vc6co" path="res://game/reloaders/firerate_reloader.gd" id="4_rqarv"] [ext_resource type="Script" uid="uid://dxk56xdihfw4m" path="res://game/reloaders/energy_reloader.gd" id="5_j5i31"]