-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.gd
89 lines (57 loc) · 1.74 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
71
72
73
74
75
76
extends Area2D
export (int) var Velocidad
export (int) var speed = 200
var Movimiento = Vector2()
var Limite
signal golpe
var target = Vector2()
var velocity = Vector2()
func _ready():
#no salga de la pantalla
hide()
Limite = get_viewport_rect().size
#movimiento del personaje con las flechas
func _process(delta):
Movimiento = Vector2()
if Input.is_action_pressed("ui_right"):
$ParticulasFuego.position.y = 0
Movimiento.x += 1
if Input.is_action_pressed("ui_left"):
$ParticulasFuego.position.y = 0
Movimiento.x -= 1
if Input.is_action_pressed("ui_down"):
if Input.is_action_pressed("ui_right") && Input.is_action_pressed("ui_left"):
$ParticulasFuego.position.y = -10
Movimiento.y += 1
if Input.is_action_pressed("ui_up"):
$ParticulasFuego.position.y = 0
Movimiento.y -= 1
if Movimiento.length() > 0:
Movimiento = Movimiento.normalized() * Velocidad
position += Movimiento*delta
#no salga de la pantalla
position.x = clamp(position.x, 0, Limite.x)
position.y = clamp(position.y, 0, Limite.y)
#animando al jugador
if Movimiento.x != 0:
$sprite_player.animation = "lado"
$sprite_player.flip_h = Movimiento.x < 0
$sprite_player.flip_v = false
elif Movimiento.y != 0:
$sprite_player.animation = "espalda"
$sprite_player.flip_v = Movimiento.y > 0
else:
#para que la animacion de frente vuela cuando no se mueve el player
$sprite_player.flip_v = false
$sprite_player.flip_h = false
$sprite_player.animation = "frente"
#esta func se ejecuta cuando el player toca otro objeto
func _on_Player_body_entered(body):
hide()
emit_signal("golpe")
$CollisionShape2D.disabled = true
#mostrar el player
func inicio(posicion):
position = posicion
show()
$CollisionShape2D.disabled = false