This commit is contained in:
2025-09-03 17:36:59 +02:00
commit 8468769d70
36 changed files with 746 additions and 0 deletions

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
**/*.png filter=lfs diff=lfs merge=lfs -text
**/*.png~ filter=lfs diff=lfs merge=lfs -text
**/*.wav filter=lfs diff=lfs merge=lfs -text
**/*.ogg filter=lfs diff=lfs merge=lfs -text

BIN
assets/asteroidx1.png LFS Normal file

Binary file not shown.

View File

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

BIN
assets/asteroidx2.png LFS Normal file

Binary file not shown.

View File

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

BIN
assets/asteroidx3.png LFS Normal file

Binary file not shown.

View File

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

BIN
assets/asteroidx4.png LFS Normal file

Binary file not shown.

View File

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

BIN
assets/ship.kra Normal file

Binary file not shown.

BIN
assets/ship.png LFS Normal file

Binary file not shown.

34
assets/ship.png.import Normal file
View File

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

BIN
assets/shoot.png LFS Normal file

Binary file not shown.

34
assets/shoot.png.import Normal file
View File

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

60
asteroid.gd Normal file
View File

@@ -0,0 +1,60 @@
extends RigidBody2D
var SPEED : float
var direction : Vector2
var type:= 1
@export var particles := load("res://destroy.tscn")
@export var asteroidx1 : = load("res://asteroidx1.tscn")
@export var asteroidx2 : = load("res://asteroidx2.tscn")
@export var asteroidx3 : = load("res://asteroidx3.tscn")
func _ready() -> void:
add_to_group("asteroid")
SPEED = randf() / 50 +50
rotation = randf_range(0.0, 360.0)
func _process(_delta: float) -> void:
linear_velocity = direction * SPEED
func split():
var packed_use: PackedScene
if type == 1:
var part = particles.instantiate()
part.global_position = global_position
get_parent().call_deferred("add_child", part)
queue_free()
return
elif type == 2:
packed_use = asteroidx1
elif type == 3:
packed_use = asteroidx2
elif type == 4:
packed_use = asteroidx3
var first = packed_use.instantiate()
var second = packed_use.instantiate()
var nor = direction.rotated(PI/2).normalized()
first.direction = direction
second.direction = direction
first.global_position = position + (2**type * nor)
first.type = type-1
second.global_position = position - (2**type * nor)
second.type = type-1
var parent = get_parent()
var part = particles.instantiate()
part.global_position = global_position
parent.call_deferred("add_child", first)
parent.call_deferred("add_child", second)
parent.call_deferred("add_child", part)
queue_free()
func _on_body_entered(body: Node) -> void:
if body.is_in_group("asteroid"):
get_parent().emit_signal("add_collision", body, self)
if body.is_in_group("shoot"):
body.queue_free()
split()

1
asteroid.gd.uid Normal file
View File

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

25
asteroidx1.tscn Normal file
View File

@@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://ditud5veuxqyb"]
[ext_resource type="Script" uid="uid://b8a23hkmesx0l" path="res://asteroid.gd" id="1_p0ukn"]
[ext_resource type="Texture2D" uid="uid://dbingmvgsgvfv" path="res://assets/asteroidx1.png" id="1_u87q6"]
[sub_resource type="CircleShape2D" id="CircleShape2D_p0ukn"]
radius = 14.0357
[node name="asteroid" type="RigidBody2D"]
collision_layer = 2
collision_mask = 2
mass = 5.0
contact_monitor = true
max_contacts_reported = 4
script = ExtResource("1_p0ukn")
[node name="Asteroid" type="Sprite2D" parent="."]
texture = ExtResource("1_u87q6")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
light_mask = 2
visibility_layer = 2
shape = SubResource("CircleShape2D_p0ukn")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

20
asteroidx2.tscn Normal file
View File

