static bodies, rigidbodies, signals custom signals, Characterbody, Trigger

This commit is contained in:
OddlyTimbot committed 2026-06-22 21:04:00 -04:00
commit d5fc80ff7b
18 files changed
+279

No files matched your search

+1
View File
@@ -0,0 +1 @@
class_name Crate extends RigidBody2D
+1
View File
@@ -0,0 +1 @@
uid://cxgsqwmbd0c8q
+37
View File
@@ -0,0 +1,37 @@
extends Node2D
var numberOfCrates = 2
var timeAvailable = 5
var timer = Timer.new()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", countdown)
timer.start()
func countdown()->void:
# reduce time left
timeAvailable-=1
if timeAvailable<=0 and numberOfCrates>0:
print("LOOOOOSAH")
get_tree().reload_current_scene()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger(body: Variant, trigger: Variant) -> void:
print("GC knows trigger fired")
body.queue_free()
numberOfCrates -=1
if numberOfCrates == 0:
print("YOU WON!!!")
get_tree().reload_current_scene()
func crateTotal(howmany):
numberOfCrates = howmany
print("GC knows about crates: "+str(numberOfCrates))
+1
View File
@@ -0,0 +1 @@
uid://dtv434qd1rfmu
+31
View File
@@ -0,0 +1,31 @@
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()
#a loop
for i in get_slide_collision_count():
var c = get_slide_collision(i)
#is this a bonkable thing?
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
+1
View File
@@ -0,0 +1 @@
uid://b1obldvd2etx7
+23
View File
@@ -0,0 +1,23 @@
extends Node2D
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../Crates"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
buildLevel()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func buildLevel()->void:
#tell GC how many crates...
var totalCrates = 0
if crates:
for obj in crates.get_children():
if obj is Crate:
totalCrates +=1
game.crateTotal(totalCrates)
+1
View File
@@ -0,0 +1 @@
uid://b5c00ybml8rj
+16
View File
@@ -0,0 +1,16 @@
extends Area2D
signal areaTriggerSignal(body, trigger)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("Trigger is ready.")
# 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("Something entered the trigger!")
areaTriggerSignal.emit(body, self)
+1
View File
@@ -0,0 +1 @@
uid://g4wclr5vnxk6