spawns, bullets, factory

This commit is contained in:
LucasLeaheySchofield committed 2025-08-11 21:08:52 -04:00
1 parent ad3d83e5bd
commit eac97fda20
17 files changed
+223 -43

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
class_name Bullet extends Area2D
var speed:float = 700
signal bulletDamageSignal(body, bullet)
func setSpeed(value:float):
speed = value
func _physics_process(delta:float) -> void:
position += transform.x * speed * delta
func _on_body_entered(body: Node2D) -> void:
print("Bullet hitting")
if body.is_in_group("shootables"):
print("This is shootable")
bulletDamageSignal.emit(body, self)
+1
View File
@@ -0,0 +1 @@
uid://bsrl75gqbvfkf
+66 -11
View File
@@ -1,29 +1,84 @@
class_name Player extends CharacterBody2D
@onready var left_cast: RayCast2D = $"Left Cast"
@onready var right_cast: RayCast2D = $"Right Cast"
@onready var left_spawn: Node2D = $LeftSpawn
@onready var right_spawn: Node2D = $RightSpawn
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var direction
enum FaceDirection{LEFT, RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
var pushTarget
var pushEnabled := false
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")
handle_input()
handle_movement(delta)
move_and_slide()
handle_collisions()
func handle_movement(delta):
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
if not is_on_floor():
velocity += get_gravity() * delta
func handle_input():
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
direction = Input.get_axis("ui_left", "ui_right")
if direction < 0:
facing = FaceDirection.LEFT
if direction > 0:
facing = FaceDirection.RIGHT
if Input.is_action_just_pressed("shove") && pushEnabled:
var shoveDirection:int
match facing:
FaceDirection.RIGHT:
shoveDirection = 1
FaceDirection.LEFT:
shoveDirection = -1
pushTarget.apply_central_impulse(Vector2(shoveDirection,0)*700)
if Input.is_action_just_pressed("shoot"):
print("Ima shoot")
match facing:
FaceDirection.RIGHT:
print("shoot to right")
%SceneManager.makeBullet(right_spawn.global_transform, 700)
FaceDirection.LEFT:
%SceneManager.makeBullet(left_spawn.global_transform, -700)
func handle_collisions():
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() * 100)
if right_cast.is_colliding() && facing ==FaceDirection.RIGHT:
print("RC is colliding")
var collider = right_cast.get_collider()
if collider is Node && collider is RigidBody2D && collider.is_in_group("pushables"):
pushTarget = collider
pushEnabled = true
if left_cast.is_colliding() && facing==FaceDirection.LEFT:
var collider = left_cast.get_collider()
if collider is Node && collider is RigidBody2D:
pushTarget = collider
pushEnabled = true
if not right_cast.is_colliding() && not left_cast.is_colliding():
pushEnabled = false
+1
View File
@@ -0,0 +1 @@
uid://crc2khytlo6r
+1
View File
@@ -0,0 +1 @@
class_name Crate extends RigidBody2D
+1
View File
@@ -0,0 +1 @@
uid://b7utyaqyc131x
+4
View File
@@ -15,3 +15,7 @@ func _on_trigger(effect: Variant, body: Variant) -> void:
print("GC sees trigger "+effect)
if not body is Player:
body.queue_free()
func bulletDamage(body, bullet):
print("GC knows about bullet hit")
body.queue_free()
+1
View File
@@ -0,0 +1 @@
uid://bt6s0tpg6lrha
+34
View File
@@ -0,0 +1,34 @@
class_name SceneManager extends Node2D
var bulletArray = []
var totalAllowedBullets = 7
var bullet = preload("res://Scenes/bullet.tscn")
@onready var game: 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
# makes and recycles bullets
func bulletFactory():
var myBullet:Bullet
if bulletArray.size() < totalAllowedBullets:
#make a new bullet
myBullet = bullet.instantiate()
myBullet.bulletDamageSignal.connect(game.bulletDamage)
owner.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func makeBullet(position, speed):
var someBullet = bulletFactory()
someBullet.setSpeed(speed)
#position the bullet
someBullet.transform = position
+1
View File
@@ -0,0 +1 @@
uid://bukc3pev3h3fq
+1
View File
@@ -0,0 +1 @@
uid://chxs44jhw6xor