an enemy :3

This commit is contained in:
qwertzuiopy 2025-03-22 13:32:53 +01:00
parent 559ab93e57
commit 02ea283fa5
36 changed files with 950 additions and 13 deletions

19
bullet/bullet.gd Normal file
View file

@ -0,0 +1,19 @@
extends RigidBody2D
class_name Bullet
var player : Player
@export var flash : PackedScene = preload("res://effects/flash.tscn")
var pref : int = 0
func _integrate_forces(state) -> void:
pref += 1
if state.get_contact_count() > 0 && pref > 10:
pref = 0
var instance = flash.instantiate()
instance.global_position = state.get_contact_collider_position(0)
get_parent().add_child(instance)
func _on_body_entered(body: Node) -> void:
if body != Player and $animation.current_animation_position < 8:
$animation.seek(8)

1
bullet/bullet.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://c3eechg8hdpsc

BIN
bullet/bullet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

34
bullet/bullet.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cnj23l3endv58"
path="res://.godot/imported/bullet.png-2c2153c0dd3b3eaf69d3b6d097e024ff.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://bullet/bullet.png"
dest_files=["res://.godot/imported/bullet.png-2c2153c0dd3b3eaf69d3b6d097e024ff.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

155
bullet/bullet.tscn Normal file
View file

@ -0,0 +1,155 @@
[gd_scene load_steps=12 format=3 uid="uid://dnndsvtgqr8eq"]
[ext_resource type="Script" uid="uid://c3eechg8hdpsc" path="res://bullet/bullet.gd" id="1_0qjqd"]
[ext_resource type="Texture2D" uid="uid://cnj23l3endv58" path="res://bullet/bullet.png" id="1_k2aps"]
[ext_resource type="Texture2D" uid="uid://coegvp4cunsnn" path="res://bullet/bullet_colors.png" id="2_6wip1"]
[sub_resource type="CircleShape2D" id="CircleShape2D_k2aps"]
radius = 4.0
[sub_resource type="Animation" id="Animation_6wip1"]
length = 0.001
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("trail:emitting")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="Animation" id="Animation_k2aps"]
resource_name = "death"
length = 10.0
step = 0.1
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1e-05, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 9.6, 10)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1e-05, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 9.6, 10)
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(10),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"queue_free"
}]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("trail:emitting")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0, 9),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [true, false]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6wip1"]
_data = {
&"RESET": SubResource("Animation_6wip1"),
&"death": SubResource("Animation_k2aps")
}
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_k2aps"]
particles_animation = true
particles_anim_h_frames = 4
particles_anim_v_frames = 1
particles_anim_loop = false
[sub_resource type="Curve" id="Curve_k2aps"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.238372, 1), 0.0, 0.0, 0, 0, Vector2(0.738372, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 4
[sub_resource type="CurveTexture" id="CurveTexture_6wip1"]
curve = SubResource("Curve_k2aps")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_k2aps"]
particle_flag_disable_z = true
emission_shape_scale = Vector3(5, 5, 0)
emission_shape = 1
emission_sphere_radius = 1.0
angle_min = -720.0
angle_max = 720.0
gravity = Vector3(0, 0, 0)
scale_curve = SubResource("CurveTexture_6wip1")
anim_offset_max = 1.0
[node name="bullet" type="RigidBody2D"]
contact_monitor = true
max_contacts_reported = 1
script = ExtResource("1_0qjqd")
[node name="collision" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_k2aps")
[node name="image" type="Sprite2D" parent="."]
modulate = Color(2, 2, 2, 1)
texture = ExtResource("1_k2aps")
[node name="animation" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_6wip1")
}
autoplay = "death"
[node name="trail" type="GPUParticles2D" parent="."]
modulate = Color(1.5, 1.5, 1.5, 1)
material = SubResource("CanvasItemMaterial_k2aps")
amount = 20
texture = ExtResource("2_6wip1")
process_material = SubResource("ParticleProcessMaterial_k2aps")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

BIN
bullet/bullet_colors.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://coegvp4cunsnn"
path="res://.godot/imported/bullet_colors.png-6427ad6150c8a2cb40e110dd08b6f774.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://bullet/bullet_colors.png"
dest_files=["res://.godot/imported/bullet_colors.png-6427ad6150c8a2cb40e110dd08b6f774.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

16
effects/flash.gd Normal file
View file

@ -0,0 +1,16 @@
extends Node2D
class_name Flash
@export var oneshot : bool = true
func _ready() -> void:
if oneshot:
flash()
func flash() -> void:
if oneshot or not $animation.is_playing():
$animation.play("flash")
func destroy() -> void:
if oneshot:
queue_free()

1
effects/flash.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://ddh5k2bh3mqp7

99
effects/flash.tscn Normal file
View file

@ -0,0 +1,99 @@
[gd_scene load_steps=10 format=3 uid="uid://800ou0i3omcs"]
[ext_resource type="Texture2D" uid="uid://coegvp4cunsnn" path="res://bullet/bullet_colors.png" id="1_7hhmj"]
[ext_resource type="Script" uid="uid://ddh5k2bh3mqp7" path="res://effects/flash.gd" id="1_xcggr"]
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_qjkh3"]
particles_animation = true
particles_anim_h_frames = 4
particles_anim_v_frames = 1
particles_anim_loop = false
[sub_resource type="Curve" id="Curve_yw30f"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.188953, 1), 0.0, 0.0, 0, 0, Vector2(0.549419, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 4
[sub_resource type="CurveTexture" id="CurveTexture_qjkh3"]
curve = SubResource("Curve_yw30f")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_yw30f"]
particle_flag_disable_z = true
angle_min = -720.0
angle_max = 720.0
spread = 180.0
initial_velocity_min = 20.0
initial_velocity_max = 20.0
gravity = Vector3(0, 0, 0)
damping_min = 30.0
damping_max = 30.0
scale_curve = SubResource("CurveTexture_qjkh3")
anim_offset_max = 1.0
[sub_resource type="Animation" id="Animation_qjkh3"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("particles:emitting")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
[sub_resource type="Animation" id="Animation_yw30f"]
resource_name = "flash"
length = 0.6
step = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("particles:emitting")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [true, false]
}
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.6),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"destroy"
}]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_g6k8r"]
_data = {
&"RESET": SubResource("Animation_qjkh3"),
&"flash": SubResource("Animation_yw30f")
}
[node name="flash" type="Node2D"]
script = ExtResource("1_xcggr")
[node name="particles" type="GPUParticles2D" parent="."]
modulate = Color(2, 2, 2, 1)
material = SubResource("CanvasItemMaterial_qjkh3")
emitting = false
amount = 100
texture = ExtResource("1_7hhmj")
lifetime = 0.3
process_material = SubResource("ParticleProcessMaterial_yw30f")
[node name="animation" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_g6k8r")
}

37
enemies/basic/basic.gd Normal file
View file

@ -0,0 +1,37 @@
extends RigidBody2D
@export var player : Player
@onready var dirmodule: DirModule = $dirmodule
@onready var shootmodule: ShootModule = $shootmodule
@onready var thruster: Thruster = $thruster
@export var thrust: float = 0.3
func _ready() -> void:
player.radar.declare_threat(self)
func _exit_tree() -> void:
player.radar.release_threat(self)
func _physics_process(_delta: float) -> void:
if player == null:
print("no target for enemy!")
return
dirmodule.active = true
dirmodule.target_position = player.global_position - 2.0 * linear_velocity.project((global_position-player.global_position).normalized().rotated(PI/2))
var diff : float = Vector2.UP.rotated(global_rotation).dot((global_position - dirmodule.target_position).normalized())
if diff < -0.3:
apply_central_impulse(thrust * Vector2.UP.rotated(global_rotation))
thruster.active = true
else:
thruster.active = false
if diff < -0.9 && not $animations.is_playing() && shootmodule.can_shoot:
$animations.play("shoot")
player.radar.declare_danger(self)
func done_shooting() -> void:
player.radar.release_danger(self)

View file

@ -0,0 +1 @@
uid://buxbgc2aypffw

BIN
enemies/basic/basic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://1541pn8483aq"
path="res://.godot/imported/basic.png-2a63e2beee8b76cb1807cbaffaa7575b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://enemies/basic/basic.png"
dest_files=["res://.godot/imported/basic.png-2a63e2beee8b76cb1807cbaffaa7575b.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

142
enemies/basic/basic.tscn Normal file
View file

@ -0,0 +1,142 @@
[gd_scene load_steps=14 format=3 uid="uid://cwedpavtb5vfc"]
[ext_resource type="Script" uid="uid://buxbgc2aypffw" path="res://enemies/basic/basic.gd" id="1_7627k"]
[ext_resource type="Texture2D" uid="uid://1541pn8483aq" path="res://enemies/basic/basic.png" id="2_ytr2k"]
[ext_resource type="Script" uid="uid://v8qsd63ypr1y" path="res://enemies/dirmodule.gd" id="3_jyvyq"]
[ext_resource type="PackedScene" uid="uid://y08tu4ftj3t4" path="res://player/thruster.tscn" id="4_prw5c"]
[ext_resource type="Script" uid="uid://cuohktgei6yfn" path="res://enemies/shootmodule.gd" id="5_a6vy3"]
[ext_resource type="PackedScene" uid="uid://dnndsvtgqr8eq" path="res://bullet/bullet.tscn" id="6_n1d5r"]
[ext_resource type="PackedScene" uid="uid://800ou0i3omcs" path="res://effects/flash.tscn" id="6_v3l44"]
[sub_resource type="CircleShape2D" id="CircleShape2D_ytr2k"]
radius = 6.0
[sub_resource type="Curve" id="Curve_jyvyq"]
_data = [Vector2(0, 0.251087), 0.0, 0.0, 0, 0, Vector2(0.271233, 1), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_prw5c"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.336986, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Animation" id="Animation_0bibs"]
length = 0.001
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="Animation" id="Animation_n1d5r"]
resource_name = "shoot"
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 1.1, -0.25, 0, 0.25, 0, 0.835, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 0.766667, 1)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 0.806, -0.25, 0, 0.25, 0, 1.177, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 0.766667, 1)
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("shootmodule")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.6),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"shoot"
}]
}
tracks/3/type = "method"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath(".")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0.8),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"done_shooting"
}]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_0bibs"]
_data = {
&"RESET": SubResource("Animation_0bibs"),
&"shoot": SubResource("Animation_n1d5r")
}
[node name="basic" type="RigidBody2D"]
visible = false
script = ExtResource("1_7627k")
thrust = 0.5
[node name="image" type="Sprite2D" parent="."]
rotation = -6.28318
texture = ExtResource("2_ytr2k")
[node name="collision" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_ytr2k")
[node name="dirmodule" type="Node" parent="."]
script = ExtResource("3_jyvyq")
pos_controll = SubResource("Curve_jyvyq")
pos_factor = 2.0
vel_controll = SubResource("Curve_prw5c")
vel_factor = 2.0
[node name="thruster" parent="." instance=ExtResource("4_prw5c")]
position = Vector2(0, 4)
[node name="shootmodule" type="Marker2D" parent="."]
position = Vector2(0, -10)
gizmo_extents = 3.0
script = ExtResource("5_a6vy3")
bullet = ExtResource("6_n1d5r")
speed = 50.0
knockback = 50.0
[node name="flash" parent="shootmodule" instance=ExtResource("6_v3l44")]
oneshot = false
[node name="animations" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_0bibs")
}

28
enemies/dirmodule.gd Normal file
View file

@ -0,0 +1,28 @@
extends Node
class_name DirModule
# in global coordinates
@export var target_position: Vector2
@export var active: bool = false
@export var offset: float = PI / 2
@export var pos_controll: Curve
@export var pos_factor: float = 1.0
@export var vel_controll: Curve
@export var vel_factor: float = 1.0
@onready var parent: RigidBody2D = get_parent()
func _physics_process(_delta: float) -> void:
if not active:
return
var diff := parent.global_position.angle_to_point(target_position) - parent.global_rotation + offset
while diff < -PI:
diff += PI * 2
while diff > PI:
diff -= PI * 2
var closeness: float = abs(diff) / PI
parent.apply_torque_impulse(
pos_factor * sign(diff) * pos_controll.sample_baked(closeness)
- vel_factor * sign(parent.angular_velocity) * vel_controll.sample_baked(closeness))

1
enemies/dirmodule.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://v8qsd63ypr1y

26
enemies/shootmodule.gd Normal file
View file

@ -0,0 +1,26 @@
extends Marker2D
class_name ShootModule
@export var bullet: PackedScene
@export var speed: float = 100.0
@export var knockback: float = 10.0
@export var timeout: float = 2.0
var can_shoot: bool = true
@onready var parent: RigidBody2D = get_parent()
func shoot() -> void:
if not can_shoot:
return
var instance : Bullet = bullet.instantiate() as Bullet
parent.get_parent().add_child(instance)
instance.global_position = global_position
instance.apply_central_impulse(Vector2.UP.rotated(global_rotation) * speed)
instance.apply_central_impulse(parent.linear_velocity.project(Vector2.UP.rotated(global_rotation)))
instance.player = parent.player
parent.apply_central_impulse(Vector2.DOWN.rotated(global_rotation) * knockback)
$flash.flash()
can_shoot = false
await get_tree().create_timer(timeout).timeout
can_shoot = true

View file

@ -0,0 +1 @@
uid://cuohktgei6yfn

30
hud/radar/radar.gd Normal file
View file

@ -0,0 +1,30 @@
extends Node2D
class_name Radar
@export var threat_packed: PackedScene
func declare_threat(node: Node2D) -> void:
var instance: Threat = threat_packed.instantiate()
instance.node = node
add_child(instance)
func release_threat(node: Node2D) -> void:
for i: int in get_child_count():
var threat: Threat = get_child(i)
if threat.node == node:
remove_child(threat)
return
func declare_danger(node: Node2D) -> void:
for i: int in get_child_count():
var threat: Threat = get_child(i)
if threat.node == node:
threat.declare_danger()
func release_danger(node: Node2D) -> void:
for i: int in get_child_count():
var threat: Threat = get_child(i)
if threat.node == node:
threat.release_danger()
func _process(_delta: float) -> void:
global_rotation = 0.0

1
hud/radar/radar.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://s6xe11km41qe

9
hud/radar/radar.tscn Normal file
View file

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://dfm1atk5lpdo4"]
[ext_resource type="Script" uid="uid://s6xe11km41qe" path="res://hud/radar/radar.gd" id="1_jp2lf"]
[ext_resource type="PackedScene" uid="uid://dwk5lnfnntqh2" path="res://hud/radar/threat.tscn" id="2_23wok"]
[node name="radar" type="Node2D"]
z_index = 1
script = ExtResource("1_jp2lf")
threat_packed = ExtResource("2_23wok")

21
hud/radar/threat.gd Normal file
View file

@ -0,0 +1,21 @@
extends Sprite2D
class_name Threat
@export var node: Node2D
const dst: float = 70.0
func _physics_process(_delta: float) -> void:
if (node.global_position - get_parent().global_position).length() < dst:
modulate.a = 0
else:
position = dst * (node.global_position - get_parent().global_position).normalized()
modulate.a = 1
func declare_danger():
print("danger")
$animations.play("blink")
func release_danger():
print("no danger")
$animations.stop()
visible = true

1
hud/radar/threat.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://bm76ox7rvuita

52
hud/radar/threat.tscn Normal file
View file

@ -0,0 +1,52 @@
[gd_scene load_steps=6 format=3 uid="uid://dwk5lnfnntqh2"]
[ext_resource type="Texture2D" uid="uid://b8u4cc61kpl" path="res://hud/radar/threat_normal.png" id="1_cuq7j"]
[ext_resource type="Script" uid="uid://bm76ox7rvuita" path="res://hud/radar/threat.gd" id="2_oq6ws"]
[sub_resource type="Animation" id="Animation_oq6ws"]
resource_name = "blink"
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 1,
"values": [false, true, false, true]
}
[sub_resource type="Animation" id="Animation_3aocn"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_3aocn"]
_data = {
&"RESET": SubResource("Animation_3aocn"),
&"blink": SubResource("Animation_oq6ws")
}
[node name="threat" type="Sprite2D"]
modulate = Color(2, 2, 2, 1)
texture = ExtResource("1_cuq7j")
script = ExtResource("2_oq6ws")
[node name="animations" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_3aocn")
}

BIN
hud/radar/threat_normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b8u4cc61kpl"
path="res://.godot/imported/threat_normal.png-3e4084ea6f7067b067f49c4502cd25f5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://hud/radar/threat_normal.png"
dest_files=["res://.godot/imported/threat_normal.png-3e4084ea6f7067b067f49c4502cd25f5.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

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 282 B

Before After
Before After

View file

@ -8,6 +8,9 @@ class_name Player
var angular_velocity_target := 0.0 var angular_velocity_target := 0.0
@onready var radar: Radar = $radar
var delay := false
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
var input := Vector2(Input.get_action_strength("right") - Input.get_action_strength("left"), Input.get_action_strength("boost")) var input := Vector2(Input.get_action_strength("right") - Input.get_action_strength("left"), Input.get_action_strength("boost"))
@ -22,6 +25,9 @@ func _physics_process(delta: float) -> void:
%thruster.active = true %thruster.active = true
else: else:
%thruster.active = false %thruster.active = false
if Input.is_action_just_pressed("shoot"):
%railgun.shoot()
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void: func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
state.angular_velocity = lerp(state.angular_velocity, angular_velocity_target, 0.1) state.angular_velocity = lerp(state.angular_velocity, angular_velocity_target, 0.1)

View file

@ -1,8 +1,12 @@
[gd_scene load_steps=11 format=3 uid="uid://b3xadpl4pu33u"] [gd_scene load_steps=18 format=3 uid="uid://b3xadpl4pu33u"]
[ext_resource type="Script" uid="uid://erjhplyctxik" path="res://player/player.gd" id="1_kkw55"] [ext_resource type="Script" uid="uid://erjhplyctxik" path="res://player/player.gd" id="1_kkw55"]
[ext_resource type="Texture2D" uid="uid://dlenptyfk1iwn" path="res://player/ship.png" id="2_1h4u8"] [ext_resource type="Texture2D" uid="uid://dlenptyfk1iwn" path="res://player/ship.png" id="2_1h4u8"]
[ext_resource type="PackedScene" uid="uid://dnndsvtgqr8eq" path="res://bullet/bullet.tscn" id="2_yw30f"]
[ext_resource type="PackedScene" uid="uid://y08tu4ftj3t4" path="res://player/thruster.tscn" id="3_r6c8y"] [ext_resource type="PackedScene" uid="uid://y08tu4ftj3t4" path="res://player/thruster.tscn" id="3_r6c8y"]
[ext_resource type="Script" uid="uid://dccya6vnwi1x4" path="res://player/railgun.gd" id="5_g6k8r"]
[ext_resource type="PackedScene" uid="uid://800ou0i3omcs" path="res://effects/flash.tscn" id="5_qjkh3"]
[ext_resource type="PackedScene" uid="uid://dfm1atk5lpdo4" path="res://hud/radar/radar.tscn" id="7_rgyib"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_6481p"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_6481p"]
friction = 0.0 friction = 0.0
@ -40,12 +44,86 @@ scale_max = 2.0
scale_curve = SubResource("CurveTexture_w2mcu") scale_curve = SubResource("CurveTexture_w2mcu")
alpha_curve = SubResource("CurveTexture_q5aon") alpha_curve = SubResource("CurveTexture_q5aon")
[sub_resource type="Animation" id="Animation_qjkh3"]
resource_name = "shoot"
length = 0.4
step = 0.1
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("%railgun/../image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.1, 0.003124, 0.835, -0.066667, -0.000579298, 0.133333, -0.000579298, 1, -0.2, 0.00127017, 0.25, 0),
"times": PackedFloat32Array(0, 0.166667, 0.4)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("%railgun/../image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0, 0, 0),
"points": PackedFloat32Array(1, -0.25, 0, 0.1, -0.000583708, 1.177, -0.066667, -0.00146496, 0.133333, -0.00517273, 1, -0.2, 0.003124, 0.25, 0),
"times": PackedFloat32Array(0, 0.166667, 0.4)
}
tracks/2/type = "method"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0.1),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"do_shoot"
}]
}
[sub_resource type="Animation" id="Animation_g6k8r"]
length = 0.001
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("%railgun/../image:scale:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("%railgun/../image:scale:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_g6k8r"]
_data = {
&"RESET": SubResource("Animation_g6k8r"),
&"shoot": SubResource("Animation_qjkh3")
}
[node name="player" type="RigidBody2D"] [node name="player" type="RigidBody2D"]
physics_material_override = SubResource("PhysicsMaterial_6481p") physics_material_override = SubResource("PhysicsMaterial_6481p")
gravity_scale = 0.0 gravity_scale = 0.0
can_sleep = false can_sleep = false
angular_damp = 2.0 angular_damp = 2.0
script = ExtResource("1_kkw55") script = ExtResource("1_kkw55")
thruster_strength = null
rotation_strength = null
drift_curve = SubResource("Curve_f6djc") drift_curve = SubResource("Curve_f6djc")
[node name="camera" type="Camera2D" parent="."] [node name="camera" type="Camera2D" parent="."]
@ -54,8 +132,8 @@ position_smoothing_enabled = true
[node name="stars" type="GPUParticles2D" parent="camera"] [node name="stars" type="GPUParticles2D" parent="camera"]
amount = 100 amount = 100
process_material = SubResource("ParticleProcessMaterial_k0vl1")
lifetime = 30.0 lifetime = 30.0
process_material = SubResource("ParticleProcessMaterial_k0vl1")
[node name="collision" type="CollisionPolygon2D" parent="."] [node name="collision" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(-5, 7, 0, -7, 5, 7, 2, 8, -2, 8) polygon = PackedVector2Array(-5, 7, 0, -7, 5, 7, 2, 8, -2, 8)
@ -66,3 +144,21 @@ texture = ExtResource("2_1h4u8")
[node name="thruster" parent="." instance=ExtResource("3_r6c8y")] [node name="thruster" parent="." instance=ExtResource("3_r6c8y")]
unique_name_in_owner = true unique_name_in_owner = true
position = Vector2(0, 8) position = Vector2(0, 8)
[node name="railgun" type="Marker2D" parent="."]
unique_name_in_owner = true
position = Vector2(0, -10)
gizmo_extents = 3.0
script = ExtResource("5_g6k8r")
bullet = ExtResource("2_yw30f")
[node name="flash" parent="railgun" instance=ExtResource("5_qjkh3")]
unique_name_in_owner = true
oneshot = false
[node name="animations" type="AnimationPlayer" parent="railgun"]
libraries = {
&"": SubResource("AnimationLibrary_g6k8r")
}
[node name="radar" parent="." instance=ExtResource("7_rgyib")]

29
player/railgun.gd Normal file
View file

@ -0,0 +1,29 @@
extends Marker2D
@export var bullet : PackedScene
@export var speed : float = 100.0
@export var knockback : float = 30.0
@onready var flash: Flash = %flash
@onready var parent: RigidBody2D = get_parent()
var can_shoot: bool = true
func shoot() -> void:
if not can_shoot or $animations.is_playing():
return
$animations.play("shoot")
func do_shoot() -> void:
if not can_shoot:
return
var instance : Bullet = bullet.instantiate() as Bullet
parent.get_parent().add_child(instance)
instance.global_position = global_position
instance.apply_central_impulse(Vector2.UP.rotated(global_rotation) * speed)
instance.player = parent
parent.apply_central_impulse(Vector2.DOWN.rotated(global_rotation) * knockback)
flash.flash()
can_shoot = false
await get_tree().create_timer(0.5).timeout
can_shoot = true

1
player/railgun.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://dccya6vnwi1x4

View file

@ -1,11 +1,16 @@
extends Marker2D extends Marker2D
class_name Thruster
@export var active : bool @export var active : bool
func _physics_process(delta: float) -> void: @onready var pushback: Area2D = $pushback
func _physics_process(_delta: float) -> void:
if active: if active:
%fire.emitting = true %fire.emitting = true
%smoke.emitting = true %smoke.emitting = true
pushback.gravity = -1500.0
else: else:
%fire.emitting = false %fire.emitting = false
%smoke.emitting = false %smoke.emitting = false
pushback.gravity = 0

View file

@ -51,15 +51,26 @@ script = ExtResource("1_ua4l5")
unique_name_in_owner = true unique_name_in_owner = true
rotation = 1.5708 rotation = 1.5708
amount = 50 amount = 50
process_material = SubResource("ParticleProcessMaterial_wobn2")
texture = ExtResource("3_gj8x6") texture = ExtResource("3_gj8x6")
lifetime = 2.0 lifetime = 2.0
fixed_fps = 60 fixed_fps = 60
process_material = SubResource("ParticleProcessMaterial_wobn2")
[node name="fire" type="GPUParticles2D" parent="."] [node name="fire" type="GPUParticles2D" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
rotation = 1.5708 rotation = 1.5708
amount = 50 amount = 50
process_material = SubResource("ParticleProcessMaterial_wobn2")
texture = ExtResource("2_jmeol") texture = ExtResource("2_jmeol")
fixed_fps = 60 fixed_fps = 60
process_material = SubResource("ParticleProcessMaterial_wobn2")
[node name="pushback" type="Area2D" parent="."]
gravity_space_override = 1
gravity_point = true
gravity_point_unit_distance = 3.0
gravity_point_center = Vector2(0, 0)
gravity_direction = Vector2(0, 0)
gravity = -1500.0
[node name="shape" type="CollisionPolygon2D" parent="pushback"]
polygon = PackedVector2Array(-3, 5, -15, 80, 14, 80, 3, 5)

View file

@ -41,6 +41,11 @@ right={
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
] ]
} }
shoot={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[physics] [physics]
@ -51,4 +56,5 @@ right={
[rendering] [rendering]
textures/canvas_textures/default_texture_filter=0 textures/canvas_textures/default_texture_filter=0
viewport/hdr_2d=true
environment/defaults/default_clear_color=Color(0, 0, 0, 1) environment/defaults/default_clear_color=Color(0, 0, 0, 1)