Adding initial turbo-basic stuff

This commit is contained in:
allfatherhatt 2024-10-01 16:43:34 +02:00
parent e5f6624df2
commit 8bb4ba71ce
28 changed files with 746 additions and 0 deletions

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

2
.gitignore vendored Normal file
View File

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

43
asteroid.gd Normal file
View File

@ -0,0 +1,43 @@
extends StaticBody2D
@export var max_health: float = 100.0 # Maximum health for the asteroid
var current_health: float
var is_destroyed: bool = false # Track if the asteroid has already been destroyed
func _ready():
current_health = max_health
update_health_label() # Update the health display when the game starts
# Function to handle taking damage
func take_damage(damage: float):
if is_destroyed: # Prevent taking damage if already destroyed
return
current_health -= damage # Subtract the damage from current health
current_health = max(current_health, 0) # Ensure health doesn't drop below 0
update_health_label() # Update the label to reflect new health value
if current_health <= 0.0:
break_apart()
# Function to handle when the asteroid is destroyed
func break_apart():
is_destroyed = true # Mark the asteroid as destroyed
queue_free() # Remove the asteroid from the scene
print("Asteroid mined!")
# Load the Cheese scene
var cheese_scene = load("res://Cheese.tscn")
# Instance the cheese
var cheese_instance = cheese_scene.instantiate()
# Set the position where the cheese should spawn (at the asteroid's position)
cheese_instance.global_position = global_position + Vector2(randf() * 50 - 25, randf() * 50 - 25)
# Add the cheese instance to the scene
get_parent().add_child(cheese_instance)
# Function to update the health label display
func update_health_label():
$AsteroidHealthLabel.text = str(round(current_health)) + " / " + str(max_health)

18
cheese.tscn Normal file
View File

@ -0,0 +1,18 @@
[gd_scene load_steps=3 format=3 uid="uid://ukjuwuhb6mq6"]
[ext_resource type="Script" path="res://cheeseCollision.gd" id="1_k5eo2"]
[ext_resource type="Texture2D" uid="uid://djwn5ruf1wln0" path="res://images/protocheese.png" id="2_xljbq"]
[node name="cheese" type="Area2D"]
position = Vector2(300, 337)
scale = Vector2(2, 2)
collision_mask = 3
script = ExtResource("1_k5eo2")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(3, 17.5, 18.5, 0, 13.5, -20.5, -16.5, -7, -16, 13)
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_xljbq")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

18
cheeseCollision.gd Normal file
View File

@ -0,0 +1,18 @@
extends Area2D
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_body_entered(body):
if body.name == "spaceship":
queue_free() # This removes the cheese from the scene
print("Cheese collected!") # Replace this with actual game logic

19
hardpoint.gd Normal file
View File

@ -0,0 +1,19 @@
extends Node2D
@export var hardpoint_id: String = "HardPoint1" # Unique identifier for this hardpoint
# Optional - can store a reference to the mounted weapon
var mounted_weapon: Node2D = null
# Method to attach a weapon to the hardpoint
func attach_weapon(weapon: Node2D) -> void:
mounted_weapon = weapon
weapon.global_position = global_position # Set weapon position to the hardpoint position
weapon.rotation = rotation # Align the weapon's rotation to the hardpoint's rotation
func _draw():
draw_circle(Vector2.ZERO, 10, Color(1, 0, 0)) # Draw a red circle at the hardpoint
func _ready():
add_to_group("hardpoints") # Add the hardpoint to the "hardpoints" group
queue_redraw() # Redraw the visual to ensure it's updated

1
icon.svg Normal file
View File

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path 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" fill="#478cbf"/><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"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

After

Width:  |  Height:  |  Size: 949 B

37
icon.svg.import Normal file
View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b738dyw75cuny"
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

