Equidistent code working in component form! Also cleaned up spacing for
increased projectiles in stock weapon by rounding remainders from division.
This commit is contained in:
parent
d419635d7f
commit
db57a0234e
17 changed files with 58 additions and 48 deletions
|
|
@ -7,7 +7,6 @@ class_name MovementComponent extends Node
|
|||
|
||||
@onready var weapon_component: WeaponComponent = %WeaponComponent
|
||||
|
||||
|
||||
@onready var screensize = get_viewport().content_scale_size
|
||||
|
||||
var input = Input.get_vector("left", "right", "up","down")
|
||||
|
|
@ -16,10 +15,11 @@ func tick(delta: float):
|
|||
# Check to see if there's a player to move
|
||||
if player == null: return
|
||||
|
||||
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_component.bullet_data.speed) * delta + (player.ship_displacement)
|
||||
player.travel = clamp(player.travel, 0, 1.9 * weapon_component.bullet_data.projectile_spacing)
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
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 +0,0 @@
|
|||
uid://otm88638j7f8
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
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
|
||||
|
|
@ -18,14 +21,16 @@ func _process(delta) -> void:
|
|||
# Read Controls
|
||||
input_component.update()
|
||||
|
||||
# Read Movement Component
|
||||
movement_component.input = input_component.move_dir
|
||||
movement_component.tick(delta)
|
||||
|
||||
# Read shooting
|
||||
# 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,112 +0,0 @@
|
|||
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
|
||||
var weapon_spacing: float = 0.1
|
||||
|
||||
@export var weapon_current : PackedScene = preload("res://scenes/stock_weapon.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")
|
||||
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
|
||||
|
||||
var bullet_resource: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
|
||||
for b in range(bullet_resource.projectiles):
|
||||
|
||||
# Instantiate the bullets
|
||||
var bullet = weapon_current.instantiate()
|
||||
get_tree().root.add_child(bullet)
|
||||
bullet.position = position + Vector2((b - (bullet.shot_data.projectiles - 1) / 2.0) * bullet.shot_data.projectile_spacing / 2.0, bullet.shot_data.projectile_origin)
|
||||
|
||||
# Get weapon speed and spacing for equidistant calculations
|
||||
#weapon_rate = bullet.shot_data.rate
|
||||
weapon_spacing = bullet.shot_data.projectile_spacing
|
||||
bullet_speed = abs(bullet.shot_data.speed)
|
||||
|
||||
# Print which weapon is firing
|
||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://bqxrdf7mtx0ev
|
||||
|
|
@ -9,7 +9,7 @@ extends Resource
|
|||
@export var damage: int = 1
|
||||
@export var speed: int = 135
|
||||
@export var projectiles: int = 2
|
||||
@export var projectile_spacing: float = 35
|
||||
@export var projectile_origin: int = -23
|
||||
@export var rate: float = 0.1
|
||||
@export var cooldown: float = 0.25
|
||||
@export var spacing: float = 35
|
||||
@export var origin: int = -23
|
||||
#@export var rate: float = 0.1
|
||||
#@export var cooldown: float = 0.25
|
||||
|
|
|
|||
|
|
@ -3,30 +3,35 @@ class_name ShootComponent extends Node
|
|||
@onready var weapon_component: Node = %WeaponComponent
|
||||
@onready var player: Player = $".."
|
||||
|
||||
var travel: float = 0
|
||||
var weapon_spacing: float = 0.1
|
||||
#var travel: float = 0
|
||||
#var weapon_spacing: float = 0.1
|
||||
|
||||
|
||||
func shoot():
|
||||
if player.travel > weapon_component.bullet_data.projectile_spacing:
|
||||
|
||||
var weapon_system = weapon_component.data
|
||||
|
||||
if player.travel > weapon_system.spacing:
|
||||
print("Travel is greater!")
|
||||
for b in range(weapon_component.bullet_data.projectiles):
|
||||
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_component.bullet_data.projectiles - 1) / 2.0) * weapon_component.bullet_data.projectile_spacing, weapon_component.bullet_data.projectile_origin)
|
||||
|
||||
## Get weapon speed and spacing for equidistant calculations
|
||||
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)
|
||||
## Get weapon speed and spacing for equidistant calculations - non comp
|
||||
#weapon_rate = bullet.weapon_component.bullet_data.rate
|
||||
#weapon_component.bullet_data.projectile_spacing = bullet.weapon_component.bullet_data.projectile_spacing
|
||||
#weapon_component.bullet_data.speed = bullet.weapon_component.bullet_data.speed
|
||||
|
||||
# Print which weapon is firing
|
||||
prints(bullet.shot_data.shot_name, "weapon fired")
|
||||
player.travel -= weapon_component.bullet_data.projectile_spacing
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next
|
||||
player.travel -= weapon_system.spacing
|
||||
|
||||
else: return
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
@onready var bullet: PackedScene = load("res://scenes/stock_weapon.tscn")
|
||||
|
||||
@export var shot_data: PlayerShot
|
||||
|
||||
|
||||
func _process(delta):
|
||||
position.y -= shot_data.speed * delta # This works normally
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
||||
queue_free()
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://d1rwqotmrag1r
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
class_name WeaponComponent extends Node
|
||||
|
||||
@export var weapon_current : PackedScene
|
||||
var bullet_data: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
var data: PlayerShot = load("res://resources/player_weapons/shot_stock.tres")
|
||||
#@export var projectile_origin: int = -23
|
||||
|
||||
#@export_category("Temp Bullet Data")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue