Added shooting
This commit is contained in:
+12
-19
@@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
class_name AbstractProjectile
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
signal velocity_updated(new_velocity: Vector2)
|
||||
signal destroyed
|
||||
|
||||
|
||||
@@ -13,38 +13,31 @@ signal destroyed
|
||||
@export var max_livetime : int
|
||||
|
||||
|
||||
var velocity : Vector2:
|
||||
set(value):
|
||||
pass
|
||||
get:
|
||||
return _velocity
|
||||
|
||||
var _velocity : Vector2:
|
||||
set(value):
|
||||
_velocity = value
|
||||
velocity_updated.emit(_velocity)
|
||||
|
||||
var _traveled_distance: float
|
||||
var _livetime: float
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_velocity = direction.normalized() * speed
|
||||
velocity = direction.normalized() * speed
|
||||
|
||||
|
||||
func move(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
|
||||
velocity += velocity.normalized() * current_acceleration
|
||||
elif current_acceleration < 0:
|
||||
if _velocity.length() > current_acceleration:
|
||||
_velocity += _velocity.normalized() * current_acceleration
|
||||
if velocity.length() > current_acceleration:
|
||||
velocity += velocity.normalized() * current_acceleration
|
||||
else:
|
||||
_velocity = Vector2.ZERO
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
|
||||
func process_distance(delta: float) -> void:
|
||||
_traveled_distance += _velocity.length() * delta
|
||||
_traveled_distance += velocity.length() * delta
|
||||
if max_distance > 0 and _traveled_distance > max_distance:
|
||||
destroyed.emit()
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bohp8yx6cldgc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ctmjb3nkxrepu" path="res://game/entities/weapons/projectiles/projectile_mover.gd" id="1_4tgfk"]
|
||||
[ext_resource type="Script" uid="uid://ctmjb3nkxrepu" path="res://game/entities/weapons/projectiles/abstract_projectile.gd" id="1_4tgfk"]
|
||||
|
||||
[node name="ProjectileMover" type="Node"]
|
||||
[node name="AbstractProjectile" type="CharacterBody2D"]
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_4tgfk")
|
||||
@@ -1,7 +1,13 @@
|
||||
extends CharacterBody2D
|
||||
extends AbstractProjectile
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var texture := PlaceholderTexture2D.new()
|
||||
texture.size = Vector2(4, 4)
|
||||
$Sprite2D.texture = texture
|
||||
|
||||
super._ready()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
move(delta)
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cnoiv8hdgossf"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cnoiv8hdgossf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://rtsf1n0djorp" path="res://game/entities/weapons/projectiles/gatling_projectile.gd" id="1_xq7oi"]
|
||||
[ext_resource type="PackedScene" uid="uid://bohp8yx6cldgc" path="res://game/entities/weapons/projectiles/projectile_mover.tscn" id="2_jnl7n"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5a440"]
|
||||
radius = 4.0
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_xq7oi"]
|
||||
size = Vector2(4, 4)
|
||||
|
||||
[node name="GatlingProjectile" type="CharacterBody2D"]
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_xq7oi")
|
||||
damage = 6
|
||||
speed = 600
|
||||
metadata/_custom_type_script = "uid://ctmjb3nkxrepu"
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("PlaceholderTexture2D_xq7oi")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_5a440")
|
||||
|
||||
[node name="ProjectileMover" parent="." instance=ExtResource("2_jnl7n")]
|
||||
|
||||
Reference in New Issue
Block a user