-
Notifications
You must be signed in to change notification settings - Fork 5
/
Player.gd
33 lines (26 loc) · 878 Bytes
/
Player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
extends KinematicBody2D
const MOVE_SPEED = 300
onready var raycast = $RayCast2D
func _ready():
yield(get_tree(), "idle_frame")
get_tree().call_group("zombies", "set_player", self)
func _physics_process(delta):
var move_vec = Vector2()
if Input.is_action_pressed("move_up"):
move_vec.y -= 1
if Input.is_action_pressed("move_down"):
move_vec.y += 1
if Input.is_action_pressed("move_left"):
move_vec.x -= 1
if Input.is_action_pressed("move_right"):
move_vec.x += 1
move_vec = move_vec.normalized()
move_and_collide(move_vec * MOVE_SPEED * delta)
var look_vec = get_global_mouse_position() - global_position
global_rotation = atan2(look_vec.y, look_vec.x)
if Input.is_action_just_pressed("shoot"):
var coll = raycast.get_collider()
if raycast.is_colliding() and coll.has_method("kill"):
coll.kill()
func kill():
get_tree().reload_current_scene()