BIN
images/AsteroidBrown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://y6phkg4twpdm"
path="res://.godot/imported/bg_space_seamless.png-aa28148dfa1d993d28c2e72eefdcdab6.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/bg_space_seamless.png"
dest_files=["res://.godot/imported/bg_space_seamless.png-aa28148dfa1d993d28c2e72eefdcdab6.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
images/glowcircle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d0o4hqaai2tpu"
path="res://.godot/imported/glowcircle.png-4797643c88aab209a866b25184909738.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/glowcircle.png"
dest_files=["res://.godot/imported/glowcircle.png-4797643c88aab209a866b25184909738.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
images/glowing_circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://di7nndrreqmtf"
path="res://.godot/imported/glowing_circle.png-4ed2edd49097f5b99b37d1372b8b318b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/glowing_circle.png"
dest_files=["res://.godot/imported/glowing_circle.png-4ed2edd49097f5b99b37d1372b8b318b.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
images/laser_turret.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bxgw2u7j4b634"
path="res://.godot/imported/laser_turret.png-1df2831a344ffa5282291095b5880ec8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://images/laser_turret.png"
dest_files=["res://.godot/imported/laser_turret.png-1df2831a344ffa5282291095b5880ec8.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
images/protocheese.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

View File

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

78
laser.gd Normal file
View File

@ -0,0 +1,78 @@
extends Node2D
@export var laser_range: float = 800.0
@export var laser_damage: float = 0.2
@export var hardpoint_id: String = "HardPoint1" # Identifier for the hardpoint to attach this laser
var hardpoint = null # Reference to the attached hardpoint
var is_firing = false # Track the laser's firing state
var current_damage_output: float = 0.0 # Track the current damage output
func _ready():
# Register the laser to the "weapons" group
add_to_group("weapons")
# Connect to the correct hardpoint when ready
call_deferred("_connect_to_hardpoint")
# Initialize LaserLine2D with two points (origin and target)
$LaserLine2D.clear_points()
$LaserLine2D.add_point(Vector2.ZERO) # Origin point
$LaserLine2D.add_point(Vector2.ZERO) # Target point (initially the same as origin)
$DamageOutputLabel.text = str(current_damage_output)
# Connect the laser to the appropriate hardpoint
func _connect_to_hardpoint():
var hardpoints = get_tree().get_nodes_in_group("hardpoints")
for h in hardpoints:
if h.hardpoint_id == hardpoint_id:
hardpoint = h
h.attach_weapon(self)
break
func fire():
is_firing = true
_process_laser(true)
current_damage_output = laser_damage
$DamageOutputLabel.text = str(current_damage_output)
func cease_fire():
is_firing = false
_process_laser(false)
current_damage_output = 0.0
$DamageOutputLabel.text = str(current_damage_output)
func _process(delta: float) -> void:
if is_firing:
_process_laser(true)
func _process_laser(active: bool):
var raycast = $LaserBeam2D
raycast.enabled = active
if active:
raycast.force_raycast_update()
if raycast.is_colliding():
var collision_point = raycast.get_collision_point()
$LaserLine2D.set_point_position(0, Vector2.ZERO)
$LaserLine2D.set_point_position(1, to_local(collision_point))
var collider = raycast.get_collider()
if collider.has_method("take_damage"):
collider.take_damage(laser_damage)
else:
$LaserLine2D.set_point_position(0, Vector2.ZERO)
$LaserLine2D.set_point_position(1, Vector2(0, -laser_range))
else:
$LaserLine2D.clear_points()
$LaserLine2D.add_point(Vector2.ZERO) # Re-add the origin point
$LaserLine2D.add_point(Vector2.ZERO) # Reset target point to origin

63
maiE190.tmp Normal file
View File

@ -0,0 +1,63 @@
[gd_scene load_steps=9 format=3 uid="uid://8ocp10j32f62"]
[ext_resource type="Texture2D" uid="uid://y6phkg4twpdm" path="res://images/bg_space_seamless.png" id="1_rpyi5"]
[ext_resource type="Texture2D" uid="uid://cran7fr1i2qou" path="res://images/spaceship-placeholder.png" id="2_f2x66"]
[ext_resource type="Script" path="res://spaceship.gd" id="3_ttkgl"]
[ext_resource type="Texture2D" uid="uid://djwn5ruf1wln0" path="res://images/protocheese.png" id="4_i7fg5"]
[ext_resource type="Script" path="res://cheeseCollision.gd" id="5_r3xo8"]
[ext_resource type="Script" path="res://asteroid.gd" id="6_n4dsl"]
[ext_resource type="Texture2D" uid="uid://buirp1h6onqai" path="res://images/AsteroidBrown.png" id="7_0tjls"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_u4a3y"]
radius = 44.0
height = 100.0
[node name="Main" type="Node2D"]
[node name="background" type="Sprite2D" parent="."]
position = Vector2(955, 535)
scale = Vector2(2, 2)
texture = ExtResource("1_rpyi5")
[node name="spaceship" type="CharacterBody2D" parent="."]
position = Vector2(960, 540)
motion_mode = 1
script = ExtResource("3_ttkgl")
[node name="Sprite2D" type="Sprite2D" parent="spaceship"]
z_index = 1
texture = ExtResource("2_f2x66")
[node name="CollisionShape2D" type="CollisionShape2D" parent="spaceship"]
position = Vector2(0, -1)
shape = SubResource("CapsuleShape2D_u4a3y")
[node name="RayCast2D" type="RayCast2D" parent="spaceship"]
position = Vector2(0, 3)
target_position = Vector2(0, -177)
[node name="cheese" type="Area2D" parent="."]
position = Vector2(300, 337)
scale = Vector2(2, 2)
script = ExtResource("5_r3xo8")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="cheese"]
polygon = PackedVector2Array(3, 17.5, 18.5, 0, 13.5, -20.5, -16.5, -7, -16, 13)
[node name="Sprite2D" type="Sprite2D" parent="cheese"]
texture = ExtResource("4_i7fg5")
[node name="asteroid" type="Area2D" parent="."]
position = Vector2(564, 144)
script = ExtResource("6_n4dsl")
[node name="Sprite2D" type="Sprite2D" parent="asteroid"]
position = Vector2(1.00006, -3.99998)
scale = Vector2(1.2, 1.181)
texture = ExtResource("7_0tjls")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="asteroid"]
position = Vector2(-519, -164)
polygon = PackedVector2Array(548, 101, 613, 169, 597, 210, 548, 240, 462, 221, 431, 184, 434, 133, 497, 90)
[connection signal="body_entered" from="cheese" to="cheese" method="_on_body_entered"]

121
main.tscn Normal file
View File

@ -0,0 +1,121 @@
[gd_scene load_steps=13 format=3 uid="uid://8ocp10j32f62"]
[ext_resource type="Texture2D" uid="uid://y6phkg4twpdm" path="res://images/bg_space_seamless.png" id="1_rpyi5"]
[ext_resource type="Texture2D" uid="uid://cran7fr1i2qou" path="res://images/spaceship-placeholder.png" id="2_f2x66"]
[ext_resource type="Script" path="res://spaceship.gd" id="3_ttkgl"]
[ext_resource type="Script" path="res://laser.gd" id="4_uhf7q"]
[ext_resource type="Script" path="res://weapons_system.gd" id="5_gf6oh"]
[ext_resource type="Script" path="res://asteroid.gd" id="6_n4dsl"]
[ext_resource type="Texture2D" uid="uid://bxgw2u7j4b634" path="res://images/laser_turret.png" id="6_qxhyw"]
[ext_resource type="Texture2D" uid="uid://buirp1h6onqai" path="res://images/AsteroidBrown.png" id="7_0tjls"]
[ext_resource type="Script" path="res://hardpoint.gd" id="7_6cr6a"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_3vtwu"]
radius = 48.0
height = 102.0
[sub_resource type="Gradient" id="Gradient_sx4rn"]
offsets = PackedFloat32Array(0.961735, 1)
colors = PackedColorArray(1, 1, 0, 1, 1, 1, 1, 0.137255)
[sub_resource type="CircleShape2D" id="CircleShape2D_w58nc"]
radius = 88.0057
[node name="Main" type="Node2D"]
[node name="background" type="Sprite2D" parent="."]
position = Vector2(955, 537)
scale = Vector2(2, 2)
texture = ExtResource("1_rpyi5")
[node name="spaceship" type="CharacterBody2D" parent="."]
position = Vector2(908, 835)
collision_layer = 2
motion_mode = 1
script = ExtResource("3_ttkgl")
[node name="Sprite2D" type="Sprite2D" parent="spaceship"]
z_index = 1
texture = ExtResource("2_f2x66")
[node name="CollisionShape2D" type="CollisionShape2D" parent="spaceship"]
position = Vector2(0, 6)
rotation = -3.14159
shape = SubResource("CapsuleShape2D_3vtwu")
[node name="Laser1" type="Node2D" parent="spaceship"]
light_mask = 2
position = Vector2(95, -159)
script = ExtResource("4_uhf7q")
[node name="LaserSprite2D" type="Sprite2D" parent="spaceship/Laser1"]
position = Vector2(0, -5)
texture = ExtResource("6_qxhyw")
[node name="LaserBeam2D" type="RayCast2D" parent="spaceship/Laser1"]
position = Vector2(0, -17)
target_position = Vector2(0, -800)
collide_with_areas = true
[node name="LaserLine2D" type="Line2D" parent="spaceship/Laser1"]
points = PackedVector2Array(0, 0, 0, 0)
default_color = Color(1, 1, 0, 0.54902)
gradient = SubResource("Gradient_sx4rn")
texture_mode = 2
joint_mode = 2
[node name="DamageOutputLabel" type="Label" parent="spaceship/Laser1"]
offset_left = 18.0
offset_top = -71.0
offset_right = 104.0
offset_bottom = -20.0
[node name="WeaponsSystem" type="Node" parent="spaceship"]
script = ExtResource("5_gf6oh")
[node name="HardPoint1" type="Node2D" parent="spaceship"]
position = Vector2(0, -46)
script = ExtResource("7_6cr6a")
[node name="asteroid" type="StaticBody2D" parent="."]
position = Vector2(564, 144)
collision_mask = 2
script = ExtResource("6_n4dsl")
[node name="Sprite2D" type="Sprite2D" parent="asteroid"]
position = Vector2(1.00006, -3.99998)
scale = Vector2(1.2, 1.181)
texture = ExtResource("7_0tjls")
[node name="AsteroidCollisionPolygon2D" type="CollisionPolygon2D" parent="asteroid"]
position = Vector2(-519, -164)
polygon = PackedVector2Array(548, 101, 613, 169, 597, 210, 548, 240, 462, 221, 431, 184, 434, 133, 497, 90)
[node name="AsteroidHealthLabel" type="Label" parent="asteroid"]
offset_left = 105.0
offset_top = 38.0
offset_right = 181.0
offset_bottom = 80.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="asteroid"]
position = Vector2(-2, 1)
shape = SubResource("CircleShape2D_w58nc")
[node name="asteroid2" type="StaticBody2D" parent="."]
position = Vector2(1405, 413)
script = ExtResource("6_n4dsl")
[node name="Sprite2D" type="Sprite2D" parent="asteroid2"]
position = Vector2(1.00006, -3.99998)
scale = Vector2(1.2, 1.181)
texture = ExtResource("7_0tjls")
[node name="AsteroidCollisionPolygon2D" type="CollisionPolygon2D" parent="asteroid2"]
position = Vector2(-519, -164)
polygon = PackedVector2Array(548, 101, 613, 169, 597, 210, 548, 240, 462, 221, 431, 184, 434, 133, 497, 90)
[node name="AsteroidHealthLabel" type="Label" parent="asteroid2"]
offset_left = 105.0
offset_top = 38.0
offset_right = 181.0
offset_bottom = 80.0

34
project.godot Normal file
View File

@ -0,0 +1,34 @@
; 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="Star Cheese - The Final Fromage"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=1920
window/size/viewport_height=1080
[input]
ui_fire={
"deadzone": 0.5,
"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,"echo":false,"script":null)
]
}
[layer_names]
2d_physics/layer_1="Environment"
2d_physics/layer_2="Player"

57
spaceship.gd Normal file
View File

@ -0,0 +1,57 @@
extends CharacterBody2D
@export var acceleration: float = 400.0
@export var max_speed: float = 1500.0
@export var rotation_speed: float = 3.0
@export var friction: float = 0.99
signal fire # Signal to start firing
signal stop_fire # Signal to stop firing
var weapons_system
func _ready():
weapons_system = $WeaponsSystem
func get_spaceship_orientation_vector() -> Vector2:
return -global_transform.y
func handle_movement(delta: float) -> void:
var thrust = Vector2.ZERO
if Input.is_action_pressed("ui_up"):
thrust = Vector2(0, -1).rotated(rotation) * acceleration * delta
velocity += thrust
if Input.is_action_pressed("ui_down"):
thrust = Vector2(0, 1).rotated(rotation) * acceleration * delta
velocity += thrust
if Input.is_action_pressed("ui_left"):
rotation -= rotation_speed * delta
if Input.is_action_pressed("ui_right"):
rotation += rotation_speed * delta
# Clamp velocity and apply friction
velocity = velocity.clamp(Vector2(-max_speed, -max_speed), Vector2(max_speed, max_speed))
velocity *= friction
var collision = move_and_collide(velocity * delta)
if collision:
print("Collided with: ", collision.get_collider().name)
var collision_normal = collision.get_normal()
velocity = velocity.slide(collision_normal)
func handle_weapons_input() -> void:
if Input.is_action_pressed("ui_fire"):
weapons_system.fire_all()
if Input.is_action_just_released("ui_fire"):
weapons_system.cease_fire_all()
func _process(delta: float) -> void:
handle_movement(delta)
handle_weapons_input()

15
weapons_system.gd Normal file
View File

@ -0,0 +1,15 @@
extends Node
var weapons = []
func _ready():
pass
func fire_all():
get_tree().call_group("weapons", "fire")
func cease_fire_all():
get_tree().call_group("weapons", "cease_fire")