summaryrefslogtreecommitdiff
path: root/src/gnu_and_bola_brawlers
diff options
context:
space:
mode:
authorAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-12-15 18:46:11 -0300
committerAndré Fabian Silva Delgado <emulatorman@parabola.nu>2016-12-15 18:46:29 -0300
commit28e2f065f638efcffd4e541234ebc070b5f51956 (patch)
treee2d9dd189322d959f229949d86b1d9407dc1242a /src/gnu_and_bola_brawlers
parent42049918c9dacfa7f75273aad9b822a8a1a077d1 (diff)
Keep the code KISS 4
Diffstat (limited to 'src/gnu_and_bola_brawlers')
-rw-r--r--src/gnu_and_bola_brawlers/main.lua109
-rw-r--r--src/gnu_and_bola_brawlers/update/default.lua106
2 files changed, 112 insertions, 103 deletions
diff --git a/src/gnu_and_bola_brawlers/main.lua b/src/gnu_and_bola_brawlers/main.lua
index ee23e64..d6278c4 100644
--- a/src/gnu_and_bola_brawlers/main.lua
+++ b/src/gnu_and_bola_brawlers/main.lua
@@ -14,109 +14,12 @@ function love.keyreleased(key, scancode)
end
function love.update(dt)
- nextTime = nextTime + (1 / fps)
-
- 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
- animation(metaSprite.bola, images.bola, dt)
-
- 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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/stand'
- elseif character.actionLeft == true and character.actionRight == true then
- metaSprite = require 'meta_sprites/bola/stand'
- elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then
- metaSprite = require 'meta_sprites/bola/stand'
- end
-
- return metaSprite
- end
- metaSprite.bola = motion(character.bola, images.bola, metaSprite.bola, dt)
-
- 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
- gravity(character.bola, dt)
-
- 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
- limit(character.bola, dt)
+ local update = require 'update/default'
+ update.time(dt)
+ update.animation(metaSprite.bola, images.bola, dt)
+ metaSprite.bola = update.motion(character.bola, images.bola, metaSprite.bola, dt)
+ update.gravity(character.bola, dt)
+ update.limit(character.bola, dt)
end
function love.draw()
diff --git a/src/gnu_and_bola_brawlers/update/default.lua b/src/gnu_and_bola_brawlers/update/default.lua
new file mode 100644
index 0000000..f6fb68e
--- /dev/null
+++ b/src/gnu_and_bola_brawlers/update/default.lua
@@ -0,0 +1,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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/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 = require 'meta_sprites/bola/stand'
+ elseif character.actionLeft == true and character.actionRight == true then
+ metaSprite = require 'meta_sprites/bola/stand'
+ elseif character.actionLeft == false and character.actionRight == false and character.actionUp == false and character.actionDown == false then
+ metaSprite = require 'meta_sprites/bola/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