Compare commits

...

4 Commits

Author SHA1 Message Date
1d82f7502d week2 prep 2026-06-29 18:14:58 -04:00
d8629e2f81 week 2 prep 2026-06-29 17:38:15 -04:00
d0819ead77 week 2 prep 2026-06-29 17:02:44 -04:00
7824bcd6cd week 2 prep 2026-06-29 16:57:59 -04:00
13 changed files with 331 additions and 69 deletions

View File

@ -15,6 +15,19 @@ run/main_scene="uid://ch6sfehmsskcs"
config/features=PackedStringArray("4.6", "Forward Plus")
config/icon="res://icon.svg"
[input]
shove={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
]
}
shoot={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
]
}
[physics]
3d/physics_engine="Jolt Physics"

14
scenes/bullet.tscn Normal file
View File

@ -0,0 +1,14 @@
[gd_scene format=3 uid="uid://bp51pocvj7p3x"]
[ext_resource type="Script" uid="uid://bvy43aky6y3er" path="res://scripts/bullet.gd" id="1_mkf8s"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h1aey"]
size = Vector2(8, 3)
[node name="Bullet" type="Area2D" unique_id=1728947011]
script = ExtResource("1_mkf8s")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=791301971]
position = Vector2(0, 0.5)
shape = SubResource("RectangleShape2D_h1aey")
debug_color = Color(0.9348346, 0.10724712, 0.5768572, 0.41960785)

View File

@ -5,7 +5,6 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_uwrxv"]
[node name="Crate" type="RigidBody2D" unique_id=1609374030]
rotation = -0.68311554
script = ExtResource("1_b66cd")
metadata/_edit_group_ = true

View File

