summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-01-31 23:51:25 +0000
committerubq323 <ubq323@ubq323.website>2023-01-31 23:51:25 +0000
commit04664ee48de5fc8b06a584e20a4b75c41dafa558 (patch)
tree49192241d64897fb34f75a92dbab1e11d706fa22 /client
parent82c4e04fa6b27a1e9cb5469d7847aef80e5a22bd (diff)
add sending of tile changes, between players. server remembers all changes made. also add better debug screen
Diffstat (limited to 'client')
-rw-r--r--client/main.lua55
-rw-r--r--client/util.lua18
2 files changed, 56 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()
diff --git a/client/util.lua b/client/util.lua
new file mode 100644
index 0000000..1d9b753
--- /dev/null
+++ b/client/util.lua
@@ -0,0 +1,18 @@
+local font = love.graphics.getFont()
+local text = love.graphics.newText(font)
+
+local function print_good(lines,x,y)
+ for _,line in ipairs(lines) do
+ text:set(line)
+ local w,h = text:getDimensions()
+ love.graphics.setColor(0,0,0,0.6)
+ love.graphics.rectangle("fill",x,y,w,h)
+ love.graphics.setColor(1,1,1)
+ love.graphics.draw(text,x,y)
+ y = y + h
+ end
+end
+
+return {
+ print_good=print_good
+}