init
This commit is contained in:
commit
389eecc9be
53
src/main.moon
Normal file
53
src/main.moon
Normal file
@ -0,0 +1,53 @@
|
||||
w, h = love.graphics.getDimensions!
|
||||
|
||||
map = {}
|
||||
map.get = (x, y) -> if map[x] return map[x][y]
|
||||
map.set = (x, y, v) ->
|
||||
map[x] = {} unless map[x]
|
||||
map[x][y] = v
|
||||
seed = love.math.random!
|
||||
scale = 10
|
||||
tileSize = 20
|
||||
camera = { x: 0, y: 0 }
|
||||
|
||||
update = ->
|
||||
if love.keyboard.isDown "a"
|
||||
camera.x -= 4
|
||||
if love.keyboard.isDown "d"
|
||||
camera.x += 4
|
||||
if love.keyboard.isDown "w"
|
||||
camera.y -= 4
|
||||
if love.keyboard.isDown "s"
|
||||
camera.y += 4
|
||||
|
||||
time, tick = 0, 1/60
|
||||
love.update = (dt) ->
|
||||
time += dt
|
||||
if time >= tick
|
||||
time -= tick
|
||||
update()
|
||||
|
||||
love.draw = ->
|
||||
a, b = math.floor(camera.x / tileSize), math.floor(camera.y / tileSize)
|
||||
i, j = camera.x % tileSize, camera.y % tileSize
|
||||
for x = 0, w / tileSize
|
||||
for y = 0, h / tileSize
|
||||
n = love.math.noise (x + a + seed) / scale, (y + b + seed) / scale
|
||||
m = love.math.noise (x + a + seed) / scale, (y + b + seed) / scale, n
|
||||
if m < 0.72
|
||||
love.graphics.setColor n, 1, 0, 1
|
||||
else
|
||||
love.graphics.setColor 1, 1, 1, 1
|
||||
X, Y = x * tileSize - i, y * tileSize - j
|
||||
love.graphics.rectangle "fill", X, Y, tileSize, tileSize
|
||||
if map.get x + a, y + b
|
||||
love.graphics.setColor 0, 0, 0, 1
|
||||
love.graphics.line X + tileSize / 2, Y + tileSize / 2, X, Y
|
||||
|
||||
love.mousepressed = (x, y, btn) ->
|
||||
X, Y = math.floor((x + camera.x) / tileSize), math.floor((y + camera.y) / tileSize)
|
||||
print X, Y
|
||||
map.set X, Y, true
|
||||
|
||||
love.keypressed = (key) ->
|
||||
love.event.quit! if key == "escape"
|
Loading…
Reference in New Issue
Block a user