diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/chunk.lua | 6 | ||||
-rw-r--r-- | client/drawing.lua | 3 | ||||
-rw-r--r-- | client/drawing2.lua | 19 | ||||
-rw-r--r-- | client/game.lua | 37 | ||||
-rw-r--r-- | client/main.lua | 3 | ||||
-rw-r--r-- | client/movement.lua | 10 | ||||
-rw-r--r-- | client/profile.lua | 5 | ||||
-rw-r--r-- | client/util.lua | 2 |
8 files changed, 57 insertions, 28 deletions
diff --git a/client/chunk.lua b/client/chunk.lua index 73fe949..f02277c 100644 --- a/client/chunk.lua +++ b/client/chunk.lua @@ -12,8 +12,10 @@ end local function tile_to_vattr(tile) -- for now tiles are always numbers -- so this just returns the input - -- this function might move to drawing.lua once it does something less trivial - assert(type(tile) == "number","can't send non-numerical tile to gpu") + -- this function might move to drawing.lua + -- once it does something less trivial + assert(type(tile) == "number", + "can't send non-numerical tile to gpu") return tile end function ChunkC.imesh_from_chunk_data(the_chunk) diff --git a/client/drawing.lua b/client/drawing.lua index e7cb45e..7e9b779 100644 --- a/client/drawing.lua +++ b/client/drawing.lua @@ -65,7 +65,8 @@ local function draw_hex(cpos,color,zoom) love.graphics.polygon("fill",_corners) if zoom > zthr0 then love.graphics.setLineWidth(0.1) - love.graphics.setColor(0,0,0,zoom>zthr1 and 1 or (zoom-zthr0)/(zthr1-zthr0)) + local a = zoom > zthr1 and 1 or (zoom-zthr0)/(zthr1-zthr0) + love.graphics.setColor(0,0,0, a) love.graphics.polygon("line",_corners) end end diff --git a/client/drawing2.lua b/client/drawing2.lua index c894e4c..800df78 100644 --- a/client/drawing2.lua +++ b/client/drawing2.lua @@ -21,8 +21,12 @@ do local function ve(n,f) return {cos(th(n)),sin(th(n)), f} end local function vi(n,f) return {ri*cos(th(n)),ri*sin(th(n)), f} end local function vo(n,f) return {ro*cos(th(n)),ro*sin(th(n)), f} end - local function apv(...) for _,x in ipairs({...}) do table.insert(vertices,x) end end - local function apm(...) for _,x in ipairs({...}) do table.insert(map,x) end end + local function apv(...) + for _,x in ipairs({...}) do table.insert(vertices,x) end + end + local function apm(...) + for _,x in ipairs({...}) do table.insert(map,x) end + end vertices[1] = {0,0, 1} for n=0,5 do apv(ve(n,1)) end @@ -88,7 +92,9 @@ vec4 position(mat4 transform_projection, vec4 vertex_position) { - vec2 instance_pos = vec2( floor(love_InstanceID/CHUNK_SIZE), mod(love_InstanceID, CHUNK_SIZE) ); + vec2 instance_pos = vec2( + floor(love_InstanceID/CHUNK_SIZE), + mod(love_InstanceID, CHUNK_SIZE) ); vertex_position.xy += hex_to_pos * instance_pos; float a = clamp( (zoom-zthr0)/zthrd, 0, 1); @@ -104,7 +110,8 @@ vec4 position(mat4 transform_projection, vec4 vertex_position) #pragma language glsl3 varying vec4 tcol; -vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) +vec4 effect(vec4 color, Image tex, + vec2 texture_coords, vec2 screen_coords) { // return vec4(tcol.xyz,0.5); return tcol; @@ -133,7 +140,9 @@ local function draw_map(camera,map) local tl = htl:to_pos() local br = hbr:to_pos() - if br.x < cam_tl.x or cam_br.x < tl.x or br.y < cam_tl.y or cam_br.y < tl.y then + if br.x < cam_tl.x or cam_br.x < tl.x + or br.y < cam_tl.y or cam_br.y < tl.y + then -- definitely not visible on screen -- this does not catch every single nonvisible chunk goto next diff --git a/client/game.lua b/client/game.lua index c5cdffb..2c259a6 100644 --- a/client/game.lua +++ b/client/game.lua @@ -115,6 +115,10 @@ local function draw_player(pl,islocal) love.graphics.setColor(0.5,0,0) love.graphics.circle("line",pl.pos.x,pl.pos.y,PLAYER_SIZE) end + + if pl.username then + util.print_good(pl.username, pl.pos.x, pl.pos.y) + end end local remote_players = {} @@ -122,7 +126,8 @@ local remote_players = {} local function update_local_player(pl,dt) local SPEED = 8*math.sqrt(3) -- 8 hexagonheights per second - if love.keyboard.isDown("lshift") or love.keyboard.isScancodeDown'kpenter' then + if love.keyboard.isDown("lshift") + or love.keyboard.isScancodeDown'kpenter' then SPEED = SPEED*2 end local function kd(codes) @@ -145,7 +150,10 @@ local function update_local_player(pl,dt) dy = dy * (math.sqrt(3)/2) end - local try_pos = Pos:make(pl.pos.x + SPEED*dt*dx, 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 = try_pos pl.pos_dirty = true @@ -180,7 +188,10 @@ local function handle_net() -- if op ~= "chunk" then print(ev.channel,ev.data) end if op == "join" then local pl = j.pl - remote_players[pl.id] = {pos=coords.Pos:make(pl.x,pl.y),color=pl.color,id=pl.id} + remote_players[pl.id] = { + pos=coords.Pos:make(pl.x,pl.y), + color=pl.color, id=pl.id + } msgbox.add(pl.id.." joined") elseif op == "leave" then local id = j.id @@ -193,7 +204,10 @@ local function handle_net() remote_players[id].pos.y = y elseif op == "you" then local pl = j.pl - local_player = {pos=coords.Pos:make(pl.x,pl.y),color=pl.color,id=pl.id} + local_player = { + pos=coords.Pos:make(pl.x,pl.y), + color=pl.color, id=pl.id, username=pl.username + } elseif op == "chunk" then local ch = ChunkC:from_packet_data(j) map:add_chunk(ch) @@ -217,7 +231,8 @@ local function update(dt) -- mouse input (place/mine) local msx,msy = love.mouse.getPosition() - local mh = camera:screen_to_world(Pos:make(msx,msy)):to_hex():round() + local mh = + camera:screen_to_world(Pos:make(msx,msy)):to_hex():round() if map:at(mh) == 0 and love.mouse.isDown(1) then map:set_at(mh,selected_tile) send_settile(mh,selected_tile) @@ -237,9 +252,10 @@ local function update(dt) end end -- unload chunks not near player - -- todo maybe: instead of immediately unloading chunks when we move away, - -- have some kind of 'last near' time, so that if player is moving back and forth, - -- we don't repeatedly unload and reload a given chunk + -- todo maybe: instead of immedately unloading chunks when we + -- move away, instead have some kind of 'last near' time, so + -- that if the player is moving back and forth, we don't + -- repeatedly unload and reload a given chunk. local to_remove = {} for cp in map:iter_chunks() do local d = player_cp:orth_dist(cp) @@ -305,7 +321,8 @@ local function draw() "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()), + "ph "..tostring(local_player.pos:to_hex()).." " + ..tostring(local_player.pos:to_hex():round()), "", "voob "..tostring(camera.zoom), "", @@ -374,8 +391,6 @@ function SCENE.load(_username) host = enet.host_create() peer = host:connect(SERVER_HOSTNAME..":8473",2) username = _username - print("got username",_username) - end function SCENE.quit() diff --git a/client/main.lua b/client/main.lua index 7388c67..f68ff79 100644 --- a/client/main.lua +++ b/client/main.lua @@ -27,7 +27,8 @@ function titlescene.draw() love.graphics.print("enter username: ",40,120) love.graphics.setColor(0,0,0,0.8) - love.graphics.rectangle('fill', 60,150, 3+normal_font:getWidth(username), 15) + love.graphics.rectangle('fill', 60,150, + 3+normal_font:getWidth(username), 15) love.graphics.setColor(1,1,1) love.graphics.print(username, 60, 150) diff --git a/client/movement.lua b/client/movement.lua index 2aa870b..5cc6b85 100644 --- a/client/movement.lua +++ b/client/movement.lua @@ -10,8 +10,6 @@ local function clamp(x,minv,maxv) return math.min(math.max(x,minv),maxv) end - - -- https://iquilezles.org/articles/distgradfunctions2d/ local function iqz_hex_sdgf(px,py, r) local kx,ky,kz = -0.866025404,0.5,0.577350269 @@ -42,7 +40,6 @@ local function iqz_hex_sdgf(px,py, r) end - -- rotate by 30 degrees local c30,s30 = math.cos(math.rad(30)), math.sin(math.rad(30)) local function t_in(x,y) return c30*x-s30*y, s30*x+c30*y end @@ -65,7 +62,8 @@ local function hex_sdgf(pos, hex) end local PLAYER_SIZE = require"common.constants".PLAYER_SIZE -local function collide_with_terrain(old_pos, try_pos, map, tries_remaining) +local function collide_with_terrain(old_pos, try_pos, map, + tries_remaining) tries_remaining = tries_remaining or 3 if tries_remaining <= 0 then return old_pos end local try_h = try_pos:to_hex():round() @@ -77,7 +75,9 @@ local function collide_with_terrain(old_pos, try_pos, map, tries_remaining) local push_dist = PLAYER_SIZE - d local push_dir = Pos:make(gx,gy) local new_try_pos = try_pos + (push_dist*push_dir) - return collide_with_terrain(old_pos,new_try_pos,map,tries_remaining-1) + return collide_with_terrain( + old_pos, new_try_pos, map, tries_remaining - 1 + ) end end end diff --git a/client/profile.lua b/client/profile.lua index 47a9806..5ed5b2a 100644 --- a/client/profile.lua +++ b/client/profile.lua @@ -1,7 +1,10 @@ local profile = require"jit.profile" local function start(period,file) local function cb(thread,samples,vmstate) - file:write(profile.dumpstack(thread,"pF;l;",-100), vmstate, " ", samples, "\n") + file:write( + profile.dumpstack(thread,"pF;l;",-100), + vmstate, " ", samples, "\n" + ) end profile.start("vli"..tonumber(period), cb) end diff --git a/client/util.lua b/client/util.lua index efeac31..2c7d90a 100644 --- a/client/util.lua +++ b/client/util.lua @@ -7,8 +7,6 @@ local function print_good(str,x,y) local W,H = love.graphics.getDimensions() if x == "center" then x = (W/2)-(w/2) end if y == "center" then y = (H/2)-(h/2) end - if x < 0 then x = W-w-(-x)+1 end - if y < 0 then y = H-h-(-y)+1 end love.graphics.setColor(0,0,0,0.8) love.graphics.rectangle("fill",x,y,w,h) love.graphics.setColor(1,1,1) |