@ -1,16 +1,14 @@
[gd_scene format=3 uid="uid://ch6sfehmsskcs"]
[ext_resource type="Script" uid="uid://dtv434qd1rfmu" path="res://scripts/game.gd" id="1_lnu2h"]
[ext_resource type="Script" uid="uid://g4wclr5vnxk6" path="res://scripts/trigger.gd" id="1_uwrxv"]
[ext_resource type="Script" uid="uid://b5c00ybml8rj" path="res://scripts/scene_manager.gd" id="2_lbhrr"]
[ext_resource type="Script" uid="uid://b1obldvd2etx7" path="res://scripts/player.gd" id="2_yqjtg"]
[ext_resource type="PackedScene" uid="uid://byl4bdrupii3k" path="res://scenes/player.tscn" id="4_iywne"]
[ext_resource type="PackedScene" uid="uid://b6cmg0k8qjoxi" path="res://scenes/crate.tscn" id="5_iywne"]
[ext_resource type="PackedScene" uid="uid://b3hgbbmb0nohj" path="res://scenes/trigger.tscn" id="5_p57ef"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"]
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_iywne"]
[node name="Game" type="Node2D" unique_id=981419409]
script = ExtResource("1_lnu2h")
@ -18,58 +16,71 @@ script = ExtResource("1_lnu2h")
[node name="SceneManager" type="Node2D" parent="." unique_id=323246552]
script = ExtResource("2_lbhrr")
[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=1863997109]
position = Vector2(555, 409)
[node name="Player" parent="." unique_id=1254268479 instance=ExtResource("4_iywne")]
position = Vector2(440.00006, 375.00003)
[node name="Crates" type="Node2D" parent="." unique_id=207771395]
[node name="Crate" parent="Crates" unique_id=1609374030 instance=ExtResource("5_iywne")]
position = Vector2(508, 373)
[node name="Crate2" parent="Crates" unique_id=1603366376 instance=ExtResource("5_iywne")]
position = Vector2(1098, 323)
[node name="Walls" type="Node2D" parent="." unique_id=1895909883]
[node name="StaticBody2D" type="StaticBody2D" parent="Walls" unique_id=1863997109]
position = Vector2(446.00006, 404)
scale = Vector2(3.4000025, 1)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1910670137]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D" unique_id=1910670137]
shape = SubResource("RectangleShape2D_8cj0n")
[node name="StaticBody2D3" type="StaticBody2D" parent="." unique_id=2089762008]
[node name="StaticBody2D4" type="StaticBody2D" parent="Walls" unique_id=575340316]
position = Vector2(516, 404)
scale = Vector2(3.4000025, 1)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D4" unique_id=522720352]
shape = SubResource("RectangleShape2D_8cj0n")
[node name="StaticBody2D3" type="StaticBody2D" parent="Walls" unique_id=2089762008]
position = Vector2(734.00006, 377)
scale = Vector2(3.4000025, 1)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D3" unique_id=892222577]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D3" unique_id=892222577]
shape = SubResource("RectangleShape2D_8cj0n")
[node name="StaticBody2D2" type="StaticBody2D" parent="." unique_id=2038269484]
[node name="StaticBody2D2" type="StaticBody2D" parent="Walls" unique_id=2038269484]
position = Vector2(681.00006, 398)
rotation = -0.7375178
scale = Vector2(3.4000025, 1)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2" unique_id=1636593491]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D2" unique_id=1636593491]
shape = SubResource("RectangleShape2D_8cj0n")
[node name="Trigger" type="Area2D" parent="." unique_id=1742156972]
[node name="StaticBody2D5" type="StaticBody2D" parent="Walls" unique_id=1787748242]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D5" unique_id=1244109335]
position = Vector2(0, 554)
shape = SubResource("WorldBoundaryShape2D_iywne")
[node name="Triggers" type="Node2D" parent="." unique_id=193669081]
[node name="Trigger" parent="Triggers" unique_id=1050615345 instance=ExtResource("5_p57ef")]
position = Vector2(621.00006, 465.00006)
scale = Vector2(4.2, 4.2)
script = ExtResource("1_uwrxv")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Trigger" unique_id=1581030951]
shape = SubResource("CircleShape2D_8cj0n")
debug_color = Color(0.3285461, 0.6189337, 0.22834331, 0.41960785)
[node name="Trigger2" parent="Triggers" unique_id=1114882050 instance=ExtResource("5_p57ef")]
position = Vector2(829, 464)
intent = "fan"
[node name="Player" type="CharacterBody2D" parent="." unique_id=1939613595]
position = Vector2(535.00006, 379.00003)
scale = Vector2(1.4799998, 1.4799998)
script = ExtResource("2_yqjtg")
metadata/_edit_group_ = true
[node name="Trigger3" parent="Triggers" unique_id=400578019 instance=ExtResource("5_p57ef")]
position = Vector2(1097, 462.99997)
intent = "teleport"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player" unique_id=312922488]
shape = SubResource("CircleShape2D_uwrxv")
debug_color = Color(0.39731503, 0.48776567, 0.95015794, 0.41960785)
[node name="Crates" type="Node2D" parent="." unique_id=207771395]
[node name="Crate" parent="Crates" unique_id=1609374030 instance=ExtResource("5_iywne")]
position = Vector2(625, 345.99997)
[node name="Crate2" parent="Crates" unique_id=1603366376 instance=ExtResource("5_iywne")]
position = Vector2(736, 347.99997)
[connection signal="areaTriggerSignal" from="Trigger" to="." method="_on_trigger"]
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]
[connection signal="areaTriggerSignal" from="Triggers/Trigger" to="." method="_on_trigger"]
[connection signal="areaTriggerSignal" from="Triggers/Trigger2" to="." method="_on_trigger"]
[connection signal="areaTriggerSignal" from="Triggers/Trigger3" to="." method="_on_trigger"]

33
scenes/player.tscn Normal file
View File

@ -0,0 +1,33 @@
[gd_scene format=3 uid="uid://byl4bdrupii3k"]
[ext_resource type="Script" uid="uid://b1obldvd2etx7" path="res://scripts/player.gd" id="1_3vyb7"]
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
[node name="Player" type="CharacterBody2D" unique_id=1254268479]
scale = Vector2(1.4799998, 1.4799998)
script = ExtResource("1_3vyb7")
[node name="Label" type="Label" parent="." unique_id=712501367]
offset_left = -19.594597
offset_top = -36.486492
offset_right = 20.405403
offset_bottom = -13.486492
text = "label"
horizontal_alignment = 1
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=771657224]
shape = SubResource("CircleShape2D_uwrxv")
debug_color = Color(0.39731503, 0.48776567, 0.95015794, 0.41960785)
[node name="RightCast" type="RayCast2D" parent="." unique_id=1585175579]
target_position = Vector2(16.216217, -0.67567575)
[node name="LeftCast" type="RayCast2D" parent="." unique_id=544087242]
target_position = Vector2(-15.540543, -0.67567575)
[node name="RightTarget" type="Marker2D" parent="." unique_id=855125472]
position = Vector2(15.540543, -8.783785)
[node name="LeftTarget" type="Marker2D" parent="." unique_id=1162416681]
position = Vector2(-14.864867, -8.783785)

