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

44 lines
1.2 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())
var player_direction = (get_global_mouse_position() - position).normalized()
$Camera.handle_offset(player_direction, _delta)
2023-08-15 20:51:29 +00:00
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()]
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
grenade_thrown.emit(grenade_marker.global_position, player_direction)
func _on_laser_timeout():
2023-10-08 17:29:32 +00:00
can_laser = true
2023-08-15 20:51:29 +00:00
func _on_grenade_timer_timeout():
2023-10-08 17:29:32 +00:00
can_grenade = true