diff options
author | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2016-12-09 23:25:33 -0300 |
---|---|---|
committer | coadde [Márcio Alexandre Silva Delgado] <coadde@parabola.nu> | 2016-12-09 23:25:33 -0300 |
commit | 03d9f891ccb2564d1c7bcfd4d2b8125ae9eb2671 (patch) | |
tree | ab04ae080b759b19d2a58876c9ecd2d9e3ed6ac2 | |
parent | c6640b313ed6430c3326cae17f0c0183d2224e80 (diff) |
Add restart time and frames animation test
-rw-r--r-- | src/test/frames_animation/main.lua | 68 | ||||
-rw-r--r-- | src/test/restart_time/main.lua | 33 |
2 files changed, 101 insertions, 0 deletions
diff --git a/src/test/frames_animation/main.lua b/src/test/frames_animation/main.lua new file mode 100644 index 0000000..35aacbc --- /dev/null +++ b/src/test/frames_animation/main.lua @@ -0,0 +1,68 @@ +function love.load() + -- window -- + love.window.setMode(250, 250) + + -- animation -- + delta = 0 + fps = 1 + + a_animation = 1 + a_frames = 7 + a_draw = 'A' + + b_animation = 1 + b_frames = 3 + b_draw = 'B' + + animation = a_animation + frames = a_frames + draw = a_draw +end + +function love.keypressed(key, scancode) + -- exit -- + if scancode == 'q' or scancode == 'escape' then + love.event.quit() + end + + -- animation -- + if scancode == 'a' then + animationKey = true + animation = b_animation + frames = b_frames + end +end + +function love.keyreleased(key, scancode) + -- animation -- + if scancode == 'a' then + animationKey = false + animation = a_animation + frames = a_frames + end +end + +function love.update(dt) + -- animation -- + delta = delta + dt + if delta >= (1 / fps) then + delta = delta - (1 / fps) + if animation < frames then + animation = animation + 1 + else + animation = 1 + end + end + + if animationKey == true then + draw = b_draw + elseif animationKey == false then + draw = a_draw + end +end + +function love.draw() + -- animation -- + love.graphics.print(draw, 0) + love.graphics.print(animation, 10) +end diff --git a/src/test/restart_time/main.lua b/src/test/restart_time/main.lua new file mode 100644 index 0000000..cf2ac13 --- /dev/null +++ b/src/test/restart_time/main.lua @@ -0,0 +1,33 @@ +function love.load() + -- window -- + love.window.setMode(250, 250) + + -- time -- + upTime = love.timer.getTime() +end + +function love.keypressed(key, scancode) + -- exit -- + if scancode == 'q' or scancode == 'escape' then + love.event.quit() + end + + -- restart -- + if scancode == 'r' then + restartKey = true + restartTime = love.timer.getTime() - upTime + end +end + +function love.update(dt) + -- time -- + currentTime = love.timer.getTime() - upTime + if restartKey == true then + currentTime = currentTime - restartTime + end +end + +function love.draw() + -- time -- + love.graphics.print(currentTime) +end |