-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.lua
139 lines (124 loc) · 3.4 KB
/
player.lua
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
129
130
131
132
133
134
135
136
137
138
139
--player.lua
player = {}
function player.load()
player.x = map.startx
player.y = map.starty
player.width = 32
player.height = 32
player.makeecho = true
player.intervalecho = 1
player.tmrecho = 0
player.animation = 1
player.direction = 2 --1:to left 2:to right
player.tmrani = 0
player.intani = 0.1
player.fin = false
player.tmrfin = 0
player.cutscene = false
player.seq = 0
player.tmrseq = 0
player.intseq = 3
end
function player.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(imgbat, quadbat[player.animation + 4 * (player.direction - 1)], player.x, player.y)
end
function player.update(dt)
--player animation
player.tmrani = player.tmrani + dt
if player.tmrani >= player.intani then
player.tmrani = player.tmrani - player.intani
if player.animation == 4 then
player.animation = 1
else
player.animation = player.animation + 1
end
end
--make echo
if player.makeecho == true then
player.tmrecho = player.tmrecho + dt
if player.tmrecho >= player.intervalecho then
player.tmrecho = player.tmrecho - player.intervalecho
echo.new(player.x + player.width / 2, player.y + player.height / 2)
end
end
--finish stage
if player.cutscene == false then
if player.fin == true then
player.tmrfin = player.tmrfin + dt
if player.tmrfin >= 1 then
map.savecleardata(game.stage, game.map)
if (game.stage == 1) and (game.map == 5) then
--cutscene 1-5
player.cutscene = true
player.makeecho = false
elseif (game.stage == 2) and (game.map == 5) then
--cutscene 2-5
player.cutscene = true
player.makeecho = false
elseif (game.stage == 3) and (game.map == 5) then
--cutscene 3-5
player.cutscene = true
player.makeecho = false
else
scene.stage.load(game.stage, game.map)
end
end
end
end
--cutscene sequence
if player.cutscene == true then
player.tmrseq = player.tmrseq + dt
if player.tmrseq >= player.intseq then
player.tmrseq = player.tmrseq - player.intseq
player.seq = player.seq + 1
if player.seq == 5 then
scene.stage.load(game.stage + 1, 1)
end
end
end
--move player
if player.fin == false then
if love.keyboard.isDown("left") == true then
player.x = player.x - dt * 150
player.direction = 1
end
if love.keyboard.isDown("right") == true then
player.x = player.x + dt * 150
player.direction = 2
end
if love.keyboard.isDown("up") == true then
player.y = player.y - dt * 150
end
if love.keyboard.isDown("down") == true then
player.y = player.y + dt * 150
end
end
--check player's position
local tmpr, tmpg, tmpb, tmpa
tmpr, tmpg, tmpb, tmpa = canvas:getPixel(player.x + player.width / 2, player.y + player.height / 2)
if tmpa == 255 then
--dead!
if player.fin == false then
player.x = map.startx
player.y = map.starty
if (game.map == 5) and (game.stage == 4) then
scene.stage.load(4, 5)
end
end
local a
for a = 1, #object.item do
if object.item[a].otype == "r" then
object.item[a].direction = 0
end
end
end
--check player and goal
if not( (game.map == 5) and (game.stage == 4) )then
if player.fin == false then
if game.check(map.goalx, map.goaly, 48, 48, player.x + player.width / 2, player.y + player.height / 2) then
player.fin = true
end
end
end
end