systeme pour avoir plusieurs armes et un shotgun thingy
This commit is contained in:
@@ -1,23 +1,32 @@
|
||||
extends Node2D
|
||||
|
||||
@export var PROJECTILE : PackedScene;
|
||||
@export var PROJECTILE_AMOUNT = 1;
|
||||
@export var COOLDOWN = .5;
|
||||
@export var SPREAD = 10;
|
||||
@export var SPREAD = .2;
|
||||
@export var RANGE_MOD = 0;
|
||||
|
||||
@onready var raycast = $RayCast2D;
|
||||
@onready var cooldown_timer = $CooldownTimer;
|
||||
|
||||
var is_on_cooldown = false;
|
||||
var rng = RandomNumberGenerator.new();
|
||||
|
||||
func fire():
|
||||
func _ready():
|
||||
rng.randomize();
|
||||
|
||||
func fire(wielder_velocity):
|
||||
if !is_on_cooldown:
|
||||
is_on_cooldown = true;
|
||||
cooldown_timer.start(COOLDOWN);
|
||||
var current_projectile : Area2D = PROJECTILE.instantiate();
|
||||
get_node("/root").add_child(current_projectile);
|
||||
|
||||
current_projectile.transform = raycast.get_global_transform()
|
||||
current_projectile.launch((get_global_mouse_position() - global_position).normalized());
|
||||
for i in PROJECTILE_AMOUNT:
|
||||
var current_projectile : Area2D = PROJECTILE.instantiate();
|
||||
get_node("/root").add_child(current_projectile);
|
||||
|
||||
current_projectile.transform = raycast.get_global_transform() ;
|
||||
current_projectile.transform.origin += (get_global_mouse_position() - global_position).normalized() * (rng.randf() * RANGE_MOD);
|
||||
current_projectile.launch((get_global_mouse_position() - global_position).rotated(rng.randf_range(SPREAD,-SPREAD)).normalized(), wielder_velocity);
|
||||
|
||||
|
||||
func _on_cooldown_timer_timeout():
|
||||
|
||||
15
Weapons/shotgun.tscn
Normal file
15
Weapons/shotgun.tscn
Normal file
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bc4mkctxjnugk"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cmtuq84761y0i" path="res://Weapons/basic_weapon.tscn" id="1_0nefe"]
|
||||
[ext_resource type="Texture2D" uid="uid://ripq64urxouv" path="res://Sprites/placeholder_shotgun.png" id="2_r5age"]
|
||||
|
||||
[node name="shotgun" instance=ExtResource("1_0nefe")]
|
||||
PROJECTILE_AMOUNT = 4
|
||||
COOLDOWN = 1.0
|
||||
SPREAD = 0.3
|
||||
RANGE_MOD = 40
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
position = Vector2(18, 3)
|
||||
scale = Vector2(1.71875, 1.71875)
|
||||
texture = ExtResource("2_r5age")
|
||||
Reference in New Issue
Block a user