26
scenes/trigger.tscn Normal file
View File

@ -0,0 +1,26 @@
[gd_scene format=3 uid="uid://b3hgbbmb0nohj"]
[ext_resource type="Script" uid="uid://g4wclr5vnxk6" path="res://scripts/trigger.gd" id="1_du5ex"]
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
[node name="Trigger" type="Area2D" unique_id=1050615345]
scale = Vector2(4.2, 4.2)
script = ExtResource("1_du5ex")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=703121924]
shape = SubResource("CircleShape2D_8cj0n")
debug_color = Color(0.3285461, 0.6189337, 0.22834331, 0.41960785)
[node name="Label" type="Label" parent="." unique_id=1171382845]
texture_filter = 1
offset_left = -18.333336
offset_top = -8.333334
offset_right = 21.666664
offset_bottom = 2.666666
theme_override_font_sizes/font_size = 7
text = "trigger"
horizontal_alignment = 1
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

19
scripts/bullet.gd Normal file
View File

@ -0,0 +1,19 @@
class_name Bullet extends Area2D
var speed:float = 700
signal bulletDamageSignal(body, bullet)
func setSpeed(value:int)->void:
speed = value
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
position += transform.x * speed *delta
func _on_body_entered(body: Node2D) -> void:
bulletDamageSignal.emit(body, self)
func _on_area_entered(area: Area2D) -> void:
bulletDamageSignal.emit(area, self)

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

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

View File

@ -1 +1,13 @@
class_name Crate extends RigidBody2D
var teleport_target: Vector2 = Vector2.ZERO
var should_teleport: bool = false
func teleport_to(position:Vector2):
teleport_target = position
should_teleport = true
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
if should_teleport:
state.transform = Transform2D.IDENTITY.translated(teleport_target)
should_teleport = false

View File

@ -1,11 +1,17 @@
extends Node2D
var numberOfCrates = 2
var timeAvailable = 5
var timeAvailable = 50
signal destroySignal(body)
signal levelChangeSignal(level)
signal fanUpSignal(body,direction)
signal teleportSignal(body)
var timer = Timer.new()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
get_window().grab_focus()
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
@ -17,21 +23,27 @@ func countdown()->void:
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
levelChangeSignal.emit("res://scenes/game.tscn")
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 _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
print("GC knows trigger fired "+intent)
match intent:
"destroy":
print("GC sending destroy signal")
destroySignal.emit(body)
"fan":
if body is RigidBody2D:
fanUpSignal.emit(body,Vector2(0,-1)*100*9)
"teleport":
if body is Crate:
teleportSignal.emit(body)
#from scene manager
func crateTotal(howmany):
numberOfCrates = howmany
print("GC knows about crates: "+str(numberOfCrates))
if numberOfCrates == 0:
print("YOU WON!!!")
levelChangeSignal.emit("res://scenes/game.tscn")
func bulletDamage()->void:
print("bullet damage")

View File

