Compare commits
8 commits
e3fb082139
...
dd9eaf6ec6
| Author | SHA1 | Date | |
|---|---|---|---|
| dd9eaf6ec6 | |||
| 1bce6ca268 | |||
| c91f8ab31d | |||
| 48a2ba3ddb | |||
| 936bcbc5e3 | |||
| 1725b8b754 | |||
| bdbc3b015f | |||
| 79122a074e |
37 changed files with 425 additions and 340 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,29 +1,24 @@
|
||||||
[gd_scene format=3 uid="uid://6wq3ynesnsha"]
|
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dulfr27gg4evl" path="res://scripts/player_component.gd" id="1_3ef36"]
|
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://Deprecated/player_refactor.gd" id="1_qlg0r"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/stock_weapon.tscn" id="2_l5qtw"]
|
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="2_qhqgy"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="3_63g5k"]
|
[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_14jeh"]
|
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="4_tg2o1"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="5_ohfsq"]
|
|
||||||
[ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="6_l5qtw"]
|
|
||||||
[ext_resource type="Script" uid="uid://bgd1hwindc2ui" path="res://scripts/shoot_component.gd" id="7_63g5k"]
|
|
||||||
[ext_resource type="Script" uid="uid://ylmao2ndp22y" path="res://scripts/weapon_component.gd" id="8_ohfsq"]
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
||||||
atlas = ExtResource("4_tg2o1")
|
atlas = ExtResource("5_qlg0r")
|
||||||
region = Rect2(28, 0, 14, 6)
|
region = Rect2(28, 0, 14, 6)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
|
||||||
atlas = ExtResource("4_tg2o1")
|
atlas = ExtResource("5_qlg0r")
|
||||||
region = Rect2(42, 0, 14, 6)
|
region = Rect2(42, 0, 14, 6)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
|
||||||
atlas = ExtResource("4_tg2o1")
|
atlas = ExtResource("5_qlg0r")
|
||||||
region = Rect2(1, 0, 14, 6)
|
region = Rect2(1, 0, 14, 6)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
|
||||||
atlas = ExtResource("4_tg2o1")
|
atlas = ExtResource("5_qlg0r")
|
||||||
region = Rect2(15, 0, 14, 6)
|
region = Rect2(15, 0, 14, 6)
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_y4r1p"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_y4r1p"]
|
||||||
|
|
@ -52,15 +47,15 @@ animations = [{
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
|
||||||
atlas = ExtResource("5_ohfsq")
|
atlas = ExtResource("4_dqkch")
|
||||||
region = Rect2(0, 0, 15, 8)
|
region = Rect2(0, 0, 15, 8)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
|
||||||
atlas = ExtResource("5_ohfsq")
|
atlas = ExtResource("4_dqkch")
|
||||||
region = Rect2(15, 0, 15, 8)
|
region = Rect2(15, 0, 15, 8)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
|
||||||
atlas = ExtResource("5_ohfsq")
|
atlas = ExtResource("4_dqkch")
|
||||||
region = Rect2(30, 0, 15, 8)
|
region = Rect2(30, 0, 15, 8)
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_3v2ag"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_3v2ag"]
|
||||||
|
|
@ -90,11 +85,11 @@ size = Vector2(24, 30)
|
||||||
size = Vector2(6, 5.75)
|
size = Vector2(6, 5.75)
|
||||||
|
|
||||||
[node name="Player" type="Area2D" unique_id=652131079]
|
[node name="Player" type="Area2D" unique_id=652131079]
|
||||||
script = ExtResource("1_3ef36")
|
script = ExtResource("1_qlg0r")
|
||||||
|
|
||||||
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
|
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
texture = ExtResource("3_63g5k")
|
texture = ExtResource("2_qhqgy")
|
||||||
hframes = 3
|
hframes = 3
|
||||||
region_rect = Rect2(0, 0, 62, 24.370766)
|
region_rect = Rect2(0, 0, 62, 24.370766)
|
||||||
|
|
||||||
|
|
@ -106,7 +101,6 @@ autoplay = "fwd"
|
||||||
|
|
||||||
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
|
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
visible = false
|
|
||||||
position = Vector2(0.5, -16)
|
position = Vector2(0.5, -16)
|
||||||
sprite_frames = SubResource("SpriteFrames_3v2ag")
|
sprite_frames = SubResource("SpriteFrames_3v2ag")
|
||||||
animation = &"stock"
|
animation = &"stock"
|
||||||
|
|
@ -131,27 +125,4 @@ debug_color = Color(0.9843137, 0, 0, 0.80784315)
|
||||||
|
|
||||||
[node name="WeaponCooldown" type="Timer" parent="." 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_14jeh")
|
|
||||||
metadata/_custom_type_script = "uid://dss0dbwr71y6m"
|
|
||||||
|
|
||||||
[node name="MovementComponent" type="Node" parent="." unique_id=964075256 node_paths=PackedStringArray("player")]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
script = ExtResource("6_l5qtw")
|
|
||||||
player = NodePath("..")
|
|
||||||
speed = 200.0
|
|
||||||
metadata/_custom_type_script = "uid://c0rikbakpcags"
|
|
||||||
|
|
||||||
[node name="ShootComponent" type="Node" parent="." unique_id=623642425]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
script = ExtResource("7_63g5k")
|
|
||||||
metadata/_custom_type_script = "uid://bgd1hwindc2ui"
|
|
||||||
|
|
||||||
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
script = ExtResource("8_ohfsq")
|
|
||||||
weapon_current = ExtResource("2_l5qtw")
|
|
||||||
metadata/_custom_type_script = "uid://ylmao2ndp22y"
|
|
||||||
|
|
||||||
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
||||||
|
|
@ -13,7 +13,7 @@ var travel: float = 0
|
||||||
var bullet_speed: int = 150
|
var bullet_speed: int = 150
|
||||||
var weapon_spacing: float = 0.1
|
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_current = load("res://scenes/stock_weapon.tscn")
|
||||||
#var weapon_cooldown = Timer
|
#var weapon_cooldown = Timer
|
||||||
|
|
@ -101,7 +101,7 @@ func shoot():
|
||||||
# Instantiate the bullets
|
# Instantiate the bullets
|
||||||
var bullet = weapon_current.instantiate()
|
var bullet = weapon_current.instantiate()
|
||||||
get_tree().root.add_child(bullet)
|
get_tree().root.add_child(bullet)
|
||||||
prints(bullet_resource.speed,bullet_resource.projectiles, bullet_resource.projectile_spacing)
|
#prints(bullet.speed,bullet.projectiles, bullet.projectile_spacing)
|
||||||
bullet.position = position + Vector2((b - (projectiles- 1) / 2.0) * PROJECTILE_SPACING /2, MUZZLE_HEIGHT)
|
bullet.position = position + Vector2((b - (projectiles- 1) / 2.0) * PROJECTILE_SPACING /2, MUZZLE_HEIGHT)
|
||||||
|
|
||||||
# Get weapon speed and spacing for equidistant calculations
|
# Get weapon speed and spacing for equidistant calculations
|
||||||
|
|
@ -110,6 +110,6 @@ func shoot():
|
||||||
#bullet_speed = bullet_resource.speed
|
#bullet_speed = bullet_resource.speed
|
||||||
|
|
||||||
# Print which weapon is firing
|
# Print which weapon is firing
|
||||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
#prints(bullet.shot_data.shot_name, "weapon fired")
|
||||||
#travel -= weapon_spacing
|
#travel -= weapon_spacing
|
||||||
|
|
||||||
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,23 +1,13 @@
|
||||||
[gd_scene format=3 uid="uid://b2ltmeb14nc17"]
|
[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://d1rwqotmrag1r" path="res://Deprecated/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="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="3_58qml"]
|
[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
|
|
||||||
projectile_spacing = 10.0
|
|
||||||
metadata/_custom_type_script = "uid://ccdohs4gduee5"
|
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
||||||
size = Vector2(12, 8)
|
size = Vector2(12, 8)
|
||||||
|
|
||||||
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
||||||
script = ExtResource("1_kx6bj")
|
script = ExtResource("1_kx6bj")
|
||||||
shot_data = SubResource("Resource_4ihvg")
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
||||||
texture = ExtResource("3_58qml")
|
texture = ExtResource("3_58qml")
|
||||||
BIN
graphics/shot_stock.png
Normal file
BIN
graphics/shot_stock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 297 B |
40
graphics/shot_stock.png.import
Normal file
40
graphics/shot_stock.png.import
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dolmy8bnc8kkt"
|
||||||
|
path="res://.godot/imported/shot_stock.png-7b8166fc7d450fe427fb3181154c3018.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://graphics/shot_stock.png"
|
||||||
|
dest_files=["res://.godot/imported/shot_stock.png-7b8166fc7d450fe427fb3181154c3018.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
|
@ -11,7 +11,7 @@ config_version=5
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Facsimile Wing"
|
config/name="Facsimile Wing"
|
||||||
run/main_scene="uid://coix5dqblmu7r"
|
run/main_scene="uid://bj4fytc3sy482"
|
||||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,9 +1,9 @@
|
||||||
class_name PlayerShot
|
class_name WeaponShot
|
||||||
extends Resource
|
extends Resource
|
||||||
|
|
||||||
@export_category("Info")
|
@export_category("Info")
|
||||||
@export var shot_name: String
|
@export var shot_name: String
|
||||||
@export var sprite: Texture2D = preload("res://graphics/shot.png")
|
@export var bullet_scene: PackedScene = null
|
||||||
|
|
||||||
@export_category("Shot Data")
|
@export_category("Shot Data")
|
||||||
@export var damage: int = 1
|
@export var damage: int = 1
|
||||||
|
|
@ -11,3 +11,7 @@ extends Resource
|
||||||
@export var projectiles: int = 2
|
@export var projectiles: int = 2
|
||||||
@export var spacing: float = 35
|
@export var spacing: float = 35
|
||||||
@export var origin: int = -23
|
@export var origin: int = -23
|
||||||
|
|
||||||
|
@export_category("Stagger")
|
||||||
|
@export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles
|
||||||
|
@export var stagger_offset: float = 5 # Time delay per projectile index
|
||||||
16
resources/player_weapons/weapon_shot_stock.tres
Normal file
16
resources/player_weapons/weapon_shot_stock.tres
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[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 = 500
|
||||||
|
projectiles = 3
|
||||||
|
spacing = 25.0
|
||||||
|
origin = -12
|
||||||
|
horizontal_offset = 8.0
|
||||||
|
stagger_offset = 0.35
|
||||||
|
metadata/_custom_type_script = "uid://7n1itonn35fm"
|
||||||
3
scenes/game.gd
Normal file
3
scenes/game.gd
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
@onready var screensize = get_viewport().content_scale_size
|
||||||
1
scenes/game.gd.uid
Normal file
1
scenes/game.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dkti4uwycpqrs
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
[gd_scene format=3 uid="uid://dqd8cxe7aj3b4"]
|
[gd_scene format=3 uid="uid://dqd8cxe7aj3b4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dkti4uwycpqrs" path="res://scenes/game.gd" id="1_lnu2h"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bj4fytc3sy482" path="res://scenes/world.tscn" id="1_uwrxv"]
|
[ext_resource type="PackedScene" uid="uid://bj4fytc3sy482" path="res://scenes/world.tscn" id="1_uwrxv"]
|
||||||
[ext_resource type="Texture2D" uid="uid://egqbrm636m4h" path="res://graphics/title.png" id="2_yqjtg"]
|
[ext_resource type="Texture2D" uid="uid://egqbrm636m4h" path="res://graphics/title.png" id="2_yqjtg"]
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=1673976895]
|
[node name="Game" type="Node2D" unique_id=1673976895]
|
||||||
|
script = ExtResource("1_lnu2h")
|
||||||
|
|
||||||
[node name="World" parent="." unique_id=1317852169 instance=ExtResource("1_uwrxv")]
|
[node name="World" parent="." unique_id=1317852169 instance=ExtResource("1_uwrxv")]
|
||||||
|
|
||||||
|
|
|
||||||
124
scenes/player.gd
124
scenes/player.gd
|
|
@ -1,108 +1,48 @@
|
||||||
extends Area2D
|
class_name Player extends Area2D
|
||||||
|
|
||||||
@export var speed: int = 150
|
# Components managed by Player
|
||||||
@export var shield_max: int = 10
|
@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
|
# Get the viewport size for positioning
|
||||||
|
@onready var screensize = get_viewport().content_scale_size
|
||||||
|
|
||||||
var shield: int = 0: set = shield_set
|
# Variables for Player shooting status
|
||||||
var can_shoot: bool = true
|
@export var can_shoot: bool = true
|
||||||
var is_shooting: bool = false
|
@export var is_shooting: bool = false
|
||||||
|
@export var muzzle_flash: bool = false
|
||||||
|
|
||||||
|
# Variables for Player position calculations for equidistant bullets
|
||||||
var previous_position: Vector2
|
var previous_position: Vector2
|
||||||
var ship_displacement: float
|
var ship_displacement: float
|
||||||
var travel: float = 0
|
var travel: float = 0
|
||||||
var bullet_speed: int = 150
|
|
||||||
|
|
||||||
@export var weapon_current : PackedScene
|
func _ready() -> void:
|
||||||
|
|
||||||
|
## Set initial start position
|
||||||
|
position = Vector2(screensize.x / 2, screensize.y - 45)
|
||||||
|
|
||||||
#var weapon_current = load("res://scenes/stock_weapon.tscn")
|
func _process(delta) -> void:
|
||||||
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
|
|
||||||
|
|
||||||
|
# Read Controls
|
||||||
func _process(delta):
|
input_component.update()
|
||||||
var input = Input.get_vector("left", "right", "up","down")
|
|
||||||
ship_displacement = position.y - previous_position.y
|
# Read Shooting
|
||||||
travel += bullet_speed * delta + abs(ship_displacement)
|
if input_component.shooting:
|
||||||
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
|
is_shooting = true
|
||||||
muzzle_damage.set("disabled", false)
|
else: is_shooting = false
|
||||||
|
|
||||||
else:
|
|
||||||
is_shooting = false
|
|
||||||
|
|
||||||
if is_shooting == true:
|
if is_shooting == true:
|
||||||
%MuzzleFlash.show()
|
shoot_component.shoot()
|
||||||
%Ship/MuzzleFlash.animation = "stock"
|
$%MuzzleFlash.show()
|
||||||
|
|
||||||
# Adjust bullet spacing before firing
|
|
||||||
if travel > weapon_spacing:
|
|
||||||
shoot()
|
|
||||||
travel -= weapon_spacing
|
|
||||||
|
|
||||||
if is_shooting == false:
|
if is_shooting == false:
|
||||||
%MuzzleFlash.hide()
|
$%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")
|
# Read Movement Component
|
||||||
|
movement_component.input = input_component.move_dir
|
||||||
|
movement_component.tick(delta)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
uid://otm88638j7f8
|
uid://dulfr27gg4evl
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
|
[gd_scene format=3 uid="uid://6wq3ynesnsha"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://scenes/player_refactor.gd" id="1_qlg0r"]
|
[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://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://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"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
|
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
|
||||||
|
[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"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
||||||
atlas = ExtResource("5_qlg0r")
|
atlas = ExtResource("5_qlg0r")
|
||||||
|
|
@ -85,7 +89,10 @@ size = Vector2(24, 30)
|
||||||
size = Vector2(6, 5.75)
|
size = Vector2(6, 5.75)
|
||||||
|
|
||||||
[node name="Player" type="Area2D" unique_id=652131079]
|
[node name="Player" type="Area2D" unique_id=652131079]
|
||||||
script = ExtResource("1_qlg0r")
|
script = ExtResource("1_ur7pv")
|
||||||
|
can_shoot = null
|
||||||
|
is_shooting = null
|
||||||
|
muzzle_flash = null
|
||||||
|
|
||||||
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
|
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
@ -105,6 +112,7 @@ position = Vector2(0.5, -16)
|
||||||
sprite_frames = SubResource("SpriteFrames_3v2ag")
|
sprite_frames = SubResource("SpriteFrames_3v2ag")
|
||||||
animation = &"stock"
|
animation = &"stock"
|
||||||
autoplay = "stock"
|
autoplay = "stock"
|
||||||
|
speed_scale = 1.75
|
||||||
|
|
||||||
[node name="MuzzleBox" type="CollisionShape2D" parent="." unique_id=1042837273]
|
[node name="MuzzleBox" type="CollisionShape2D" parent="." unique_id=1042837273]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
@ -125,4 +133,26 @@ debug_color = Color(0.9843137, 0, 0, 0.80784315)
|
||||||
|
|
||||||
[node name="WeaponCooldown" type="Timer" parent="." 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_paths=PackedStringArray("player")]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("5_ur7pv")
|
||||||
|
player = NodePath("..")
|
||||||
|
speed = 200.0
|
||||||
|
metadata/_custom_type_script = "uid://c0rikbakpcags"
|
||||||
|
|
||||||
|
[node name="ShootComponent" type="Node" parent="." unique_id=623642425]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("6_y4r1p")
|
||||||
|
metadata/_custom_type_script = "uid://bgd1hwindc2ui"
|
||||||
|
|
||||||
|
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
script = ExtResource("7_d2wvv")
|
||||||
|
metadata/_custom_type_script = "uid://ylmao2ndp22y"
|
||||||
|
|
||||||
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
extends Area2D
|
|
||||||
|
|
||||||
@onready var bullet: PackedScene = load("res://scenes/stock_weapon.tscn")
|
|
||||||
|
|
||||||
@export var shot_data: PlayerShot
|
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
|
|
||||||
#Calculation position along Y axis
|
|
||||||
position.y -= shot_data.speed * delta
|
|
||||||
|
|
||||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
|
||||||
queue_free()
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
[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"]
|
|
||||||
|
|
||||||
[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")
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
|
||||||
texture = ExtResource("3_mvdrj")
|
|
||||||
region_enabled = true
|
|
||||||
region_rect = Rect2(7, 6, 4, 12)
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1890946059]
|
|
||||||
shape = SubResource("RectangleShape2D_mvdrj")
|
|
||||||
|
|
||||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=985862716]
|
|
||||||
rect = Rect2(-3, -7, 6, 14)
|
|
||||||
|
|
||||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
|
||||||
40
scenes/weapon_stock.gd
Normal file
40
scenes/weapon_stock.gd
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Time offset when this bullet was fired (relative to other bullets in the same shot)
|
||||||
|
var time_offset: float = 0.5
|
||||||
|
|
||||||
|
# When this bullet should fire (absolute time)
|
||||||
|
var fire_time: float = 0.0
|
||||||
|
|
||||||
|
# Track if this bullet is currently active in the shot
|
||||||
|
var is_active: bool = false
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
var current_time = Time.get_ticks_msec() / 1000.0
|
||||||
|
|
||||||
|
# Fire if it's time and bullet isn't already active
|
||||||
|
if !is_active and current_time >= fire_time:
|
||||||
|
activate()
|
||||||
|
|
||||||
|
# Move the bullet
|
||||||
|
position.y -= shot_data.speed * delta
|
||||||
|
|
||||||
|
func activate():
|
||||||
|
is_active = true
|
||||||
|
visible = true
|
||||||
|
|
||||||
|
# # Emit signal for hit detection
|
||||||
|
# emit_signal("activate")
|
||||||
|
|
||||||
|
func _on_visible_on_screen_notifier_2d_screen_exited():
|
||||||
|
queue_free()
|
||||||
|
|
||||||
|
# Set fire_time for the next shot (staggered firing)
|
||||||
|
var current_time = Time.get_ticks_msec() / 1000.0
|
||||||
|
fire_time = current_time + shot_data.stagger_offset
|
||||||
1
scenes/weapon_stock.gd.uid
Normal file
1
scenes/weapon_stock.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://c5blhfopjpfny
|
||||||
53
scenes/weapon_stock.tscn
Normal file
53
scenes/weapon_stock.tscn
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
[gd_scene format=3 uid="uid://ddpclu2vdy2ve"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://c5blhfopjpfny" path="res://scenes/weapon_stock.gd" id="1_u1d5o"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bnpm8b62n1pr5" path="res://graphics/shot_stock_og.png" id="2_u1d5o"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_5bykt"]
|
||||||
|
atlas = ExtResource("2_u1d5o")
|
||||||
|
region = Rect2(0, 0, 7, 11)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_vsqoq"]
|
||||||
|
atlas = ExtResource("2_u1d5o")
|
||||||
|
region = Rect2(7, 0, 7, 11)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_yqx5m"]
|
||||||
|
atlas = ExtResource("2_u1d5o")
|
||||||
|
region = Rect2(14, 0, 7, 11)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_fdubj"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_5bykt")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_vsqoq")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_yqx5m")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"default",
|
||||||
|
"speed": 24.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
||||||
|
size = Vector2(6.666667, 14)
|
||||||
|
|
||||||
|
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
||||||
|
script = ExtResource("1_u1d5o")
|
||||||
|
|
||||||
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1831184252]
|
||||||
|
scale = Vector2(1.5, 1.5)
|
||||||
|
sprite_frames = SubResource("SpriteFrames_fdubj")
|
||||||
|
autoplay = "default"
|
||||||
|
frame_progress = 0.35886022
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1890946059]
|
||||||
|
shape = SubResource("RectangleShape2D_mvdrj")
|
||||||
|
|
||||||
|
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=985862716]
|
||||||
|
rect = Rect2(-3, -7, 6, 14)
|
||||||
|
|
||||||
|
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://14fhj8834pkq" path="res://scenes/ui.tscn" id="1_nnsk1"]
|
[ext_resource type="PackedScene" uid="uid://14fhj8834pkq" path="res://scenes/ui.tscn" id="1_nnsk1"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b3dqvd23nbmrm" path="res://graphics/cloud layers.png" id="3_4wyf3"]
|
[ext_resource type="Texture2D" uid="uid://b3dqvd23nbmrm" path="res://graphics/cloud layers.png" id="3_4wyf3"]
|
||||||
[ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player_revision.tscn" id="3_k0juu"]
|
[ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player.tscn" id="3_k0juu"]
|
||||||
|
|
||||||
[node name="World" type="Node2D" unique_id=1317852169]
|
[node name="World" type="Node2D" unique_id=1317852169]
|
||||||
|
|
||||||
|
|
@ -78,4 +78,3 @@ hframes = 4
|
||||||
frame = 3
|
frame = 3
|
||||||
|
|
||||||
[node name="Player" parent="Level" unique_id=652131079 instance=ExtResource("3_k0juu")]
|
[node name="Player" parent="Level" unique_id=652131079 instance=ExtResource("3_k0juu")]
|
||||||
position = Vector2(106, 312)
|
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,29 @@
|
||||||
class_name MovementComponent extends Node
|
class_name MovementComponent extends Node
|
||||||
|
|
||||||
|
|
||||||
@export var player: Area2D
|
@export var player: Area2D
|
||||||
@export var speed: float = 275
|
@export var speed: float = 275
|
||||||
@export var bounds_x: int = 12
|
@export var bounds_x: int = 12
|
||||||
@export var bounds_y: int = 12
|
@export var bounds_y: int = 12
|
||||||
|
|
||||||
@onready var weapon_component: WeaponComponent = %WeaponComponent
|
@onready var weapon_component: Node = %WeaponComponent
|
||||||
|
|
||||||
@onready var screensize = get_viewport().content_scale_size
|
@onready var screensize = get_viewport().content_scale_size
|
||||||
|
|
||||||
var input = Input.get_vector("left", "right", "up","down")
|
var input = Input.get_vector("left", "right", "up","down")
|
||||||
|
|
||||||
func tick(delta: float):
|
func tick(delta: float):
|
||||||
|
|
||||||
# Check to see if there's a player to move
|
# Check to see if there's a player to move
|
||||||
if player == null: return
|
if player == null: return
|
||||||
|
|
||||||
# Shorten variable for accessing weapon_component for clarity
|
# Shorten variable for accessing weapon_component for clarity
|
||||||
var weapon_system = weapon_component.data
|
var weapon_system = weapon_component.data
|
||||||
|
|
||||||
# Calculate ship to bullet displacement
|
# Calculate ship to bullet displacement
|
||||||
player.ship_displacement = player.position.y - player.previous_position.y
|
player.ship_displacement = player.position.y - player.previous_position.y
|
||||||
player.travel += abs(weapon_system.speed) * delta + (player.ship_displacement)
|
player.travel += abs(weapon_system.speed) * delta + (player.ship_displacement)
|
||||||
player.travel = clamp(player.travel, 0, 1.9 * weapon_system.spacing)
|
player.travel = clamp(player.travel, 0, 1.9 * weapon_system.spacing)
|
||||||
|
|
||||||
# Thruster animation in relation to player movement
|
# Thruster animation in relation to player movement
|
||||||
if input.x > 0:
|
if input.x > 0:
|
||||||
player.position.x = player.position.x+1
|
player.position.x = player.position.x+1
|
||||||
|
|
@ -39,10 +40,10 @@ func tick(delta: float):
|
||||||
player.position.x = player.position.x
|
player.position.x = player.position.x
|
||||||
%Ship/Thrusters.flip_h = false
|
%Ship/Thrusters.flip_h = false
|
||||||
%Ship/Thrusters.animation = "fwd"
|
%Ship/Thrusters.animation = "fwd"
|
||||||
|
|
||||||
# Get previous positon for equidistant bullet calculation
|
# Get previous positon for equidistant bullet calculation
|
||||||
player.previous_position = player.position
|
player.previous_position = player.position
|
||||||
|
|
||||||
# Move player within screenbounds
|
# Move player within screenbounds
|
||||||
player.position += input * speed * delta
|
player.position += input * speed * delta
|
||||||
player.position = player.position.clamp(Vector2i(bounds_x,bounds_y), screensize - Vector2i(bounds_x,bounds_y))
|
player.position = player.position.clamp(Vector2i(bounds_x,bounds_y), screensize - Vector2i(bounds_x,bounds_y))
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
class_name Player 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://dulfr27gg4evl
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
class_name PlayerShotResource
|
|
||||||
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,46 @@
|
||||||
class_name ShootComponent extends Node
|
class_name ShootComponent extends Node
|
||||||
|
|
||||||
|
@export var stagger_offset: float = 0.5 # Time delay per projectile index (seconds)
|
||||||
|
@export var horizontal_offset: float = 1.0 # Horizontal distance per projectile index
|
||||||
|
|
||||||
@onready var weapon_component: Node = %WeaponComponent
|
@onready var weapon_component: Node = %WeaponComponent
|
||||||
@onready var player: Player = $".."
|
@onready var player = $".."
|
||||||
|
|
||||||
func shoot():
|
func shoot():
|
||||||
|
var weapon_data = weapon_component.data # WeaponShot resource configuration
|
||||||
# Shorten variable for accessing weapon_component for clarity
|
var current_time = Time.get_ticks_msec() / 1000.0
|
||||||
var weapon_system = weapon_component.data
|
var total_projectiles = weapon_data.projectiles
|
||||||
|
|
||||||
if player.travel > weapon_system.spacing:
|
if player.travel > weapon_data.spacing:
|
||||||
|
|
||||||
for b in range(weapon_system.projectiles):
|
# Calculate center index for symmetrical staggering
|
||||||
|
var center_index = (total_projectiles - 1) / 2.0
|
||||||
# Instantiate the bullets
|
|
||||||
var bullet = weapon_component.weapon_current.instantiate()
|
if total_projectiles > 0:
|
||||||
get_tree().root.add_child(bullet)
|
for b in range(total_projectiles):
|
||||||
# Adjust bullet spacing before firing
|
var bullet_scene = weapon_data.bullet_scene
|
||||||
|
var bullet := bullet_scene.instantiate() as Node
|
||||||
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)
|
get_tree().root.add_child(bullet)
|
||||||
print(b, bullet.position.x)
|
|
||||||
|
# Calculate index relative to center (0 = center, -1/+1 = first from center)
|
||||||
# Print which weapon is firing
|
var index_from_center: float = b - center_index
|
||||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
|
||||||
|
# Calculate timing offset for staggered firing
|
||||||
# Subtract projectile spacing from current Player travel for next
|
var time_offset: float = index_from_center * stagger_offset
|
||||||
player.travel -= weapon_system.spacing
|
|
||||||
|
# Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve)
|
||||||
else: return
|
var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset
|
||||||
|
|
||||||
|
# Calculate vertical offset from center point (symmetrical vertical spread)
|
||||||
|
var distance_from_center: float = abs(index_from_center)
|
||||||
|
var vertical_offset: float = (distance_from_center * weapon_data.origin * -1) / 2
|
||||||
|
|
||||||
|
# Final position combines symmetrical horizontal spread with symmetrical vertical spacing
|
||||||
|
bullet.position = player.position + Vector2(bullet_horizontal_offset, weapon_data.origin + (vertical_offset + weapon_data.origin - total_projectiles))
|
||||||
|
|
||||||
|
# Set timing properties on the bullet
|
||||||
|
bullet.time_offset = time_offset
|
||||||
|
bullet.fire_time = current_time + time_offset
|
||||||
|
|
||||||
|
# Subtract projectile spacing from current Player travel for next shot
|
||||||
|
player.travel -= weapon_data.spacing
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,9 @@
|
||||||
class_name WeaponComponent extends Node
|
class_name WeaponComponent extends Node
|
||||||
|
|
||||||
@export var weapon_current : PackedScene
|
@export var loaded_weapon: PackedScene = load("res://scenes/weapon_stock.tscn")
|
||||||
var data: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
var data : WeaponShot = load("res://resources/player_weapons/weapon_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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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