@@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://d2jxc24g18ab1"]
[ext_resource type="Script" uid="uid://b8a23hkmesx0l" path="res://asteroid.gd" id="1_ka8bu"]
[ext_resource type="Texture2D" uid="uid://bby053xsfn3cp" path="res://assets/asteroidx2.png" id="2_e2m2r"]
[node name="asteroid" type="RigidBody2D"]
collision_layer = 2
collision_mask = 2
mass = 10.0
contact_monitor = true
max_contacts_reported = 4
script = ExtResource("1_ka8bu")
[node name="Asteroid" type="Sprite2D" parent="."]
texture = ExtResource("2_e2m2r")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(16, -23, 3, -29, -11, -27, -22, -12, -27, 2, -25, 21, -6, 30, 17, 23, 23, 10, 29, 1, 20, -8)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

20
asteroidx3.tscn Normal file
View File

@@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://buy8yafwaicq8"]
[ext_resource type="Script" uid="uid://b8a23hkmesx0l" path="res://asteroid.gd" id="1_e451a"]
[ext_resource type="Texture2D" uid="uid://dt08ism4ulfay" path="res://assets/asteroidx3.png" id="2_beklf"]
[node name="asteroid" type="RigidBody2D"]
collision_layer = 2
collision_mask = 2
mass = 20.0
contact_monitor = true
max_contacts_reported = 4
script = ExtResource("1_e451a")
[node name="Asteroid" type="Sprite2D" parent="."]
texture = ExtResource("2_beklf")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(23, 10, 36, -11, 22, -32, 8, -43, -32, -40, -40, -25, -43, 1, -40, 23, -24, 41, 3, 43, 38, 19)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

20
asteroidx4.tscn Normal file
View File

@@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://xldavgivpb3j"]
[ext_resource type="Script" uid="uid://b8a23hkmesx0l" path="res://asteroid.gd" id="1_pojcu"]
[ext_resource type="Texture2D" uid="uid://bs836c8u5j3y6" path="res://assets/asteroidx4.png" id="2_gv6mu"]
[node name="asteroid" type="RigidBody2D"]
collision_layer = 2
collision_mask = 2
mass = 40.0
contact_monitor = true
max_contacts_reported = 4
script = ExtResource("1_pojcu")
[node name="Asteroid" type="Sprite2D" parent="."]
texture = ExtResource("2_gv6mu")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(55, 3, 35, -20, 34, -40, 1, -49, -35, -52, -55, -29, -58, -1, -48, 30, -22, 53, 13, 58, 40, 30)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

14
destroy.gd Normal file
View File

@@ -0,0 +1,14 @@
extends CPUParticles2D
var time :=0.0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
emitting = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
time+=delta
if time >= 10:
queue_free()

1
destroy.gd.uid Normal file
View File

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

22
destroy.tscn Normal file
View File

@@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://bl3ans3gkp8ll"]
[ext_resource type="Texture2D" uid="uid://ckgjtmh5asu4w" path="res://assets/shoot.png" id="1_4xjek"]
[ext_resource type="Script" uid="uid://bgbncoa145y1l" path="res://destroy.gd" id="2_owou8"]
[sub_resource type="Gradient" id="Gradient_owou8"]
offsets = PackedFloat32Array(0, 0.553333, 1)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0.772549, 1, 1, 1, 0)
[node name="CPUParticles2D" type="CPUParticles2D"]
emitting = false
amount = 16
texture = ExtResource("1_4xjek")
lifetime = 2.5
one_shot = true
explosiveness = 0.5
randomness = 0.46
spread = 180.0
gravity = Vector2(0, 0)
initial_velocity_max = 50.0
color_ramp = SubResource("Gradient_owou8")
script = ExtResource("2_owou8")

1
icon.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>

After

Width:  |  Height:  |  Size: 994 B

37
icon.svg.import Normal file
View File

@@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bt0r4svityy4x"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

45
main_game.tscn Normal file
View File

