diff options
author | ubq323 <ubq323@ubq323.website> | 2025-06-10 11:05:42 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-06-10 11:05:42 +0100 |
commit | e7b9cbca4f71b04fb6dd9e05406aa9c5486a4ea8 (patch) | |
tree | fdf2ad61cc58032f35ac18aa1f621334a0270049 /client | |
parent | 6f45066de41001ed7c4d7e7b7db4b2e87b7ef3b3 (diff) |
more tiny things
Diffstat (limited to 'client')
-rw-r--r-- | client/game.lua | 45 | ||||
-rw-r--r-- | client/menu.lua | 2 |
2 files changed, 27 insertions, 20 deletions
diff --git a/client/game.lua b/client/game.lua index 59c5799..38fb1a8 100644 --- a/client/game.lua +++ b/client/game.lua @@ -1,13 +1,13 @@ local G = love.graphics local common = require 'common' local Camera = require'r.camera' -local Pos = require'r.pos' +local Pos = require"r.pos" local Rect = require'r.rect' local class = require'r.class' local enet = require'enet' -local pprint = require'pprint' local json = require'dkjson' local rle = require'r.rle' +local print_good = require'r.print_good' local M = {} @@ -24,6 +24,8 @@ local host, conn function M.load(_host,_conn,j) host=_host conn=_conn lp.pos=Pos(j.pos.x,j.pos.y) lp.name=j.name lp.color=j.color end +local show={ui=true,debug=false} + local directions = {w=Pos(0,-1),a=Pos(-1,0),s=Pos(0,1),d=Pos(1,0)} function M.keypressed(k,s,r) if directions[s] then @@ -31,7 +33,9 @@ function M.keypressed(k,s,r) else local tgt = lp.pos + directions[s] local val = not chunks:tile(tgt); chunks:set_tile(tgt,val) conn:send(json.encode{type='tile',pos=tgt,tile=val}) end - elseif s=='space' then cam.zoom = cam.zoom == 10 and 20 or 10 end end + elseif k=='space' then cam.zoom = cam.zoom == 10 and 20 or 10 + elseif k=='tab' then show.ui = not show.ui + elseif k=='f3' then show.debug = not show.debug end end function love.keyreleased(k,s) if s==lp.dir then lp.dir=nil end end function lp.update(dt) lp.movetimer = lp.movetimer - dt @@ -42,7 +46,7 @@ function lp.update(dt) lp.pos = newpos lp.movetimer = 1 / SPEED end end end local function draw_player(player,no_label) G.setColor(player.color) G.circle('fill',player.pos.x,player.pos.y,0.3) - if not no_label then local f = G.getFont() + if show.ui and not no_label then local f = G.getFont() local txtw,h = f:getWidth(player.name), f:getHeight() local centre = cam:world_to_screen(player.pos-Pos(0,.4))-Pos(0,h/2) local bb = Rect:from_centre_dims(centre,txtw,h) @@ -53,7 +57,6 @@ function lp.draw() draw_player(lp,true) end function M.update(dt) lp.update(dt) local ev = host and host:service() while ev do - -- pprint(ev) if ev.type == 'receive' then local j = json.decode(ev.data) local pos if j.pos then pos = Pos(j.pos.x,j.pos.y) end if j.type == 'player' then players[j.name] = {name=j.name,pos=pos,color=j.color} @@ -77,19 +80,25 @@ function M.draw() local t = chunks:tile(Pos(x,y)) if t ~= nil then G.setColor(colors[t~=(x<0)]) G.rectangle('fill',x-0.5,y-0.5,1,1) end end end lp.draw() - for _,player in pairs(players) do draw_player(player) end - -- G.origin() G.setColor(1,0,0) - -- G.print(tostring(lp.pos),100,100) - -- G.setColor(0,0,0,0.8) - -- G.rectangle('fill',0,0,100,100) - -- G.setColor(1,1,1) - -- for cx=-7,7 do for cy=-7,7 do local p=Pos(cx,cy) if chunks:get(p) then - -- p = (p + Pos(7,7))*10 - -- G.setColor(1,1,1) G.rectangle('fill',p.x,p.y,10,10) - -- G.setColor(0,0,1) G.rectangle('line',p.x,p.y,10,10) - -- end end end - -- local p = (lp.pos/common.SIZE+Pos(7,7))*10 - -- G.setColor(1,0,0) G.rectangle('fill',p.x-1,p.y-1,2,2) + local playernames = {} + for _,player in pairs(players) do draw_player(player) table.insert(playernames,player.name) end + table.sort(playernames) playernames = table.concat(playernames,'\n') + G.origin() + if show.ui then print_good(playernames,0,0) end + if show.debug then + G.setColor(1,0,0) + G.print(tostring(lp.pos),100,100) + G.setColor(0,0,0,0.8) + G.rectangle('fill',0,0,100,100) + G.setColor(1,1,1) + for cx=-7,7 do for cy=-7,7 do local p=Pos(cx,cy) if chunks:get(p) then + p = (p + Pos(7,7))*10 + G.setColor(1,1,1) G.rectangle('fill',p.x,p.y,10,10) + G.setColor(0,0,1) G.rectangle('line',p.x,p.y,10,10) + end end end + local p = (lp.pos/common.SIZE+Pos(7,7))*10 + G.setColor(1,0,0) G.rectangle('fill',p.x-1,p.y-1,2,2) + end end return M diff --git a/client/menu.lua b/client/menu.lua index a6eccfb..c447e7d 100644 --- a/client/menu.lua +++ b/client/menu.lua @@ -5,7 +5,6 @@ local G = love.graphics local utf8 = require'utf8' local enet = require'enet' local json = require'dkjson' -local pprint = require'pprint' local qw = require'r.qw' local logo = G.newImage"logo.png" logo:setFilter'nearest' @@ -97,7 +96,6 @@ end function love.update(dt) local ev = host and host:service() while ev do - pprint(ev) if ev.type == 'receive' then local j = json.decode(ev.data) if j.type == 'you' then switch_scene('game',host,conn,j) return elseif j.type == 'error' then print('hi') state.errmsg = j.msg conn:disconnect_later() ConnectButton:unclick() |