Added shooter ship
This commit is contained in:
parent
154da5104e
commit
ab3ac4af66
10 changed files with 232 additions and 4 deletions
14
scenes/Ships/Modules/Hulls/shooter_hull.tscn
Normal file
14
scenes/Ships/Modules/Hulls/shooter_hull.tscn
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://bckgb423wsdrw"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bsu4eqwdfewwi" path="res://scenes/Ships/Modules/Hulls/hull.tscn" id="1_7i1ve"]
|
||||
[ext_resource type="Texture2D" uid="uid://bxtd2ij1dc1d3" path="res://sprites/shooter.png" id="2_gvwov"]
|
||||
|
||||
[node name="Hull" instance=ExtResource("1_7i1ve")]
|
||||
max_hp = 10.0
|
||||
|
||||
[node name="Sprite" parent="." index="0"]
|
||||
position = Vector2(0, 0.5)
|
||||
texture = ExtResource("2_gvwov")
|
||||
|
||||
[node name="Collision" parent="." index="1"]
|
||||
polygon = PackedVector2Array(-52.5, 15, -52.5, 51, -69.5, 61, -63.5, 71, -62.5, 71, 76.5, 1, 76.5, 0, -62.5, -70, -63.5, -70, -69.5, -60, -52.5, -50, -52.5, -14, -62.5, -14, -75.5, -28, -76.5, -28, -76.5, 29, -75.5, 29, -61.5, 15)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://pev6k21vqaem"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://pev6k21vqaem"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Ship/ship.gd" id="1_82bba"]
|
||||
[ext_resource type="PackedScene" uid="uid://bkd4gyhlota7l" path="res://scenes/Ships/Modules/Hulls/kamikaze_hull.tscn" id="2_165nu"]
|
||||
|
|
@ -9,6 +9,19 @@
|
|||
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/WanderingState.gd" id="6_emcj1"]
|
||||
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/AttackState.gd" id="7_ilmkp"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_nif6i"]
|
||||
resource_name = "health_shield_counter"
|
||||
script/source = "extends Label
|
||||
|
||||
## Text with placeholder
|
||||
@onready var unformatted_text: String = text
|
||||
## Shortcut to get_parent().get_parent().get_parent()
|
||||
@onready var ship: Ship = get_parent().get_parent().get_parent()
|
||||
|
||||
func _process(_delta):
|
||||
text = unformatted_text.format([ship.hull.hp, ship.hull.max_hp, ship.shield.capacity, ship.shield.max_capacity])
|
||||
"
|
||||
|
||||
[node name="KamikazeShip" type="Node2D"]
|
||||
script = ExtResource("1_82bba")
|
||||
|
||||
|
|
@ -38,4 +51,24 @@ wait_time = 10.0
|
|||
[node name="AttackState" type="Node" parent="StateTree"]
|
||||
script = ExtResource("7_ilmkp")
|
||||
|
||||
[node name="StatHolder" type="Node" parent="."]
|
||||
|
||||
[node name="StatCarry" type="Node2D" parent="StatHolder"]
|
||||
|
||||
[node name="HealthShield" type="Label" parent="StatHolder/StatCarry"]
|
||||
offset_left = -49.0
|
||||
offset_top = -133.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -84.0
|
||||
text = "{0}/{1} HP
|
||||
{2}/{3} SP"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
script = SubResource("GDScript_nif6i")
|
||||
|
||||
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="."]
|
||||
remote_path = NodePath("../StatHolder/StatCarry")
|
||||
update_rotation = false
|
||||
update_scale = false
|
||||
|
||||
[connection signal="timeout" from="StateTree/WanderingState/UpdateDestination" to="StateTree/WanderingState" method="update_destination"]
|
||||
|
|
|
|||
80
scenes/Ships/NPC Ships/shooter_ship.tscn
Normal file
80
scenes/Ships/NPC Ships/shooter_ship.tscn
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://yso8f0y5kg50"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Ship/ship.gd" id="1_o387g"]
|
||||
[ext_resource type="PackedScene" uid="uid://bckgb423wsdrw" path="res://scenes/Ships/Modules/Hulls/shooter_hull.tscn" id="2_kthut"]
|
||||
[ext_resource type="PackedScene" uid="uid://mw4kwxoeqch3" path="res://scenes/Ships/Modules/Engines/engine.tscn" id="3_ysnrn"]
|
||||
[ext_resource type="PackedScene" uid="uid://bunboi5ouscw8" path="res://scenes/Ships/Modules/Shields/shield.tscn" id="4_5rkla"]
|
||||
[ext_resource type="Script" path="res://scripts/Ship/weapons.gd" id="5_f305p"]
|
||||
[ext_resource type="PackedScene" uid="uid://bf10g066l8grd" path="res://scenes/Ships/Modules/Weapons/laser.tscn" id="6_hun72"]
|
||||
[ext_resource type="Script" path="res://scripts/State Machine/tree.gd" id="7_5uvtf"]
|
||||
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/WanderingState.gd" id="8_i8jwt"]
|
||||
[ext_resource type="Script" path="res://scripts/State Machine/Shooter/AttackState.gd" id="9_0eak7"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_r7j0p"]
|
||||
resource_name = "health_shield_counter"
|
||||
script/source = "extends Label
|
||||
|
||||
## Text with placeholder
|
||||
@onready var unformatted_text: String = text
|
||||
## Shortcut to get_parent().get_parent().get_parent()
|
||||
@onready var ship: Ship = get_parent().get_parent().get_parent()
|
||||
|
||||
func _process(_delta):
|
||||
text = unformatted_text.format([ship.hull.hp, ship.hull.max_hp, ship.shield.capacity, ship.shield.max_capacity])
|
||||
"
|
||||
|
||||
[node name="ShooterShip" type="Node2D"]
|
||||
process_mode = 1
|
||||
script = ExtResource("1_o387g")
|
||||
|
||||
[node name="HullHolder" type="Node" parent="."]
|
||||
|
||||
[node name="Hull" parent="HullHolder" instance=ExtResource("2_kthut")]
|
||||
|
||||
[node name="Engine" parent="." instance=ExtResource("3_ysnrn")]
|
||||
|
||||
[node name="Shield" parent="." instance=ExtResource("4_5rkla")]
|
||||
max_capacity = 3
|
||||
|
||||
[node name="Weapons" type="Node2D" parent="."]
|
||||
script = ExtResource("5_f305p")
|
||||
|
||||
[node name="Laser" parent="Weapons" instance=ExtResource("6_hun72")]
|
||||
position = Vector2(67, 0.5)
|
||||
max_gun_rotation = 15.0
|
||||
action_id = "shoot"
|
||||
ammo_type = "n/a"
|
||||
ammo_consumption = 0.0
|
||||
|
||||
[node name="StateTree" type="Node" parent="." node_paths=PackedStringArray("state")]
|
||||
script = ExtResource("7_5uvtf")
|
||||
state = NodePath("WanderingState")
|
||||
|
||||
[node name="WanderingState" type="Node" parent="StateTree"]
|
||||
script = ExtResource("8_i8jwt")
|
||||
|
||||
[node name="UpdateDestination" type="Timer" parent="StateTree/WanderingState"]
|
||||
wait_time = 10.0
|
||||
|
||||
[node name="AttackState" type="Node" parent="StateTree"]
|
||||
script = ExtResource("9_0eak7")
|
||||
|
||||
[node name="StatHolder" type="Node" parent="."]
|
||||
|
||||
[node name="StatCarry" type="Node2D" parent="StatHolder"]
|
||||
|
||||
[node name="HealthShield" type="Label" parent="StatHolder/StatCarry"]
|
||||
offset_left = -49.0
|
||||
offset_top = -133.0
|
||||
offset_right = 50.0
|
||||
offset_bottom = -84.0
|
||||
text = "{0}/{1} HP
|
||||
{2}/{3} SP"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
script = SubResource("GDScript_r7j0p")
|
||||
|
||||
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="."]
|
||||
remote_path = NodePath("../StatHolder/StatCarry")
|
||||
update_rotation = false
|
||||
update_scale = false
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://crneq2enhxsw5"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://crneq2enhxsw5"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bsnrcw64qr2hr" path="res://scenes/Star Systems/star_system_template.tscn" id="1_2ai1l"]
|
||||
[ext_resource type="PackedScene" uid="uid://dk3nvl8f0v24e" path="res://scenes/base_template.tscn" id="3_m5ica"]
|
||||
[ext_resource type="PackedScene" uid="uid://pev6k21vqaem" path="res://scenes/Ships/NPC Ships/kamikaze_ship.tscn" id="4_i6rbg"]
|
||||
[ext_resource type="PackedScene" uid="uid://yso8f0y5kg50" path="res://scenes/Ships/NPC Ships/shooter_ship.tscn" id="5_o3ny8"]
|
||||
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="7_jyplv"]
|
||||
|
||||
[node name="StarSystem" instance=ExtResource("1_2ai1l")]
|
||||
|
|
@ -25,4 +26,7 @@ position = Vector2(19, 10)
|
|||
position = Vector2(7171, -28)
|
||||
|
||||
[node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
|
||||
position = Vector2(4245, -1247)
|
||||
position = Vector2(-444, -228)
|
||||
|
||||
[node name="ShooterShip" parent="FactionAggressive" index="1" instance=ExtResource("5_o3ny8")]
|
||||
position = Vector2(204, 491)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ size = Vector2(4, 32)
|
|||
|
||||
[node name="Laser" type="Node2D" node_paths=PackedStringArray("collider")]
|
||||
script = ExtResource("1_6nacn")
|
||||
speed = 600.0
|
||||
speed = 1000.0
|
||||
collider = NodePath("Collision")
|
||||
|
||||
[node name="LaserBody" type="Line2D" parent="."]
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ func process(_delta):
|
|||
# checking if need to apply torque
|
||||
destination_degrees = rad_to_deg(ship.global_position.angle_to_point(target.global_position))
|
||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||
|
||||
if abs(current_destination_difference) > destination_difference:
|
||||
ship.engine.rotation_axis = clamp(current_destination_difference / 360 + 0.5 * sign(current_destination_difference), -1.0, 1.0)
|
||||
else:
|
||||
|
|
@ -44,6 +45,7 @@ func process(_delta):
|
|||
ship.hull.apply_central_force(Vector2.from_angle(ship.hull.rotation) * additional_stab_force)
|
||||
# making ship always accelerate
|
||||
ship.engine.acceleration_axis = 1.0
|
||||
|
||||
var distance_to_target = ship.global_position.distance_to(target.global_position)
|
||||
if distance_to_target > target_loss_distance:
|
||||
get_parent().transit("WanderingState")
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ func enter(_message):
|
|||
func process(_delta):
|
||||
# checking if need to apply torque
|
||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||
|
||||
if abs(current_destination_difference) > destination_difference:
|
||||
ship.engine.rotation_axis = clamp(current_destination_difference / 360 + 0.5 * sign(current_destination_difference), -1.0, 1.0)
|
||||
else:
|
||||
|
|
|
|||
60
scripts/State Machine/Shooter/AttackState.gd
Normal file
60
scripts/State Machine/Shooter/AttackState.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
extends State
|
||||
|
||||
## If target is further than this distance, transit to WanderingState
|
||||
@export var target_loss_distance: float = 1536.0
|
||||
## Node which is being targeted by this ship
|
||||
var target: Node2D
|
||||
## Shortcut to get_parent().get_parent()
|
||||
@onready var ship = get_parent().get_parent()
|
||||
## Ship will strive to achieve this angle
|
||||
var destination_degrees: float = 0:
|
||||
set(value):
|
||||
if value > 180:
|
||||
destination_degrees = value - 360
|
||||
elif value < -180:
|
||||
destination_degrees = 360 + value
|
||||
else:
|
||||
destination_degrees = value
|
||||
## Delta to destination_degrees
|
||||
var destination_difference: float
|
||||
|
||||
var current_destination_difference: float:
|
||||
set(value):
|
||||
if value > 180:
|
||||
current_destination_difference = value - 360
|
||||
else:
|
||||
current_destination_difference = value
|
||||
|
||||
## Gun node to change its behavior
|
||||
var gun: Node2D
|
||||
|
||||
func enter(message: Dictionary):
|
||||
if message.has("target"):
|
||||
target = message["target"]
|
||||
gun = ship.weapons.list[0]
|
||||
destination_difference = gun.max_gun_rotation / 2
|
||||
else:
|
||||
get_parent().transit("WanderingState")
|
||||
|
||||
func process(_delta):
|
||||
# checking if need to apply torque
|
||||
destination_degrees = rad_to_deg(ship.global_position.angle_to_point(target.global_position))
|
||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||
|
||||
if abs(current_destination_difference) > destination_difference:
|
||||
ship.engine.rotation_axis = clamp(current_destination_difference / 360 + 0.5 * sign(current_destination_difference), -1.0, 1.0)
|
||||
gun.shoot_request = 0.0
|
||||
else:
|
||||
ship.engine.rotation_axis = 0.0
|
||||
gun.shoot_request = 1.0
|
||||
|
||||
var distance_to_target = ship.global_position.distance_to(target.global_position)
|
||||
if distance_to_target > target_loss_distance:
|
||||
get_parent().transit("WanderingState")
|
||||
gun.gun_rotation = 0.0
|
||||
gun.shoot_request = 0.0
|
||||
return
|
||||
|
||||
ship.engine.acceleration_axis = clamp((distance_to_target - 256) / 256 + 0.3, -1.0, 1.0)
|
||||
gun.gun_rotation = current_destination_difference
|
||||
|
||||
BIN
sprites/shooter.png
Normal file
BIN
sprites/shooter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
34
sprites/shooter.png.import
Normal file
34
sprites/shooter.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bxtd2ij1dc1d3"
|
||||
path="res://.godot/imported/shooter.png-dc69c2835aa11bc6878a2e4130c257c1.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/shooter.png"
|
||||
dest_files=["res://.godot/imported/shooter.png-dc69c2835aa11bc6878a2e4130c257c1.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
Loading…
Add table
Add a link
Reference in a new issue