then there were rockets

This commit is contained in:
OddlyTimbot committed 2026-07-01 08:06:42 -04:00
1 parent b4bae4bb14
commit 404f518ddd
6 files changed
+57 -3

No files matched your search

+10 -3
View File
@@ -1,7 +1,7 @@
class_name Player extends CharacterBody2D
signal pushSignal(body, direction)
signal shootSignal(markerPosition, speed)
signal fireSignal(markerPosition, direction, speed)
@onready var right_cast: RayCast2D = $RightCast
@onready var left_cast: RayCast2D = $LeftCast
@onready var right_spawn: Marker2D = $RightSpawn
@@ -39,7 +39,7 @@ func _physics_process(delta: float) -> void:
pushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
if pushLeftEnabled and facing==FaceDirection.LEFT:
pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
#Handle Shoot
#Handle Shoot Bullet
if Input.is_action_just_pressed("shoot"):
print("Ima shoot a bullet")
#marker postion, speed
@@ -48,7 +48,14 @@ func _physics_process(delta: float) -> void:
shootSignal.emit(right_spawn.global_transform, 800)
FaceDirection.LEFT:
shootSignal.emit(left_spawn.global_transform, 800)
#Handle fire rocket
if Input.is_action_just_pressed("fire"):
print("Ima fire rocket")
match facing:
FaceDirection.RIGHT:
fireSignal.emit(right_spawn.global_transform,Vector2(1,0), 800)
FaceDirection.LEFT:
fireSignal.emit(left_spawn.global_transform,Vector2(1,0), 800)
# 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")
+17
View File
@@ -0,0 +1,17 @@
class_name Rocket extends RigidBody2D
func _ready() -> void:
#Rockets expolode in time
var timer = Timer.new()
add_child(timer)
timer.wait_time = 4
timer.one_shot = true
timer.connect("timeout", splode)
timer.start()
func _on_body_entered(body: Node) -> void:
print("Rocket hit a target")
#should i splode myself?
func splode()->void:
self.queue_free()
+1
View File
@@ -0,0 +1 @@
uid://bv3ixqvmjrf8j
+9
View File
@@ -4,6 +4,8 @@ extends Node2D
@onready var player: Player = $"../Player"
var bullet = preload("res://scenes/bullet.tscn")
var rocket = preload("res://scenes/rocket.tscn")
var bulletArray:Array[Bullet] = []
var totalAllowedBullets:int = 7
@@ -12,6 +14,7 @@ func _ready() -> void:
#signals from the view
player.pushSignal.connect(pushTarget)
player.shootSignal.connect(makeBullet)
player.fireSignal.connect(makeRocket)
#signals from the GameController
game.destroySignal.connect(destroy)
@@ -71,3 +74,9 @@ func makeBullet(spawnPosition, speed)->void:
myBullet.transform = spawnPosition
myBullet.setSpeed(speed)
func makeRocket(spawnPosition, direction, speed)->void:
print("make a rocket")
var myRocket = rocket.instantiate()
add_sibling(myRocket)
myRocket.transform = spawnPosition
pushTarget(myRocket,direction*speed)