From 2605a085e2b003d7cb83db88e14839330d623103 Mon Sep 17 00:00:00 2001 From: "Kevin (O) Gorman" Date: Mon, 6 Jan 2025 20:34:02 -0500 Subject: [PATCH] destroy the crates --- scenes/game.tscn | 13 ++++++++++--- .../{charcontroller.gd => charController.gd} | 5 +++++ scripts/gameController.gd | 17 +++++++++++++++++ scripts/trigger.gd | 4 ++++ 4 files changed, 36 insertions(+), 3 deletions(-) rename scripts/{charcontroller.gd => charController.gd} (75%) create mode 100644 scripts/gameController.gd diff --git a/scenes/game.tscn b/scenes/game.tscn index e5a8454..729a038 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=3 uid="uid://dhgts0kodsujx"] +[gd_scene load_steps=9 format=3 uid="uid://dhgts0kodsujx"] [ext_resource type="PackedScene" uid="uid://djkjmi7bo58uv" path="res://scenes/crate.tscn" id="1_6shkr"] -[ext_resource type="Script" path="res://scripts/charcontroller.gd" id="2_uc4yi"] +[ext_resource type="Script" path="res://scripts/gameController.gd" id="1_7tjsy"] +[ext_resource type="Script" path="res://scripts/charController.gd" id="2_uc4yi"] [ext_resource type="Script" path="res://scripts/trigger.gd" id="3_t4lk8"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_n7xvc"] @@ -17,6 +18,7 @@ radius = 32.5576 radius = 62.0 [node name="Game" type="Node2D"] +script = ExtResource("1_7tjsy") [node name="firstPlatform" type="StaticBody2D" parent="."] position = Vector2(595, 310) @@ -43,6 +45,7 @@ position = Vector2(629, 37) [node name="CharacterBody2D" type="CharacterBody2D" parent="."] position = Vector2(524, 393) script = ExtResource("2_uc4yi") +PUSH_FORCE = 50 metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] @@ -50,7 +53,7 @@ shape = SubResource("CircleShape2D_uvblg") debug_color = Color(0.872789, 0.000463018, 0.842707, 0.42) [node name="Area2D" type="Area2D" parent="."] -position = Vector2(833, 354) +position = Vector2(952, 434) script = ExtResource("3_t4lk8") metadata/_edit_group_ = true @@ -58,4 +61,8 @@ metadata/_edit_group_ = true shape = SubResource("CircleShape2D_5ph8t") debug_color = Color(0.630721, 0.529414, 1.92523e-07, 0.42) +[node name="RigidBody2D3" parent="." instance=ExtResource("1_6shkr")] +position = Vector2(534, 53) + +[connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] diff --git a/scripts/charcontroller.gd b/scripts/charController.gd similarity index 75% rename from scripts/charcontroller.gd rename to scripts/charController.gd index 9347282..6a0ced6 100644 --- a/scripts/charcontroller.gd +++ b/scripts/charController.gd @@ -3,6 +3,7 @@ extends CharacterBody2D const SPEED = 500.0 const JUMP_VELOCITY = -600.0 +@export var PUSH_FORCE = 90 func _physics_process(delta: float) -> void: @@ -23,3 +24,7 @@ func _physics_process(delta: float) -> void: 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()*PUSH_FORCE) diff --git a/scripts/gameController.gd b/scripts/gameController.gd new file mode 100644 index 0000000..9f7fcd9 --- /dev/null +++ b/scripts/gameController.gd @@ -0,0 +1,17 @@ +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 _on_trigger(effect: Variant, body) -> void: + print("they were triggered!") + if body is RigidBody2D: + print("crate spotted") + body.queue_free() diff --git a/scripts/trigger.gd b/scripts/trigger.gd index 6252cf8..81b6ab8 100644 --- a/scripts/trigger.gd +++ b/scripts/trigger.gd @@ -1,5 +1,7 @@ extends Area2D +@export var effect = "alert" +signal areaTrigger(effect, Object) # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -13,3 +15,5 @@ func _process(delta: float) -> void: func _on_body_entered(body: Node2D) -> void: print("I'm triggered!") + areaTrigger.emit(effect, body) +