blob: 064f7d099285f9e29cd6cca5744d3ca5d5a955a6 (
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
|
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)
if character.jump.higher > 0 and character.actionA == true then
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
end
if character.actionLeft == true and character.actionRight == false then
metaSprite = character.walk
character.position.x = character.position.x - (character.velocity * dt)
character.scale.x = -1
end
if character.actionRight == true and character.actionLeft == false then
metaSprite = character.walk
character.position.x = character.position.x + (character.velocity * dt)
character.scale.x = 1
end
if character.actionUp == true and character.actionDown == false then
metaSprite = character.walk
character.position.y = character.position.y - (character.velocity * dt)
character.jump.ground = character.position.y
end
if character.actionDown == true and character.actionUp == false then
metaSprite = character.walk
character.position.y = character.position.y + (character.velocity * dt)
character.jump.ground = character.position.y
end
if character.actionUp == true and character.actionDown == true then
metaSprite = character.stand
elseif character.actionLeft == true and character.actionRight == true then
metaSprite = character.stand
elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then
metaSprite = character.stand
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
|