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
|
||||
128
Deprecated/_player.tscn
Normal file
128
Deprecated/_player.tscn
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
|
||||
|
||||
[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"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
||||
atlas = ExtResource("5_qlg0r")
|
||||
region = Rect2(28, 0, 14, 6)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
|
||||
atlas = ExtResource("5_qlg0r")
|
||||
region = Rect2(42, 0, 14, 6)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
|
||||
atlas = ExtResource("5_qlg0r")
|
||||
region = Rect2(1, 0, 14, 6)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
|
||||
atlas = ExtResource("5_qlg0r")
|
||||
region = Rect2(15, 0, 14, 6)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_y4r1p"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_tuyoq")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fjrip")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"banked",
|
||||
"speed": 15.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_smehm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ur7pv")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fwd",
|
||||
"speed": 15.0
|
||||
}]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
|
||||
atlas = ExtResource("4_dqkch")
|
||||
region = Rect2(0, 0, 15, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
|
||||
atlas = ExtResource("4_dqkch")
|
||||
region = Rect2(15, 0, 15, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
|
||||
atlas = ExtResource("4_dqkch")
|
||||
region = Rect2(30, 0, 15, 8)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_3v2ag"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qlg0r")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_y4r1p")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_d2wvv")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"stock",
|
||||
"speed": 15.0
|
||||
}]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qlg0r"]
|
||||
size = Vector2(24, 10)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tuyoq"]
|
||||
size = Vector2(24, 30)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dqkch"]
|
||||
size = Vector2(6, 5.75)
|
||||
|
||||
[node name="Player" type="Area2D" unique_id=652131079]
|
||||
script = ExtResource("1_qlg0r")
|
||||
|
||||
[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="Ship" unique_id=2096876587]
|
||||
position = Vector2(0, 15)
|
||||
sprite_frames = SubResource("SpriteFrames_y4r1p")
|
||||
animation = &"fwd"
|
||||
autoplay = "fwd"
|
||||
|
||||
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(0.5, -16)
|
||||
sprite_frames = SubResource("SpriteFrames_3v2ag")
|
||||
animation = &"stock"
|
||||
autoplay = "stock"
|
||||
|
||||
[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="." 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="." 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="." unique_id=269678170]
|
||||
|
||||
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
|
||||
115
Deprecated/player_refactor.gd
Normal file
115
Deprecated/player_refactor.gd
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
extends Area2D
|
||||
|
||||
@export var speed: int = 150
|
||||
@export var shield_max: int = 10
|
||||
|
||||
|
||||
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
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@export var weapon_current : PackedScene = preload("res://scenes/weapon_stock.tscn")
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
@onready var muzzle_damage = %MuzzleBox
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
|
||||
# Calculate position and travel for equidistant bullet calculations
|
||||
ship_displacement = abs(position.y - previous_position.y)
|
||||
travel += bullet_speed * delta - 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:
|
||||
print("Travel is greater!")
|
||||
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 = 5
|
||||
const PROJECTILE_SPACING: float = 20
|
||||
const MUZZLE_HEIGHT: int = -23
|
||||
|
||||
var bullet_resource: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
|
||||
for b in range(projectiles):
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_current.instantiate()
|
||||
get_tree().root.add_child(bullet)
|
||||
#prints(bullet.speed,bullet.projectiles, bullet.projectile_spacing)
|
||||
bullet.position = position + Vector2((b - (projectiles- 1) / 2.0) * PROJECTILE_SPACING /2, MUZZLE_HEIGHT)
|
||||
|
||||
# Get weapon speed and spacing for equidistant calculations
|
||||
#weapon_rate = bullet.shot_data.rate
|
||||
weapon_spacing = PROJECTILE_SPACING
|
||||
#bullet_speed = bullet_resource.speed
|
||||
|
||||
# Print which weapon is firing
|
||||
#prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
#travel -= weapon_spacing
|
||||
|
||||
1
Deprecated/player_refactor.gd.uid
Normal file
1
Deprecated/player_refactor.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bqxrdf7mtx0ev
|
||||
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
Deprecated/stock_weapon.gd.uid
Normal file
1
Deprecated/stock_weapon.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d1rwqotmrag1r
|
||||
20
Deprecated/stock_weapon_single_old.tscn
Normal file
20
Deprecated/stock_weapon_single_old.tscn
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
[gd_scene format=3 uid="uid://b2ltmeb14nc17"]
|
||||
|
||||
[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="RectangleShape2D" id="RectangleShape2D_mvdrj"]
|
||||
size = Vector2(12, 8)
|
||||
|
||||
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
|
||||
script = ExtResource("1_kx6bj")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225]
|
||||
texture = ExtResource("3_58qml")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1890946059]
|
||||
shape = SubResource("RectangleShape2D_mvdrj")
|
||||
|
||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=985862716]
|
||||
|
||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue