This repository has been archived on 2024-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
HoppyEaster/Scripts/WeaponSystem/Projectile.gd

37 lines
851 B
GDScript3
Raw Permalink Normal View History

extends Area2D
2023-04-09 21:22:44 +00:00
@export var speed : float = 80.0
@export var damage : int = 1
@export var audio_pool := []
@export_flags_2d_physics var map_collision_layer : int
@export_flags_2d_physics var bunny_collision_layer : int
2023-04-09 21:22:44 +00:00
var dir : float
func _ready():
get_node(audio_pool[randi_range(0, 2)]).play()
pass
func _process(delta):
2023-04-09 21:22:44 +00:00
self.translate(Vector2(cos(dir), sin(dir)) * speed * delta)
self.rotate(delta * 30)
pass
func _on_collision(body):
var collided_layer = null;
2023-04-08 15:17:48 +00:00
if body.get_class() == "TileMap":
collided_layer = body.tile_set.get_physics_layer_collision_layer(0)
2023-04-08 15:17:48 +00:00
if(body.has_method("get_collision_layer")):
collided_layer = body.get_collision_layer()
if collided_layer & map_collision_layer:
queue_free()
if collided_layer & bunny_collision_layer:
2023-04-16 12:36:10 +00:00
var bunny = body as Bunny
bunny.damage(damage)
queue_free()
2023-04-08 15:17:48 +00:00
pass
2023-04-16 12:36:10 +00:00