-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinematicPlayer.gd
128 lines (109 loc) · 2.81 KB
/
KinematicPlayer.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
extends KinematicBody2D
const SPEED = 200
var movedir = Vector2(0,0)
var spritedir = "down"
var can_go = true
var can_fire = false
var how_fire = Vector2()
var fire_rotate = 0
var time = 5
var shoot_time = 1
var is_live = true
var health = 100
var Bullet = preload('res://player/Bullet.tscn')
func fire():
var bul = Bullet.instance()
bul.position = position + how_fire
bul.rotation_degrees = fire_rotate
get_node('../').add_child(bul)
time = 0
func _physics_process(delta):
controls_loop()
movement_loop()
spritedir_loop()
time += delta
if (time > shoot_time):
time = 5
$"../"/Bars/Player_bars/player1_mana_bar.set_value(time)
$"../"/Bars/Player_bars/player1_health_bar.set_value(health)
if (health == 0):
health = -1
time = 0
is_live = false
$"../"/EndGameScreen/CanvasLayer/Label.show()
if (time > 1.4 and is_live == false):
get_tree().paused = true
#if is_on_wall():
if (Input.is_action_pressed("ui_fire")):
if spritedir == "left":# and test_move(transform, Vector2(-1,0)):
$anim.play("pushleft")
can_go = false
can_fire = false
fire_rotate = -180
how_fire = Vector2(-10, 2)
if (time > shoot_time):
fire()
#anim_switch("push")
if spritedir == "right":# and test_move(transform, Vector2(1,0)):
$anim.play("pushright")
can_go = false
can_fire = false
fire_rotate = 0
how_fire = Vector2(10, 2)
if (time > shoot_time):
fire()
#anim_switch("push")
if spritedir == "up":# and test_move(transform, Vector2(0,-1)):
$anim.play("pushup")
can_go = false
can_fire = false
fire_rotate = -90
how_fire = Vector2(0, -10)
if (time > shoot_time):
fire()
#anim_switch("push")
if spritedir == "down":# and test_move(transform, Vector2(0,1)):
$anim.play("pushdown")
can_go = false
can_fire = false
fire_rotate = 90
how_fire = Vector2(0, 10)
if (time > shoot_time):
fire()
#anim_switch("push")
elif movedir != Vector2(0,0):
anim_switch("walk")
can_go = true
can_fire = true
else:
anim_switch("idle")
can_go = true
can_fire = true
func controls_loop():
var LEFT = Input.is_action_pressed("ui_left")
var RIGHT = Input.is_action_pressed("ui_right")
var UP = Input.is_action_pressed("ui_up")
var DOWN = Input.is_action_pressed("ui_down")
if (can_fire == false):
movedir.x = 0
movedir.y = 0
if (can_go == true):
movedir.x = -int(LEFT) + int(RIGHT)
movedir.y = -int(UP) + int(DOWN)
func movement_loop():
var motion = movedir.normalized() * SPEED
move_and_slide(motion, Vector2(0,0))
func spritedir_loop():
match movedir:
Vector2(-1,0):
spritedir = "left"
Vector2(1,0):
spritedir = "right"
Vector2(0,-1):
spritedir = "up"
Vector2(0,1):
spritedir = "down"
func anim_switch(animation):
var newanim = str(animation, spritedir)
if $anim.current_animation != newanim:
$anim.play(newanim)