summaryrefslogtreecommitdiff
path: root/client/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.lua')
-rw-r--r--client/main.lua21
1 files changed, 14 insertions, 7 deletions
diff --git a/client/main.lua b/client/main.lua
index d58551e..4941814 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -15,6 +15,7 @@ local camera = require"camera".Camera:make()
local Chunk = require"common.chunk".Chunk
local util = require"util"
local Map = require"common.map".Map
+local movement = require"movement"
-- local pprint=require"common.pprint"
-- pprint.setup{show_all=true}
@@ -56,26 +57,26 @@ local function update_local_player(pl,dt)
local dy = kd"s"-kd"w"
if dx == 0 and dy == 0 then
- pl.pos_dirty = false
return
end
if dx ~= 0 and dy ~= 0 then
+ -- 60degrees direction, to follow hex grid
+ -- instead of 45degrees diagonal
dx = dx * 0.5
dy = dy * (math.sqrt(3)/2)
end
- pl.pos.x = pl.pos.x + SPEED * dt * dx
- pl.pos.y = pl.pos.y + SPEED * dt * dy
+ local try_pos = Pos:make(pl.pos.x + SPEED*dt*dx, pl.pos.y + SPEED*dt*dy)
+ pl.pos = movement.collide_with_terrain(pl.pos,try_pos,map)
pl.pos_dirty = true
-
-
end
local function sync_local_player(pl)
-- send updated info about local player to server
if pl.pos_dirty then
peer:send(json.encode{t="ppos",x=pl.pos.x,y=pl.pos.y})
+ pl.pos_dirty = false
end
end
@@ -95,9 +96,7 @@ function love.update(dt)
local mh = camera:screen_to_world(Pos:make(love.mouse.getPosition())):to_hex():round()
if false== map:at(mh) and love.mouse.isDown(1) then
- print("place at",mh)
map:set_at(mh,true)
- -- print(mh,true)
send_settile(mh,true)
elseif map:at(mh) and love.mouse.isDown(2) then
map:set_at(mh,false)
@@ -185,6 +184,8 @@ function love.draw()
local wm = camera:screen_to_world(sm)
local hm = wm:to_hex()
+ sdf_d,sdf_gx,sdf_gy = movement.hex_sdgf(wm, coords.Hex:make(3,3))
+
love.graphics.origin()
if _G.debugmode and local_player then
util.print_good({
@@ -198,7 +199,13 @@ function love.draw()
"voob "..tostring(camera.zoom),
"-",
"fps "..tostring(love.timer.getFPS()),
+ "-",
+ "sdf "..tostring(sdf_d)
+
},10,10)
+ love.graphics.setColor(0,1,0)
+ love.graphics.setLineWidth(5)
+ love.graphics.line(sm.x,sm.y, sm.x+50*sdf_gx, sm.y+50*sdf_gy)
end
end