Rewriting ships: Added weapon base and changed hull parent to Node
This commit is contained in:
parent
95274d0a5b
commit
6957169ba5
13 changed files with 121 additions and 37 deletions
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
[node name="Shield" type="Node2D" node_paths=PackedStringArray("shield_recharge_timer", "laser_recharge_timer")]
|
[node name="Shield" type="Node2D" node_paths=PackedStringArray("shield_recharge_timer", "laser_recharge_timer")]
|
||||||
script = ExtResource("1_sexol")
|
script = ExtResource("1_sexol")
|
||||||
shield_recharge_timer = NodePath("")
|
shield_recharge_timer = NodePath("ShieldTimer")
|
||||||
laser_recharge_timer = NodePath("")
|
laser_recharge_timer = NodePath("LaserTimer")
|
||||||
|
|
||||||
[node name="ShieldTimer" type="Timer" parent="."]
|
[node name="ShieldTimer" type="Timer" parent="."]
|
||||||
wait_time = 5.0
|
wait_time = 5.0
|
||||||
|
|
|
||||||
16
scenes/Ships/Modules/Weapons/weapon.tscn
Normal file
16
scenes/Ships/Modules/Weapons/weapon.tscn
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://ryy1tdrxmjav"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/Ship/weapon.gd" id="1_ga8vg"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://djmoij5kuou3j" path="res://scenes/projectiles/Laser.tscn" id="2_qo148"]
|
||||||
|
|
||||||
|
[node name="Weapon" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
|
||||||
|
script = ExtResource("1_ga8vg")
|
||||||
|
projectile = ExtResource("2_qo148")
|
||||||
|
shoot_timer = NodePath("ShootTimer")
|
||||||
|
spawner_points = [NodePath("Spawner")]
|
||||||
|
|
||||||
|
[node name="ShootTimer" type="Timer" parent="."]
|
||||||
|
wait_time = 0.25
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="Spawner" type="Node2D" parent="."]
|
||||||
|
|
@ -1,21 +1,13 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://dok3i8u5t1ka4"]
|
[gd_scene load_steps=4 format=3 uid="uid://dok3i8u5t1ka4"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"]
|
[ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"]
|
||||||
[ext_resource type="Shader" path="res://shaders/ship.gdshader" id="2_dbojl"]
|
|
||||||
[ext_resource type="Script" path="res://scripts/Ship/player_input_controller.gd" id="3_0e84a"]
|
[ext_resource type="Script" path="res://scripts/Ship/player_input_controller.gd" id="3_0e84a"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://ryy1tdrxmjav" path="res://scenes/Ships/Modules/Weapons/weapon.tscn" id="4_fy1be"]
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_u1mh3"]
|
|
||||||
resource_local_to_scene = true
|
|
||||||
resource_name = "Shield Material"
|
|
||||||
shader = ExtResource("2_dbojl")
|
|
||||||
shader_parameter/wave_centers = PackedVector2Array()
|
|
||||||
shader_parameter/wave_distances = PackedFloat32Array(-1)
|
|
||||||
shader_parameter/color = Color(1, 0, 0, 1)
|
|
||||||
shader_parameter/max_distance = 20.0
|
|
||||||
shader_parameter/bublic_size = 20.0
|
|
||||||
|
|
||||||
[node name="PlayerShip" instance=ExtResource("1_6x7bu")]
|
[node name="PlayerShip" instance=ExtResource("1_6x7bu")]
|
||||||
material = SubResource("ShaderMaterial_u1mh3")
|
|
||||||
|
|
||||||
[node name="InputController" type="Node2D" parent="." index="3"]
|
[node name="InputController" type="Node2D" parent="." index="0"]
|
||||||
script = ExtResource("3_0e84a")
|
script = ExtResource("3_0e84a")
|
||||||
|
|
||||||
|
[node name="Weapon" parent="Weapons" index="0" instance=ExtResource("4_fy1be")]
|
||||||
|
action_id = "primary"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@
|
||||||
[node name="Ship" type="Node2D"]
|
[node name="Ship" type="Node2D"]
|
||||||
script = ExtResource("2_n14ml")
|
script = ExtResource("2_n14ml")
|
||||||
|
|
||||||
[node name="Hull" parent="." instance=ExtResource("3_upgeg")]
|
[node name="HullHolder" type="Node" parent="."]
|
||||||
|
|
||||||
|
[node name="Hull" parent="HullHolder" instance=ExtResource("3_upgeg")]
|
||||||
|
|
||||||
[node name="Engine" parent="." instance=ExtResource("4_adr14")]
|
[node name="Engine" parent="." instance=ExtResource("4_adr14")]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://ckdttdkoo1t0s"]
|
[gd_scene load_steps=6 format=3 uid="uid://ckdttdkoo1t0s"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="1_b1l1c"]
|
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="1_b1l1c"]
|
||||||
[ext_resource type="Shader" path="res://shaders/ship.gdshader" id="2_15op6"]
|
[ext_resource type="Shader" path="res://shaders/ship.gdshader" id="2_15op6"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/misc/ProjectilesContainer.gd" id="3_amh71"]
|
||||||
|
|
||||||
[sub_resource type="GDScript" id="GDScript_6w8qb"]
|
[sub_resource type="GDScript" id="GDScript_6w8qb"]
|
||||||
resource_name = "gogo"
|
resource_name = "gogo"
|
||||||
|
|
@ -83,12 +84,12 @@ func check_for_item(modules : Array[String]) -> Array[String]:
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if Input.is_action_just_released(\"pause\"):
|
if Input.is_action_just_released(\"pause\"):
|
||||||
get_tree().change_scene_to_file(\"res://scenes/MainMenu.tscn\")
|
get_tree().change_scene_to_file(\"res://scenes/MainMenu.tscn\")
|
||||||
"
|
"
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_634ti"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_m15k8"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
resource_name = "Shield Material"
|
resource_name = "Shield Material"
|
||||||
shader = ExtResource("2_15op6")
|
shader = ExtResource("2_15op6")
|
||||||
|
|
@ -117,6 +118,9 @@ vertical_alignment = 1
|
||||||
autowrap_mode = 2
|
autowrap_mode = 2
|
||||||
|
|
||||||
[node name="PlayerShip" parent="." instance=ExtResource("1_b1l1c")]
|
[node name="PlayerShip" parent="." instance=ExtResource("1_b1l1c")]
|
||||||
material = SubResource("ShaderMaterial_634ti")
|
material = SubResource("ShaderMaterial_m15k8")
|
||||||
position = Vector2(608, 352)
|
position = Vector2(608, 352)
|
||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
[node name="ProjectileContainer" type="Node2D" parent="."]
|
||||||
|
script = ExtResource("3_amh71")
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ extends RigidBody2D
|
||||||
|
|
||||||
class_name Hull
|
class_name Hull
|
||||||
|
|
||||||
## Shortcut to get_parent()
|
## Shortcut to get_parent().get_parent()
|
||||||
@onready var ship: Ship = get_parent()
|
@onready var ship: Ship = get_parent().get_parent()
|
||||||
|
|
||||||
## Hull ID to use with the Game.get_module func
|
## Hull ID to use with the Game.get_module func
|
||||||
@export var id: String = "hull"
|
@export var id: String = "hull"
|
||||||
|
|
@ -36,3 +36,8 @@ func add_ammunition(which: String, value: float) -> bool:
|
||||||
if ammunition[which] > max_ammunition[which]:
|
if ammunition[which] > max_ammunition[which]:
|
||||||
ammunition[which] = max_ammunition[which]
|
ammunition[which] = max_ammunition[which]
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
## Update ship's position and rotation
|
||||||
|
func _physics_process(_delta):
|
||||||
|
ship.position = position
|
||||||
|
ship.rotation = rotation
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,9 @@ extends Node2D
|
||||||
func _physics_process(_delta) -> void:
|
func _physics_process(_delta) -> void:
|
||||||
ship.engine.acceleration_axis = Input.get_axis("deccelerate", "accelerate")
|
ship.engine.acceleration_axis = Input.get_axis("deccelerate", "accelerate")
|
||||||
ship.engine.rotation_axis = Input.get_axis("rotateleft", "rotateright")
|
ship.engine.rotation_axis = Input.get_axis("rotateleft", "rotateright")
|
||||||
|
for weapon in ship.weapons.list:
|
||||||
|
match weapon.action_id:
|
||||||
|
"primary":
|
||||||
|
weapon.shoot_request = Input.get_action_strength("shootprimary")
|
||||||
|
"secondary":
|
||||||
|
weapon.shoot_request = Input.get_action_strength("shootsecondary")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ signal destroyed
|
||||||
## Reference to the engine module
|
## Reference to the engine module
|
||||||
@onready var engine: ShipEngine = $Engine
|
@onready var engine: ShipEngine = $Engine
|
||||||
## Reference to the hull module
|
## Reference to the hull module
|
||||||
@onready var hull: Hull = $Hull
|
@onready var hull: Hull = $HullHolder/Hull
|
||||||
## Reference to the shield module
|
## Reference to the shield module
|
||||||
@onready var shield: Shield = $Shield
|
@onready var shield: Shield = $Shield
|
||||||
## Reference to weapons node
|
## Reference to weapons node
|
||||||
|
|
@ -20,6 +20,7 @@ signal destroyed
|
||||||
var faction : Game.Faction = Game.Faction.Player
|
var faction : Game.Faction = Game.Faction.Player
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
hull.global_position += global_position
|
||||||
destroyed.connect(destroy)
|
destroyed.connect(destroy)
|
||||||
|
|
||||||
## Reset all required variables
|
## Reset all required variables
|
||||||
|
|
|
||||||
51
scripts/Ship/weapon.gd
Normal file
51
scripts/Ship/weapon.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
class_name Weapon
|
||||||
|
|
||||||
|
## Weapon ID to be used with Game.get_module()
|
||||||
|
@export var id: String = "weapon"
|
||||||
|
## Variable to use with input controller to determine which weapon to shoot
|
||||||
|
@export var action_id: String = "null"
|
||||||
|
## Projectile scene which will be created on shoot()
|
||||||
|
@export var projectile: PackedScene
|
||||||
|
## Applies additional angle (in degrees) while shooting
|
||||||
|
@export var spread: float = 0
|
||||||
|
## Ammo type that will be consumed
|
||||||
|
@export var ammo_type: String = "n/a"
|
||||||
|
## How much ammo will be consumet each shoot() call
|
||||||
|
@export var ammo_consumption: float = 0
|
||||||
|
## Timer to make cooldown between shots
|
||||||
|
@export var shoot_timer: Timer
|
||||||
|
## Points where projectiles will spawn
|
||||||
|
@export var spawner_points: Array[Node2D]
|
||||||
|
## Shortcut to get_parent().get_parent()
|
||||||
|
@onready var ship: Ship = get_parent().get_parent()
|
||||||
|
## Spread, converted to radians
|
||||||
|
var deviation: float = deg_to_rad(spread)
|
||||||
|
## Input variable to determine will the ship shoot
|
||||||
|
var shoot_request: bool = false
|
||||||
|
|
||||||
|
## Emits when shoot() is called
|
||||||
|
signal weapon_shooted
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
func _process(_delta) -> void:
|
||||||
|
var can_shoot = ship.hull.ammunition[ammo_type] >= ammo_consumption and shoot_timer.is_stopped()
|
||||||
|
if can_shoot and shoot_request:
|
||||||
|
shoot()
|
||||||
|
ship.hull.add_ammunition(ammo_type, -ammo_consumption)
|
||||||
|
shoot_timer.start()
|
||||||
|
if ammo_type == "Laser Energy":
|
||||||
|
ship.shield.laser_recharge_timer.start()
|
||||||
|
|
||||||
|
func shoot() -> void:
|
||||||
|
for spawner in spawner_points:
|
||||||
|
var projectile_instance = projectile.instantiate()
|
||||||
|
ProjectileContainer.instance.add_child(projectile_instance)
|
||||||
|
projectile_instance.global_position = spawner.global_position
|
||||||
|
projectile_instance.global_rotation = spawner.global_rotation + randf_range(-deviation/2, deviation/2)
|
||||||
|
projectile_instance.faction = ship.faction
|
||||||
|
projectile_instance.modulate = ship.modulate
|
||||||
|
weapon_shooted.emit()
|
||||||
|
|
@ -3,23 +3,30 @@ extends Node2D
|
||||||
# TODO: implement add_weapon
|
# TODO: implement add_weapon
|
||||||
|
|
||||||
## Shortcut to get_parent()
|
## Shortcut to get_parent()
|
||||||
@onready var ship = get_parent()
|
@onready var ship: Ship = get_parent()
|
||||||
## List of weapons
|
## List of weapons
|
||||||
var list: Array[Weapon] = get_children() as Array[Weapon]
|
@onready var list: Array[Node] = get_children() as Array[Node]
|
||||||
|
|
||||||
## 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[Weapon]
|
list = get_children() as Array[Node]
|
||||||
|
|
||||||
## Removes weapon with given ID and returns true if successful
|
## Removes weapon with given ID
|
||||||
func remove_weapon(id: String) -> bool:
|
func remove_weapon(id: String) -> void:
|
||||||
for weapon in list:
|
for weapon in list:
|
||||||
if weapon.id == id:
|
if weapon.id == id:
|
||||||
list.erase(weapon)
|
list.erase(weapon)
|
||||||
weapon.free()
|
weapon.free()
|
||||||
return true
|
break
|
||||||
return false
|
update_weapon_list()
|
||||||
|
|
||||||
## Adds weapon with given ID to list
|
## Adds weapon with given ID to list
|
||||||
func add_weapon(id: String) -> void:
|
func add_weapon(_id: String) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
## Returns a reference to weapon with given id if it exists, otherwise returns null
|
||||||
|
func get_weapon(id: String) -> Weapon:
|
||||||
|
for weapon in list:
|
||||||
|
if weapon.id == id:
|
||||||
|
return weapon as Weapon
|
||||||
|
return null
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ class_name Game
|
||||||
enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION}
|
enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION}
|
||||||
enum AMMO_TYPE {NULL, LASER_ENERGY, ROCKETS}
|
enum AMMO_TYPE {NULL, LASER_ENERGY, ROCKETS}
|
||||||
enum BASE_TYPE {POWER, MINING, FOOD, TRADING, MODULE}
|
enum BASE_TYPE {POWER, MINING, FOOD, TRADING, MODULE}
|
||||||
enum Faction {Player, Peaceful, Neutral, Aggressive}
|
enum Faction {None, Player, Peaceful, Neutral, Aggressive}
|
||||||
|
|
||||||
const DEFAULT_ITEM = preload("res://items/test_item.tres")
|
const DEFAULT_ITEM = preload("res://items/test_item.tres")
|
||||||
const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")
|
const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class_name Projectile
|
||||||
@export var collider : Area2D
|
@export var collider : Area2D
|
||||||
@export var lifetime : float = 10
|
@export var lifetime : float = 10
|
||||||
|
|
||||||
var faction = "none"
|
var faction: Game.Faction = Game.Faction.None
|
||||||
var destination_angle : float
|
var destination_angle : float
|
||||||
var target : Node2D = self
|
var target : Node2D = self
|
||||||
|
|
||||||
|
|
@ -34,10 +34,10 @@ func _physics_process(delta):
|
||||||
func _on_collision(body):
|
func _on_collision(body):
|
||||||
match body.collision_layer:
|
match body.collision_layer:
|
||||||
1:
|
1:
|
||||||
if body.faction != faction:
|
if body.ship.faction != faction:
|
||||||
if target != self:
|
if target != self:
|
||||||
target.queue_free()
|
target.queue_free()
|
||||||
body.shield.deal_damage(damage,global_position)
|
body.ship.shield.deal_damage(damage)
|
||||||
queue_free()
|
queue_free()
|
||||||
2:
|
2:
|
||||||
if target != self:
|
if target != self:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
class_name Weapon
|
# class_name Weapon
|
||||||
|
|
||||||
@export var projectile : PackedScene
|
@export var projectile : PackedScene
|
||||||
@export var spread : float = 0
|
@export var spread : float = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue