Refactored weapon and shoot component use and resources.
This commit is contained in:
parent
79122a074e
commit
bdbc3b015f
29 changed files with 239 additions and 435 deletions
108
Deprecated/_player.gd
Normal file
108
Deprecated/_player.gd
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
extends Area2D
|
||||
|
||||
@export var speed: int = 150
|
||||
@export var shield_max: int = 10
|
||||
|
||||
#var ship = %Ship
|
||||
|
||||
var shield: int = 0: set = shield_set
|
||||
var can_shoot: bool = true
|
||||
var is_shooting: bool = false
|
||||
var previous_position: Vector2
|
||||
var ship_displacement: float
|
||||
var travel: float = 0
|
||||
var bullet_speed: int = 150
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
|
||||
#var weapon_current = load("res://scenes/stock_weapon.tscn")
|
||||
var weapon_cooldown = Timer
|
||||
var weapon_rate: float = 0.1
|
||||
var weapon_timer: float = 0.0
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
@onready var muzzle_damage = %MuzzleBox
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
ship_displacement = position.y - previous_position.y
|
||||
travel += bullet_speed * delta + abs(ship_displacement)
|
||||
travel = clamp(travel, 0, 1.9 * weapon_spacing)
|
||||
|
||||
# Sprite feedback based one player input
|
||||
if input.x > 0:
|
||||
%Ship/Thrusters.position.x = $Ship.position.x+1
|
||||
%Ship.frame = 2
|
||||
%Ship/Thrusters.flip_h = true
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
elif input.x < 0:
|
||||
%Ship/Thrusters.position.x = $Ship.position.x-1
|
||||
%Ship.frame = 1
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
else:
|
||||
%Ship.frame = 0
|
||||
%Ship/Thrusters.position.x = $Ship.position.x
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "fwd"
|
||||
|
||||
# Get previous positon for equidistant bullet calculation
|
||||
previous_position = position
|
||||
|
||||
# Move the ship based on input within the screen bounds
|
||||
position += input * speed * delta
|
||||
position = position.clamp(Vector2(12,12), screensize - Vector2(12,12))
|
||||
|
||||
# Enable muzzle damage hitbox upon firing
|
||||
if Input.is_action_pressed("shoot"):
|
||||
is_shooting = true
|
||||
muzzle_damage.set("disabled", false)
|
||||
|
||||
else:
|
||||
is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
%MuzzleFlash.show()
|
||||
%Ship/MuzzleFlash.animation = "stock"
|
||||
|
||||
# Adjust bullet spacing before firing
|
||||
if travel > weapon_spacing:
|
||||
shoot()
|
||||
travel -= weapon_spacing
|
||||
|
||||
if is_shooting == false:
|
||||
%MuzzleFlash.hide()
|
||||
muzzle_damage.set("disabled", true)
|
||||
|
||||
func shield_set(_value: int):
|
||||
return
|
||||
|
||||
|
||||
func _on_weapon_cooldown_timeout() -> void:
|
||||
#print("You can shoot again!")
|
||||
#can_shoot = true
|
||||
return
|
||||
|
||||
|
||||
func shoot():
|
||||
var projectiles: int = 3
|
||||
const PROJECTILE_SPACING: float = 10
|
||||
const MUZZLE_HEIGHT: int = -23
|
||||
for b in projectiles:
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_current.instantiate()
|
||||
get_tree().root.add_child(bullet)
|
||||
bullet.position = position + Vector2((b - (projectiles - 1) / 2.0) * PROJECTILE_SPACING, MUZZLE_HEIGHT)
|
||||
|
||||
# Get weapon speed and spacing for equidistant calculations
|
||||
weapon_rate = bullet.shot_data.rate
|
||||
weapon_spacing = bullet.shot_data.projectile_spacing
|
||||
bullet_speed = bullet.shot_data.speed
|
||||
|
||||
# Print which weapon is firing
|
||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
|
||||
|
||||
1
Deprecated/_player.gd.uid
Normal file
1
Deprecated/_player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://otm88638j7f8
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://scenes/player_refactor.gd" id="1_qlg0r"]
|
||||
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://Deprecated/player_refactor.gd" id="1_qlg0r"]
|
||||
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="2_qhqgy"]
|
||||
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="4_dqkch"]
|
||||
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
|
||||
|
|
@ -13,7 +13,7 @@ var travel: float = 0
|
|||
var bullet_speed: int = 150
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@export var weapon_current : PackedScene = preload("res://scenes/stock_weapon.tscn")
|
||||
@export var weapon_current : PackedScene = preload("res://scenes/weapon_stock.tscn")
|
||||
|
||||
#var weapon_current = load("res://scenes/stock_weapon.tscn")
|
||||
#var weapon_cooldown = Timer
|
||||
15
Deprecated/stock_weapon.gd
Normal file
15
Deprecated/stock_weapon.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Area2D
|
||||
|
||||
@onready var bullet: PackedScene = load("res://scenes/weapon_stock.tscn")
|
||||
|
||||
@onready var shot_data: = load("res://resources/player_weapons/weapon_shot_stock.tres")
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
#Calculation position along Y axis
|
||||
position.y -= shot_data.speed * delta # Original Speed
|
||||
#position.y -= 330 * delta # non-shot_data testing
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
||||
queue_free()
|
||||
|
|
@ -1,22 +1,13 @@
|
|||
[gd_scene format=3 uid="uid://b2ltmeb14nc17"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d1rwqotmrag1r" path="res://scenes/stock_weapon.gd" id="1_kx6bj"]
|
||||
[ext_resource type="Script" uid="uid://ccdohs4gduee5" path="res://scripts/player_shot.gd" id="2_5286c"]
|
||||
[ext_resource type="Script" uid="uid://d1rwqotmrag1r" path="res://Deprecated/stock_weapon.gd" id="1_kx6bj"]
|
||||
[ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="3_58qml"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_4ihvg"]
|
||||
script = ExtResource("2_5286c")
|
||||
shot_name = "Stock"
|
||||
speed = 350
|
||||
projectiles = 3
|
||||
metadata/_custom_type_script = "uid://ccdohs4gduee5"
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
||||
size = Vector2(12, 8)
|
||||
|
||||
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
||||
script = ExtResource("1_kx6bj")
|
||||
shot_data = SubResource("Resource_4ihvg")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
||||
texture = ExtResource("3_58qml")
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="PlayerShot" format=3 uid="uid://cels8t3hqjtsu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ccdohs4gduee5" path="res://scripts/player_shot.gd" id="1_t07sl"]
|
||||
[ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="2_xc6g1"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_t07sl")
|
||||
shot_name = "Stock"
|
||||
speed = 500
|
||||
spacing = 28.0
|
||||
metadata/_custom_type_script = "uid://ccdohs4gduee5"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
[gd_resource type="Resource" script_class="PlayerShot" format=3 uid="uid://c4c7anpgfq2po"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ccdohs4gduee5" path="res://scripts/player_shot.gd" id="1_reevt"]
|
||||
[ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="2_xsuf1"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_reevt")
|
||||
shot_name = "Stock"
|
||||
speed = 500
|
||||
metadata/_custom_type_script = "uid://ccdohs4gduee5"
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
class_name WeaponShot
|
||||
|
||||
extends Resource
|
||||
|
||||
@export_category("Info")
|
||||
@export var shot_name: String
|
||||
@export var sprite: Texture2D = preload("res://graphics/shot.png")
|
||||
@export var bullet_scene: PackedScene = null
|
||||
|
||||
#@export var sprite: Texture2D = preload("res://graphics/shot.png")
|
||||
|
||||
@export_category("Shot Data")
|
||||
@export var damage: int = 1
|
||||
14
resources/player_weapons/weapon_shot_stock.tres
Normal file
14
resources/player_weapons/weapon_shot_stock.tres
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://b75ae840k03dy"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/weapon_stock.tscn" id="1_by0nb"]
|
||||
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapons/weapon_shot.gd" id="2_by0nb"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_by0nb")
|
||||
shot_name = "Stock Shot"
|
||||
bullet_scene = ExtResource("1_by0nb")
|
||||
speed = 375
|
||||
projectiles = 3
|
||||
spacing = 25.0
|
||||
origin = -20
|
||||
metadata/_custom_type_script = "uid://7n1itonn35fm"
|
||||
114
scenes/player.gd
114
scenes/player.gd
|
|
@ -1,108 +1,34 @@
|
|||
extends Area2D
|
||||
class_name Player extends Area2D
|
||||
|
||||
@export var speed: int = 150
|
||||
@export var shield_max: int = 10
|
||||
# Components managed by Player
|
||||
@onready var input_component: InputComponent = %InputComponent
|
||||
@onready var movement_component: MovementComponent = %MovementComponent
|
||||
@onready var shoot_component: ShootComponent = %ShootComponent
|
||||
@onready var weapon_component: WeaponComponent = %WeaponComponent
|
||||
|
||||
#var ship = %Ship
|
||||
# Variables for Player shooting status
|
||||
@export var can_shoot: bool = true
|
||||
@export var is_shooting: bool = false
|
||||
|
||||
var shield: int = 0: set = shield_set
|
||||
var can_shoot: bool = true
|
||||
var is_shooting: bool = false
|
||||
# Variables for Player position calculations for equidistant bullets
|
||||
var previous_position: Vector2
|
||||
var ship_displacement: float
|
||||
var travel: float = 0
|
||||
var bullet_speed: int = 150
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
|
||||
#var weapon_current = load("res://scenes/stock_weapon.tscn")
|
||||
var weapon_cooldown = Timer
|
||||
var weapon_rate: float = 0.1
|
||||
var weapon_timer: float = 0.0
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
@onready var muzzle_damage = %MuzzleBox
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
ship_displacement = position.y - previous_position.y
|
||||
travel += bullet_speed * delta + abs(ship_displacement)
|
||||
travel = clamp(travel, 0, 1.9 * weapon_spacing)
|
||||
func _process(delta) -> void:
|
||||
|
||||
# Sprite feedback based one player input
|
||||
if input.x > 0:
|
||||
%Ship/Thrusters.position.x = $Ship.position.x+1
|
||||
%Ship.frame = 2
|
||||
%Ship/Thrusters.flip_h = true
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
elif input.x < 0:
|
||||
%Ship/Thrusters.position.x = $Ship.position.x-1
|
||||
%Ship.frame = 1
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
else:
|
||||
%Ship.frame = 0
|
||||
%Ship/Thrusters.position.x = $Ship.position.x
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "fwd"
|
||||
# Read Controls
|
||||
input_component.update()
|
||||
|
||||
# Get previous positon for equidistant bullet calculation
|
||||
previous_position = position
|
||||
|
||||
# Move the ship based on input within the screen bounds
|
||||
position += input * speed * delta
|
||||
position = position.clamp(Vector2(12,12), screensize - Vector2(12,12))
|
||||
|
||||
# Enable muzzle damage hitbox upon firing
|
||||
if Input.is_action_pressed("shoot"):
|
||||
# Read Shooting
|
||||
if input_component.shooting:
|
||||
is_shooting = true
|
||||
muzzle_damage.set("disabled", false)
|
||||
|
||||
else:
|
||||
is_shooting = false
|
||||
else: is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
%MuzzleFlash.show()
|
||||
%Ship/MuzzleFlash.animation = "stock"
|
||||
|
||||
# Adjust bullet spacing before firing
|
||||
if travel > weapon_spacing:
|
||||
shoot()
|
||||
travel -= weapon_spacing
|
||||
|
||||
if is_shooting == false:
|
||||
%MuzzleFlash.hide()
|
||||
muzzle_damage.set("disabled", true)
|
||||
|
||||
func shield_set(_value: int):
|
||||
return
|
||||
|
||||
|
||||
func _on_weapon_cooldown_timeout() -> void:
|
||||
#print("You can shoot again!")
|
||||
#can_shoot = true
|
||||
return
|
||||
|
||||
|
||||
func shoot():
|
||||
var projectiles: int = 3
|
||||
const PROJECTILE_SPACING: float = 10
|
||||
const MUZZLE_HEIGHT: int = -23
|
||||
for b in projectiles:
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_current.instantiate()
|
||||
get_tree().root.add_child(bullet)
|
||||
bullet.position = position + Vector2((b - (projectiles - 1) / 2.0) * PROJECTILE_SPACING, MUZZLE_HEIGHT)
|
||||
|
||||
# Get weapon speed and spacing for equidistant calculations
|
||||
weapon_rate = bullet.shot_data.rate
|
||||
weapon_spacing = bullet.shot_data.projectile_spacing
|
||||
bullet_speed = bullet.shot_data.speed
|
||||
|
||||
# Print which weapon is firing
|
||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
|
||||
shoot_component.shoot()
|
||||
|
||||
# Read Movement Component
|
||||
movement_component.input = input_component.move_dir
|
||||
movement_component.tick(delta)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
uid://otm88638j7f8
|
||||
uid://dulfr27gg4evl
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene format=3 uid="uid://6wq3ynesnsha"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dulfr27gg4evl" path="res://scenes/player_component.gd" id="1_ur7pv"]
|
||||
[ext_resource type="Script" uid="uid://dulfr27gg4evl" path="res://scenes/player.gd" id="1_ur7pv"]
|
||||
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="2_qhqgy"]
|
||||
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="4_dqkch"]
|
||||
[ext_resource type="Script" uid="uid://dss0dbwr71y6m" path="res://scripts/input_component.gd" id="4_smehm"]
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
[ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="5_ur7pv"]
|
||||
[ext_resource type="Script" uid="uid://bgd1hwindc2ui" path="res://scripts/shoot_component.gd" id="6_y4r1p"]
|
||||
[ext_resource type="Script" uid="uid://ylmao2ndp22y" path="res://scripts/weapon_component.gd" id="7_d2wvv"]
|
||||
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/stock_weapon.tscn" id="8_3v2ag"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
||||
atlas = ExtResource("5_qlg0r")
|
||||
|
|
@ -89,24 +88,22 @@ size = Vector2(24, 30)
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dqkch"]
|
||||
size = Vector2(6, 5.75)
|
||||
|
||||
[node name="PlayerComponent" type="Node" unique_id=1732759225]
|
||||
|
||||
[node name="Player" type="Area2D" parent="." unique_id=652131079]
|
||||
[node name="Player" type="Area2D" unique_id=652131079]
|
||||
script = ExtResource("1_ur7pv")
|
||||
|
||||
[node name="Ship" type="Sprite2D" parent="Player" unique_id=1155866924]
|
||||
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
|
||||
unique_name_in_owner = true
|
||||
texture = ExtResource("2_qhqgy")
|
||||
hframes = 3
|
||||
region_rect = Rect2(0, 0, 62, 24.370766)
|
||||
|
||||
[node name="Thrusters" type="AnimatedSprite2D" parent="Player/Ship" unique_id=2096876587]
|
||||
[node name="Thrusters" type="AnimatedSprite2D" parent="Ship" unique_id=2096876587]
|
||||
position = Vector2(0, 15)
|
||||
sprite_frames = SubResource("SpriteFrames_y4r1p")
|
||||
animation = &"fwd"
|
||||
autoplay = "fwd"
|
||||
|
||||
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Player/Ship" unique_id=1584132038]
|
||||
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
position = Vector2(0.5, -16)
|
||||
|
|
@ -114,33 +111,34 @@ sprite_frames = SubResource("SpriteFrames_3v2ag")
|
|||
animation = &"stock"
|
||||
autoplay = "stock"
|
||||
|
||||
[node name="MuzzleBox" type="CollisionShape2D" parent="Player" unique_id=1042837273]
|
||||
[node name="MuzzleBox" type="CollisionShape2D" parent="." unique_id=1042837273]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(0, -17)
|
||||
shape = SubResource("RectangleShape2D_qlg0r")
|
||||
disabled = true
|
||||
debug_color = Color(1, 0.5058824, 0.21960784, 0.41960785)
|
||||
|
||||
[node name="HelpBox" type="CollisionShape2D" parent="Player" unique_id=938667427]
|
||||
[node name="HelpBox" type="CollisionShape2D" parent="." unique_id=938667427]
|
||||
position = Vector2(0, 3)
|
||||
shape = SubResource("RectangleShape2D_tuyoq")
|
||||
debug_color = Color(0, 1, 0, 0.41960785)
|
||||
|
||||
[node name="HitBox" type="CollisionShape2D" parent="Player" unique_id=485826453]
|
||||
[node name="HitBox" type="CollisionShape2D" parent="." unique_id=485826453]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("RectangleShape2D_dqkch")
|
||||
debug_color = Color(0.9843137, 0, 0, 0.80784315)
|
||||
|
||||
[node name="WeaponCooldown" type="Timer" parent="Player" unique_id=269678170]
|
||||
[node name="WeaponCooldown" type="Timer" parent="." unique_id=269678170]
|
||||
|
||||
[node name="InputComponent" type="Node" parent="." unique_id=2022056363]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("4_smehm")
|
||||
metadata/_custom_type_script = "uid://dss0dbwr71y6m"
|
||||
|
||||
[node name="MovementComponent" type="Node" parent="." unique_id=964075256]
|
||||
[node name="MovementComponent" type="Node" parent="." unique_id=964075256 node_paths=PackedStringArray("player")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("5_ur7pv")
|
||||
player = NodePath("..")
|
||||
speed = 200.0
|
||||
metadata/_custom_type_script = "uid://c0rikbakpcags"
|
||||
|
||||
|
|
@ -152,7 +150,6 @@ metadata/_custom_type_script = "uid://bgd1hwindc2ui"
|
|||
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("7_d2wvv")
|
||||
weapon_current = ExtResource("8_3v2ag")
|
||||
metadata/_custom_type_script = "uid://ylmao2ndp22y"
|
||||
|
||||
[connection signal="timeout" from="Player/WeaponCooldown" to="Player" method="_on_weapon_cooldown_timeout"]
|
||||
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
class_name Player extends Node
|
||||
|
||||
# Components managed by Player
|
||||
@onready var input_component: InputComponent = %InputComponent
|
||||
@onready var movement_component: MovementComponent = %MovementComponent
|
||||
@onready var shoot_component: ShootComponent = %ShootComponent
|
||||
@onready var weapon_component: WeaponComponent = %WeaponComponent
|
||||
|
||||
# Variables for Player shooting status
|
||||
@export var can_shoot: bool = true
|
||||
@export var is_shooting: bool = false
|
||||
|
||||
# Variables for Player position calculations for equidistant bullets
|
||||
var previous_position: Vector2
|
||||
var ship_displacement: float
|
||||
var travel: float = 0
|
||||
|
||||
|
||||
func _process(delta) -> void:
|
||||
|
||||
# Read Controls
|
||||
input_component.update()
|
||||
|
||||
# Read Shooting
|
||||
if input_component.shooting:
|
||||
is_shooting = true
|
||||
else: is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
shoot_component.shoot()
|
||||
|
||||
# Read Movement Component
|
||||
movement_component.input = input_component.move_dir
|
||||
movement_component.tick(delta)
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://dulfr27gg4evl
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
@onready var bullet: PackedScene = load("res://scenes/stock_weapon.tscn")
|
||||
|
||||
@export var shot_data: WeaponShot
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
#Calculation position along Y axis
|
||||
position.y -= shot_data.speed * delta # Original Speed
|
||||
#position.y -= 330 * delta # non-shot_data testing
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
||||
queue_free()
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
[gd_scene format=3 uid="uid://ddpclu2vdy2ve"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d1rwqotmrag1r" path="res://scenes/stock_weapon.gd" id="1_hsma2"]
|
||||
[ext_resource type="Resource" uid="uid://cels8t3hqjtsu" path="res://resources/player_weapons/shot_stock.tres" id="2_mvdrj"]
|
||||
[ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="3_mvdrj"]
|
||||
[ext_resource type="Script" uid="uid://d1rwqotmrag1r" path="res://Deprecated/stock_weapon.gd" id="1_u1d5o"]
|
||||
[ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="2_5bykt"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
||||
size = Vector2(6, 14)
|
||||
|
||||
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
||||
script = ExtResource("1_hsma2")
|
||||
shot_data = ExtResource("2_mvdrj")
|
||||
script = ExtResource("1_u1d5o")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
||||
texture = ExtResource("3_mvdrj")
|
||||
texture = ExtResource("2_5bykt")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(7, 6, 4, 12)
|
||||
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
# Component types for the game's architecture
|
||||
# All components extend Node and are meant to be attached to parent objects
|
||||
|
||||
class_name compoents extends Node
|
||||
|
||||
var move_dir: Vector2 = Vector2.ZERO
|
||||
var shoot_pressed: bool = false
|
||||
var shooting: bool = false
|
||||
|
||||
|
||||
func update() -> void:
|
||||
move_dir = Input.get_vector("left", "right", "up", "down")
|
||||
shoot_pressed = Input.is_action_just_pressed("shoot")
|
||||
shooting = Input.is_action_pressed("shoot")
|
||||
|
||||
|
||||
class_name MovementComponent extends Node
|
||||
|
||||
@export var player: Area2D
|
||||
@export var speed: float = 275
|
||||
@export var bounds_x: int = 12
|
||||
@export var bounds_y: int = 12
|
||||
|
||||
@onready var weapon_component: Node = %WeaponComponent
|
||||
|
||||
@onready var screensize = get_viewport().content_scale_size
|
||||
|
||||
var input = Input.get_vector("left", "right", "up", "down")
|
||||
|
||||
func tick(delta: float):
|
||||
# Check to see if there's a player to move
|
||||
if player == null: return
|
||||
|
||||
# Shorten variable for accessing weapon_component for clarity
|
||||
var weapon_system = weapon_component.data
|
||||
|
||||
# Calculate ship to bullet displacement
|
||||
player.ship_displacement = player.position.y - player.previous_position.y
|
||||
player.travel += abs(weapon_system.speed) * delta + (player.ship_displacement)
|
||||
player.travel = clamp(player.travel, 0, 1.9 * weapon_system.spacing)
|
||||
|
||||
# Thruster animation in relation to player movement
|
||||
if input.x > 0:
|
||||
player.position.x = player.position.x + 1
|
||||
%Ship.frame = 2
|
||||
%Ship/Thrusters.flip_h = true
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
elif input.x < 0:
|
||||
player.position.x = player.position.x - 1
|
||||
%Ship.frame = 1
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "banked"
|
||||
else:
|
||||
%Ship.frame = 0
|
||||
player.position.x = player.position.x
|
||||
%Ship/Thrusters.flip_h = false
|
||||
%Ship/Thrusters.animation = "fwd"
|
||||
|
||||
# Get previous position for equidistant bullet calculation
|
||||
player.previous_position = player.position
|
||||
|
||||
# Move player within screen bounds
|
||||
player.position += input * speed * delta
|
||||
player.position = player.position.clamp(Vector2i(bounds_x, bounds_y), screensize - Vector2i(bounds_x, bounds_y))
|
||||
|
||||
|
||||
class_name ShootComponent extends Node
|
||||
|
||||
@onready var weapon_component: Node = %WeaponComponent
|
||||
@onready var player: PlayerComponent = $".."
|
||||
|
||||
func shoot():
|
||||
|
||||
# Shorten variable for accessing weapon_component for clarity
|
||||
var weapon_system = weapon_component.data
|
||||
|
||||
if player.travel > weapon_system.spacing:
|
||||
|
||||
for b in range(weapon_system.projectiles):
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_component.weapon_current.instantiate()
|
||||
get_tree().root.add_child(bullet)
|
||||
# Adjust bullet spacing before firing
|
||||
|
||||
bullet.position = player.position + Vector2((b - (weapon_system.projectiles - 1) / 2.0) * round(round((weapon_system.projectiles + weapon_system.spacing / 2)) / 2), weapon_system.origin)
|
||||
print(b, bullet.position.x)
|
||||
|
||||
# Print which weapon is firing
|
||||
print(b, bullet.shot_data.shot_name, "weapon fired")
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next
|
||||
player.travel -= weapon_system.spacing
|
||||
|
||||
else: return
|
||||
|
||||
|
||||
class_name PlayerComponent extends Area2D
|
||||
|
||||
# Components managed by Player
|
||||
@onready var input_component: InputComponent = $InputComponent
|
||||
@onready var movement_component: MovementComponent = $MovementComponent
|
||||
@onready var shoot_component: ShootComponent = $ShootComponent
|
||||
@onready var weapon_component: WeaponComponent = $WeaponComponent
|
||||
|
||||
# Variables for Player shooting status
|
||||
@export var can_shoot: bool = true
|
||||
@export var is_shooting: bool = false
|
||||
|
||||
# Variables for Player position calculations for equidistant bullets
|
||||
var previous_position: Vector2
|
||||
var ship_displacement: float
|
||||
var travel: float = 0
|
||||
|
||||
|
||||
func _process(delta) -> void:
|
||||
|
||||
# Read Controls
|
||||
input_component.update()
|
||||
|
||||
# Read Shooting
|
||||
if input_component.shooting:
|
||||
is_shooting = true
|
||||
else: is_shooting = false
|
||||
|
||||
if is_shooting == true:
|
||||
shoot_component.shoot()
|
||||
|
||||
# Read Movement Component
|
||||
movement_component.input = input_component.move_dir
|
||||
movement_component.tick(delta)
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://imu0upeiufxn
|
||||
|
|
@ -1,19 +1,17 @@
|
|||
class_name MovementComponent extends Node
|
||||
|
||||
|
||||
@export var player: Area2D
|
||||
@export var speed: float = 275
|
||||
@export var bounds_x: int = 12
|
||||
@export var bounds_y: int = 12
|
||||
|
||||
@onready var weapon_component: Node = %WeaponComponent
|
||||
@onready var player = $"../Player"
|
||||
|
||||
@onready var screensize = get_viewport().content_scale_size
|
||||
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
|
||||
func tick(delta: float):
|
||||
prints(tick)
|
||||
|
||||
# Check to see if there's a player to move
|
||||
if player == null: return
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
class_name PlayerShot
|
||||
extends Resource
|
||||
|
||||
@export_category("Info")
|
||||
@export var shot_name: String
|
||||
@export var sprite: Texture2D = preload("res://graphics/shot.png")
|
||||
|
||||
@export_category("Shot Data")
|
||||
@export var damage: int = 1
|
||||
@export var speed: int = 135
|
||||
@export var projectiles: int = 2
|
||||
@export var spacing: float = 35
|
||||
@export var origin: int = -23
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://ccdohs4gduee5
|
||||
|
|
@ -1,31 +1,32 @@
|
|||
class_name ShootComponent extends Node
|
||||
|
||||
@onready var weapon_component: Node = %WeaponComponent
|
||||
@onready var player = $"../Player"
|
||||
@onready var player = $".."
|
||||
|
||||
|
||||
# Change from instantiating WeaponComponent to instantiating Shot nodes
|
||||
func shoot():
|
||||
var weapon_data = weapon_component.data # WeaponShot resource configuration
|
||||
|
||||
# Shorten variable for accessing weapon_component for clarity
|
||||
var weapon_system = weapon_component.data
|
||||
if player.travel > weapon_data.spacing:
|
||||
for b in range(weapon_data.projectiles):
|
||||
|
||||
if player.travel > weapon_system.spacing:
|
||||
# Get the Shot scene from the WeaponShot resource
|
||||
var bullet_scene = weapon_data.bullet_scene # Or however you store it
|
||||
|
||||
for b in range(weapon_system.projectiles):
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_component.weapon_current.instantiate()
|
||||
# Instantiate the bullet based data
|
||||
var bullet := bullet_scene.instantiate() as Node
|
||||
get_tree().root.add_child(bullet)
|
||||
|
||||
# Set up the bullet from resource data
|
||||
#bullet.shot_data = weapon_data # Pass the configuration
|
||||
|
||||
# Adjust bullet spacing before firing
|
||||
|
||||
bullet.position = player.position + Vector2((b - (weapon_system.projectiles - 1) / 2.0) * round(round((weapon_system.projectiles + weapon_system.spacing / 2)) / 2), weapon_system.origin)
|
||||
bullet.position = player.position + Vector2((b - (weapon_data.projectiles - 1) / 2.0) * round(round((weapon_data.projectiles + weapon_data.spacing / 2)) / 2 - 2), weapon_data.origin)
|
||||
print(b, bullet.position.x)
|
||||
|
||||
# Print which weapon is firing
|
||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
print(weapon_data.shot_name + " "+"fired!")
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next
|
||||
player.travel -= weapon_system.spacing
|
||||
player.travel -= weapon_data.spacing
|
||||
|
||||
else: return
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
class_name WeaponComponent extends Node
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
var data : PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
#@export var projectile_origin: int = -23
|
||||
@export var loaded_weapon: PackedScene = load("res://scenes/weapon_stock.tscn")
|
||||
var data : WeaponShot = load("res://resources/player_weapons/weapon_shot_stock.tres")
|
||||
|
||||
#@export_category("Temp Bullet Data")
|
||||
#@export var projectiles: int = 3
|
||||
#@export var projectile_spacing: float = 10
|
||||
|
||||
#var damage: int = 0
|
||||
#var speed: int = 135
|
||||
#var projectiles: int = 2
|
||||
#var rate: float = 0.1
|
||||
#var cooldown: float = 0.25
|
||||
#var projectile_spacing: float = 10
|
||||
|
||||
func get_bullet_scene() -> PackedScene:
|
||||
return data.weapon_shot # Reference to the Shot scene from the resource
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
class_name WeaponComponent extends Node
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
var data: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
#@export var projectile_origin: int = -23
|
||||
|
||||
#@export_category("Temp Bullet Data")
|
||||
#@export var projectiles: int = 3
|
||||
#@export var projectile_spacing: float = 10
|
||||
|
||||
#var damage: int = 0
|
||||
#var speed: int = 135
|
||||
#var projectiles: int = 2
|
||||
#var rate: float = 0.1
|
||||
#var cooldown: float = 0.25
|
||||
#var projectile_spacing: float = 10
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://cy50u6ksjqvjc
|
||||
Loading…
Add table
Add a link
Reference in a new issue