godot-ultimate-tutorial/scenes/levels/level.gd
2023-08-15 22:51:29 +02:00

26 lines
672 B
GDScript

extends Node2D
var laser_scene: PackedScene = preload("res://scenes/projectiles/laser.tscn")
var grenade_scene: PackedScene = preload("res://scenes/projectiles/grenade.tscn")
func _on_gate_player_entered_gate(body):
print("player has entered gate")
print(body)
func _on_player_laser_fired(pos, dir):
var laser = laser_scene.instantiate() as Area2D
laser.position = pos
laser.direction = dir
laser.rotation = dir.angle()
$Projectiles.add_child(laser)
func _on_player_grenade_thrown(pos, dir):
var grenade = grenade_scene.instantiate() as RigidBody2D
grenade.position = pos
grenade.linear_velocity = dir * grenade.speed
$Projectiles.add_child(grenade)