Made kamikaze behavior and also fixed borders
This commit is contained in:
parent
ac263a1e65
commit
1ee0b529a8
10 changed files with 41 additions and 44 deletions
|
|
@ -8,6 +8,7 @@ position = Vector2(0.5, 0)
|
||||||
gravity_scale = 0.0
|
gravity_scale = 0.0
|
||||||
angular_damp = 1.0
|
angular_damp = 1.0
|
||||||
script = ExtResource("1_7nfg8")
|
script = ExtResource("1_7nfg8")
|
||||||
|
collision_damage = 15.0
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite2D" parent="."]
|
[node name="Sprite" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("2_vhl4r")
|
texture = ExtResource("2_vhl4r")
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
[ext_resource type="Texture2D" uid="uid://bchkncbniclhh" path="res://sprites/kamikaze.png" id="2_8ba3c"]
|
[ext_resource type="Texture2D" uid="uid://bchkncbniclhh" path="res://sprites/kamikaze.png" id="2_8ba3c"]
|
||||||
|
|
||||||
[node name="Hull" instance=ExtResource("1_l56rl")]
|
[node name="Hull" instance=ExtResource("1_l56rl")]
|
||||||
|
collision_mask = 3
|
||||||
max_hp = 10.0
|
max_hp = 10.0
|
||||||
velocity_collision_treshold = 150.0
|
velocity_collision_treshold = 150.0
|
||||||
collision_damage = 10.0
|
collision_damage = 10.0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://pev6k21vqaem"]
|
[gd_scene load_steps=9 format=3 uid="uid://pev6k21vqaem"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/Ship/ship.gd" id="1_82bba"]
|
[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"]
|
[ext_resource type="PackedScene" uid="uid://bkd4gyhlota7l" path="res://scenes/Ships/Modules/Hulls/kamikaze_hull.tscn" id="2_165nu"]
|
||||||
[ext_resource type="PackedScene" uid="uid://mw4kwxoeqch3" path="res://scenes/Ships/Modules/Engines/engine.tscn" id="3_plu72"]
|
[ext_resource type="PackedScene" uid="uid://mw4kwxoeqch3" path="res://scenes/Ships/Modules/Engines/engine.tscn" id="3_plu72"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bunboi5ouscw8" path="res://scenes/Ships/Modules/Shields/shield.tscn" id="4_aos8x"]
|
[ext_resource type="PackedScene" uid="uid://bunboi5ouscw8" path="res://scenes/Ships/Modules/Shields/shield.tscn" id="4_aos8x"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/Ship/weapons.gd" id="5_8eieq"]
|
||||||
[ext_resource type="Script" path="res://scripts/State Machine/tree.gd" id="5_m8m3f"]
|
[ext_resource type="Script" path="res://scripts/State Machine/tree.gd" id="5_m8m3f"]
|
||||||
[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/WanderingState.gd" id="6_emcj1"]
|
||||||
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/AttackState.gd" id="7_ilmkp"]
|
[ext_resource type="Script" path="res://scripts/State Machine/Kamikaze/AttackState.gd" id="7_ilmkp"]
|
||||||
|
|
@ -22,6 +23,7 @@ collision_damage = 15.0
|
||||||
max_capacity = 5
|
max_capacity = 5
|
||||||
|
|
||||||
[node name="Weapons" type="Node2D" parent="."]
|
[node name="Weapons" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("5_8eieq")
|
||||||
|
|
||||||
[node name="StateTree" type="Node" parent="." node_paths=PackedStringArray("state")]
|
[node name="StateTree" type="Node" parent="." node_paths=PackedStringArray("state")]
|
||||||
script = ExtResource("5_m8m3f")
|
script = ExtResource("5_m8m3f")
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@ height = 16384
|
||||||
scroll_offset = Vector2(681.667, 317.783)
|
scroll_offset = Vector2(681.667, 317.783)
|
||||||
stars_amount = 4000
|
stars_amount = 4000
|
||||||
|
|
||||||
[node name="SystemBorder" parent="Background" index="0"]
|
[node name="Nebula" parent="Background" index="0" node_paths=PackedStringArray("tracked_node")]
|
||||||
default_color = Color(1, 1, 1, 1)
|
|
||||||
|
|
||||||
[node name="Nebula" parent="Background" index="1" node_paths=PackedStringArray("tracked_node")]
|
|
||||||
tracked_node = NodePath("../../FactionPlayer/PlayerShip")
|
tracked_node = NodePath("../../FactionPlayer/PlayerShip")
|
||||||
color_background = Color(0.276474, 0.0962249, 0.200656, 1)
|
color_background = Color(0.276474, 0.0962249, 0.200656, 1)
|
||||||
|
|
||||||
|
|
@ -28,4 +25,4 @@ position = Vector2(19, 10)
|
||||||
position = Vector2(7171, -28)
|
position = Vector2(7171, -28)
|
||||||
|
|
||||||
[node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
|
[node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
|
||||||
position = Vector2(687, -302)
|
position = Vector2(147, 92)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func _ready():
|
||||||
resource_name = "get_border_points"
|
resource_name = "get_border_points"
|
||||||
script/source = "extends Line2D
|
script/source = "extends Line2D
|
||||||
|
|
||||||
@onready var star_system = get_parent().get_parent()
|
@onready var star_system = get_parent()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var halved_width = star_system.width / 2
|
var halved_width = star_system.width / 2
|
||||||
|
|
@ -65,14 +65,6 @@ script = SubResource("GDScript_4yoh5")
|
||||||
process_mode = 1
|
process_mode = 1
|
||||||
layer = -10
|
layer = -10
|
||||||
|
|
||||||
[node name="SystemBorder" type="Line2D" parent="Background"]
|
|
||||||
z_index = -99
|
|
||||||
points = PackedVector2Array(0, 0, 1280, 0, 1280, 720, 0, 720)
|
|
||||||
closed = true
|
|
||||||
width = 8.0
|
|
||||||
default_color = Color(1, 1, 1, 0.521569)
|
|
||||||
script = SubResource("GDScript_r38d8")
|
|
||||||
|
|
||||||
[node name="Nebula" type="ColorRect" parent="Background"]
|
[node name="Nebula" type="ColorRect" parent="Background"]
|
||||||
z_index = -100
|
z_index = -100
|
||||||
material = ExtResource("4_o0ld7")
|
material = ExtResource("4_o0ld7")
|
||||||
|
|
@ -99,3 +91,11 @@ faction = 3
|
||||||
[node name="FactionAggressive" type="Node" parent="."]
|
[node name="FactionAggressive" type="Node" parent="."]
|
||||||
script = ExtResource("7_wm3vi")
|
script = ExtResource("7_wm3vi")
|
||||||
faction = 4
|
faction = 4
|
||||||
|
|
||||||
|
[node name="SystemBorder" type="Line2D" parent="."]
|
||||||
|
z_index = -99
|
||||||
|
points = PackedVector2Array(0, 0, 1280, 0, 1280, 720, 0, 720)
|
||||||
|
closed = true
|
||||||
|
width = 8.0
|
||||||
|
default_color = Color(1, 1, 1, 0.521569)
|
||||||
|
script = SubResource("GDScript_r38d8")
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,12 @@ func _physics_process(_delta):
|
||||||
ship.rotation = rotation
|
ship.rotation = rotation
|
||||||
scalar_velocity = linear_velocity.length()
|
scalar_velocity = linear_velocity.length()
|
||||||
|
|
||||||
func _on_body_entered(_body):
|
func _on_body_entered(body):
|
||||||
if scalar_velocity >= velocity_collision_treshold:
|
if scalar_velocity >= velocity_collision_treshold:
|
||||||
ship.shield.deal_damage(20.0 * (scalar_velocity / velocity_collision_treshold))
|
var damage = collision_damage * (scalar_velocity / velocity_collision_treshold)
|
||||||
|
ship.shield.deal_damage(damage)
|
||||||
|
if body is Ship:
|
||||||
|
body.shield.deal_damage(damage / 2)
|
||||||
|
|
||||||
func warp_to_position(location: Vector2):
|
func warp_to_position(location: Vector2):
|
||||||
position = location
|
position = location
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ func _ready() -> void:
|
||||||
destroyed.connect(destroy_timeout)
|
destroyed.connect(destroy_timeout)
|
||||||
|
|
||||||
func destroy_timeout():
|
func destroy_timeout():
|
||||||
get_tree().create_timer(0.02).timeout.connect(destroy)
|
destroy()
|
||||||
|
get_tree().create_timer(0.05).timeout.connect(hull.warp_to_position.bind(spawn_position))
|
||||||
|
|
||||||
## Reset all required variables
|
## Reset all required variables
|
||||||
func destroy() -> void:
|
func destroy() -> void:
|
||||||
|
|
@ -32,7 +33,6 @@ func destroy() -> void:
|
||||||
hull.linear_velocity = Vector2.ZERO
|
hull.linear_velocity = Vector2.ZERO
|
||||||
hull.angular_velocity = 0.0
|
hull.angular_velocity = 0.0
|
||||||
shield.capacity = shield.max_capacity
|
shield.capacity = shield.max_capacity
|
||||||
hull.warp_to_position(spawn_position)
|
|
||||||
|
|
||||||
## Swaps old hull with the new one
|
## Swaps old hull with the new one
|
||||||
func change_hull(new_hull_id: String) -> void:
|
func change_hull(new_hull_id: String) -> void:
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ extends Node2D
|
||||||
## Shortcut to get_parent()
|
## Shortcut to get_parent()
|
||||||
@onready var ship: Ship = get_parent()
|
@onready var ship: Ship = get_parent()
|
||||||
## List of weapons
|
## List of weapons
|
||||||
@onready var list: Array[Node] = get_children() as Array[Node]
|
@onready var list: Array[Node] = get_children()
|
||||||
|
|
||||||
## Updates list with actual children of this node
|
## Updates list with actual children of this node
|
||||||
func update_weapon_list() -> void:
|
func update_weapon_list() -> void:
|
||||||
list = get_children() as Array[Node]
|
list = get_children()
|
||||||
|
|
||||||
## Removes weapon with given ID
|
## Removes weapon with given ID
|
||||||
func remove_weapon(id: String) -> void:
|
func remove_weapon(id: String) -> void:
|
||||||
|
|
@ -25,8 +25,8 @@ func add_weapon(_id: String) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## Returns a reference to weapon with given id if it exists, otherwise returns null
|
## Returns a reference to weapon with given id if it exists, otherwise returns null
|
||||||
func get_weapon(id: String) -> Weapon:
|
func get_weapon(id: String) -> Node:
|
||||||
for weapon in list:
|
for weapon in list:
|
||||||
if weapon.id == id:
|
if weapon.id == id:
|
||||||
return weapon as Weapon
|
return weapon
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,16 @@ var destination_degrees: float = 0:
|
||||||
destination_degrees = 360 + value
|
destination_degrees = 360 + value
|
||||||
else:
|
else:
|
||||||
destination_degrees = value
|
destination_degrees = value
|
||||||
## Difference between current rotation and destination angle, in degrees. Sign determines torque direction.
|
|
||||||
var current_destination_difference: float = 0:
|
|
||||||
set(value):
|
|
||||||
if value < 0:
|
|
||||||
current_destination_difference = 180 + value
|
|
||||||
if current_destination_difference > 180:
|
|
||||||
current_destination_difference = value - 180
|
|
||||||
## Delta to destination_degrees
|
## Delta to destination_degrees
|
||||||
var destination_difference: float = 5.0
|
var destination_difference: float = 5.0
|
||||||
|
|
||||||
|
var current_destination_difference: float:
|
||||||
|
set(value):
|
||||||
|
if value > 180:
|
||||||
|
current_destination_difference = value - 360
|
||||||
|
else:
|
||||||
|
current_destination_difference = value
|
||||||
|
|
||||||
func enter(message: Dictionary):
|
func enter(message: Dictionary):
|
||||||
if message.has("target"):
|
if message.has("target"):
|
||||||
target = message["target"]
|
target = message["target"]
|
||||||
|
|
@ -37,9 +37,8 @@ func process(_delta):
|
||||||
# checking if need to apply torque
|
# checking if need to apply torque
|
||||||
destination_degrees = rad_to_deg(ship.global_position.angle_to_point(target.global_position))
|
destination_degrees = rad_to_deg(ship.global_position.angle_to_point(target.global_position))
|
||||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||||
var rotation_sign = sign(current_destination_difference)
|
|
||||||
if abs(current_destination_difference) > destination_difference:
|
if abs(current_destination_difference) > destination_difference:
|
||||||
ship.engine.rotation_axis = rotation_sign * (current_destination_difference / 180)
|
ship.engine.rotation_axis = clamp(current_destination_difference / 360 + 0.5 * sign(current_destination_difference), -1.0, 1.0)
|
||||||
else:
|
else:
|
||||||
ship.engine.rotation_axis = 0.0
|
ship.engine.rotation_axis = 0.0
|
||||||
ship.hull.apply_central_force(Vector2.from_angle(ship.hull.rotation) * additional_stab_force)
|
ship.hull.apply_central_force(Vector2.from_angle(ship.hull.rotation) * additional_stab_force)
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,8 @@ var destination_degrees: float = 0:
|
||||||
destination_degrees = 360 + value
|
destination_degrees = 360 + value
|
||||||
else:
|
else:
|
||||||
destination_degrees = value
|
destination_degrees = value
|
||||||
## Difference between current rotation and destination angle, in degrees. Sign determines torque direction.
|
|
||||||
var current_destination_difference: float = 0:
|
|
||||||
set(value):
|
|
||||||
if value < 0:
|
|
||||||
current_destination_difference = 180 + value
|
|
||||||
if current_destination_difference > 180:
|
|
||||||
current_destination_difference = value - 180
|
|
||||||
## Delta to destination_degrees
|
## Delta to destination_degrees
|
||||||
var destination_difference: float = 15.0
|
var destination_difference: float = 1.0
|
||||||
## available map bounds (use with absolute position)
|
## available map bounds (use with absolute position)
|
||||||
var available_bounds: Vector2
|
var available_bounds: Vector2
|
||||||
# for testing purposes only
|
# for testing purposes only
|
||||||
|
|
@ -42,10 +35,11 @@ func enter(_message):
|
||||||
|
|
||||||
func process(_delta):
|
func process(_delta):
|
||||||
# checking if need to apply torque
|
# checking if need to apply torque
|
||||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
var current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||||
var rotation_sign = sign(current_destination_difference)
|
var other_destination_difference = ship.hull.global_rotation_degrees - destination_degrees
|
||||||
if abs(current_destination_difference) > destination_difference:
|
var min_difference = min(abs(current_destination_difference), abs(other_destination_difference))
|
||||||
ship.engine.rotation_axis = rotation_sign * (current_destination_difference / 180)
|
if min_difference > destination_difference:
|
||||||
|
ship.engine.rotation_axis = min_difference / 180
|
||||||
else:
|
else:
|
||||||
ship.engine.rotation_axis = 0.0
|
ship.engine.rotation_axis = 0.0
|
||||||
# making ship always accelerate
|
# making ship always accelerate
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue