45 lines
1.1 KiB
GDScript
45 lines
1.1 KiB
GDScript
extends CharacterBody2D
|
|
|
|
@export var MAX_SPEED: float = 200
|
|
@export var SHOOT_NODE: PackedScene
|
|
|
|
const SPEED = 25.0
|
|
const JUMP_VELOCITY = -400.0
|
|
var mouse_position: Vector2 = Vector2.ZERO
|
|
var horizontal : float
|
|
var vertical : float
|
|
var vector_temp:= Vector2(1, 0)
|
|
var rota_temp: float
|
|
var delay := 0.0
|
|
|
|
func _input(event):
|
|
pass
|
|
if event is InputEventMouseMotion:
|
|
mouse_position = event.position
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
delay += delta
|
|
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
|
|
shoot()
|
|
delay = 0
|
|
|
|
|
|
horizontal = Input.get_axis("ui_up", "ui_down")
|
|
vertical = Input.get_axis("ui_left", "ui_right")
|
|
|
|
velocity.x = move_toward(velocity.x, MAX_SPEED * vertical, SPEED)
|
|
velocity.y = move_toward(velocity.y, MAX_SPEED * horizontal, SPEED)
|
|
if horizontal != 0 or vertical != 0:
|
|
vector_temp = Vector2(vertical, horizontal)
|
|
rotation = atan2(vector_temp.y, vector_temp.x)
|
|
|
|
move_and_slide()
|
|
|
|
|
|
func shoot()->void:
|
|
var new = SHOOT_NODE.instantiate()
|
|
new.direction = vector_temp
|
|
new.position = position + (18 * vector_temp.normalized())
|
|
get_parent().add_child(new)
|