@ -1,10 +1,28 @@
extends CharacterBody2D
class_name Player extends CharacterBody2D
@onready var label: Label = $Label
@onready var rightRay: RayCast2D = $RightCast
@onready var leftRay: RayCast2D = $LeftCast
@onready var right_target: Marker2D = $RightTarget
@onready var left_target: Marker2D = $LeftTarget
var pushRightEnabled:=false
var pushLeftEnabled := false
var pushTarget
var pushTimer:int = 0
signal forcePushSignal(body,direction)
signal shootSignal(targetPosition, speed)
#track facing direction
enum FaceDirection {LEFT,RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
@ -13,12 +31,45 @@ func _physics_process(delta: float) -> void:
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Handle shove
if Input.is_action_just_pressed("shove"):
pushTimer = Time.get_ticks_msec() #record start of build
#Handle shove
if Input.is_action_just_released("shove"):
var pushForce = Time.get_ticks_msec() - pushTimer
#do a maximium force value
if pushForce>4000:
pushForce = 4000
if pushRightEnabled and facing==FaceDirection.RIGHT:
label.text = "shove"
forcePushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
if pushLeftEnabled and facing==FaceDirection.LEFT:
forcePushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
label.text = "shove"
# Handle Shoot
if Input.is_action_just_pressed("shoot"):
print("Player wants to shoot")
match facing:
FaceDirection.RIGHT:
print("Shoot to the right")
#%SceneManager.makeBullet(right_target.global_transform, 700)
shootSignal.emit(right_target.global_transform, 700)
FaceDirection.LEFT:
print("Shoot to the left")
#%SceneManager.makeBullet(left_target.global_transform, -700)
shootSignal.emit(left_target.global_transform, -700)
# 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
if direction>0:
facing = FaceDirection.RIGHT
else:
facing = FaceDirection.LEFT
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
@ -28,4 +79,23 @@ func _physics_process(delta: float) -> void:
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)
forcePushSignal.emit(c.get_collider(), -c.get_normal() * 100)
if rightRay.is_colliding():
#get the thing causing the collision
var collider = rightRay.get_collider()
if collider is Node:
pushRightEnabled = true
pushTarget = collider
else:
pushRightEnabled = false
if leftRay.is_colliding():
#get the thing causing the collision
var collider = leftRay.get_collider()
if collider is Node:
pushLeftEnabled = true
pushTarget = collider
else:
pushLeftEnabled = false

View File

@ -1,23 +1,72 @@
extends Node2D
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../Crates"
@onready var player: CharacterBody2D = $"../Player"
var bullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array[Bullet] = []
var totalAllowedBullets:int = 7
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#wire up view
player.forcePushSignal.connect(push)
player.shootSignal.connect(makeBullet)
#wire up gamecontroller
game.destroySignal.connect(destroy)
game.levelChangeSignal.connect(changeScene)
game.fanUpSignal.connect(push)
game.teleportSignal.connect(teleport)
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
updateCrates()
func updateCrates()->void:
var _crateTotal:int = 0
if crates:
for obj in crates.get_children():
if obj is Crate:
totalCrates +=1
if not obj.tree_exited.is_connected(updateCrates):
obj.tree_exited.connect(updateCrates)
_crateTotal +=1
game.crateTotal(_crateTotal)
game.crateTotal(totalCrates)
#applies impulse to rigidbodies
func push(body, direction)->void:
body.apply_central_impulse(direction)
func teleport(body, _bodyposition=null)->void:
print("teleport a body")
if body is Crate:
var viewport_size = get_viewport().get_visible_rect().size
var random_x = randf_range(0, viewport_size.x)
var random_y = randf_range(0, viewport_size.y)
var newPosition = Vector2(random_x,random_y)
body.teleport_to(newPosition)
func destroy(body)->void:
body.queue_free()
func changeScene(level)->void:
get_tree().call_deferred("change_scene_to_file",level)
func bulletFactory()->Bullet :
var myBullet:Bullet
#how many bullets have been made?
if bulletArray.size() <= totalAllowedBullets:
myBullet = bullet.instantiate()
if not myBullet.bulletDamageSignal.is_connected(game.bulletDamage):
myBullet.bulletDamageSignal.connect(game.bulletDamage)
add_sibling(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func makeBullet(targetPosition:Transform2D, speed:int)->void:
var myBullet:Bullet = bulletFactory()
myBullet.transform = targetPosition
myBullet.setSpeed(speed)
myBullet.set_process(true)

View File

@ -1,9 +1,12 @@
extends Area2D
signal areaTriggerSignal(body, trigger)
signal areaTriggerSignal(body, trigger, intent)
@export var intent:String="destroy"
@onready var label: Label = $Label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("Trigger is ready.")
label.text = str(intent)
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -13,4 +16,4 @@ func _process(delta: float) -> void:
func _on_body_entered(body: Node2D) -> void:
print("Something entered the trigger!")
areaTriggerSignal.emit(body, self)
areaTriggerSignal.emit(body, self, intent)