Added shooting
This commit is contained in:
@@ -23,8 +23,8 @@ func _physics_process(delta: float) -> void:
|
|||||||
for index : int in weapon_actions:
|
for index : int in weapon_actions:
|
||||||
if index >= weapons.size(): break
|
if index >= weapons.size(): break
|
||||||
|
|
||||||
if Input.is_action_pressed(weapon_actions[index][0], true):
|
if Input.is_action_pressed(weapon_actions[index][0]):
|
||||||
ship.shoot(weapons[index])
|
ship.shoot(weapons[index])
|
||||||
|
|
||||||
if Input.is_action_pressed(weapon_actions[index][1], true):
|
if Input.is_action_pressed(weapon_actions[index][1]):
|
||||||
ship.reload(weapons[index])
|
ship.reload(weapons[index])
|
||||||
|
|||||||
+12
-19
@@ -1,7 +1,7 @@
|
|||||||
extends Node
|
class_name AbstractProjectile
|
||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
signal velocity_updated(new_velocity: Vector2)
|
|
||||||
signal destroyed
|
signal destroyed
|
||||||
|
|
||||||
|
|
||||||
@@ -13,38 +13,31 @@ signal destroyed
|
|||||||
@export var max_livetime : int
|
@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 _traveled_distance: float
|
||||||
var _livetime: float
|
var _livetime: float
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
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:
|
func process_acceleration(delta: float) -> void:
|
||||||
var current_acceleration := acceleration * delta
|
var current_acceleration := acceleration * delta
|
||||||
if current_acceleration > 0:
|
if current_acceleration > 0:
|
||||||
_velocity += _velocity.normalized() * current_acceleration
|
velocity += velocity.normalized() * current_acceleration
|
||||||
elif current_acceleration < 0:
|
elif current_acceleration < 0:
|
||||||
if _velocity.length() > current_acceleration:
|
if velocity.length() > current_acceleration:
|
||||||
_velocity += _velocity.normalized() * current_acceleration
|
velocity += velocity.normalized() * current_acceleration
|
||||||
else:
|
else:
|
||||||
_velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
|
||||||
|
|
||||||
func process_distance(delta: float) -> void:
|
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:
|
if max_distance > 0 and _traveled_distance > max_distance:
|
||||||
destroyed.emit()
|
destroyed.emit()
|
||||||
|
|
||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://bohp8yx6cldgc"]
|
[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")
|
script = ExtResource("1_4tgfk")
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
extends CharacterBody2D
|
extends AbstractProjectile
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
var texture := PlaceholderTexture2D.new()
|
var texture := PlaceholderTexture2D.new()
|
||||||
texture.size = Vector2(4, 4)
|
texture.size = Vector2(4, 4)
|
||||||
$Sprite2D.texture = texture
|
$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="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"]
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_xq7oi"]
|
||||||
radius = 4.0
|
size = Vector2(4, 4)
|
||||||
|
|
||||||
[node name="GatlingProjectile" type="CharacterBody2D"]
|
[node name="GatlingProjectile" type="CharacterBody2D"]
|
||||||
|
motion_mode = 1
|
||||||
script = ExtResource("1_xq7oi")
|
script = ExtResource("1_xq7oi")
|
||||||
|
damage = 6
|
||||||
|
speed = 600
|
||||||
metadata/_custom_type_script = "uid://ctmjb3nkxrepu"
|
metadata/_custom_type_script = "uid://ctmjb3nkxrepu"
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
texture = SubResource("PlaceholderTexture2D_xq7oi")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_5a440")
|
|
||||||
|
|
||||||
[node name="ProjectileMover" parent="." instance=ExtResource("2_jnl7n")]
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func can_shoot() -> bool:
|
func can_shoot() -> bool:
|
||||||
return _bullets_in_magazine > 0
|
return _countdown <= 0
|
||||||
|
|
||||||
|
|
||||||
func shoot() -> void:
|
func shoot() -> void:
|
||||||
@@ -46,6 +46,7 @@ func reload() -> void:
|
|||||||
if _countdown > 0 or _bullets_in_magazine == magazine_size: return
|
if _countdown > 0 or _bullets_in_magazine == magazine_size: return
|
||||||
var random_delay := _random.randf_range(-_reload_time_tenth, _reload_time_tenth)
|
var random_delay := _random.randf_range(-_reload_time_tenth, _reload_time_tenth)
|
||||||
_countdown = reload_time + random_delay
|
_countdown = reload_time + random_delay
|
||||||
|
print("reload")
|
||||||
|
|
||||||
|
|
||||||
func get_process_percent() -> int:
|
func get_process_percent() -> int:
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ func _init() -> void:
|
|||||||
add_child(firerate_reloader)
|
add_child(firerate_reloader)
|
||||||
|
|
||||||
var magazine_reloader := preload("res://game/entities/weapons/reloaders/magazine_reloader.gd").new()
|
var magazine_reloader := preload("res://game/entities/weapons/reloaders/magazine_reloader.gd").new()
|
||||||
magazine_reloader.magazine_size = 5
|
magazine_reloader.magazine_size = 300
|
||||||
magazine_reloader.reload_time = 3
|
magazine_reloader.reload_time = 2
|
||||||
reloaders.append(magazine_reloader)
|
reloaders.append(magazine_reloader)
|
||||||
add_child(magazine_reloader)
|
add_child(magazine_reloader)
|
||||||
|
|
||||||
@@ -42,6 +42,11 @@ func _ready() -> void:
|
|||||||
func shoot() -> void:
|
func shoot() -> void:
|
||||||
if not _can_shoot(): return
|
if not _can_shoot(): return
|
||||||
print("shot")
|
print("shot")
|
||||||
|
|
||||||
|
var projectile := preload("res://game/entities/weapons/projectiles/gatling_projectile.tscn").instantiate()
|
||||||
|
projectile.direction = Vector2.RIGHT
|
||||||
|
add_child(projectile)
|
||||||
|
|
||||||
for reloader in reloaders:
|
for reloader in reloaders:
|
||||||
reloader.shoot()
|
reloader.shoot()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user