Add a savegame system using slots and a main menu, allow player to move RigidBody2Ds using apply_impulse(), increased physics tick, enabled FXAA, and more.

This commit is contained in:
ChaoticByte 2024-10-01 23:19:37 +02:00
parent 35ebe26340
commit 5a67d46d6f
No known key found for this signature in database
13 changed files with 291 additions and 25 deletions

5
menu/menu.gd Normal file
View file

@ -0,0 +1,5 @@
extends Node2D
func _physics_process(_delta: float) -> void:
if NodeRegistry.player.position.y > 1000:
NodeRegistry.player.position = Vector2(0, 0)

55
menu/menu.tscn Normal file
View file

@ -0,0 +1,55 @@
[gd_scene load_steps=4 format=3 uid="uid://bqmpoix37kutp"]
[ext_resource type="PackedScene" uid="uid://cbynoofsjcl45" path="res://core/polygon.tscn" id="1_8p275"]
[ext_resource type="Script" path="res://menu/menu.gd" id="1_g2w4y"]
[ext_resource type="PackedScene" uid="uid://c40fli7qcma78" path="res://menu/slot/slot.tscn" id="3_rc4dm"]
[node name="Menu" type="Node2D"]
position = Vector2(0, -1)
script = ExtResource("1_g2w4y")
[node name="Label" type="Label" parent="."]
offset_left = -192.0
offset_top = -15.0
offset_right = 192.0
offset_bottom = 65.0
theme_override_font_sizes/font_size = 52
text = "Main Menu"
horizontal_alignment = 1
vertical_alignment = 2
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="Polygon" parent="StaticBody2D" instance=ExtResource("1_8p275")]
polygon = PackedVector2Array(-256, 209, 320, 209, 320, 193, -272, 193, -272, 601, -304, 601, -304, 617, -256, 617)
[node name="SaveGameSlots" type="Node2D" parent="."]
position = Vector2(-448, 177)
[node name="Saves" type="Label" parent="SaveGameSlots"]
offset_left = -64.0
offset_top = -176.0
offset_right = 64.0
offset_bottom = -112.0
theme_override_font_sizes/font_size = 42
text = "Saves"
horizontal_alignment = 1
vertical_alignment = 2
[node name="Slot0" parent="SaveGameSlots" instance=ExtResource("3_rc4dm")]
slot_label = "0"
[node name="Slot1" parent="SaveGameSlots" instance=ExtResource("3_rc4dm")]
position = Vector2(0, 128)
slot_idx = 1
slot_label = "1"
[node name="Slot2" parent="SaveGameSlots" instance=ExtResource("3_rc4dm")]
position = Vector2(0, 256)
slot_idx = 2
slot_label = "2"
[node name="Slot3" parent="SaveGameSlots" instance=ExtResource("3_rc4dm")]
position = Vector2(0, 384)
slot_idx = 3
slot_label = "3"

21
menu/slot/slot.gd Normal file
View file

@ -0,0 +1,21 @@
extends Node2D
@export var slot_idx: int
@export var slot_label: String = ""
func _ready() -> void:
$Label.text = str(slot_label)
func _on_area_2d_load_body_entered(body: Node2D) -> void:
# load slot & start game
if body == NodeRegistry.player:
Gamestate.current_slot = slot_idx
Gamestate.load_slot()
Levels.load_entrypoint(Gamestate.last_entrypoint)
func _on_area_2d_delete_body_entered(body: Node2D) -> void:
# reset slot on disk
if body == NodeRegistry.player:
Gamestate.reset_slot(slot_idx)
NodeRegistry.player.position = Levels.mainmenu_player_pos

35
menu/slot/slot.tscn Normal file
View file

@ -0,0 +1,35 @@
[gd_scene load_steps=3 format=3 uid="uid://c40fli7qcma78"]
[ext_resource type="PackedScene" uid="uid://cbynoofsjcl45" path="res://core/polygon.tscn" id="1_2cb7u"]
[ext_resource type="Script" path="res://menu/slot/slot.gd" id="1_3dgi0"]
[node name="Slot" type="Node2D"]
script = ExtResource("1_3dgi0")
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="platform" parent="StaticBody2D" instance=ExtResource("1_2cb7u")]
polygon = PackedVector2Array(44, 16, -44, 16, -44, 48, -64, 48, -64, 16, -80, 16, -80, 56, 80, 56, 80, 16, 64, 16, 64, 48, 44, 48)
[node name="Area2D_Load" type="Area2D" parent="."]
[node name="Polygon" parent="Area2D_Load" instance=ExtResource("1_2cb7u")]
polygon = PackedVector2Array(44, 48, 64, 48, 64, 24, 44, 24)
color = Color(0, 1, 0, 1)
[node name="Area2D_Delete" type="Area2D" parent="."]
[node name="Polygon" parent="Area2D_Delete" instance=ExtResource("1_2cb7u")]
polygon = PackedVector2Array(-64, 48, -44, 48, -44, 24, -64, 24)
color = Color(1, 0, 0, 1)
[node name="Label" type="Label" parent="."]
offset_left = -16.0
offset_top = -32.0
offset_right = 16.0
text = "_"
horizontal_alignment = 1
vertical_alignment = 1
[connection signal="body_entered" from="Area2D_Load" to="." method="_on_area_2d_load_body_entered"]
[connection signal="body_entered" from="Area2D_Delete" to="." method="_on_area_2d_delete_body_entered"]