Init commit

This commit is contained in:
Benjamin Morgan 2025-10-19 20:04:59 -06:00
commit a4452b69c4
59 changed files with 1259 additions and 0 deletions

4
.editorconfig Normal file
View file

@ -0,0 +1,4 @@
root = true
[*]
charset = utf-8

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# Godot 4+ specific ignores
.godot/
/android/

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://1jbq4x3kmhn1"]
[ext_resource type="Script" uid="uid://cg4pd7sdvx3qc" path="res://Enemies/Scripts/asteroid.gd" id="1_wfjj5"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="2_3al5e"]
[sub_resource type="CircleShape2D" id="CircleShape2D_p0ukn"]
radius = 6.0
[node name="Asteroid" type="Area2D"]
script = ExtResource("1_wfjj5")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(2, 2)
texture = ExtResource("2_3al5e")
region_enabled = true
region_rect = Rect2(41, 17, 6, 6)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_p0ukn")

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://dx86f17gehnea"]
[ext_resource type="Script" uid="uid://cg4pd7sdvx3qc" path="res://Enemies/Scripts/asteroid.gd" id="1_tn6au"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="2_pp4o0"]
[sub_resource type="CircleShape2D" id="CircleShape2D_1l7hq"]
radius = 7.0
[node name="Asteroid" type="Area2D"]
script = ExtResource("1_tn6au")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_pp4o0")
region_enabled = true
region_rect = Rect2(32, 2, 15, 13)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(1, 0)
shape = SubResource("CircleShape2D_1l7hq")

View file

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://cl6diy6jr73gw"]
[ext_resource type="Script" uid="uid://cg4pd7sdvx3qc" path="res://Enemies/Scripts/asteroid.gd" id="1_csx0u"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="2_cn0tk"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_ft5of"]
radius = 6.0
height = 16.0
[node name="Asteroid" type="Area2D"]
script = ExtResource("1_csx0u")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(3, 3)
texture = ExtResource("2_cn0tk")
region_enabled = true
region_rect = Rect2(34, 26, 4, 5)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 1)
shape = SubResource("CapsuleShape2D_ft5of")

View file

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://3l5rlho4v4l3"]
[ext_resource type="Script" uid="uid://cg4pd7sdvx3qc" path="res://Enemies/Scripts/asteroid.gd" id="1_ub6x2"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="2_m5fot"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8kah6"]
radius = 2.8242884
height = 9.961488
[node name="Asteroid" type="Area2D"]
script = ExtResource("1_ub6x2")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(2, 2)
texture = ExtResource("2_m5fot")
region_enabled = true
region_rect = Rect2(42, 26, 4, 4)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 0.73129296
shape = SubResource("CapsuleShape2D_8kah6")

View file

@ -0,0 +1,28 @@
extends Area2D
var velocity = Vector2(0, 0)
var rot_velocity = 0
var explosion = preload('res://Scenes/explosion.tscn')
var pop = preload("res://Sounds/Explosion5.wav")
func _ready() -> void:
connect("body_entered", _on_body_entered)
func _physics_process(delta):
position += velocity * delta
rotation += rot_velocity * delta
Utils.wrap_position(self)
func _on_body_entered(body):
if body.name == "Ship":
Game.set_lives(Game.lives - 1)
Utils.play_sound(pop, get_parent())
var boom = explosion.instantiate()
boom.position = body.global_position
boom.scale = Vector2(6, 6)
get_parent().add_child(boom)
body.reset()
queue_free()

View file

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

55
Scenes/explosion.tscn Normal file
View file

@ -0,0 +1,55 @@
[gd_scene load_steps=8 format=3 uid="uid://g6cu38jl3h32"]
[ext_resource type="Script" uid="uid://lawrmxvtimw1" path="res://Scripts/explosion.gd" id="1_a801j"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="2_4okmj"]
[sub_resource type="AtlasTexture" id="AtlasTexture_vxas0"]
atlas = ExtResource("2_4okmj")
region = Rect2(48, 31, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_j4sxf"]
atlas = ExtResource("2_4okmj")
region = Rect2(32, 31, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_m5xho"]
atlas = ExtResource("2_4okmj")
region = Rect2(16, 31, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_kmxf7"]
atlas = ExtResource("2_4okmj")
region = Rect2(0, 31, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_l04k4"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_vxas0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_j4sxf")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_m5xho")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_kmxf7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_j4sxf")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_vxas0")
}],
"loop": true,
"name": &"default",
"speed": 12.0
}]
[node name="Node2D" type="Node2D"]
[node name="Area2D" type="Area2D" parent="."]
script = ExtResource("1_a801j")
[node name="Explosion" type="AnimatedSprite2D" parent="Area2D"]
sprite_frames = SubResource("SpriteFrames_l04k4")
autoplay = "default"

