then there were rockets

This commit is contained in:
OddlyTimbot 2026-07-01 08:06:42 -04:00
parent b4bae4bb14
commit 404f518ddd
6 changed files with 57 additions and 3 deletions

View File

@ -27,6 +27,11 @@ shoot={
"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":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null) "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":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
] ]
} }
fire={
"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":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
]
}
[physics] [physics]

15
scenes/rocket.tscn Normal file
View File

@ -0,0 +1,15 @@
[gd_scene format=3 uid="uid://do4vf0eh7ku01"]
[ext_resource type="Script" uid="uid://bv3ixqvmjrf8j" path="res://scripts/rocket.gd" id="1_3341w"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_00dr1"]
size = Vector2(12, 4)
[node name="Rocket" type="RigidBody2D" unique_id=2026133878]
script = ExtResource("1_3341w")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1980926328]
shape = SubResource("RectangleShape2D_00dr1")
debug_color = Color(0.63964945, 0.5193221, 0.22762358, 0.41960785)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,7 +1,7 @@
class_name Player extends CharacterBody2D class_name Player extends CharacterBody2D
signal pushSignal(body, direction) signal pushSignal(body, direction)
signal shootSignal(markerPosition, speed) signal shootSignal(markerPosition, speed)
signal fireSignal(markerPosition, direction, speed)
@onready var right_cast: RayCast2D = $RightCast @onready var right_cast: RayCast2D = $RightCast
@onready var left_cast: RayCast2D = $LeftCast @onready var left_cast: RayCast2D = $LeftCast
@onready var right_spawn: Marker2D = $RightSpawn @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)) pushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
if pushLeftEnabled and facing==FaceDirection.LEFT: if pushLeftEnabled and facing==FaceDirection.LEFT:
pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100)) pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
#Handle Shoot #Handle Shoot Bullet
if Input.is_action_just_pressed("shoot"): if Input.is_action_just_pressed("shoot"):
print("Ima shoot a bullet") print("Ima shoot a bullet")
#marker postion, speed #marker postion, speed
@ -48,7 +48,14 @@ func _physics_process(delta: float) -> void:
shootSignal.emit(right_spawn.global_transform, 800) shootSignal.emit(right_spawn.global_transform, 800)
FaceDirection.LEFT: FaceDirection.LEFT:
shootSignal.emit(left_spawn.global_transform, 800) 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. # Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions. # As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right") var direction := Input.get_axis("ui_left", "ui_right")

17
scripts/rocket.gd Normal file
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
scripts/rocket.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://bv3ixqvmjrf8j

View File

@ -4,6 +4,8 @@ extends Node2D
@onready var player: Player = $"../Player" @onready var player: Player = $"../Player"
var bullet = preload("res://scenes/bullet.tscn") var bullet = preload("res://scenes/bullet.tscn")
var rocket = preload("res://scenes/rocket.tscn")
var bulletArray:Array[Bullet] = [] var bulletArray:Array[Bullet] = []
var totalAllowedBullets:int = 7 var totalAllowedBullets:int = 7
@ -12,6 +14,7 @@ func _ready() -> void:
#signals from the view #signals from the view
player.pushSignal.connect(pushTarget) player.pushSignal.connect(pushTarget)
player.shootSignal.connect(makeBullet) player.shootSignal.connect(makeBullet)
player.fireSignal.connect(makeRocket)
#signals from the GameController #signals from the GameController
game.destroySignal.connect(destroy) game.destroySignal.connect(destroy)
@ -71,3 +74,9 @@ func makeBullet(spawnPosition, speed)->void:
myBullet.transform = spawnPosition myBullet.transform = spawnPosition
myBullet.setSpeed(speed) 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)