@@ -0,0 +1,45 @@
[gd_scene load_steps=5 format=3 uid="uid://btcb75wp78ory"]
[ext_resource type="PackedScene" uid="uid://36q833dx6dmq" path="res://ship.tscn" id="1_1oj5k"]
[ext_resource type="PackedScene" uid="uid://b6hqwxrexoa2n" path="res://spawner.tscn" id="2_yx7mw"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1oj5k"]
size = Vector2(20, 640)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yx7mw"]
size = Vector2(640, 20)
[node name="main_game" type="Node2D"]
[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 640.0
offset_bottom = 640.0
color = Color(0, 0, 0, 1)
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(320, 320)
[node name="CharacterBody2D" parent="." instance=ExtResource("1_1oj5k")]
position = Vector2(156, 206)
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2(0, 320)
shape = SubResource("RectangleShape2D_1oj5k")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2(640, 320)
shape = SubResource("RectangleShape2D_1oj5k")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2(320, 0)
shape = SubResource("RectangleShape2D_yx7mw")
[node name="CollisionShape2D4" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2(320, 640)
shape = SubResource("RectangleShape2D_yx7mw")
[node name="spawner" parent="." node_paths=PackedStringArray("player") instance=ExtResource("2_yx7mw")]
player = NodePath("../CharacterBody2D")
distance = 500.0

64
project.godot Normal file
View File

@@ -0,0 +1,64 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="asteroid"
run/main_scene="uid://btcb75wp78ory"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=640
window/size/viewport_height=640
[input]
ui_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, 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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
]
}
ui_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
, 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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
]
}
ui_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, 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":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
]
}
ui_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, 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":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
]
}
[physics]
2d/default_gravity_vector=Vector2(0, 0)
[rendering]
textures/canvas_textures/default_texture_filter=0

44
ship.gd Normal file
View File

@@ -0,0 +1,44 @@
extends CharacterBody2D
@export var MAX_SPEED: float = 200
@export var SHOOT_NODE: PackedScene
const SPEED = 25.0
const JUMP_VELOCITY = -400.0
var mouse_position: Vector2 = Vector2.ZERO
var horizontal : float
var vertical : float
var vector_temp:= Vector2(1, 0)
var rota_temp: float
var delay := 0.0
func _input(event):
pass
if event is InputEventMouseMotion:
mouse_position = event.position
func _physics_process(delta: float) -> void:
delay += delta
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
shoot()
delay = 0
horizontal = Input.get_axis("ui_up", "ui_down")
vertical = Input.get_axis("ui_left", "ui_right")
velocity.x = move_toward(velocity.x, MAX_SPEED * vertical, SPEED)
velocity.y = move_toward(velocity.y, MAX_SPEED * horizontal, SPEED)
if horizontal != 0 or vertical != 0:
vector_temp = Vector2(vertical, horizontal)
rotation = atan2(vector_temp.y, vector_temp.x)
move_and_slide()
func shoot()->void:
var new = SHOOT_NODE.instantiate()
new.direction = vector_temp
new.position = position + (18 * vector_temp.normalized())
get_parent().add_child(new)

1
ship.gd.uid Normal file
View File

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

21
ship.tscn Normal file
View File

