4 game objects, working characterbody, basic impulses

This commit is contained in:
OddlyTimbot 2024-11-18 20:48:50 -05:00
parent d3e28f22b8
commit 2b8c206abc
5 changed files with 147 additions and 0 deletions

View File

@ -11,5 +11,12 @@ config_version=5
[application]
config/name="NovemberGame"
run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"
[file_customization]
folder_colors={
"res://scripts/": "green"
}

View File

@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://dm71h7adhhf8u"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dbirr"]
size = Vector2(30, 32)
[node name="RigidBody2D" type="RigidBody2D" groups=["box"]]
position = Vector2(531, 339)
rotation = 2.64233
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_dbirr")
debug_color = Color(0.747094, 0.350436, 0.149052, 0.42)

View File

@ -0,0 +1,75 @@
[gd_scene load_steps=8 format=3 uid="uid://cmh68gsfunmwa"]
[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_14xrk"]
[ext_resource type="Script" path="res://scripts/trigger.gd" id="2_tsnf5"]
[ext_resource type="PackedScene" uid="uid://dm71h7adhhf8u" path="res://scenes/box.tscn" id="3_pi0u1"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rcjag"]
size = Vector2(84, 12)
[sub_resource type="CircleShape2D" id="CircleShape2D_pg3nc"]
radius = 18.1108
[sub_resource type="RectangleShape2D" id="RectangleShape2D_supj4"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_c5gsu"]
[node name="Game" type="Node2D"]
[node name="Platform" type="StaticBody2D" parent="."]
position = Vector2(523, 407)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform"]
shape = SubResource("RectangleShape2D_rcjag")
[node name="Platform2" type="StaticBody2D" parent="."]
position = Vector2(658, 415)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform2"]
shape = SubResource("RectangleShape2D_rcjag")
[node name="Platform3" type="StaticBody2D" parent="."]
position = Vector2(725, 328)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Platform3"]
shape = SubResource("RectangleShape2D_rcjag")
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
position = Vector2(504, 382)
script = ExtResource("1_14xrk")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
shape = SubResource("CircleShape2D_pg3nc")
debug_color = Color(0.178776, 0.565003, 0.825276, 0.42)
[node name="Area2D" type="Area2D" parent="."]
position = Vector2(519, 464)
scale = Vector2(10.92, 1)
script = ExtResource("2_tsnf5")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_supj4")
debug_color = Color(0.793021, 0.25626, 0.844091, 0.42)
[node name="RigidBody2D" parent="." instance=ExtResource("3_pi0u1")]
position = Vector2(571, 331)
[node name="RigidBody2D2" parent="." instance=ExtResource("3_pi0u1")]
[node name="RigidBody2D3" parent="." instance=ExtResource("3_pi0u1")]
position = Vector2(479, 288)
rotation = 1.16823
[node name="StaticBody2D" type="StaticBody2D" parent="."]
position = Vector2(508, 565)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
shape = SubResource("WorldBoundaryShape2D_c5gsu")
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]

View File

@ -0,0 +1,30 @@
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
const BUMPFORCE = 50
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 c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * BUMPFORCE)

View File

@ -0,0 +1,22 @@
extends Area2D
var BoxCount = 0
var MaxBoxes = 3
# 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 _on_body_entered(body: Node2D) -> void:
print("Trigger saw a thing")
if body.is_in_group("box"):
print("box hit the trigger")
BoxCount +=1
if BoxCount >= MaxBoxes:
print("YU WUN")