summaryrefslogtreecommitdiff
path: root/client/main.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-01-27 21:53:57 +0000
committerubq323 <ubq323@ubq323.website>2023-01-27 22:03:22 +0000
commit9fff52daa2df79133a29ff94d340bdaf406eb514 (patch)
treeab695c761cd325c76a9607dcba7c5f750e9910fd /client/main.lua
parentd0916d568a00f5171b96fbc3bfc19ff263affc27 (diff)
multitudinous things
Diffstat (limited to 'client/main.lua')
-rw-r--r--client/main.lua64
1 files changed, 38 insertions, 26 deletions
diff --git a/client/main.lua b/client/main.lua
index b5d322e..3d7a598 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -1,40 +1,42 @@
local enet = require"enet"
local words = require"common.words"
-local SERVER_HOSTNAME = "ubq323.website"
-local PLAYER_SIZE = 30
+-- local SERVER_HOSTNAME = "ubq323.website"
+local SERVER_HOSTNAME = "localhost"
+local PLAYER_SIZE = 0.7
local local_player = nil
+local drawing = require"drawing"
+local coords = require"common.coords"
+local camera = require"camera".Camera.make()
-math.randomseed(os.time())
+-- local pprint=require"common.pprint"
+-- pprint.setup{show_all=true}
--- {
--- pos={100,100},
--- color={love.math.colorFromBytes(0xdf,0x73,0xff)},
--- }
-local host,peer
+math.randomseed(os.time())
+local host,peer
local chunk = require"common.chunk".Chunk.make()
-local function draw_player(pl,me)
+local function draw_player(pl,islocal)
local hplsz = PLAYER_SIZE/2
love.graphics.setColor(pl.color)
- love.graphics.rectangle("fill",pl.pos[1]-hplsz,pl.pos[2]-hplsz,PLAYER_SIZE,PLAYER_SIZE)
- love.graphics.setColor(0,0,0)
- love.graphics.print(tostring(pl.id),pl.pos[1],pl.pos[2])
- if me then
- love.graphics.setColor(1,1,1)
- love.graphics.rectangle("line",pl.pos[1]-hplsz,pl.pos[2]-hplsz,PLAYER_SIZE,PLAYER_SIZE)
+ love.graphics.rectangle("fill",pl.pos.x-hplsz,pl.pos.y-hplsz,PLAYER_SIZE,PLAYER_SIZE)
+ -- love.graphics.print(tostring(pl.id),pl.pos.x,pl.pos.y)
+ if islocal then
+ love.graphics.setLineWidth(0.01)
+ love.graphics.setColor(0.5,0,0)
+ love.graphics.rectangle("line",pl.pos.x-hplsz,pl.pos.y-hplsz,PLAYER_SIZE,PLAYER_SIZE)
end
end
local remote_players = {}
local function update_local_player(pl,dt)
- local SPEED = 300 -- pixels/sec
+ local SPEED = 10 -- pixels/sec
local function kd(code)
if love.keyboard.isScancodeDown(code) then return 1 else return 0 end
end
@@ -51,21 +53,25 @@ local function update_local_player(pl,dt)
dy = dy / math.sqrt(2)
end
- pl.pos[1] = pl.pos[1] + SPEED * dt * dx
- pl.pos[2] = pl.pos[2] + SPEED * dt * dy
+ pl.pos.x = pl.pos.x + SPEED * dt * dx
+ pl.pos.y = pl.pos.y + SPEED * dt * dy
pl.pos_dirty = true
+
+
end
local function sync_local_player(pl,peer)
-- send updated info about local player to server
if pl.pos_dirty then
- peer:send(words.join("ppos",pl.pos[1],pl.pos[2]))
+ peer:send(words.join("ppos",pl.pos.x,pl.pos.y))
end
end
function love.update(dt)
if local_player then
update_local_player(local_player,dt)
+ if love.keyboard.isScancodeDown"q" then camera.zoom = camera.zoom*1.05 end
+ if love.keyboard.isScancodeDown"e" then camera.zoom = camera.zoom/1.05 end
sync_local_player(local_player,peer)
end
repeat
@@ -82,7 +88,7 @@ function love.update(dt)
r=tonumber(r)
g=tonumber(g)
b=tonumber(b)
- remote_players[id] = {pos={x,y},color={r,g,b},id=id}
+ remote_players[id] = {pos=coords.Pos.make(x,y),color={r,g,b},id=id}
elseif op == "leave" then
local id = tonumber(w[2])
remote_players[id]=nil
@@ -92,8 +98,8 @@ function love.update(dt)
x=tonumber(x)
y=tonumber(y)
assert(remote_players[id],"wheeze")
- remote_players[id].pos[1] = x
- remote_players[id].pos[2] = y
+ remote_players[id].pos.x = x
+ remote_players[id].pos.y = y
elseif op == "you" then
local id,x,y,r,g,b = unpack(w,2)
id=tonumber(id)
@@ -102,7 +108,7 @@ function love.update(dt)
r=tonumber(r)
g=tonumber(g)
b=tonumber(b)
- local_player = {pos={x,y},color={r,g,b},id=id}
+ local_player = {pos=coords.Pos.make(x,y),color={r,g,b},id=id}
end
end
until not ev
@@ -110,6 +116,14 @@ end
function love.draw()
love.graphics.clear(1,1,1)
+ love.graphics.origin()
+ if local_player then
+ camera.pos = local_player.pos
+ end
+ camera:apply_trans()
+
+ drawing.draw_chunk(chunk)
+
if local_player then
draw_player(local_player,true)
end
@@ -117,12 +131,10 @@ function love.draw()
draw_player(pl)
end
- -- require"drawing".drawhex({x=200,y=200},40)
- require"drawing".draw_chunk(chunk)
-
end
function love.load()
+ -- require"profile".start(10,io.open("./trace","w"))
host = enet.host_create()
peer = host:connect(SERVER_HOSTNAME..":8473")
end