Skip to content

Commit

Permalink
rework to work with variable resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Jan 5, 2014
1 parent 208698e commit 3d4d88c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 55 deletions.
1 change: 1 addition & 0 deletions conf.lua
@@ -1,4 +1,5 @@
function love.conf(t)
t.title = "hexoboros"
t.author = "stick"
t.window.resizable = true
end
4 changes: 2 additions & 2 deletions hexhelper.lua
Expand Up @@ -7,15 +7,15 @@ end

function hexx(i, j)
if hex_valid(i, j) then
return 512 + 74*(i-5)
return width / 2 + 74 * (i-5) * scale
else
return nil
end
end

function hexy(i, j)
if hex_valid(i, j) then
return 352 + j*82 - hexcnts[i]*41
return height * 0.445 + (j * 82 - hexcnts[i]*41) * scale
else
return nil
end
Expand Down
15 changes: 6 additions & 9 deletions level.lua
Expand Up @@ -57,8 +57,7 @@ function Level:draw()
px = px + math.random(0,6*self.winning*self.winning)
py = py + math.random(0,6*self.winning*self.winning)
end
love.graphics.draw(img['hex'], px, py, 0, 1, 1, 48, 48)
-- love.graphics.print(i..','..j, px+8, py+22)
love.graphics.draw(img['hex'], px, py, 0, scale, scale, 48, 48)
end
end
end
Expand All @@ -68,7 +67,7 @@ function Level:draw()
for k = 1, # t do
local tx = hexx(t[k][1], t[k][2])
local ty = hexy(t[k][1], t[k][2])
love.graphics.draw(img['hex-light'], tx, ty, 0, 1, 1, 64, 64)
love.graphics.draw(img['hex-light'], tx, ty, 0, scale, scale, 64, 64)
end
end

Expand All @@ -91,8 +90,8 @@ function Level:draw()
love.graphics.setColor(255, 255, 255, 255)

love.graphics.print('Level: ' .. self.title, 10, 10)
love.graphics.draw(img['hex'], 1024-48, 48, 0, 1, 1, 48, 48)
love.graphics.printf('Menu', 1024-48, 48-5, 0, 'center')
love.graphics.draw(img['hex'], width-48 * scale, 48 * scale, 0, scale, scale, 48, 48)
love.graphics.printf('Menu', width-48 * scale, (48 - 5) * scale, 0, 'center')

end

Expand All @@ -101,7 +100,7 @@ function Level:click(x, y, button)
return
end
-- menu clicked
if x > 940 and y < 88 then
if x > width - 88 * scale and y < 88 * scale then
gamestate = 'intro'
level = nil
return
Expand All @@ -113,7 +112,7 @@ function Level:click(x, y, button)
for j = 1, hexcnts[i] do
rx = hexx(i,j)
ry = hexy(i,j)
if rx and ry and math.abs(rx-x) < 40 and math.abs(ry-y) < 40 then
if rx and ry and math.abs(rx-x) < 40 * scale and math.abs(ry-y) < 40 * scale then
ci = i
cj = j
end
Expand Down Expand Up @@ -207,8 +206,6 @@ function Level:update()
end
if self.winning > 1.0 then
particles:setColors(8, 246, 255, 0, 255, 255, 255, 128)
-- gamestate = 'chooser'
-- level = nil
level = Level:new(nil)
gamestate = 'level'
end
Expand Down
55 changes: 16 additions & 39 deletions main.lua
@@ -1,7 +1,13 @@
require 'level'

function love.resize(w, h)
width, height = love.window.getDimensions()
scale = height * 4 / 3 / 1024
end

function love.load()
love.window.setMode(1024, 768, {fullscreen=false})

love.resize(love.window.getWidth(), love.window.getHeight())

img = {}
img['fire'] = love.graphics.newImage('images/fire.png')
Expand All @@ -17,7 +23,7 @@ function love.load()
font = love.graphics.newFont('images/cs_regular.ttf', 22)