67
Scenes/game_over.tscn Normal file
View file

@ -0,0 +1,67 @@
[gd_scene load_steps=4 format=3 uid="uid://dliccivjx8fcm"]
[ext_resource type="Script" uid="uid://cf1vwutwpi4rf" path="res://Scripts/game_over.gd" id="1_ojehl"]
[sub_resource type="LabelSettings" id="LabelSettings_i2yjh"]
font_size = 72
[sub_resource type="LabelSettings" id="LabelSettings_ojehl"]
font_size = 32
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ojehl")
[node name="Container" type="Control" parent="."]
layout_mode = 1
anchors_preset = 13
anchor_left = 0.5
anchor_right = 0.5
anchor_bottom = 1.0
offset_top = -100.0
offset_bottom = -100.0
grow_horizontal = 2
grow_vertical = 2
[node name="Title" type="Label" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -195.0
offset_right = 195.0
offset_bottom = 99.0
grow_horizontal = 2
text = "Game Over"
label_settings = SubResource("LabelSettings_i2yjh")
[node name="Score" type="Label" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -60.5
offset_top = 85.0
offset_right = 60.5
offset_bottom = 130.0
grow_horizontal = 2
text = "Score: 0"
label_settings = SubResource("LabelSettings_ojehl")
[node name="New Game" type="Button" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -46.5
offset_top = 150.0
offset_right = 46.5
offset_bottom = 181.0
grow_horizontal = 2
text = "New Game"

21
Scenes/laser.tscn Normal file
View file

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://nf2xr7ufei5a"]
[ext_resource type="Script" uid="uid://csldj2x1axso1" path="res://Scripts/laser.gd" id="1_6vqwg"]
[ext_resource type="Texture2D" uid="uid://cv84w0y2jg3i3" path="res://Sprites/i_are_spaceship.png" id="1_fn5yt"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6vqwg"]
radius = 3.0
height = 10.0
[node name="Laser" type="Area2D"]
script = ExtResource("1_6vqwg")
[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(-1, 1)
scale = Vector2(2, 2)
texture = ExtResource("1_fn5yt")
region_enabled = true
region_rect = Rect2(34, 17, 3, 7)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CapsuleShape2D_6vqwg")

9
Scenes/life.tscn Normal file
View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://j2mr8pluyo37"]
[ext_resource type="Texture2D" uid="uid://cvfsmhdbgh8vh" path="res://Sprites/idle_spaceship.png" id="1_bkce2"]
[node name="Life" type="TextureRect"]
offset_right = 15.0
offset_bottom = 24.0
texture = ExtResource("1_bkce2")
stretch_mode = 4

64
Scenes/main_menu.tscn Normal file
View file

@ -0,0 +1,64 @@
[gd_scene load_steps=3 format=3 uid="uid://c4ld5hjy5d8g3"]
[ext_resource type="Script" uid="uid://dxbdiq4y3mqtd" path="res://Scripts/main_menu.gd" id="1_28flt"]
[sub_resource type="LabelSettings" id="LabelSettings_i2yjh"]
font_size = 72
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_28flt")
[node name="Container" type="Control" parent="."]
layout_mode = 1
anchors_preset = 13
anchor_left = 0.5
anchor_right = 0.5
anchor_bottom = 1.0
offset_top = -100.0
offset_bottom = -100.0
grow_horizontal = 2
grow_vertical = 2
[node name="Title" type="Label" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -195.0
offset_right = 195.0
offset_bottom = 99.0
grow_horizontal = 2
text = "Asteroids"
label_settings = SubResource("LabelSettings_i2yjh")
horizontal_alignment = 1
[node name="New Game" type="Button" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -46.5
offset_top = 111.0
offset_right = 46.5
offset_bottom = 142.0
grow_horizontal = 2
text = "New Game"
[node name="Quit" type="Button" parent="Container"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -46.5
offset_top = 150.0
offset_right = 46.5
offset_bottom = 181.0
grow_horizontal = 2
text = "Quit"

97
Scenes/ship.tscn Normal file
View file

@ -0,0 +1,97 @@
[gd_scene load_steps=16 format=3 uid="uid://dwvw8qerrwuu0"]
[ext_resource type="Script" uid="uid://p443pc5fxxg0" path="res://Scripts/ship.gd" id="1_6ejuo"]
[ext_resource type="PackedScene" uid="uid://nf2xr7ufei5a" path="res://Scenes/laser.tscn" id="2_8aq7e"]
[ext_resource type="Texture2D" uid="uid://bdwr76wwjquob" path="res://Sprites/fly_spaceship.png" id="3_cmder"]
[ext_resource type="AudioStream" uid="uid://docuh1bqh2uba" path="res://Sounds/laser4.wav" id="3_fwcnm"]
[ext_resource type="Texture2D" uid="uid://cvfsmhdbgh8vh" path="res://Sprites/idle_spaceship.png" id="4_fwcnm"]
[ext_resource type="Texture2D" uid="uid://dtcdw0p6jcw00" path="res://Sprites/left_spaceship.png" id="5_cmder"]
[ext_resource type="Texture2D" uid="uid://c0quqc1en7jo" path="res://Sprites/right_spaceship.png" id="6_fwcnm"]
[sub_resource type="AtlasTexture" id="AtlasTexture_272bh"]
atlas = ExtResource("3_cmder")
region = Rect2(15, 0, 15, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_5vw27"]
atlas = ExtResource("3_cmder")
region = Rect2(0, 0, 15, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_kxdp2"]
atlas = ExtResource("5_cmder")
region = Rect2(15, 0, 15, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_v2j2m"]
atlas = ExtResource("5_cmder")
region = Rect2(0, 0, 15, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_1m05r"]
atlas = ExtResource("6_fwcnm")
region = Rect2(15, 0, 15, 24)
[sub_resource type="AtlasTexture" id="AtlasTexture_ssryt"]
atlas = ExtResource("6_fwcnm")
region = Rect2(0, 0, 15, 24)
[sub_resource type="SpriteFrames" id="SpriteFrames_1bvp3"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_272bh")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5vw27")
}],
"loop": true,
"name": &"fly",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("4_fwcnm")
}],
"loop": true,
"name": &"idle",
"speed": 0.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_kxdp2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_v2j2m")
}],
"loop": true,
"name": &"left",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_1m05r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ssryt")
}],
"loop": true,
"name": &"right",
"speed": 5.0
}]
[sub_resource type="ConvexPolygonShape2D" id="ConvexPolygonShape2D_kek77"]
points = PackedVector2Array(-6, 0, -7, 7, 8, 7, 7, 0, 0, -8)
[node name="Ship" type="CharacterBody2D"]
script = ExtResource("1_6ejuo")
Laser = ExtResource("2_8aq7e")
pew = ExtResource("3_fwcnm")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_1bvp3")
animation = &"right"
autoplay = "idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -4)
shape = SubResource("ConvexPolygonShape2D_kek77")
[node name="Muzzle" type="Marker2D" parent="."]
position = Vector2(0, -15)

7
Scripts/explosion.gd Normal file
View file

@ -0,0 +1,7 @@
extends Area2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Free self after 1.5 seconds
await get_tree().create_timer(0.5).timeout
queue_free()

1
Scripts/explosion.gd.uid Normal file
View file

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

88
Scripts/game.gd Normal file
View file

@ -0,0 +1,88 @@
extends Node2D
var score: int = 0
var lives: int = 0
var added_lives: int = 0
var score_label: Label
var lives_box: HBoxContainer
var spawner: Node2D
var player: CharacterBody2D
var ui: CanvasLayer
var game_over_ui: Control
var menu_ui: Control
var life_icon = preload("res://Scenes/life.tscn")
var menu_scn = preload("res://Scenes/main_menu.tscn")
var game_over_scn = preload("res://Scenes/game_over.tscn")
var ship = preload("res://Scenes/ship.tscn")
var life = preload("res://Sounds/extra_life.wav")
func _ready() -> void:
menu_ui = menu_scn.instantiate()
menu_ui.new_game.connect(_new_game)
menu_ui.quit_game.connect(_quit_game)
await get_tree().process_frame
ui.add_child(menu_ui)
func set_score(amount: int):
score = amount
score_label.text = "Score: " + str(score)
if floor(score / 10000.0) > added_lives:
added_lives += 1
set_lives(lives + 1)
var snd = AudioStreamPlayer.new()
add_child(snd)
snd.stream = life
snd.play()
snd.finished.connect(func(): snd.queue_free())
func set_lives(amount: int):
lives = amount
var icons = lives_box.get_children()
var diff = lives - len(icons);
if diff > 0:
for i in range(diff):
lives_box.add_child(life_icon.instantiate())
else:
if lives >= 0:
for i in range(abs(diff)):
lives_box.remove_child(icons[len(icons) - 1])
icons.remove_at(len(icons) - 1)
if lives == 0:
spawner.stop()
for node in get_tree().get_nodes_in_group("enemies"):
node.queue_free()
player.queue_free()
score_label.visible = false
game_over_ui = game_over_scn.instantiate()
game_over_ui.new_game.connect(_new_game)
game_over_ui.set_score(score)
ui.add_child(game_over_ui)
func _new_game():
if score_label:
score_label.visible = true
set_lives(3)
spawner.start()
set_score(0)
if game_over_ui:
game_over_ui.queue_free()
if menu_ui:
menu_ui.queue_free()
player = ship.instantiate()
player.position = get_viewport_rect().size / 2
get_tree().current_scene.add_child(player)
func _quit_game():
get_tree().quit()

1
Scripts/game.gd.uid Normal file
View file

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

12
Scripts/game_over.gd Normal file
View file

@ -0,0 +1,12 @@
extends Control
signal new_game
func set_score(amount: int):
$Container/Score.text = "Score: " + str(amount)
func _ready():
$"Container/New Game".pressed.connect(_emit_new)
func _emit_new():
emit_signal("new_game")

1
Scripts/game_over.gd.uid Normal file
View file

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

37
Scripts/laser.gd Normal file
View file

@ -0,0 +1,37 @@
extends Area2D
var explosion = preload('res://Scenes/explosion.tscn')
var pop = preload("res://Sounds/Explosion.wav")
var speed = 750
var half_size: Vector2 # half of sprite dimensions (used for wrapping)
func _ready() -> void:
connect("area_entered", _on_body_entered)
half_size = Utils.get_half_size(self)
func _physics_process(delta):
position += -transform.y * speed * delta
var rect = get_viewport_rect()
if position.x < -half_size.x or position.x > rect.size.x + half_size.x or position.y < -half_size.y or position.y > rect.size.y + half_size.y:
#print_debug("FREED")
queue_free()
func _on_body_entered(body):
if body.is_in_group("enemies"):
body.queue_free()
Utils.play_sound(pop, get_parent())
var boom = explosion.instantiate()
boom.position = body.global_position
boom.scale = body.scale
get_parent().add_child(boom)
Game.set_score(Game.score + 100)
queue_free()
#print_debug("KILLED")

1
Scripts/laser.gd.uid Normal file
View file

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

6
Scripts/lives.gd Normal file
View file

@ -0,0 +1,6 @@
extends HBoxContainer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Game.lives_box = self

1
Scripts/lives.gd.uid Normal file
View file

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

14
Scripts/main_menu.gd Normal file
View file

@ -0,0 +1,14 @@
extends Control
signal new_game
signal quit_game
func _ready():
$"Container/New Game".pressed.connect(_emit_new)
$Container/Quit.pressed.connect(_emit_quit)
func _emit_new():
emit_signal("new_game")
func _emit_quit():
emit_signal("quit_game")

1
Scripts/main_menu.gd.uid Normal file
View file

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

6
Scripts/score.gd Normal file
View file

@ -0,0 +1,6 @@
extends Label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Game.score_label = self

1
Scripts/score.gd.uid Normal file
View file

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

63
Scripts/ship.gd Normal file
View file

@ -0,0 +1,63 @@
extends CharacterBody2D
const ROT_SPEED = 3.0
const MOVE_ACC = 100
const FRICTION = 0.995
const FIRE_RATE = 0.2
@export var Laser: PackedScene
@export var pew: Resource
var speed = Vector2(0, 0)
var last_shot = 0.0
func _ready() -> void:
Game.player = self
func _physics_process(delta: float) -> void:
var forward = Input.is_action_pressed("ui_up")
var left = Input.is_action_pressed("ui_left")
var right = Input.is_action_pressed("ui_right")
if left:
rotation -= ROT_SPEED * delta
if $AnimatedSprite2D.animation != "left":
$AnimatedSprite2D.play("left")
if right:
rotation += ROT_SPEED * delta
if $AnimatedSprite2D.animation != "right":
$AnimatedSprite2D.play("right")
if forward:
speed += Vector2.UP.rotated(rotation) * MOVE_ACC * delta
if $AnimatedSprite2D.animation != "fly":
$AnimatedSprite2D.play("fly")
if Input.is_action_pressed("ui_down"):
speed -= Vector2.UP.rotated(rotation) * MOVE_ACC * delta
if !(forward || left || right) and $AnimatedSprite2D.animation != "idle":
$AnimatedSprite2D.play("idle")
speed *= FRICTION
velocity = speed
move_and_slide()
Utils.wrap_position(self)
# --- Fire projectile on space ---
last_shot += delta
if Input.is_action_pressed("ui_accept") and last_shot >= FIRE_RATE: # default = Space/Enter
var bullet = Laser.instantiate()
Utils.play_sound(pew, self)
get_parent().add_child(bullet)
bullet.transform = $Muzzle.global_transform
last_shot = 0.0
func reset():
position = get_viewport_rect().size / 2
speed = Vector2(0, 0)

1
Scripts/ship.gd.uid Normal file
View file

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

84
Scripts/spawner.gd Normal file
View file

@ -0,0 +1,84 @@
extends Node2D
var timer: Timer
var asteroids := [
preload('res://Enemies/Scenes/asteroidTiny.tscn'),
preload('res://Enemies/Scenes/asteroidSm.tscn'),
preload('res://Enemies/Scenes/asteroid.tscn'),
preload('res://Enemies/Scenes/asteroidBig.tscn')
]
var screen_size: Vector2
func _ready():
Game.spawner = self
screen_size = get_viewport_rect().size
# Call spawn_enemy() every spawn_interval seconds
timer = Timer.new()
timer.wait_time = spawn_time_from_score(Game.score)
timer.timeout.connect(spawn_enemy)
add_child(timer)
func spawn_time_from_score(score: int) -> float:
var min_time = 0.3
var max_time = 2.0
var max_score = 50000.0
# Clamp score so it doesnt overshoot
var clamped_score = clamp(score, 0, max_score)
# Normalized value [0..1]
var t = float(clamped_score) / max_score
# Logarithmic easing (slows down progression)
# Use log10 but you can tweak the base for different curves
var curved_t = log(1.0 + 9.0 * t) / log(10.0) # maps 0..1 to 0..1, but with log shape
# Interpolate between max_time and min_time
return lerp(max_time, min_time, curved_t)
func spawn_enemy():
var enemy = asteroids[randi_range(0, 3)].instantiate()
var pos = get_random_edge_position()
enemy.position = pos
# Direction vector toward center
var center = screen_size * 0.5
var dir = (center - pos).normalized()
# Add some randomness so it's not always perfect
var angle_variation = randf_range(-0.5, 0.5) # radians (~±14 degrees)
dir = dir.rotated(angle_variation)
# Apply starting velocity
enemy.rot_velocity = randf_range(0, PI)
enemy.velocity = dir * randf_range(50, 200)
enemy.rotation = randf_range(0, PI)
var scl = randi_range(1, 5)
enemy.scale = Vector2(scl, scl)
enemy.add_to_group("enemies")
add_child(enemy)
timer.wait_time = spawn_time_from_score(Game.score)
func get_random_edge_position() -> Vector2:
# Pick which edge (0=top,1=bottom,2=left,3=right)
var edge = randi() % 4
match edge:
0: # top
return Vector2(randf() * screen_size.x, 0)
1: # bottom
return Vector2(randf() * screen_size.x, screen_size.y)
2: # left
return Vector2(0, randf() * screen_size.y)
3: # right
return Vector2(screen_size.x, randf() * screen_size.y)
return Vector2.ZERO
func stop():
timer.stop()
func start():
timer.start()

1
Scripts/spawner.gd.uid Normal file
View file

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

6
Scripts/ui.gd Normal file
View file

@ -0,0 +1,6 @@
extends CanvasLayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Game.ui = self

1
Scripts/ui.gd.uid Normal file
View file

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

43
Scripts/utils.gd Normal file
View file

@ -0,0 +1,43 @@
extends Node2D
func get_half_size(sprt: Node2D):
var half_size: Vector2
if sprt is Sprite2D:
half_size = (sprt.texture.get_size() * sprt.scale) / 2.0
elif sprt is AnimatedSprite2D:
var tex: Texture2D = sprt.sprite_frames.get_frame_texture(sprt.animation, 0)
if tex:
half_size = (tex.get_size() * sprt.scale) / 2.0
else:
half_size = Vector2.ZERO
else:
half_size = Vector2.ZERO
return half_size
func wrap_position(node: Node2D) -> void:
var rect = node.get_viewport_rect()
var pos = node.position
var half_size = get_half_size(node)
# Horizontal wrap
if pos.x < -half_size.x:
pos.x = rect.size.x + half_size.x
elif pos.x > rect.size.x + half_size.x:
pos.x = -half_size.x
# Vertical wrap
if pos.y < -half_size.y:
pos.y = rect.size.y + half_size.y
elif pos.y > rect.size.y + half_size.y:
pos.y = -half_size.y
node.position = pos
func play_sound(sound: Resource, parent: Node2D):
var player = AudioStreamPlayer.new()
parent.add_child(player)
player.stream = sound
player.play()
player.finished.connect(func(): player.queue_free())

1
Scripts/utils.gd.uid Normal file
View file

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

BIN
Sounds/Explosion.wav Normal file

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://damfiglhgbndg"
path="res://.godot/imported/Explosion.wav-df129fcef001a99a7ebca62c066fad7f.sample"
[deps]
source_file="res://Sounds/Explosion.wav"
dest_files=["res://.godot/imported/Explosion.wav-df129fcef001a99a7ebca62c066fad7f.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2

BIN
Sounds/Explosion5.wav Normal file

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bbcbp35voy82q"
path="res://.godot/imported/Explosion5.wav-e35eb32510b5624844f55312473cea80.sample"
[deps]
source_file="res://Sounds/Explosion5.wav"
dest_files=["res://.godot/imported/Explosion5.wav-e35eb32510b5624844f55312473cea80.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2

BIN
Sounds/extra_life.wav Normal file

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://fyesvv48iu8r"
path="res://.godot/imported/extra_life.wav-b029094bd39138c35926eb8f28e384dd.sample"
[deps]
source_file="res://Sounds/extra_life.wav"
dest_files=["res://.godot/imported/extra_life.wav-b029094bd39138c35926eb8f28e384dd.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2

BIN
Sounds/laser4.wav Normal file

Binary file not shown.

24
Sounds/laser4.wav.import Normal file
View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://docuh1bqh2uba"
path="res://.godot/imported/laser4.wav-026c5e7ca4997824f763173d5cb83d5d.sample"
[deps]
source_file="res://Sounds/laser4.wav"
dest_files=["res://.godot/imported/laser4.wav-026c5e7ca4997824f763173d5cb83d5d.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2

BIN
Sprites/fly_spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bdwr76wwjquob"
path="res://.godot/imported/fly_spaceship.png-09f18472abff441559058c1b32552609.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/fly_spaceship.png"
dest_files=["res://.godot/imported/fly_spaceship.png-09f18472abff441559058c1b32552609.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Sprites/i_are_spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cv84w0y2jg3i3"
path="res://.godot/imported/i_are_spaceship.png-f1773335f0779d276b4232000f51f2ad.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/i_are_spaceship.png"
dest_files=["res://.godot/imported/i_are_spaceship.png-f1773335f0779d276b4232000f51f2ad.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Sprites/idle_spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cvfsmhdbgh8vh"
path="res://.godot/imported/idle_spaceship.png-50f9870f8c75b88f0c2ffe9c1ebb048d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/idle_spaceship.png"
dest_files=["res://.godot/imported/idle_spaceship.png-50f9870f8c75b88f0c2ffe9c1ebb048d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Sprites/left_spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dtcdw0p6jcw00"
path="res://.godot/imported/left_spaceship.png-203801d0667ec1f88f7d829433d9f923.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/left_spaceship.png"
dest_files=["res://.godot/imported/left_spaceship.png-203801d0667ec1f88f7d829433d9f923.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Sprites/right_spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c0quqc1en7jo"
path="res://.godot/imported/right_spaceship.png-3cbfec901222e0eb10821f64c8fb11ef.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/right_spaceship.png"
dest_files=["res://.godot/imported/right_spaceship.png-3cbfec901222e0eb10821f64c8fb11ef.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Sprites/space.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

40
Sprites/space.png.import Normal file
View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cuqofgxmpn2fu"
path="res://.godot/imported/space.png-700a9bfbdde92801716d216837fb3742.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/space.png"
dest_files=["res://.godot/imported/space.png-700a9bfbdde92801716d216837fb3742.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

45
main.tscn Normal file
View file

@ -0,0 +1,45 @@
[gd_scene load_steps=7 format=3 uid="uid://cmlg48m6buclv"]
[ext_resource type="Texture2D" uid="uid://cuqofgxmpn2fu" path="res://Sprites/space.png" id="1_7mycd"]
[ext_resource type="Script" uid="uid://dpa4j6me328ak" path="res://Scripts/ui.gd" id="2_272bh"]
[ext_resource type="Script" uid="uid://efye4dftj3u6" path="res://Scripts/score.gd" id="3_5vw27"]
[ext_resource type="Script" uid="uid://mfgrqlsgsyrx" path="res://Scripts/spawner.gd" id="4_1bvp3"]
[ext_resource type="Script" uid="uid://miwfeu4n6uh7" path="res://Scripts/lives.gd" id="4_kek77"]
[sub_resource type="LabelSettings" id="LabelSettings_7mycd"]
[node name="Node2D" type="Node2D"]
[node name="Background" type="TextureRect" parent="."]
offset_right = 1153.0
offset_bottom = 648.0
texture = ExtResource("1_7mycd")
stretch_mode = 1
[node name="UI" type="CanvasLayer" parent="."]
script = ExtResource("2_272bh")
[node name="Score" type="Label" parent="UI"]
visible = false
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -66.0
offset_top = 2.0
offset_right = -5.0
offset_bottom = 25.0
grow_horizontal = 0
text = "Score: 0"
label_settings = SubResource("LabelSettings_7mycd")
horizontal_alignment = 2
script = ExtResource("3_5vw27")
[node name="Lives" type="HBoxContainer" parent="UI"]
offset_left = 6.0
offset_top = 6.0
offset_right = 46.0
offset_bottom = 46.0
script = ExtResource("4_kek77")
[node name="Spawner" type="Node2D" parent="."]
script = ExtResource("4_1bvp3")

70
project.godot Normal file
View file

@ -0,0 +1,70 @@
; 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="Asteroids"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.5", "GL Compatibility")
[autoload]
Game="*res://Scripts/game.gd"
Utils="*res://Scripts/utils.gd"
[display]
window/stretch/mode="viewport"
window/stretch/scale=1.5
[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":0,"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":0,"location":0,"echo":false,"script":null)
]
}
[rendering]
textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
2d/snap/snap_2d_transforms_to_pixel=true
2d/snap/snap_2d_vertices_to_pixel=true
2d/canvas_textures/default_texture_filter=0
2d/stretch/scale=1.5