bullets firing, scene manager, teleport, force push

This commit is contained in:
OddlyTimbot committed 2026-10-06 20:58:28 -04:00
1 parent c8d5474785
commit 60bde97dba
15 files changed
+250 -53

No files matched your search

+8
View File
@@ -27,6 +27,14 @@ folder_colors={
"res://scripts/": "red" "res://scripts/": "red"
} }
[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":76,"key_label":0,"unicode":108,"location":0,"echo":false,"script":null)
]
}
[physics] [physics]
3d/physics_engine="Jolt Physics" 3d/physics_engine="Jolt Physics"
+16
View File
@@ -0,0 +1,16 @@
[gd_scene format=3 uid="uid://qrewcx81o1xi"]
[ext_resource type="Script" uid="uid://ryrc3a88d0nh" path="res://scripts/bullet.gd" id="1_mkf8s"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvphy"]
size = Vector2(12, 6)
[node name="Bullet" type="Area2D" unique_id=1877237172]
script = ExtResource("1_mkf8s")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=117632852]
shape = SubResource("RectangleShape2D_mvphy")
debug_color = Color(0.9521257, 0.20191753, 0.23529023, 0.41960785)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
+13
View File
@@ -0,0 +1,13 @@
[gd_scene format=3 uid="uid://5xgx7qarkj3o"]
[ext_resource type="Script" uid="uid://rp1f47ytyerd" path="res://scripts/crate.gd" id="1_b66cd"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o7s7a"]
[node name="Crate" type="RigidBody2D" unique_id=721458511]
script = ExtResource("1_b66cd")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=536978238]
shape = SubResource("RectangleShape2D_o7s7a")
debug_color = Color(0.8398786, 0.37498713, 0.22887537, 0.41960785)
+28 -45
View File
@@ -1,24 +1,23 @@
[gd_scene format=3 uid="uid://cxa67u8cwsn6x"] [gd_scene format=3 uid="uid://cxa67u8cwsn6x"]
[ext_resource type="Script" uid="uid://ct51411gsine2" path="res://scripts/gamecontroller.gd" id="1_lnu2h"] [ext_resource type="Script" uid="uid://ct51411gsine2" path="res://scripts/gamecontroller.gd" id="1_lnu2h"]
[ext_resource type="Script" uid="uid://ct34rf6jscqmo" path="res://scripts/player.gd" id="1_uwrxv"] [ext_resource type="Script" uid="uid://dv2q4p6jb8h4s" path="res://scripts/scene_manager.gd" id="2_lbhrr"]
[ext_resource type="Script" uid="uid://ck2uw1e2b0646" path="res://scripts/trigger.gd" id="1_yqjtg"] [ext_resource type="PackedScene" uid="uid://b22qsgmtr231s" path="res://scenes/trigger.tscn" id="2_lnu2h"]
[ext_resource type="PackedScene" uid="uid://5xgx7qarkj3o" path="res://scenes/crate.tscn" id="3_iywne"]
[ext_resource type="PackedScene" uid="uid://dtegcgc8xcxfg" path="res://scenes/player.tscn" id="4_iywne"]
[ext_resource type="PackedScene" uid="uid://qrewcx81o1xi" path="res://scenes/bullet.tscn" id="6_p57ef"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvphy"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mvphy"]
size = Vector2(66, 20) size = Vector2(66, 20)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o7s7a"]
[sub_resource type="CircleShape2D" id="CircleShape2D_mvphy"]
radius = 27.0
[sub_resource type="CircleShape2D" id="CircleShape2D_o7s7a"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_mvphy"] [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_mvphy"]
[node name="Game" type="Node2D" unique_id=989312165] [node name="Game" type="Node2D" unique_id=989312165]
script = ExtResource("1_lnu2h") script = ExtResource("1_lnu2h")
[node name="SceneManager" type="Node2D" parent="." unique_id=1778809182]
script = ExtResource("2_lbhrr")
[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=1148293182] [node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=1148293182]
position = Vector2(568, 408) position = Vector2(568, 408)
metadata/_edit_group_ = true metadata/_edit_group_ = true
@@ -26,41 +25,11 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1634682333] [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1634682333]
shape = SubResource("RectangleShape2D_mvphy") shape = SubResource("RectangleShape2D_mvphy")
[node name="RigidBody2D" type="RigidBody2D" parent="." unique_id=622131877] [node name="RigidBody2D" parent="." unique_id=721458511 instance=ExtResource("3_iywne")]
position = Vector2(541, 379) position = Vector2(740, 551)
rotation = -0.32228005
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D" unique_id=1349809273] [node name="Player" parent="." unique_id=735255374 instance=ExtResource("4_iywne")]
shape = SubResource("RectangleShape2D_o7s7a") position = Vector2(572, 385)
debug_color = Color(0.8398786, 0.37498713, 0.22887537, 0.41960785)
[node name="RigidBody2D2" type="RigidBody2D" parent="." unique_id=684295328]
position = Vector2(510.00006, 297)
rotation = -1.1398602
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2" unique_id=1289600515]
shape = SubResource("RectangleShape2D_o7s7a")
debug_color = Color(0.8398786, 0.37498713, 0.22887537, 0.41960785)
[node name="Trigger" type="Area2D" parent="." unique_id=1736949874]
position = Vector2(515, 472)
script = ExtResource("1_yqjtg")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Trigger" unique_id=840899447]
shape = SubResource("CircleShape2D_mvphy")
debug_color = Color(0.76538396, 0.26260582, 0.8980484, 0.41960785)
[node name="CharacterBody2D" type="CharacterBody2D" parent="." unique_id=509013756]
position = Vector2(591, 387)
script = ExtResource("1_uwrxv")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D" unique_id=566367520]
shape = SubResource("CircleShape2D_o7s7a")
debug_color = Color(0.19446194, 0.63244796, 0.32305, 0.41960785)
[node name="StaticBody2D2" type="StaticBody2D" parent="." unique_id=958110307] [node name="StaticBody2D2" type="StaticBody2D" parent="." unique_id=958110307]
position = Vector2(538, 582) position = Vector2(538, 582)
@@ -69,5 +38,19 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2" unique_id=1123970436] [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2" unique_id=1123970436]
shape = SubResource("WorldBoundaryShape2D_mvphy") shape = SubResource("WorldBoundaryShape2D_mvphy")
[connection signal="areaTriggered" from="Trigger" to="." method="_on_trigger"] [node name="Triggers" type="Node2D" parent="." unique_id=1308561168]
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]
[node name="Trigger" parent="Triggers" unique_id=1346685745 instance=ExtResource("2_lnu2h")]
position = Vector2(390, 541)
[node name="Trigger2" parent="Triggers" unique_id=110247025 instance=ExtResource("2_lnu2h")]
position = Vector2(514, 502)
effect = "teleport"
[node name="Crate" parent="." unique_id=1367266345 instance=ExtResource("3_iywne")]
position = Vector2(635, 553)
[node name="Bullet" parent="." unique_id=1877237172 instance=ExtResource("6_p57ef")]
position = Vector2(305, 562)
[connection signal="areaTriggered" from="Triggers/Trigger" to="." method="_on_trigger"]
+25
View File
@@ -0,0 +1,25 @@
[gd_scene format=3 uid="uid://dtegcgc8xcxfg"]
[ext_resource type="Script" uid="uid://ct34rf6jscqmo" path="res://scripts/player.gd" id="1_3vyb7"]
[sub_resource type="CircleShape2D" id="CircleShape2D_o7s7a"]
[node name="Player" type="CharacterBody2D" unique_id=735255374]
script = ExtResource("1_3vyb7")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1869095904]
shape = SubResource("CircleShape2D_o7s7a")
debug_color = Color(0.19446194, 0.63244796, 0.32305, 0.41960785)
[node name="RightCast" type="RayCast2D" parent="." unique_id=714147844]
target_position = Vector2(16, 0)
[node name="LeftCast" type="RayCast2D" parent="." unique_id=1570883453]
target_position = Vector2(-16, 0)
[node name="RightSpawn" type="Marker2D" parent="." unique_id=1276129807]
position = Vector2(14, -6)
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=522145742]
position = Vector2(-15, -6)
+16
View File
@@ -0,0 +1,16 @@
[gd_scene format=3 uid="uid://b22qsgmtr231s"]
[ext_resource type="Script" uid="uid://ck2uw1e2b0646" path="res://scripts/trigger.gd" id="1_du5ex"]
[sub_resource type="CircleShape2D" id="CircleShape2D_mvphy"]
radius = 27.0
[node name="Trigger" type="Area2D" unique_id=1346685745]
script = ExtResource("1_du5ex")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=936278424]
shape = SubResource("CircleShape2D_mvphy")
debug_color = Color(0.76538396, 0.26260582, 0.8980484, 0.41960785)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
+18
View File
@@ -0,0 +1,18 @@
class_name Bullet extends Area2D
var speed:= 700
signal bulletDamageSignal(body, bullet)
# 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:
position += transform.x * speed * delta
func _on_body_entered(body: Node2D) -> void:
print("Bullet hit somethin")
bulletDamageSignal.emit(body, self)
+1
View File
@@ -0,0 +1 @@
uid://ryrc3a88d0nh
+22
View File
@@ -0,0 +1,22 @@
class_name Crate extends RigidBody2D
var teleport_target: Vector2 = Vector2.ZERO
var should_teleport: bool = false
# 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 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
+1
View File
@@ -0,0 +1 @@
uid://rp1f47ytyerd
+17 -5
View File
@@ -1,6 +1,6 @@
extends Node2D class_name GameController extends Node2D
signal teleportSignal(body:RigidBody2D)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
pass # Replace with function body. pass # Replace with function body.
@@ -13,6 +13,18 @@ func _process(delta: float) -> void:
func _on_trigger(effect: Variant, Object: Variant) -> void: func _on_trigger(effect: Variant, Object: Variant) -> void:
print("GC knows about trigger") print("GC knows about trigger")
if effect == "destroy": match effect:
if not Object is Player: "destroy":
Object.queue_free() if not Object is Player:
Object.queue_free()
"teleport":
print("Trigger wants to teleport")
if Object is Crate:
teleportSignal.emit(Object)
func _on_bullet_hit(body, bullet) -> void:
print("GC knows bullet hit")
if body is Crate:
body.queue_free()
bullet.queue_free()
+51 -1
View File
@@ -1,5 +1,20 @@
class_name Player extends CharacterBody2D class_name Player extends CharacterBody2D
@onready var right_cast: RayCast2D = $RightCast
@onready var left_cast: RayCast2D = $LeftCast
@onready var right_spawn: Marker2D = $RightSpawn
@onready var left_spawn: Marker2D = $LeftSpawn
@export var shove_power:= 800
@export var bump_power:=100
enum FaceDirection {LEFT,RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
var pushRightEnabled = false
var pushLeftEnabled = false
var pushTarget:Crate
const SPEED = 300.0 const SPEED = 300.0
const JUMP_VELOCITY = -400.0 const JUMP_VELOCITY = -400.0
@@ -10,6 +25,17 @@ func _physics_process(delta: float) -> void:
if not is_on_floor(): if not is_on_floor():
velocity += get_gravity() * delta velocity += get_gravity() * delta
# Handle shove
if Input.is_action_just_pressed("shove"):
print("Player wants to shove")
if pushRightEnabled and facing==FaceDirection.RIGHT:
#shove right
pushTarget.apply_central_impulse(Vector2(1,0) * shove_power )
if pushLeftEnabled and facing == FaceDirection.LEFT:
#shove left
pushTarget.apply_central_impulse(Vector2(-1,0) * shove_power )
# Handle jump. # Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor(): if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY velocity.y = JUMP_VELOCITY
@@ -19,6 +45,11 @@ func _physics_process(delta: float) -> void:
var direction := Input.get_axis("ui_left", "ui_right") var direction := Input.get_axis("ui_left", "ui_right")
if direction: if direction:
velocity.x = direction * SPEED velocity.x = direction * SPEED
# set player direction
if direction < 0:
facing = FaceDirection.LEFT
if direction > 0:
facing = FaceDirection.RIGHT
else: else:
velocity.x = move_toward(velocity.x, 0, SPEED) velocity.x = move_toward(velocity.x, 0, SPEED)
@@ -27,4 +58,23 @@ func _physics_process(delta: float) -> void:
for i in get_slide_collision_count(): for i in get_slide_collision_count():
var c = get_slide_collision(i) var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D: if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * 200 ) c.get_collider().apply_central_impulse(-c.get_normal() * bump_power )
if right_cast.is_colliding():
print("Something on my right")
#get the thing I can shove
var collider = right_cast.get_collider()
if collider is Node:
pushRightEnabled = true
pushTarget = collider
else:
pushRightEnabled = false
if left_cast.is_colliding():
print("Something on my left")
var collider = left_cast.get_collider()
if collider is Node:
pushLeftEnabled = true
pushTarget = collider
else:
pushLeftEnabled = false
+31
View File
@@ -0,0 +1,31 @@
class_name SceneManager extends Node2D
@onready var triggers: Node2D = $"../Triggers"
@onready var game: GameController = $".."
@onready var bullet: Bullet = $"../Bullet"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
buildLevel()
game.teleportSignal.connect(teleport)
bullet.bulletDamageSignal.connect(game._on_bullet_hit)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func buildLevel()->void:
if triggers:
for obj in triggers.get_children():
if obj is Trigger:
if not obj.areaTriggered.is_connected(game._on_trigger):
obj.areaTriggered.connect(game._on_trigger)
func teleport(body, _bodyposition=null)->void:
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)
+1
View File
@@ -0,0 +1 @@
uid://dv2q4p6jb8h4s
+2 -2
View File
@@ -1,6 +1,6 @@
extends Area2D class_name Trigger extends Area2D
var effect="destroy" @export var effect:String ="destroy"
signal areaTriggered(effect, Object) signal areaTriggered(effect, Object)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void: