-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript_personagem.gd
60 lines (43 loc) · 1.63 KB
/
script_personagem.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
extends KinematicBody2D
var tipo_disparo = 1
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
$P1.visible = false
$P2.visible = false
if (Global.tipo_personagem == 1):
$P1.visible = true
elif(Global.tipo_personagem == 2):
$P2.visible = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
var velocidade = 250
func _process(delta):
#Movimentacao da nave
if (Input.is_action_pressed("paraCima")):
global_position.y -= (velocidade * delta) #cima
elif (Input.is_action_pressed("paraBaixo")):
global_position.y += (velocidade * delta) #baixo
if (Input.is_action_pressed("paraEsquerda")):
global_position.x -= (velocidade * delta) #esquerda
elif (Input.is_action_pressed("paraDireita")):
global_position.x += (velocidade * delta) #direita
#Limita o personagem dentro da tela do jogo
var larguraJanela = get_viewport().size.x
var alturaJanela = get_viewport().size.y
global_position.x = clamp(global_position.x, 50, larguraJanela-50)
global_position.y = clamp(global_position.y, 50, alturaJanela-50)
#Disparo
if (Input.is_action_just_pressed("disparar")):
var cena_disparo = preload("res://cena_disparo.tscn")
var objeto_disparo = cena_disparo.instance()
objeto_disparo.global_position = $Position2D.global_position
objeto_disparo.get_node("Area2D").tipoDisparo = tipo_disparo
get_tree().root.add_child(objeto_disparo)
$AudioStreamPlayer.play(0.3)
func _on_Timer_timeout():
tipo_disparo = 1
func morrer():
queue_free()
get_tree().change_scene("res://cena_game_over.tscn")