Added projectile deletion

This commit is contained in:
2025-11-03 20:20:29 +03:00
parent b22f6c44dd
commit 832db6f531
10 changed files with 116 additions and 15 deletions
+2
View File
@@ -7,6 +7,8 @@
script = ExtResource("1_3a8sv")
[node name="Ship" parent="." instance=ExtResource("2_ktqbp")]
collision_layer = 2
collision_mask = 21
size = Vector2(48, 32)
acceleration = 46
deceleration = 23
+1
View File
@@ -7,6 +7,7 @@ height = 20.0
[node name="Ship" type="CharacterBody2D"]
disable_mode = 1
collision_layer = 7
motion_mode = 1
wall_min_slide_angle = 3.1415927
script = ExtResource("1_6isjb")
@@ -2,6 +2,13 @@ class_name AbstractProjectile
extends CharacterBody2D
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
@@ -12,6 +19,20 @@ signal destroyed
@export var max_distance : int
@export var max_livetime : int
@export var collide_player: bool:
set(value):
collide_player = value
_apply_collision_mask()
get:
return collide_player
@export var collide_enemies: bool:
set(value):
collide_enemies = value
_apply_collision_mask()
get:
return collide_enemies
var _traveled_distance: float
var _livetime: float
@@ -19,10 +40,14 @@ var _livetime: float
func _ready() -> void:
velocity = direction.normalized() * speed
_apply_collision_mask()
func move(delta: float) -> void:
position += velocity * delta
func _physics_process(_delta: float) -> void:
var was_collided := move_and_slide()
if was_collided:
destroyed.emit()
queue_free()
func process_acceleration(delta: float) -> void:
@@ -46,3 +71,21 @@ func process_livetime(delta: float) -> void:
_livetime += delta
if _livetime > max_livetime:
destroyed.emit()
func _apply_collision_mask() -> void:
collision_mask |= PROJECTILE_BORDER_LAYER
if collide_player:
collision_layer |= ENEMY_PROJECTILE_LAYER
collision_mask |= PLAYER_LAYER
else:
collision_layer &= ~ENEMY_PROJECTILE_LAYER
collision_mask &= ~PLAYER_LAYER
if collide_enemies:
collision_layer |= PLAYER_PROJECTILE_LAYER
collision_mask |= ENEMY_LAYER
else:
collision_layer &= ~PLAYER_PROJECTILE_LAYER
collision_mask &= ~ENEMY_LAYER
@@ -3,5 +3,7 @@
[ext_resource type="Script" uid="uid://ctmjb3nkxrepu" path="res://game/entities/weapons/projectiles/abstract_projectile.gd" id="1_4tgfk"]
[node name="AbstractProjectile" type="CharacterBody2D"]
collision_layer = 0
collision_mask = 0
motion_mode = 1
script = ExtResource("1_4tgfk")
@@ -7,7 +7,3 @@ func _ready() -> void:
$Sprite2D.texture = texture
super._ready()
func _physics_process(delta: float) -> void:
move(delta)
@@ -1,11 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://cnoiv8hdgossf"]
[gd_scene load_steps=4 format=3 uid="uid://cnoiv8hdgossf"]
[ext_resource type="Script" uid="uid://rtsf1n0djorp" path="res://game/entities/weapons/projectiles/gatling_projectile.gd" id="1_xq7oi"]
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_xq7oi"]
size = Vector2(4, 4)
[sub_resource type="CircleShape2D" id="CircleShape2D_xq7oi"]
radius = 1.0
[node name="GatlingProjectile" type="CharacterBody2D"]
collision_layer = 0
collision_mask = 0
motion_mode = 1
script = ExtResource("1_xq7oi")
damage = 6
@@ -16,3 +21,4 @@ metadata/_custom_type_script = "uid://ctmjb3nkxrepu"
texture = SubResource("PlaceholderTexture2D_xq7oi")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_xq7oi")
+14 -2
View File
@@ -2,6 +2,11 @@ class_name Weapon
extends Node2D
enum Belonging { PLAYER, ENEMY }
@export var belonging: Belonging
@export var damage : int
@export var bullet_per_shot : int
@export var sector_angle : int
@@ -41,10 +46,17 @@ func _ready() -> void:
func shoot() -> void:
if not _can_shoot(): return
print("shot")
var projectile := preload("res://game/entities/weapons/projectiles/gatling_projectile.tscn").instantiate()
projectile.direction = Vector2.RIGHT
match belonging:
Belonging.PLAYER:
projectile.direction = Vector2.RIGHT
projectile.collide_enemies = true
Belonging.ENEMY:
projectile.direction = Vector2.LEFT
projectile.collide_player = true
add_child(projectile)
for reloader in reloaders:
+4
View File
@@ -4,5 +4,9 @@
[node name="Weapon" type="Node2D"]
script = ExtResource("1_4oq3a")
belonging = null
damage = null
bullet_per_shot = null
sector_angle = null
[node name="Sprite2D" type="Sprite2D" parent="."]
+35 -5
View File
@@ -4,28 +4,58 @@
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ltkyg"]
[node name="Passage" type="StaticBody2D"]
[node name="Passage" type="Node"]
script = ExtResource("1_ltkyg")
[node name="CollisionTop" type="CollisionShape2D" parent="."]
[node name="World" type="StaticBody2D" parent="."]
collision_mask = 0
[node name="CollisionTop" type="CollisionShape2D" parent="World"]
position = Vector2(320, 0)
rotation = 3.1415927
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionBottom" type="CollisionShape2D" parent="."]
[node name="CollisionBottom" type="CollisionShape2D" parent="World"]
position = Vector2(320, 360)
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionLeft" type="CollisionShape2D" parent="."]
[node name="CollisionLeft" type="CollisionShape2D" parent="World"]
position = Vector2(0, 180)
rotation = 1.5707964
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionRight" type="CollisionShape2D" parent="."]
[node name="CollisionRight" type="CollisionShape2D" parent="World"]
position = Vector2(640, 180)
rotation = -1.5707964
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="ProjectileBorder" type="StaticBody2D" parent="."]
collision_layer = 32
collision_mask = 0
[node name="CollisionTop" type="CollisionShape2D" parent="ProjectileBorder"]
position = Vector2(320, -50)
rotation = 3.1415927
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionBottom" type="CollisionShape2D" parent="ProjectileBorder"]
position = Vector2(320, 410)
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionLeft" type="CollisionShape2D" parent="ProjectileBorder"]
position = Vector2(-50, 180)
rotation = 1.5707964
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
[node name="CollisionRight" type="CollisionShape2D" parent="ProjectileBorder"]
position = Vector2(690, 180)
rotation = -1.5707964
shape = SubResource("WorldBoundaryShape2D_ltkyg")
one_way_collision = true
+6 -1
View File
@@ -346,7 +346,12 @@ previous_reactor_scheme={
[layer_names]
2d_physics/layer_1="Player"
2d_physics/layer_1="World"
2d_physics/layer_2="Player"
2d_physics/layer_3="Enemy"
2d_physics/layer_4="PlayerProjectile"
2d_physics/layer_5="EnemyProjectile"
2d_physics/layer_6="ProjectileBorder"
[rendering]