particles = love.graphics.newParticleSystem(img['fire'], 200)
particles:setPosition(512, 384)
particles:setPosition(width / 2, height / 2)
particles:setOffset(0, 0)
particles:setBufferSize(1000)
particles:setEmissionRate(200)
Expand Down Expand Up @@ -46,8 +52,6 @@ function love.update(dt)
particles:update(dt)
if gamestate == 'intro' then
-- nothing
elseif gamestate == 'chooser' then
-- nothing
else -- level
level:update()
end
Expand All @@ -56,53 +60,30 @@ end
function love.draw()
love.graphics.draw(particles, 0, 0)
if gamestate == 'intro' then
love.graphics.draw(img['intro'], 0, 0)
love.graphics.draw(img['hex'], 256, 576, 0, 1, 1, 48, 48)
love.graphics.draw(img['hex'], 768, 576, 0, 1, 1, 48, 48)
love.graphics.draw(img['intro'], width / 2, height / 2, 0, scale, scale, 512, 384)
love.graphics.draw(img['hex'], width / 4, height * 0.75, 0, scale, scale, 48, 48)
love.graphics.draw(img['hex'], width * 0.75, height * 0.75, 0, scale, scale, 48, 48)
love.graphics.setFont(font)
love.graphics.printf('Play', 258, 571, 0, 'center')
love.graphics.printf('Exit', 770, 571, 0, 'center')
elseif gamestate == 'chooser' then
for i = 1, 10 do
for j = 1, 8 do
love.graphics.draw(img['hex'], 93.1*i, 85.3*j, 0, 1, 1, 48, 48)
love.graphics.printf(i+j*10-10, 93.1*i+2, 85.3*j-3, 0, 'center')
end
end
love.graphics.printf('Play', width / 4, height * 0.75 - 5 * scale, 0, 'center')
love.graphics.printf('Exit', width * 0.75, height * 0.75 - 5 * scale, 0, 'center')
else -- level
level:draw()
end
end

function love.mousepressed(x, y, button)
if gamestate == 'intro' then
if math.abs(y-560) < 40 then
if math.abs(x-256) < 40 then
if math.abs(y - height * 0.75) < 40 then
if math.abs(x - width / 4) < 40 then
love.audio.play(snd['click'])
-- gamestate = 'chooser'
-- generate random level instead of level chooser for now
gamestate = 'level'
level = Level:new(nil)
end
if math.abs(x-768) < 40 then
if math.abs(x- width * 0.75) < 40 then
love.audio.play(snd['click'])
love.event.push('quit')
end
end
elseif gamestate == 'chooser' then
local lvlnum = 0
for i = 1, 10 do
for j = 1, 8 do
if math.abs(x-93.1*i) < 40 and math.abs(y-85.3*j) < 40 then
lvlnum = i+j*10-10
end
end
end
if lvlnum > 0 then
level = Level:new(lvlnum)
gamestate = 'level'
love.audio.play(snd['click'])
end
else -- level
level:click(x, y, button)
end
Expand All @@ -113,10 +94,6 @@ function love.keypressed(key, unicode)
if key == 'escape' then
love.event.push('quit')
end
elseif gamestate == 'chooser' then
if key == 'escape' then
gamestate = 'intro'
end
else -- level
if key == 'escape' then
gamestate = 'intro'
Expand Down
10 changes: 5 additions & 5 deletions snake.lua
Expand Up @@ -51,10 +51,10 @@ function Snake:draw_head(winning)
end
rx = rx + math.random(0,8*winning*winning)
ry = ry + math.random(0,8*winning*winning)
love.graphics.draw(img['fire'], rx, ry, 0, 2, 2, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2, 2, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2, 2, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2, 2, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2 * scale, 2 * scale, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2 * scale, 2 * scale, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2 * scale, 2 * scale, 16, 16)
love.graphics.draw(img['fire'], rx, ry, 0, 2 * scale, 2 * scale, 16, 16)
love.graphics.setColor(255, 255, 255, 255)
end

Expand Down Expand Up @@ -114,7 +114,7 @@ function Snake:draw(winning)
end
local tx = lx+(rx-lx)/16*i + math.random(0,8*winning*winning)
local ty = ly+(ry-ly)/16*i + math.random(0,8*winning*winning)
love.graphics.draw(img['fire'], tx, ty, 0, 1, 1, 16, 16)
love.graphics.draw(img['fire'], tx, ty, 0, scale, scale, 16, 16)
love.graphics.setColor(rgba)
blink = blink + 1
end
Expand Down

0 comments on commit 3d4d88c

Please sign in to comment.