blob: b14349bee220f4c1f162a88125afc3da73d52d63 (
plain)
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
140
141
142
143
144
145
146
147
|
local update = {}
update.time = function(dt)
nextTime = nextTime + (1 / fps)
end
update.animation = function(metaSprite, images, dt)
--Increase actual elapsed time with new dt
metaSprite.elapsedTime = metaSprite.elapsedTime + dt --AnimationStart
--In order to know if it is necessary to change the frame
if metaSprite.elapsedTime >= (1 / metaSprite.fps) then
metaSprite.elapsedTime = metaSprite.elapsedTime - (1 / metaSprite.fps)
if metaSprite.currentFrame == # metaSprite then --If current frame is equal to long metaSprite list
metaSprite.currentFrame = 1 -- Return to first frame
else
metaSprite.currentFrame = metaSprite.currentFrame + 1 --Next frame
end
end
images.quad = metaSprite[metaSprite.currentFrame] --Update with new fame
end
update.motion = function(character, images, metaSprite, dt)
-- Check if press button up/down, left/right at same time, no button press and character is not jumping then metaSprite is stand
if ((character.actionUp == true and character.actionDown == true) or (character.actionLeft == true and character.actionRight == true) or (character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false)) and character.actionA == false and character.jump.isJumping == false then
if metaSprite ~= character.stand then
print("(update.motion) -> load stand meta sprite")
metaSprite = character.stand
metaSprite.currentFrame = 1
metaSprite.fps = 9
end
end
-- Check if it is jumping or falling
if character.jump.higher > 0 and character.actionUp == false and character.actionDown == false and character.actionA == true then
if metaSprite ~= character.jump then
print("(update.motion) -> load jump meta sprite")
metaSprite = character.jump
metaSprite.currentFrame = 1
metaSprite.fps = 6
end
if character.jump.limitButtonJump == false then
character.jump.higher = character.jump.higher - dt
character.jump.velocity = character.jump.velocity + character.jump.height * (dt / character.jump.higherMax)
end
elseif (character.jump.velocity > 0 and character.actionUp == false and character.actionDown == false) then
if metaSprite ~= character.fall then
print("(update.motion) -> load fall meta sprite")
metaSprite = character.fall
metaSprite.currentFrame = 1
metaSprite.fps = 6
end
end
--Check if left button has been pressed
if character.actionLeft == true and character.actionRight == false then
if character.jump.higher > 0 and character.actionA == false and character.jump.isJumping == false and metaSprite ~= character.walk then
print("(update.motion) -> load walk meta sprite")
metaSprite = character.walk
metaSprite.currentFrame = 1
metaSprite.fps = 9
end
character.position.x = character.position.x - (character.velocity * dt)
character.scale.x = -1
end
--Check if right button has been pressed
if character.actionRight == true and character.actionLeft == false then
if character.jump.higher > 0 and character.actionA == false and character.jump.isJumping == false and metaSprite ~= character.walk then
print("(update.motion) -> load walk meta sprite")
metaSprite = character.walk
metaSprite.currentFrame = 1
metaSprite.fps = 9
end
character.position.x = character.position.x + (character.velocity * dt)
character.scale.x = 1
end
--Check if up button has been pressed
if character.actionUp == true and character.actionDown == false then
if metaSprite ~= character.walk then
print("(update.motion) -> load walk meta sprite")
metaSprite = character.walk
metaSprite.currentFrame = 1
metaSprite.fps = 9
end
character.position.y = character.position.y - (character.velocity * dt)
character.jump.ground = character.position.y
end
--Check if down button has been pressed
if character.actionDown == true and character.actionUp == false then
if metaSprite ~= character.walk then
print("(update.motion) -> load walk meta sprite")
metaSprite = character.walk
metaSprite.currentFrame = 1
metaSprite.fps = 9
end
character.position.y = character.position.y + (character.velocity * dt)
character.jump.ground = character.position.y
end
return metaSprite
end
update.gravity = function(character, dt)
if character.jump.velocity ~= 0 then
character.jump.isJumping = true
character.position.y = character.position.y + (character.jump.velocity * dt)
character.jump.velocity = character.jump.velocity - (character.gravity * dt)
end
if character.position.y > character.jump.ground then
character.jump.velocity = 0
character.position.y = character.jump.ground
character.jump.higher = character.jump.higherMax
character.jump.limitButtonJump = false
character.jump.isJumping = false
character.actionA = false
if love.keyboard.isScancodeDown(controller.player1.up) then
character.actionUp = true
elseif love.keyboard.isScancodeDown(controller.player1.down) then
character.actionDown = true
end
end
end
update.limit = function(character, dt)
if character.position.x <= character.origin.x then
character.position.x = character.origin.x
elseif character.position.x >= windowProfile.mode.width - character.origin.x then
character.position.x = windowProfile.mode.width - character.origin.x
end
if character.position.y <= character.origin.y then
character.position.y = character.origin.y
elseif character.position.y >= windowProfile.mode.height - character.origin.y then
character.position.y = windowProfile.mode.height - character.origin.y
end
end
return update
|