@@ -0,0 +1,21 @@
[gd_scene load_steps=5 format=3 uid="uid://36q833dx6dmq"]
[ext_resource type="Script" uid="uid://c3i2bhlectmoo" path="res://ship.gd" id="1_4cq66"]
[ext_resource type="Texture2D" uid="uid://b037piy3tkefs" path="res://assets/ship.png" id="1_l3rv8"]
[ext_resource type="PackedScene" uid="uid://b1jtii12cqye1" path="res://shoot.tscn" id="2_v4325"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4cq66"]
size = Vector2(16, 28)
[node name="CharacterBody2D" type="CharacterBody2D"]
script = ExtResource("1_4cq66")
SHOOT_NODE = ExtResource("2_v4325")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource("RectangleShape2D_4cq66")
[node name="Ship" type="Sprite2D" parent="."]
texture_filter = 1
rotation = 1.5708
texture = ExtResource("1_l3rv8")

17
shoot.gd Normal file
View File

@@ -0,0 +1,17 @@
extends RigidBody2D
@export var SPEED : float = 100.0
var direction: Vector2:
set(val):
direction = val.normalized() * SPEED
var time := 0.0
func _ready() -> void:
add_to_group("shoot")
func _process(delta: float) -> void:
linear_velocity = direction
time += delta
#if time >= 2:
# self.queue_free()

1
shoot.gd.uid Normal file
View File

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

22
shoot.tscn Normal file
View File

@@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://b1jtii12cqye1"]
[ext_resource type="Texture2D" uid="uid://ckgjtmh5asu4w" path="res://assets/shoot.png" id="1_ttj7r"]
[ext_resource type="Script" uid="uid://dsd0opfd8kyow" path="res://shoot.gd" id="1_vnmmp"]
[sub_resource type="CircleShape2D" id="CircleShape2D_yt1ub"]
radius = 5.0
[node name="shoot" type="RigidBody2D"]
collision_layer = 2
collision_mask = 2
mass = 0.001
gravity_scale = 0.0
script = ExtResource("1_vnmmp")
SPEED = 400.0
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
texture = ExtResource("1_ttj7r")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_yt1ub")

67
spawner.gd Normal file
View File

@@ -0,0 +1,67 @@
extends Node2D
@export var asteroidx1 : PackedScene
@export var asteroidx2 : PackedScene
@export var asteroidx3 : PackedScene
@export var asteroidx4 : PackedScene
@export var player : CharacterBody2D
@export var distance:= 600.0
var current_time := 0.0
var list_of_collision_1 : Array[Node]
var list_of_collision_2 : Array[Node]
signal add_collision
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var tmp : Vector2
for i in range(list_of_collision_1.size()):
if list_of_collision_1[i] and list_of_collision_2[i]:
var normal_vec = (list_of_collision_1[i].position - list_of_collision_2[i].position).normalized()
tmp = list_of_collision_1[i].direction
list_of_collision_1[i].direction = (list_of_collision_2[i].direction + normal_vec).normalized()
list_of_collision_2[i].direction = (tmp - normal_vec).normalized()
list_of_collision_1 = []
list_of_collision_2 = []
current_time += delta
if current_time >= 2.0:
current_time = 0
spawn()
func spawn():
var choice = randi_range(1, 4)
var new
if choice == 1:
new = asteroidx1.instantiate()
new.type = 1
elif choice == 2:
new = asteroidx2.instantiate()
new.type = 2
elif choice == 3:
new = asteroidx3.instantiate()
new.type = 3
elif choice == 4:
new = asteroidx4.instantiate()
new.type = 4
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360)) + Vector2(320, 320)
new.global_position = new_global_position
new.direction = (player.global_position - new_global_position).normalized()
add_child(new)
func _add_collision(body1 : Node, body2: Node) -> void:
for i in range(list_of_collision_1.size()):
if list_of_collision_1[i] == body1 and list_of_collision_2[i]== body2:
return
if list_of_collision_1[i] == body2 and list_of_collision_2[i] == body1:
return
list_of_collision_1.append(body1)
list_of_collision_2.append(body2)

1
spawner.gd.uid Normal file
View File

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

16
spawner.tscn Normal file
View File

@@ -0,0 +1,16 @@
[gd_scene load_steps=6 format=3 uid="uid://b6hqwxrexoa2n"]
[ext_resource type="Script" uid="uid://bclp1tkc2npvv" path="res://spawner.gd" id="1_yp5lu"]
[ext_resource type="PackedScene" uid="uid://ditud5veuxqyb" path="res://asteroidx1.tscn" id="2_7ocbr"]
[ext_resource type="PackedScene" uid="uid://d2jxc24g18ab1" path="res://asteroidx2.tscn" id="3_mv5bd"]
[ext_resource type="PackedScene" uid="uid://buy8yafwaicq8" path="res://asteroidx3.tscn" id="4_h3fkd"]
[ext_resource type="PackedScene" uid="uid://xldavgivpb3j" path="res://asteroidx4.tscn" id="5_qmymf"]
[node name="spawner" type="Node2D"]
script = ExtResource("1_yp5lu")
asteroidx1 = ExtResource("2_7ocbr")
asteroidx2 = ExtResource("3_mv5bd")
asteroidx3 = ExtResource("4_h3fkd")
asteroidx4 = ExtResource("5_qmymf")
[connection signal="add_collision" from="." to="." method="_add_collision"]