-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.gd
70 lines (58 loc) · 1.46 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
extends KinematicBody2D
signal shoot
var id = 8
var info_text_node = "hola"
const MAX_JUMPS = 2
const GRAVITY = 10
const WALK_SPEED = 300
const JUMP_POWER = 300
const FLOOR_NORMAL = Vector2(0, -1)
var velocity = Vector2()
var available_jumps = 0
var life = 100
var shield = 0
var looking_to = Vector2(0, 1)
var _KEY_UP = ""
var _KEY_LEFT = ""
var _KEY_RIGHT = ""
func set_controls(key_left, key_up, key_right):
_KEY_UP = key_up
_KEY_LEFT = key_left
_KEY_RIGHT = key_right
# Called when the node enters the scene tree for the first time.
func _ready():
print(_KEY_UP)
looking_to.x = 1
life = 100;
func _physics_process(delta):
if is_on_floor():
available_jumps = 2
if !is_on_floor():
velocity.y += GRAVITY
velocity.x = 0
if Input.is_action_pressed(_KEY_LEFT):
velocity.x -= WALK_SPEED
looking_to.x = -1
if Input.is_action_pressed(_KEY_RIGHT):
velocity.x += WALK_SPEED
looking_to.x = 1
if Input.is_action_just_pressed(_KEY_UP):
_jump()
looking_to.y = -1
if Input.is_action_just_pressed("ui_accept"):
print("k pasa bro")
_shoot()
move_and_slide(velocity, FLOOR_NORMAL, false)
func _jump():
print(available_jumps)
if is_on_floor():
available_jumps = 1
velocity.y = -JUMP_POWER
# Do not do the first jump when its not in the floor
elif available_jumps != MAX_JUMPS:
if available_jumps > 0:
velocity.y = -JUMP_POWER
available_jumps -= 1
func _shoot():
print("shooting to %d" % looking_to.x)
emit_signal("shoot", self, looking_to)