Add game basics

This commit is contained in:
winnieWK 2025-06-02 20:57:07 -04:00
parent 8e4b4700b7
commit 342042d984
10 changed files with 155 additions and 0 deletions

View File

@ -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"
}

16
scenes/areaTrigger.tscn Normal file
View File

@ -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"]

12
scenes/crate.tscn Normal file
View File

@ -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)

51
scenes/game.tscn Normal file
View File

@ -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"]

19
scripts/gameController.gd Normal file
View File

@ -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")

View File

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

30
scripts/playerBody.gd Normal file
View File

@ -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)

View File

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

16
scripts/trigger.gd Normal file
View File

@ -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)

1
scripts/trigger.gd.uid Normal file
View File

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