summaryrefslogtreecommitdiff
path: root/client/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.lua')
-rw-r--r--client/main.lua55
1 files changed, 38 insertions, 17 deletions
diff --git a/client/main.lua b/client/main.lua
index 819753f..6572621 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -12,6 +12,7 @@ local coords = require"common.coords"
local Pos = coords.Pos
local camera = require"camera".Camera.make()
local Chunk = require"common.chunk".Chunk
+local util = require"util"
-- local pprint=require"common.pprint"
-- pprint.setup{show_all=true}
@@ -23,6 +24,12 @@ local host,peer
local chunk
+local f3mode = true
+
+function love.keypressed(key,scancode,isrepeat)
+ if scancode == "f3" then f3mode = not f3mode end
+end
+
local function draw_player(pl,islocal)
local hplsz = PLAYER_SIZE/2
love.graphics.setColor(pl.color)
@@ -69,6 +76,10 @@ local function sync_local_player(pl,peer)
end
end
+local function send_settile(hpos,tile)
+ peer:send(json.encode{t="settile",q=hpos.q,r=hpos.r,tile=tile})
+end
+
function love.update(dt)
if local_player then
update_local_player(local_player,dt)
@@ -76,6 +87,19 @@ function love.update(dt)
if love.keyboard.isScancodeDown"e" then camera.zoom = camera.zoom/1.05 end
sync_local_player(local_player,peer)
end
+ if chunk then
+ local mh = camera:screen_to_world(Pos.make(love.mouse.getPosition())):to_hex():round()
+ if false== chunk:at(mh) and love.mouse.isDown(1) then
+ chunk:set_at(mh,true)
+ print(mh,true)
+ send_settile(mh,true)
+ elseif chunk:at(mh) and love.mouse.isDown(2) then
+ chunk:set_at(mh,false)
+ print(mh,false)
+ send_settile(mh,false)
+ end
+ end
+
repeat
local ev = host:service()
if ev and ev.type == "receive" then
@@ -98,6 +122,9 @@ function love.update(dt)
local_player = {pos=coords.Pos.make(pl.x,pl.y),color=pl.color,id=pl.id}
elseif op == "chunk" then
chunk = Chunk.from_packet_data(j)
+ elseif op == "settile" then
+ local h = coords.Hex.make(j.q,j.r)
+ chunk:set_at(h,j.tile)
end
end
until not ev
@@ -127,25 +154,19 @@ function love.draw()
local sm = Pos.make(love.mouse.getPosition())
local wm = camera:screen_to_world(sm)
- local hm = wm:to_hex():round()
-
- local tl,br = camera:extents()
+ local hm = wm:to_hex()
love.graphics.origin()
- love.graphics.scale(2)
- love.graphics.setColor(0,0,0)
- love.graphics.print(table.concat(
- {"sm "..tostring(sm),
- "wm "..tostring(wm),
- "hm "..tostring(hm),
- "",
- "tl "..tostring(tl),
- "br "..tostring(br)},
- "\n"),10,10)
-
-
-
-
+ if f3mode and local_player then
+ util.print_good({
+ "ms "..tostring(sm),
+ "mw "..tostring(wm),
+ "mh "..tostring(hm).." "..tostring(hm:round()),
+ "-",
+ "pw "..tostring(local_player.pos),
+ "ph "..tostring(local_player.pos:to_hex()).." "..tostring(local_player.pos:to_hex():round())
+ },10,10)
+ end
end
function love.load()