aboutsummaryrefslogtreecommitdiffstats
path: root/KinematicBody2D.gd
blob: 03dd45f51d384ed9dbaba34210143a1f9a09b8af (plain)
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
extends KinematicBody2D

export (int) var speed = 200
var spawn_object = load("res://Bullet.tscn")
var velocity = Vector2()
onready var globals = get_node("/root/Global")

func get_input():
	velocity = Vector2()
	if Input.is_action_pressed("right"):
		velocity.x += 1
	if Input.is_action_pressed("left"):
		velocity.x -= 1
	if Input.is_action_pressed("down"):
		velocity.y += 1
	if Input.is_action_pressed("up"):
		velocity.y -= 1
	velocity = velocity.normalized() * speed

func _physics_process(delta):
	


	get_input()
	globals.playerPos = global_position
	velocity = move_and_slide(velocity)
	if Input.is_action_just_pressed("click"):
		var obj = spawn_object.instance()
		obj.position = get_position()
		obj.position.x -= 500		
		obj.position.y -= 250
		add_child(obj)