first commit
This commit is contained in:
commit
ff7be2c06f
16
main.lua
Normal file
16
main.lua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
dofile("player.lua")
|
||||||
|
dofile("map.lua")
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
maplib.draw()
|
||||||
|
player.draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.load()
|
||||||
|
maplib.createmap()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
player.test()
|
||||||
|
end
|
48
map.lua
Normal file
48
map.lua
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
math.randomseed( os.time() )
|
||||||
|
|
||||||
|
--the map library
|
||||||
|
maplib = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--create tiles
|
||||||
|
mapheight = 48
|
||||||
|
mapwidth = 50
|
||||||
|
tiles = {}
|
||||||
|
function maplib.createmap()
|
||||||
|
for x = 1,mapwidth do
|
||||||
|
tiles[x] = {}
|
||||||
|
for y = 1,mapheight do
|
||||||
|
tiles[x][y] = {}
|
||||||
|
|
||||||
|
local randomtile = math.random(0,1)
|
||||||
|
if randomtile == 0 then
|
||||||
|
tiles[x][y]["tile"] = ""
|
||||||
|
elseif randomtile == 1 then
|
||||||
|
tiles[x][y]["tile"] = "*"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--executed in love.draw to draw map
|
||||||
|
function maplib.draw()
|
||||||
|
love.graphics.setColor(255,255,255,255)
|
||||||
|
for x = 1,mapwidth do
|
||||||
|
for y = 1,mapheight do
|
||||||
|
love.graphics.print(tiles[x][y]["tile"], x*12, y*12)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[ a test
|
||||||
|
for x = 1,10 do
|
||||||
|
local line = ""
|
||||||
|
for y = 1,10 do
|
||||||
|
line = line..tiles.x.y
|
||||||
|
end
|
||||||
|
print(line.."\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
]]--
|
25
player.lua
Normal file
25
player.lua
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
--the player library
|
||||||
|
player = {}
|
||||||
|
player.playerx,player.playery = 0,0
|
||||||
|
|
||||||
|
--controls
|
||||||
|
function player.test()
|
||||||
|
if love.keyboard.isDown("left") then
|
||||||
|
player.playerx = player.playerx - 1
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown("right") then
|
||||||
|
player.playerx = player.playerx + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if love.keyboard.isDown("up") then
|
||||||
|
player.playery = player.playery - 1
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown("down") then
|
||||||
|
player.playery = player.playery + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function player.draw()
|
||||||
|
love.graphics.setColor(255,0,0,255)
|
||||||
|
love.graphics.print("8", player.playerx, player.playery)
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user