diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/camera.lua | 23 | ||||
| -rw-r--r-- | client/conf.lua | 2 | ||||
| -rw-r--r-- | client/main.lua | 24 | 
3 files changed, 22 insertions, 27 deletions
diff --git a/client/camera.lua b/client/camera.lua index bb1d8a6..d4d7901 100644 --- a/client/camera.lua +++ b/client/camera.lua @@ -2,7 +2,6 @@ local coords = require"common.coords"  local class = require"common.class"  -- in screen units -local screen_width, screen_height = love.graphics.getDimensions()  -- zoom is screen pixels per world unit  local Camera = class() @@ -11,28 +10,36 @@ function Camera.make(cls,pos,zoom)  	zoom = zoom or 30  	return setmetatable({pos=pos,zoom=zoom},cls)  end +local function screen_offset() +	-- in screen units, not in world units ! +	local W,H = love.graphics.getDimensions() +	return coords.Pos:make(W/2,H/2) +end  function Camera.apply_trans(self) -	-- love.graphics.origin() +	local so = screen_offset() +  	-- centre (0,0) in the middle of the screen -	love.graphics.translate(screen_width/2,screen_height/2) -	-- apply camera transformations +	love.graphics.translate(so.x,so.y) +	-- apply camera transformations  	love.graphics.scale(self.zoom)  	love.graphics.translate(-self.pos.x,-self.pos.y)  end -local screen_offset = coords.Pos:make(screen_width/2,screen_height/2)  function Camera.screen_to_world(self,pos) -	return (pos-screen_offset)/self.zoom + self.pos +	local so = screen_offset() +	return (pos-so)/self.zoom + self.pos  end  function Camera.world_to_screen(self,pos) -	return (pos-self.pos) * self.zoom + screen_offset +	local so = screen_offset() +	return (pos-self.pos) * self.zoom + so  end  function Camera.extents(self) +	local W,H = love.graphics.getDimensions()  	-- returns top left and bottom right pos's in world coords  	return self:screen_to_world(coords.Pos:make(0,0)), -			self:screen_to_world(coords.Pos:make(screen_width,screen_height)) +			self:screen_to_world(coords.Pos:make(W,H))  end diff --git a/client/conf.lua b/client/conf.lua index e207e09..76459ff 100644 --- a/client/conf.lua +++ b/client/conf.lua @@ -1,3 +1,5 @@  function love.conf(t)  	t.window.title = "hexagon emulator" +	t.window.resizable = true +  end diff --git a/client/main.lua b/client/main.lua index 9de4290..a6cc4b6 100644 --- a/client/main.lua +++ b/client/main.lua @@ -34,7 +34,6 @@ mousewheel: zoom in/out  F1: show/hide this help  F3: show/hide debug -F11: toggle "big mode" (bad)  enter: toggle chat]] @@ -62,18 +61,8 @@ local show_controls = false  local this_chatmsg = ""  local chatmsg_text = love.graphics.newText(love.graphics.getFont()) -local big_mode = false -local orig_w,orig_h = love.graphics.getDimensions()  function love.keypressed(key,scancode,isrepeat) -	if key == "f11" then -		big_mode = not big_mode -		if big_mode then -			love.window.setMode(orig_w*2,orig_h*2) -		else -			love.window.setMode(orig_w,orig_h) -		end -	end  	if ui_mode == "normal" then  		if key == "f3" then _G.debugmode = not _G.debugmode end  		if key == "f1" then show_controls = not show_controls end @@ -174,7 +163,6 @@ function love.update(dt)  		-- mouse input  		local msx,msy = love.mouse.getPosition() -		if big_mode then msx,msy = msx/2,msy/2 end  		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) @@ -251,7 +239,6 @@ end  function love.draw()  	love.graphics.clear(1,1,1)  	love.graphics.origin() -	if big_mode then love.graphics.scale(2) end  	if local_player then  		camera.pos = local_player.pos  	end @@ -274,23 +261,22 @@ function love.draw()  	local hm = wm:to_hex()  	love.graphics.origin() -	if big_mode then love.graphics.scale(2) end  	util.print_good(tostring(selected_tile), 400,10)  	if _G.debugmode and local_player then -		util.print_good({ +		util.print_good(table.concat({  			 "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()), -			 "-", +			 "",  			 "voob "..tostring(camera.zoom), -			 "-", +			 "",  			 "fps "..tostring(love.timer.getFPS()),  			 "ping "..tostring(peer:round_trip_time()), -		 },10,10) +		 },"\n"),10,10)  	 end  	 if show_controls then  		 util.print_good(help_text,300,200)  | 
