Added enemies
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
class_name EnemyController
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
@warning_ignore("unused_signal")
|
||||||
|
signal accelerate(direction: Vector2, delta: float)
|
||||||
|
|
||||||
|
@warning_ignore("unused_signal")
|
||||||
|
signal shoot(weapon_index: int)
|
||||||
|
|
||||||
|
|
||||||
|
@warning_ignore("unused_signal")
|
||||||
|
signal reload(weapon_index: int)
|
||||||
|
|
||||||
|
|
||||||
|
@warning_ignore("unused_parameter")
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
for i in 10:
|
||||||
|
shoot.emit(i)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bs8qqj6yepfln
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bsqehbymixust"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bs8qqj6yepfln" path="res://game/controllers/enemy_controller.gd" id="1_10a67"]
|
||||||
|
|
||||||
|
[node name="EnemyController" type="Node"]
|
||||||
|
script = ExtResource("1_10a67")
|
||||||
@@ -2,6 +2,26 @@ class_name AbstractShip
|
|||||||
extends CharacterBody2D
|
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 WEAPONS := [
|
||||||
|
CANNON, GATLING, LASER,
|
||||||
|
LAUNCHER, MINELAYER, PLASMA,
|
||||||
|
RAILGUN, SHRAPNEL, TESLA,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
signal destroyed
|
||||||
|
|
||||||
|
|
||||||
@onready var sprite := $Sprite2D
|
@onready var sprite := $Sprite2D
|
||||||
@onready var collision := $CollisionShape2D
|
@onready var collision := $CollisionShape2D
|
||||||
|
|
||||||
@@ -16,6 +36,14 @@ extends CharacterBody2D
|
|||||||
var _weapons : Array[AbstractWeapon]
|
var _weapons : Array[AbstractWeapon]
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
for pos in weapon_positions:
|
||||||
|
var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate()
|
||||||
|
weapon.position = pos
|
||||||
|
add_child(weapon)
|
||||||
|
_weapons.append(weapon)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
var was_collided := move_and_slide()
|
var was_collided := move_and_slide()
|
||||||
if was_collided:
|
if was_collided:
|
||||||
@@ -57,3 +85,4 @@ func _get_new_speed(accel: float, decel: float, current_speed: float) -> float:
|
|||||||
|
|
||||||
func _on_health_depleted() -> void:
|
func _on_health_depleted() -> void:
|
||||||
queue_free()
|
queue_free()
|
||||||
|
destroyed.emit()
|
||||||
|
|||||||
@@ -18,8 +18,5 @@ shape = SubResource("CircleShape2D_xxtvk")
|
|||||||
|
|
||||||
[node name="Health" type="Node" parent="."]
|
[node name="Health" type="Node" parent="."]
|
||||||
script = ExtResource("2_n766o")
|
script = ExtResource("2_n766o")
|
||||||
max_shield = 1000
|
|
||||||
max_armor = 1000
|
|
||||||
max_hull = 1000
|
|
||||||
|
|
||||||
[connection signal="depleted" from="Health" to="." method="_on_health_depleted"]
|
[connection signal="depleted" from="Health" to="." method="_on_health_depleted"]
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class_name AbstractEnemyShip
|
||||||
|
extends AbstractShip
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
super._ready()
|
||||||
|
for weapon in _weapons:
|
||||||
|
weapon.belonging = AbstractWeapon.Belonging.ENEMY
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://byicf1t0807pq
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
[gd_scene load_steps=4 format=3 uid="uid://dwsn0lf1e3578"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_28j6l"]
|
||||||
|
[ext_resource type="Script" uid="uid://byicf1t0807pq" path="res://game/entities/ships/enemies/abstract_enemy_ship.gd" id="2_fwvrd"]
|
||||||
|
[ext_resource type="Script" uid="uid://bs8qqj6yepfln" path="res://game/controllers/enemy_controller.gd" id="3_vfnhw"]
|
||||||
|
|
||||||
|
[node name="AbstractEnemyShip" instance=ExtResource("1_28j6l")]
|
||||||
|
collision_layer = 4
|
||||||
|
collision_mask = 0
|
||||||
|
script = ExtResource("2_fwvrd")
|
||||||
|
|
||||||
|
[node name="EnemyController" type="Node" parent="." index="3"]
|
||||||
|
script = ExtResource("3_vfnhw")
|
||||||
|
metadata/_custom_type_script = "uid://bs8qqj6yepfln"
|
||||||
|
|
||||||
|
[connection signal="accelerate" from="EnemyController" to="." method="accelerate"]
|
||||||
|
[connection signal="reload" from="EnemyController" to="." method="reload"]
|
||||||
|
[connection signal="shoot" from="EnemyController" to="." method="shoot"]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class_name HeavyEnemyShip
|
||||||
|
extends AbstractEnemyShip
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cxomr1oojcrcl
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://d3epy8w15qmjm"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_wvvpj"]
|
||||||
|
[ext_resource type="Script" uid="uid://cxomr1oojcrcl" path="res://game/entities/ships/enemies/heavy/heavy_enemy_ship.gd" id="2_3umer"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_cuapu"]
|
||||||
|
size = Vector2(64, 48)
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_cuapu"]
|
||||||
|
radius = 23.0
|
||||||
|
height = 62.0
|
||||||
|
|
||||||
|
[node name="HeavyEnemyShip" instance=ExtResource("1_wvvpj")]
|
||||||
|
script = ExtResource("2_3umer")
|
||||||
|
acceleration = 30
|
||||||
|
deceleration = 18
|
||||||
|
max_speed = 60
|
||||||
|
weapon_positions = Array[Vector2]([Vector2(0, 12), Vector2(0, 0), Vector2(0, -12)])
|
||||||
|
|
||||||
|
[node name="Sprite2D" parent="." index="0"]
|
||||||
|
texture = SubResource("PlaceholderTexture2D_cuapu")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
rotation = 1.5707964
|
||||||
|
shape = SubResource("CapsuleShape2D_cuapu")
|
||||||
|
|
||||||
|
[node name="Health" parent="." index="2"]
|
||||||
|
max_hull = 200
|
||||||
|
|
||||||
|
[connection signal="accelerate" from="EnemyController" to="." method="accelerate"]
|
||||||
|
[connection signal="reload" from="EnemyController" to="." method="reload"]
|
||||||
|
[connection signal="shoot" from="EnemyController" to="." method="shoot"]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class_name MediumEnemyShip
|
||||||
|
extends AbstractEnemyShip
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dcpqrdvp4nk82
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://cye5ndbh0ht7w"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_16owb"]
|
||||||
|
[ext_resource type="Script" uid="uid://dcpqrdvp4nk82" path="res://game/entities/ships/enemies/medium/medium_enemy_ship.gd" id="2_dgwiy"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_4jmkv"]
|
||||||
|
size = Vector2(32, 48)
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4jmkv"]
|
||||||
|
radius = 15.0
|
||||||
|
height = 46.0
|
||||||
|
|
||||||
|
[node name="MediumEnemyShip" instance=ExtResource("1_16owb")]
|
||||||
|
script = ExtResource("2_dgwiy")
|
||||||
|
acceleration = 92
|
||||||
|
deceleration = 46
|
||||||
|
max_speed = 92
|
||||||
|
weapon_positions = Array[Vector2]([Vector2(0, 10), Vector2(0, -10)])
|
||||||
|
|
||||||
|
[node name="Sprite2D" parent="." index="0"]
|
||||||
|
texture = SubResource("PlaceholderTexture2D_4jmkv")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
shape = SubResource("CapsuleShape2D_4jmkv")
|
||||||
|
|
||||||
|
[node name="Health" parent="." index="2"]
|
||||||
|
max_hull = 100
|
||||||
|
|
||||||
|
[connection signal="accelerate" from="EnemyController" to="." method="accelerate"]
|
||||||
|
[connection signal="reload" from="EnemyController" to="." method="reload"]
|
||||||
|
[connection signal="shoot" from="EnemyController" to="." method="shoot"]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class_name SmallEnemyShip
|
||||||
|
extends AbstractEnemyShip
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://btcce3nflycrs
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://cbf3kumeoqpba"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_lt1av"]
|
||||||
|
[ext_resource type="Script" uid="uid://btcce3nflycrs" path="res://game/entities/ships/enemies/small/small_enemy_ship.gd" id="2_bw04d"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_bw04d"]
|
||||||
|
size = Vector2(32, 16)
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_lopve"]
|
||||||
|
radius = 7.0
|
||||||
|
|
||||||
|
[node name="SmallEnemyShip" instance=ExtResource("1_lt1av")]
|
||||||
|
script = ExtResource("2_bw04d")
|
||||||
|
acceleration = 180
|
||||||
|
deceleration = 80
|
||||||
|
max_speed = 120
|
||||||
|
weapon_positions = Array[Vector2]([Vector2(0, 0)])
|
||||||
|
|
||||||
|
[node name="Sprite2D" parent="." index="0"]
|
||||||
|
texture = SubResource("PlaceholderTexture2D_bw04d")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
rotation = 1.5707964
|
||||||
|
shape = SubResource("CapsuleShape2D_lopve")
|
||||||
|
|
||||||
|
[node name="Health" parent="." index="2"]
|
||||||
|
max_hull = 50
|
||||||
|
|
||||||
|
[connection signal="accelerate" from="EnemyController" to="." method="accelerate"]
|
||||||
|
[connection signal="reload" from="EnemyController" to="." method="reload"]
|
||||||
|
[connection signal="shoot" from="EnemyController" to="." method="shoot"]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class_name PlayerShip
|
||||||
|
extends AbstractShip
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
super._ready()
|
||||||
|
for weapon in _weapons:
|
||||||
|
weapon.belonging = AbstractWeapon.Belonging.PLAYER
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
[gd_scene load_steps=6 format=3 uid="uid://br074cqcnul3d"]
|
[gd_scene load_steps=6 format=3 uid="uid://br074cqcnul3d"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_6otxb"]
|
[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_6otxb"]
|
||||||
[ext_resource type="Script" uid="uid://ruxw1n03iq4i" path="res://game/entities/ships/player_ship.gd" id="2_625ti"]
|
[ext_resource type="Script" uid="uid://ruxw1n03iq4i" path="res://game/entities/ships/player/player_ship.gd" id="2_625ti"]
|
||||||
[ext_resource type="Script" uid="uid://dgevigih7owxd" path="res://game/controllers/player_controller.gd" id="3_dj8f1"]
|
[ext_resource type="Script" uid="uid://dgevigih7owxd" path="res://game/controllers/player_controller.gd" id="3_dj8f1"]
|
||||||
|
|
||||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dj8f1"]
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_dj8f1"]
|
||||||
size = Vector2(48, 32)
|
size = Vector2(48, 32)
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_dj8f1"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_dj8f1"]
|
||||||
height = 20.0
|
radius = 15.0
|
||||||
|
height = 46.0
|
||||||
|
|
||||||
[node name="PlayerShip" instance=ExtResource("1_6otxb")]
|
[node name="PlayerShip" instance=ExtResource("1_6otxb")]
|
||||||
collision_layer = 3
|
collision_layer = 3
|
||||||
@@ -22,8 +23,12 @@ weapon_positions = Array[Vector2]([Vector2(0, 8), Vector2(0, -8)])
|
|||||||
texture = SubResource("PlaceholderTexture2D_dj8f1")
|
texture = SubResource("PlaceholderTexture2D_dj8f1")
|
||||||
|
|
||||||
[node name="CollisionShape2D" parent="." index="1"]
|
[node name="CollisionShape2D" parent="." index="1"]
|
||||||
|
rotation = 1.5707964
|
||||||
shape = SubResource("CapsuleShape2D_dj8f1")
|
shape = SubResource("CapsuleShape2D_dj8f1")
|
||||||
|
|
||||||
|
[node name="Health" parent="." index="2"]
|
||||||
|
max_hull = 1000
|
||||||
|
|
||||||
[node name="PlayerController" type="Node" parent="." index="3"]
|
[node name="PlayerController" type="Node" parent="." index="3"]
|
||||||
script = ExtResource("3_dj8f1")
|
script = ExtResource("3_dj8f1")
|
||||||
metadata/_custom_type_script = "uid://dgevigih7owxd"
|
metadata/_custom_type_script = "uid://dgevigih7owxd"
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
class_name PlayerShip
|
|
||||||
extends AbstractShip
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const CANNON = preload("res://game/entities/weapons/cannon/cannon.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const GATLING = preload("res://game/entities/weapons/gatling/gatling.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const LASER = preload("res://game/entities/weapons/laser/laser.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const LAUNCHER = preload("res://game/entities/weapons/launcher/launcher.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const MINELAYER = preload("res://game/entities/weapons/minelayer/minelayer.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const PLASMA = preload("res://game/entities/weapons/plasma/plasma.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const RAILGUN = preload("res://game/entities/weapons/railgun/railgun.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const SHRAPNEL = preload("res://game/entities/weapons/shrapnel/shrapnel.tscn")
|
|
||||||
@warning_ignore("unused_local_constant")
|
|
||||||
const TESLA = preload("res://game/entities/weapons/tesla/tesla.tscn")
|
|
||||||
|
|
||||||
var weapons := [
|
|
||||||
GATLING.instantiate(),
|
|
||||||
RAILGUN.instantiate(),
|
|
||||||
]
|
|
||||||
|
|
||||||
for index in weapons.size():
|
|
||||||
var weapon : Node2D = weapons[index]
|
|
||||||
if index < weapon_positions.size():
|
|
||||||
weapon.position = weapon_positions[index]
|
|
||||||
add_child(weapons[index])
|
|
||||||
_weapons.append(weapon)
|
|
||||||
+22
-1
@@ -1,8 +1,29 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
const SMALL_ENEMY = preload("res://game/entities/ships/enemies/small/small_enemy_ship.tscn")
|
||||||
|
const MEDIUM_ENEMY = preload("res://game/entities/ships/enemies/medium/medium_enemy_ship.tscn")
|
||||||
|
const HEAVY_ENEMY = preload("res://game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn")
|
||||||
|
|
||||||
|
const PLAYER := preload("res://game/entities/ships/player/player_ship.tscn")
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
const PLAYER := preload("res://game/entities/ships/player_ship.tscn")
|
_create_player()
|
||||||
|
_create_random_enemy()
|
||||||
|
|
||||||
|
|
||||||
|
func _create_player() -> void:
|
||||||
var player : PlayerShip = PLAYER.instantiate()
|
var player : PlayerShip = PLAYER.instantiate()
|
||||||
add_child(player)
|
add_child(player)
|
||||||
player.position = Vector2(100, 100)
|
player.position = Vector2(100, 100)
|
||||||
|
player.destroyed.connect(_create_player)
|
||||||
|
|
||||||
|
|
||||||
|
func _create_random_enemy() -> void:
|
||||||
|
const ENEMIES := [ SMALL_ENEMY, MEDIUM_ENEMY, HEAVY_ENEMY ]
|
||||||
|
|
||||||
|
var enemy : AbstractEnemyShip = ENEMIES.pick_random().instantiate()
|
||||||
|
add_child(enemy)
|
||||||
|
enemy.position = Vector2(550, 180)
|
||||||
|
enemy.destroyed.connect(_create_random_enemy)
|
||||||
|
|||||||
Reference in New Issue
Block a user