2017-06-22 15:49:55 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
var bullet = load("res://Bullet.tscn")
|
2017-06-27 14:50:14 +01:00
|
|
|
var player_movement_speed = 256 # pixels per second
|
2017-06-22 15:49:55 +01:00
|
|
|
var velocity = Vector2(0, 0)
|
|
|
|
var pointer
|
|
|
|
|
2017-06-27 14:50:14 +01:00
|
|
|
var velocity_mul = 1
|
|
|
|
|
2017-06-22 15:49:55 +01:00
|
|
|
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
|
|
|
|
|
2017-06-27 14:50:14 +01:00
|
|
|
if Input.is_action_pressed("move_slow"):
|
|
|
|
velocity_mul = 0.5
|
|
|
|
else:
|
|
|
|
velocity_mul = 1
|
|
|
|
|
2017-06-22 15:49:55 +01:00
|
|
|
# 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())
|
|
|
|
|
2017-06-27 14:50:14 +01:00
|
|
|
self.move(velocity * velocity_mul * (player_movement_speed * delta))
|
2017-06-22 15:49:55 +01:00
|
|
|
velocity.x = 0
|
|
|
|
velocity.y = 0
|