godot-ultimate-tutorial/scenes/player/player.gd

44 lines
1.3 KiB
GDScript3
Raw Normal View History

2023-08-15 20:51:29 +00:00
extends CharacterBody2D
var can_laser: bool = true
var can_grenade: bool = true
signal laser_fired(pos: Vector2, direction: Vector2)
signal grenade_thrown(pos: Vector2, direction: Vector2)
func _process(_delta):
var direction = Input.get_vector("left","right","up","down")
velocity = direction * 500
move_and_slide()
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("primary action") and can_laser:
can_laser = false
$LaserTimer.start()
#randomly select a marker for the laser start
var laser_markers = $LaserStartPositions.get_children()
var selected_laser = laser_markers[randi() % laser_markers.size()]
var player_direction = (get_global_mouse_position() - position).normalized()
laser_fired.emit(selected_laser.global_position, player_direction)
if Input.is_action_just_pressed("secondary action") and can_grenade:
can_grenade = false
$GrenadeTimer.start()
var grenade_marker = $GrenadeStartPositions/GrenadeMarker1
var player_direction = (get_global_mouse_position() - position).normalized()
grenade_thrown.emit(grenade_marker.global_position, player_direction)
func _on_laser_timeout():
can_laser = true # Replace with function body.
func _on_grenade_timer_timeout():
can_grenade = true # Replace with function body.