codename-scribe/Player.gd

40 lines
996 B
GDScript

extends KinematicBody2D
var bullet = load("res://Bullet.tscn")
var velocity = Vector2(0, 0)
var pointer
func _ready():
# Called every time the node is added to the scene.
pointer = get_node("Pointer")
set_fixed_process(true)
func _fixed_process(delta):
var point_dir = (get_viewport().get_mouse_pos() - get_global_pos()).normalized()
if Input.is_action_pressed("move_left"):
velocity.x = -1
if Input.is_action_pressed("move_right"):
velocity.x = 1
if Input.is_action_pressed("move_up"):
velocity.y = -1
if Input.is_action_pressed("move_down"):
velocity.y = 1
# shooty
if Input.is_action_pressed("primary_fire"):
var new_bullet = bullet.instance()
new_bullet.set_pos(pointer.get_node("Sprite").get_global_pos() + velocity)
new_bullet.set_bullet_velocity(velocity, point_dir)
get_parent().add_child(new_bullet) # add to tree
# rotatey pointer thingy
pointer.look_at(get_viewport().get_mouse_pos())
self.move(velocity)
velocity.x = 0
velocity.y = 0