54 lines
1.6 KiB
GDScript
54 lines
1.6 KiB
GDScript
class_name Weapon
|
|
extends Node2D
|
|
|
|
@onready var arena : Node2D = get_parent().get_parent()
|
|
|
|
@onready var bullet_scene : Resource = preload("res://src/scenes/weapons/_bullet.tscn")
|
|
@onready var tracker_bullet_scene : Resource = preload("res://src/scenes/weapons/_trackerbullet.tscn")
|
|
|
|
var fancy_name : String = "GIVEMEANAME"
|
|
|
|
func _ready() -> void:
|
|
if arena == null:
|
|
push_error("No arena!")
|
|
queue_free()
|
|
|
|
func connect_up(plr : CharacterBody2D) -> void:
|
|
plr.attack.connect(_on_player_attack)
|
|
pass
|
|
|
|
func get_fancy_name() -> String:
|
|
return fancy_name
|
|
|
|
func set_fancy_name(fname : String) -> void:
|
|
fancy_name = fname
|
|
|
|
func spawn_tracker_bullet(damage : int = 10) -> void:
|
|
var tbullet : RigidBody2D = tracker_bullet_scene.instantiate()
|
|
|
|
var track_this : CharacterBody2D = arena.get_closest_enemy(get_parent())
|
|
if track_this == null:
|
|
return
|
|
tbullet.set_tracked(track_this)
|
|
|
|
tbullet.set_damage(damage)
|
|
tbullet.add_collision_exception_with(get_parent())
|
|
tbullet.set_position(get_global_position())
|
|
|
|
get_parent().get_parent().add_child(tbullet)
|
|
|
|
func spawn_bullet(damage : int = 10) -> void:
|
|
var bullet : RigidBody2D = bullet_scene.instantiate()
|
|
|
|
var direction : float = get_parent().get_node("Sprite2D").get_scale().x # get player's direction
|
|
bullet.set_direction(direction) # and apply it
|
|
bullet.set_damage(damage) # set custom weapon damage
|
|
|
|
bullet.add_collision_exception_with(get_parent()) # don't collide with player
|
|
bullet.set_position(get_global_position()) # set position to staff position
|
|
|
|
get_parent().get_parent().add_child(bullet) # add to arena
|
|
|
|
func _on_player_attack() -> void:
|
|
push_error("No weapon type defined!")
|