Added love folder and tommy
This commit is contained in:
60
love/tommy/main.lua
Normal file
60
love/tommy/main.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
require "Tserial"
|
||||
|
||||
function love.load()
|
||||
|
||||
love.filesystem.setIdentity("tommy")
|
||||
saveFile = "test.lua"
|
||||
|
||||
-- Check if Save file exists
|
||||
save_exists = love.filesystem.exists(saveFile)
|
||||
|
||||
player = {}
|
||||
|
||||
player.x = 100
|
||||
player.y = 100
|
||||
player.w = 25
|
||||
player.h = 25
|
||||
player.speed = 100
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
if key == "q" then
|
||||
love.event.quit()
|
||||
end
|
||||
|
||||
-- save
|
||||
if key == "s" then
|
||||
love.filesystem.write(saveFile, Tserial.pack(player, false, true))
|
||||
end
|
||||
|
||||
-- Load
|
||||
if key == "l" then
|
||||
if save_exists then
|
||||
player = Tserial.unpack( love.filesystem.read( saveFile ) )
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
--Move character left or right
|
||||
if love.keyboard.isDown("right") then
|
||||
player.x = player.x + player.speed*dt
|
||||
elseif love.keyboard.isDown("left") then
|
||||
player.x = player.x - player.speed*dt
|
||||
end
|
||||
|
||||
--Also able to move or up down at the same time as one of the above
|
||||
if love.keyboard.isDown("up") then
|
||||
player.y = player.y - player.speed*dt
|
||||
elseif love.keyboard.isDown ("down") then
|
||||
player.y = player.y + player.speed*dt
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
--draw the rectangle. Fill/line for the type,
|
||||
--(x,y, width, height)
|
||||
love.graphics.rectangle("line", player.x, player.y, player.w, player.h)
|
||||
end
|
||||
Reference in New Issue
Block a user