diff options
Diffstat (limited to 'client/game.lua')
-rw-r--r-- | client/game.lua | 37 |
1 files changed, 26 insertions, 11 deletions
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() |