init
This commit is contained in:
commit
d2d4d57509
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.lua
|
17
src/Player.moon
Normal file
17
src/Player.moon
Normal file
@ -0,0 +1,17 @@
|
||||
import floor from math
|
||||
import tileSize from require "constants"
|
||||
|
||||
class Player
|
||||
new: (@x=0, @y=0) =>
|
||||
@speed = 2500 -- 100
|
||||
update: (dt) =>
|
||||
if love.keyboard.isDown "w"
|
||||
@y -= @speed * dt
|
||||
if love.keyboard.isDown "a"
|
||||
@x -= @speed * dt
|
||||
if love.keyboard.isDown "s"
|
||||
@y += @speed * dt
|
||||
if love.keyboard.isDown "d"
|
||||
@x += @speed * dt
|
||||
tile: => return floor(@x/tileSize), floor(@y/tileSize)
|
||||
offset: => return @x % tileSize, @y % tileSize
|
51
src/World.moon
Normal file
51
src/World.moon
Normal file
@ -0,0 +1,51 @@
|
||||
import random, noise from love.math
|
||||
|
||||
class World
|
||||
new: =>
|
||||
@generateSeed!
|
||||
get: (x, y) =>
|
||||
map = @map
|
||||
unless map[x]
|
||||
map[x] = {}
|
||||
unless map[x][y]
|
||||
p = @precipitation(x, y)
|
||||
-- map[x][y] = { 1 - p, 1 - p, 1, 1 }
|
||||
h = @height(x, y)
|
||||
-- map[x][y] = { h, h, h, 1 }
|
||||
t = @temperature(x, y)
|
||||
-- map[x][y] = { t, 0, 0, 1 }
|
||||
map[x][y] = { t, h, p, 1 }
|
||||
return map[x][y]
|
||||
generateSeed: =>
|
||||
@map = {}
|
||||
@precipitationXOffset = random! * 256
|
||||
@precipitationYOffset = random! * 256
|
||||
@precipitationScale = random! * 0.009 + 0.001
|
||||
@temperatureXOffset = random! * 256
|
||||
@temperatureYOffset = random! * 256
|
||||
@temperatureScale = random! * 0.009 + 0.001
|
||||
@heightXOffset = random! * 256
|
||||
@heightYOffset = random! * 256
|
||||
@heightScale = random! * 0.009 + 0.001
|
||||
@heightAmplitude = random! * 0.9 + 0.1 -- max: 1, min: 0.1
|
||||
@heightXOffset2 = random! * 256
|
||||
@heightYOffset2 = random! * 256
|
||||
@heightScale2 = random! * 0.012 + 0.008
|
||||
@heightAmplitude2 = random! * 0.09 + 0.01 -- max: 0.1, min: 0.01
|
||||
@heightXOffset3 = random! * 256
|
||||
@heightYOffset3 = random! * 256
|
||||
@heightScale3 = random! * 0.092 + 0.01
|
||||
@heightAmplitude3 = random! * 0.009 + 0.001 -- max: 0.01, min: 0.001
|
||||
precipitation: (x, y) =>
|
||||
return noise((x + @precipitationXOffset) * @precipitationScale, (y + @precipitationYOffset) * @precipitationScale)
|
||||
temperature: (x, y) =>
|
||||
return noise((x + @temperatureXOffset) * @temperatureScale, (y + @temperatureYOffset) * @temperatureScale)
|
||||
height: (x, y) =>
|
||||
h = noise((x + @heightXOffset) * @heightScale, (y + @heightYOffset) * @heightScale) * @heightAmplitude +
|
||||
noise((x + @heightXOffset2) * @heightScale2, (y + @heightYOffset2) * @heightScale2) * @heightAmplitude2 +
|
||||
noise((x + @heightXOffset3) * @heightScale3, (y + @heightYOffset3) * @heightScale3) * @heightAmplitude3
|
||||
-- max: 1.11, min: 0.111
|
||||
-- slope = (output_end - output_start) / (input_end - input_start)
|
||||
-- output = output_start + slope * (input - input_start)
|
||||
slope = 1 / (1.11 - 0.111)
|
||||
return slope * (h - 0.111)
|
3
src/constants.moon
Normal file
3
src/constants.moon
Normal file
@ -0,0 +1,3 @@
|
||||
return {
|
||||
tileSize: 20
|
||||
}
|
46
src/main.moon
Normal file
46
src/main.moon
Normal file
@ -0,0 +1,46 @@
|
||||
import random from love.math
|
||||
import tileSize from require "constants"
|
||||
w, h = love.graphics.getDimensions!
|
||||
screen = { w: math.floor(w/tileSize), h: math.floor(h/tileSize)}
|
||||
|
||||
Player = require "Player"
|
||||
player = Player!
|
||||
|
||||
World = require "World"
|
||||
world = World!
|
||||
|
||||
time, step = 0, 1/30
|
||||
love.update = (dt) ->
|
||||
time += dt
|
||||
if time >= step
|
||||
time -= step
|
||||
player\update step
|
||||
|
||||
love.draw = ->
|
||||
x, y = player\tile!
|
||||
screenX, screenY = 0, 0
|
||||
xOffset, yOffset = player\offset!
|
||||
for x = x - screen.w/2, x + screen.w/2
|
||||
for y = y - screen.h/2, y + screen.h/2
|
||||
tile = world\get x, y
|
||||
if tile
|
||||
love.graphics.setColor tile
|
||||
else
|
||||
love.graphics.setColor 0, 0, 0, 1
|
||||
love.graphics.rectangle "fill", screenX * tileSize - xOffset, screenY * tileSize - yOffset, tileSize, tileSize
|
||||
screenY += 1
|
||||
screenY = 0
|
||||
screenX += 1
|
||||
love.graphics.setColor 1, 0, 0, 1
|
||||
love.graphics.circle "line", w/2, h/2, 5
|
||||
|
||||
love.keypressed = (key) ->
|
||||
love.event.quit! if key == "escape"
|
||||
|
||||
if key == "="
|
||||
player.speed *= 5
|
||||
if key == "-"
|
||||
player.speed /= 5
|
||||
|
||||
if key == "r"
|
||||
world\generateSeed!
|
Loading…
Reference in New Issue
Block a user