Bullets firing and scene manager witih teleportation and force push

This commit is contained in:
ArunKirupananthan committed 2026-10-06 20:58:28 -04:00
1 parent 94012868f0
commit 4e9a117b77
15 files changed
+260 -60

No files matched your search

+8
View File
@@ -27,6 +27,14 @@ folder_colors={
"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]
3d/physics_engine="Jolt Physics"
+16
View File
@@ -0,0 +1,16 @@
[gd_scene format=3 uid="uid://dh08kl1i4ssa7"]
[ext_resource type="Script" uid="uid://cvcvibt6begmk" path="res://scripts/bullet.gd" id="1_mkf8s"]
[sub_resource type="CircleShape2D" id="CircleShape2D_daopg"]
radius = 9.055386
[node name="Bullet" type="Area2D" unique_id=273509445]
script = ExtResource("1_mkf8s")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=292911264]
shape = SubResource("CircleShape2D_daopg")
debug_color = Color(0.78356177, 0, 0.1389513, 0.41960785)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
+16
View File
@@ -0,0 +1,16 @@
[gd_scene format=3 uid="uid://n3nikeltgorc"]
[ext_resource type="Script" uid="uid://bm4rr2spukcxt" path="res://scripts/crate.gd" id="1_b66cd"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kvpdf"]
size = Vector2(18.97712, 20)
[node name="Crate" type="RigidBody2D" unique_id=1917613907]
script = ExtResource("1_b66cd")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=551067750]
position = Vector2(-0.51144075, 0)
scale = Vector2(1.0000001, 1.0000001)
shape = SubResource("RectangleShape2D_kvpdf")
debug_color = Color(0.7640784, 0.29976174, 0.010127576, 0.41960785)
+36 -50
View File
@@ -1,26 +1,24 @@
[gd_scene format=3 uid="uid://bmghctv58ymhx"]
[ext_resource type="Script" uid="uid://ci5kwydrjchlr" path="res://scripts/gamecontoller.gd" id="1_lnu2h"]
[ext_resource type="Script" uid="uid://k5itsiku45rk" path="res://scripts/player.gd" id="1_uwrxv"]
[ext_resource type="Script" uid="uid://qdgabfyqg4v4" path="res://scripts/trigger.gd" id="1_yqjtg"]
[ext_resource type="Script" uid="uid://ccrtmkeh3wxoc" path="res://scripts/scenemanager.gd" id="2_lbhrr"]
[ext_resource type="PackedScene" uid="uid://bf2snjwsm1g01" path="res://scenes/trigger.tscn" id="2_lnu2h"]
[ext_resource type="PackedScene" uid="uid://n3nikeltgorc" path="res://scenes/crate.tscn" id="3_iywne"]
[ext_resource type="PackedScene" uid="uid://bbascciqs68u" path="res://scenes/player.tscn" id="4_iywne"]
[ext_resource type="PackedScene" uid="uid://dh08kl1i4ssa7" path="res://scenes/bullet.tscn" id="6_p57ef"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_daopg"]
size = Vector2(156, 39.5)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kvpdf"]
size = Vector2(95.25, 20)
[sub_resource type="CircleShape2D" id="CircleShape2D_daopg"]
radius = 65.06919
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_daopg"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_daopg"]
distance = -534.0
[node name="Game" type="Node2D" unique_id=2025408499]
script = ExtResource("1_lnu2h")
[node name="SceneManager" type="Node2D" parent="." unique_id=46020717]
script = ExtResource("2_lbhrr")
[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=50045338]
position = Vector2(356, 397)
metadata/_edit_group_ = true
@@ -28,51 +26,39 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1746367507]
shape = SubResource("RectangleShape2D_daopg")
[node name="RigidBody2D" type="RigidBody2D" parent="." unique_id=1155250024]
position = Vector2(-86, 6.000002)
rotation = -0.07132487
metadata/_edit_group_ = true
[node name="RigidBody2D" parent="." unique_id=1917613907 instance=ExtResource("3_iywne")]
position = Vector2(-132.00002, 24.999996)
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D" unique_id=1735923422]
position = Vector2(391, 309)
shape = SubResource("RectangleShape2D_kvpdf")
debug_color = Color(0.7640784, 0.29976174, 0.010127576, 0.41960785)
[node name="RigidBody2D2" type="RigidBody2D" parent="." unique_id=1925655640]
position = Vector2(420, 226)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2" unique_id=471803879]
position = Vector2(-17.625, 0)
rotation = 0.16720873
shape = SubResource("RectangleShape2D_kvpdf")
debug_color = Color(0.7640784, 0.29976174, 0.010127576, 0.41960785)
[node name="trigger" type="Area2D" parent="." unique_id=970658975]
position = Vector2(255, 470)
scale = Vector2(0.8503403, 0.740157)
script = ExtResource("1_yqjtg")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="trigger" unique_id=496847008]
shape = SubResource("CircleShape2D_daopg")
debug_color = Color(0.90523595, 0.00013803899, 0.7489745, 0.41960785)
[node name="CharacterBody2D" type="CharacterBody2D" parent="." unique_id=613044494]
position = Vector2(340, 352)
script = ExtResource("1_uwrxv")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D" unique_id=1901684918]
shape = SubResource("CapsuleShape2D_daopg")
debug_color = Color(0.42452708, 0.6028724, 0.041758128, 0.41960785)
[node name="Player" parent="." unique_id=680748920 instance=ExtResource("4_iywne")]
position = Vector2(339, 351)
[node name="StaticBody2D2" type="StaticBody2D" parent="." unique_id=2128236600]
position = Vector2(344, 11)
position = Vector2(346, 57)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2" unique_id=1639942213]
shape = SubResource("WorldBoundaryShape2D_daopg")
[connection signal="areatriggered" from="trigger" to="." method="_on_trigger"]
[connection signal="body_entered" from="trigger" to="trigger" method="_on_body_entered"]
[node name="Triggers" type="Node2D" parent="." unique_id=1735917497]
[node name="trigger" parent="Triggers" unique_id=1921053799 instance=ExtResource("2_lnu2h")]
position = Vector2(492, 471)
[node name="trigger2" parent="Triggers" unique_id=520292665 instance=ExtResource("2_lnu2h")]
position = Vector2(204, 338)
effect = "teleport"
[node name="Crate" parent="Triggers" unique_id=6318362 instance=ExtResource("3_iywne")]
position = Vector2(400, 304)
[node name="trigger3" parent="Triggers" unique_id=2118176855 instance=ExtResource("2_lnu2h")]
position = Vector2(161, 482.99997)
[node name="Crate" parent="." unique_id=1661527763 instance=ExtResource("3_iywne")]
position = Vector2(280, 291)
[node name="Crate2" parent="." unique_id=1011126838 instance=ExtResource("3_iywne")]
position = Vector2(367, 201)
[node name="Bullet" parent="." unique_id=273509445 instance=ExtResource("6_p57ef")]
position = Vector2(97, 365)
+25
View File
@@ -0,0 +1,25 @@
[gd_scene format=3 uid="uid://bbascciqs68u"]
[ext_resource type="Script" uid="uid://k5itsiku45rk" path="res://scripts/player.gd" id="1_3vyb7"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_daopg"]
[node name="Player" type="CharacterBody2D" unique_id=680748920]
script = ExtResource("1_3vyb7")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=308149451]
shape = SubResource("CapsuleShape2D_daopg")
debug_color = Color(0.42452708, 0.6028724, 0.041758128, 0.41960785)
[node name="RightCast" type="RayCast2D" parent="." unique_id=1878095713]
target_position = Vector2(16, 0)
[node name="LeftCast" type="RayCast2D" parent="." unique_id=1441120401]
target_position = Vector2(-16, 0)
[node name="RightSpawn" type="Marker2D" parent="." unique_id=1621013334]
position = Vector2(16, -7)
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=774488423]
position = Vector2(-16, -7)
+17
View File
@@ -0,0 +1,17 @@
[gd_scene format=3 uid="uid://bf2snjwsm1g01"]
[ext_resource type="Script" uid="uid://qdgabfyqg4v4" path="res://scripts/trigger.gd" id="1_du5ex"]
[sub_resource type="CircleShape2D" id="CircleShape2D_daopg"]
radius = 65.06919
[node name="trigger" type="Area2D" unique_id=1921053799]
scale = Vector2(0.8503403, 0.740157)
script = ExtResource("1_du5ex")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=647978856]
shape = SubResource("CircleShape2D_daopg")
debug_color = Color(0.90523595, 0.00013803899, 0.7489745, 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 something")
bulletDamageSignal.emit(body,self)
+1
View File
@@ -0,0 +1 @@
uid://cvcvibt6begmk
+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://bm4rr2spukcxt
+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.
func _ready() -> void:
pass # Replace with function body.
@@ -13,6 +13,18 @@ func _process(delta: float) -> void:
func _on_trigger(effect: Variant, Object: Variant) -> void:
print ("Game controller knows about trigger")
if effect == "destroy":
if not Object is Player:
Object.queue_free()
match effect:
"destroy":
if not Object is Player:
Object.queue_free()
"teleport":
print("Trigger wants to teleport")
if Object is Crate :
teleportSignal.emit(Object)
#Object.teleport_to()
func _on_bullet_hit(body,bullet)-> void:
print ("GC knows bullet hit")
if body is Crate:
body.queue_free()
bullet.queue_free()
+47 -1
View File
@@ -1,5 +1,19 @@
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 JUMP_VELOCITY = -400.0
@@ -10,6 +24,15 @@ func _physics_process(delta: float) -> void:
if not is_on_floor():
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.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
@@ -19,6 +42,11 @@ func _physics_process(delta: float) -> void:
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
#Set player direction
if direction < 0:
facing = FaceDirection.LEFT
if direction > 0:
facing = FaceDirection.RIGHT
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
@@ -27,4 +55,22 @@ func _physics_process(delta: float) -> void:
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() * 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://ccrtmkeh3wxoc
+4 -4
View File
@@ -1,6 +1,6 @@
extends Area2D
var effect="destroy"
signal areatriggered(effect, Object)
class_name Trigger extends Area2D
@export var effect:String ="destroy"
signal AreaTriggered(effect, Object)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@@ -13,4 +13,4 @@ func _process(delta: float) -> void:
func _on_body_entered(body: Node2D) -> void:
print("Trigger was triggered")
areatriggered.emit(effect, body)
AreaTriggered.emit(effect, body)