From 342042d9849a78cf4784b4859e1a6a54d8cdc438 Mon Sep 17 00:00:00 2001 From: winnieWK Date: Mon, 2 Jun 2025 20:57:07 -0400 Subject: [PATCH] Add game basics --- project.godot | 8 ++++++ scenes/areaTrigger.tscn | 16 +++++++++++ scenes/crate.tscn | 12 +++++++++ scenes/game.tscn | 51 +++++++++++++++++++++++++++++++++++ scripts/gameController.gd | 19 +++++++++++++ scripts/gameController.gd.uid | 1 + scripts/playerBody.gd | 30 +++++++++++++++++++++ scripts/playerBody.gd.uid | 1 + scripts/trigger.gd | 16 +++++++++++ scripts/trigger.gd.uid | 1 + 10 files changed, 155 insertions(+) create mode 100644 scenes/areaTrigger.tscn create mode 100644 scenes/crate.tscn create mode 100644 scenes/game.tscn create mode 100644 scripts/gameController.gd create mode 100644 scripts/gameController.gd.uid create mode 100644 scripts/playerBody.gd create mode 100644 scripts/playerBody.gd.uid create mode 100644 scripts/trigger.gd create mode 100644 scripts/trigger.gd.uid diff --git a/project.godot b/project.godot index 9b0a40f..a802c85 100644 --- a/project.godot +++ b/project.godot @@ -11,5 +11,13 @@ config_version=5 [application] config/name="juneGame" +run/main_scene="uid://bqhrdmmqohi0n" config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://icon.svg" + +[file_customization] + +folder_colors={ +"res://scenes/": "red", +"res://scripts/": "orange" +} diff --git a/scenes/areaTrigger.tscn b/scenes/areaTrigger.tscn new file mode 100644 index 0000000..4263b34 --- /dev/null +++ b/scenes/areaTrigger.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://4av2mmfp5ofy"] + +[ext_resource type="Script" uid="uid://cpe6ky8vs5iw" path="res://scripts/trigger.gd" id="1_65eai"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"] +radius = 54.6717 + +[node name="Area2D" type="Area2D"] +script = ExtResource("1_65eai") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_uwrxv") +debug_color = Color(0.742979, 0.286678, 0.905956, 0.42) + +[connection signal="body_entered" from="." to="." method="onBodyEntered"] diff --git a/scenes/crate.tscn b/scenes/crate.tscn new file mode 100644 index 0000000..a35ccfd --- /dev/null +++ b/scenes/crate.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://cwkxvudu2hvld"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_uwrxv"] +size = Vector2(75, 64) + +[node name="RigidBody2D" type="RigidBody2D"] +rotation = 0.840501 +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_uwrxv") +debug_color = Color(0.753447, 0.447124, 0.266538, 0.42) diff --git a/scenes/game.tscn b/scenes/game.tscn new file mode 100644 index 0000000..36c9b81 --- /dev/null +++ b/scenes/game.tscn @@ -0,0 +1,51 @@ +[gd_scene load_steps=7 format=3 uid="uid://bqhrdmmqohi0n"] + +[ext_resource type="Script" uid="uid://dpd3j1180cf7a" path="res://scripts/gameController.gd" id="1_lnu2h"] +[ext_resource type="Script" uid="uid://ce1dyrh5wvtc2" path="res://scripts/playerBody.gd" id="1_uwrxv"] +[ext_resource type="PackedScene" uid="uid://cwkxvudu2hvld" path="res://scenes/crate.tscn" id="2_lbhrr"] +[ext_resource type="PackedScene" uid="uid://4av2mmfp5ofy" path="res://scenes/areaTrigger.tscn" id="3_lnu2h"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"] +size = Vector2(1096, 55.5) + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8cj0n"] + +[node name="game" type="Node2D"] +script = ExtResource("1_lnu2h") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2(580, 583) +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_8cj0n") + +[node name="RigidBody2D" parent="." instance=ExtResource("2_lbhrr")] +position = Vector2(960, 187) + +[node name="CharacterBody2D" type="CharacterBody2D" parent="."] +position = Vector2(589, 281) +script = ExtResource("1_uwrxv") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] +shape = SubResource("CapsuleShape2D_8cj0n") +debug_color = Color(0.284982, 0.626275, 0.216672, 0.42) + +[node name="Area2D" parent="." instance=ExtResource("3_lnu2h")] +position = Vector2(449, 498) + +[node name="Area2D2" parent="." instance=ExtResource("3_lnu2h")] +position = Vector2(718, 496) +effect = "powerUp" + +[node name="RigidBody2D2" parent="." instance=ExtResource("2_lbhrr")] +position = Vector2(412, 286) +rotation = -0.228399 + +[node name="RigidBody2D3" parent="." instance=ExtResource("2_lbhrr")] +position = Vector2(788, 246) +rotation = -0.710361 + +[connection signal="onAreaEntered" from="Area2D" to="." method="onAreaEntered"] +[connection signal="onAreaEntered" from="Area2D2" to="." method="onAreaEntered"] diff --git a/scripts/gameController.gd b/scripts/gameController.gd new file mode 100644 index 0000000..2e886e7 --- /dev/null +++ b/scripts/gameController.gd @@ -0,0 +1,19 @@ +extends Node2D + + +# 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: + pass + + +func onAreaEntered(effect, obj) -> void: + if effect == "destroy": + print("destroy the object") + obj.queue_free() + elif effect == "powerUp": + print("power up the object") diff --git a/scripts/gameController.gd.uid b/scripts/gameController.gd.uid new file mode 100644 index 0000000..779ae41 --- /dev/null +++ b/scripts/gameController.gd.uid @@ -0,0 +1 @@ +uid://dpd3j1180cf7a diff --git a/scripts/playerBody.gd b/scripts/playerBody.gd new file mode 100644 index 0000000..89d7d0b --- /dev/null +++ b/scripts/playerBody.gd @@ -0,0 +1,30 @@ +extends CharacterBody2D + + +const SPEED = 300.0 +const JUMP_VELOCITY = -400.0 + + +func _physics_process(delta: float) -> void: + # Add the gravity. + if not is_on_floor(): + velocity += get_gravity() * delta + + # Handle jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var direction := Input.get_axis("ui_left", "ui_right") + if direction: + velocity.x = direction * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + + move_and_slide() + + for i in get_slide_collision_count(): + var collision = get_slide_collision(i) + if collision.get_collider() is RigidBody2D: + collision.get_collider().apply_central_impulse(collision.get_normal() * 100) diff --git a/scripts/playerBody.gd.uid b/scripts/playerBody.gd.uid new file mode 100644 index 0000000..d28bf15 --- /dev/null +++ b/scripts/playerBody.gd.uid @@ -0,0 +1 @@ +uid://ce1dyrh5wvtc2 diff --git a/scripts/trigger.gd b/scripts/trigger.gd new file mode 100644 index 0000000..472e7a0 --- /dev/null +++ b/scripts/trigger.gd @@ -0,0 +1,16 @@ +extends Area2D + +@export var effect = "destroy" + +signal onAreaEntered(effect, Object) +# 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: + pass + +func onBodyEntered(body: Node2D) -> void: + onAreaEntered.emit(effect, body) diff --git a/scripts/trigger.gd.uid b/scripts/trigger.gd.uid new file mode 100644 index 0000000..ef676ac --- /dev/null +++ b/scripts/trigger.gd.uid @@ -0,0 +1 @@ +uid://cpe6ky8vs5iw