Fixed weapons scenes inheritance

This commit is contained in:
2025-11-08 02:23:42 +03:00
parent 32fa3dca57
commit 8f7e7aa78f
40 changed files with 277 additions and 412 deletions
+16 -51
View File
@@ -1,83 +1,45 @@
class_name AbstractProjectile
extends CharacterBody2D
extends Area2D
const PLAYER_LAYER = 2
const ENEMY_LAYER = 4
const PLAYER_PROJECTILE_LAYER = 8
const ENEMY_PROJECTILE_LAYER = 16
const PROJECTILE_BORDER_LAYER = 32
signal destroyed
@export_range(0, 250) var damage : int
@export_range(0, 1000) var speed : int
@export_range(0, 10) var piercing: int
@export var damage : int
@export var speed : int
@export var direction : Vector2
@export var acceleration : int
@export var max_distance : int
@export var max_livetime : int
@export var piercing: int
var direction : Vector2
var ship_velocity: Vector2
@export var collide_player: bool:
var collide_player: bool:
set(value):
collide_player = value
_apply_collision_mask()
get:
return collide_player
@export var collide_enemies: bool:
var collide_enemies: bool:
set(value):
collide_enemies = value
_apply_collision_mask()
get:
return collide_enemies
var _traveled_distance: float
var _livetime: float
var _velocity: Vector2
func _ready() -> void:
velocity = direction.normalized() * speed
_velocity = direction.normalized() * speed + ship_velocity
_apply_collision_mask()
func _physics_process(_delta: float) -> void:
var was_collided := move_and_slide()
if was_collided:
destroyed.emit()
queue_free()
func _physics_process(delta: float) -> void:
position += _velocity * delta
func process_acceleration(delta: float) -> void:
var current_acceleration := acceleration * delta
if current_acceleration > 0:
velocity += velocity.normalized() * current_acceleration
elif current_acceleration < 0:
if velocity.length() > current_acceleration:
velocity += velocity.normalized() * current_acceleration
else:
velocity = Vector2.ZERO
func process_distance(delta: float) -> void:
_traveled_distance += velocity.length() * delta
if max_distance > 0 and _traveled_distance > max_distance:
destroyed.emit()
queue_free()
func process_livetime(delta: float) -> void:
_livetime += delta
if _livetime > max_livetime:
destroyed.emit()
queue_free()
func _apply_collision_mask() -> void:
collision_mask |= PROJECTILE_BORDER_LAYER
if collide_player:
collision_layer |= ENEMY_PROJECTILE_LAYER
collision_mask |= PLAYER_LAYER
@@ -91,4 +53,7 @@ func _apply_collision_mask() -> void:
else:
collision_layer &= ~PLAYER_PROJECTILE_LAYER
collision_mask &= ~ENEMY_LAYER
func _on_screen_exited() -> void:
queue_free()