Game window can be resized in the menu (and in the game, but the ground won't resize)
This commit is contained in:
parent
d0cb00bfa3
commit
d70107214a
6 changed files with 53 additions and 20 deletions
6
conf.lua
6
conf.lua
|
@ -3,9 +3,9 @@ require 'settings'
|
||||||
|
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
t.window.title = "Fysplane"
|
t.window.title = "Fysplane"
|
||||||
t.window.width = WIDTH
|
t.window.width = INITIAL_WIDTH
|
||||||
t.window.height = HEIGHT
|
t.window.height = INITIAL_HEIGHT
|
||||||
t.window.resizable = false
|
t.window.resizable = true
|
||||||
t.window.vsync = true
|
t.window.vsync = true
|
||||||
|
|
||||||
-- LÖVE version
|
-- LÖVE version
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
Class = require 'hump.class'
|
Class = require 'hump.class'
|
||||||
require 'entities/rectangle'
|
require 'entities/rectangle'
|
||||||
|
require 'utils'
|
||||||
|
|
||||||
Ground = Class{
|
Ground = Class{
|
||||||
__includes = Rectangle,
|
__includes = Rectangle,
|
||||||
|
@ -7,10 +8,15 @@ Ground = Class{
|
||||||
init = function(self, level)
|
init = function(self, level)
|
||||||
local groundImg = love.graphics.newImage('resources/graphics/ground.png')
|
local groundImg = love.graphics.newImage('resources/graphics/ground.png')
|
||||||
Rectangle.init(self,
|
Rectangle.init(self,
|
||||||
(love.window.getWidth() - 1600) / 2, love.window.getHeight(),
|
-200, levelHeight(),
|
||||||
level, "static",
|
level, "static",
|
||||||
0, 1600, 20, 0, groundImg)
|
0,
|
||||||
|
levelWidth() + 400, 20, 0, groundImg)
|
||||||
self.fixture:setRestitution(0)
|
self.fixture:setRestitution(0)
|
||||||
self.fixture:setFriction(0.5)
|
self.fixture:setFriction(0.5)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
update = function(self, dt)
|
||||||
|
self.body:setY(levelHeight() - 10)
|
||||||
|
end;
|
||||||
}
|
}
|
||||||
|
|
34
level.lua
34
level.lua
|
@ -19,12 +19,8 @@ Level = Class{
|
||||||
self.world = love.physics.newWorld(GRAVITY_X, GRAVITY_Y, true)
|
self.world = love.physics.newWorld(GRAVITY_X, GRAVITY_Y, true)
|
||||||
|
|
||||||
-- Draw background to canvas so we don't redraw it every time
|
-- Draw background to canvas so we don't redraw it every time
|
||||||
self.background = love.graphics.newImage('resources/graphics/sky.png')
|
self.oldWidth, self.oldHeight = 0, 0
|
||||||
self.bgCanvas = love.graphics.newCanvas()
|
self:updateBackground()
|
||||||
love.graphics.setCanvas(self.bgCanvas)
|
|
||||||
love.graphics.setColor(255, 255, 255, 255)
|
|
||||||
love.graphics.draw(self.background)
|
|
||||||
love.graphics.setCanvas()
|
|
||||||
|
|
||||||
self.makePlanes = { [1] = function()
|
self.makePlanes = { [1] = function()
|
||||||
return Plane(100, 400, INITIAL_PLANE_SPEED, 0,
|
return Plane(100, 400, INITIAL_PLANE_SPEED, 0,
|
||||||
|
@ -32,16 +28,33 @@ Level = Class{
|
||||||
self)
|
self)
|
||||||
end,
|
end,
|
||||||
[2] = function()
|
[2] = function()
|
||||||
return Plane(WIDTH - 100 - 100, 300, -INITIAL_PLANE_SPEED, 0,
|
return Plane(levelWidth() - 100 - 100, 300, -INITIAL_PLANE_SPEED, 0,
|
||||||
0, 255, 0, -- green
|
0, 255, 0, -- green
|
||||||
self)
|
self)
|
||||||
end }
|
end }
|
||||||
|
|
||||||
self.planes = { [1] = self.makePlanes[1](),
|
self.planes = { [1] = self.makePlanes[1](),
|
||||||
[2] = self.makePlanes[2]() }
|
[2] = self.makePlanes[2]() }
|
||||||
|
|
||||||
Ground(self);
|
Ground(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
updateBackground = function(self)
|
||||||
|
local w, h = levelWidth(), levelHeight()
|
||||||
|
if w ~= self.oldWidth or h ~= self.oldHeight then
|
||||||
|
local background = love.graphics.newImage('resources/graphics/sky.png')
|
||||||
|
self.bgCanvas = love.graphics.newCanvas()
|
||||||
|
love.graphics.setCanvas(self.bgCanvas)
|
||||||
|
love.graphics.setColor(255, 255, 255, 255)
|
||||||
|
love.graphics.draw(background, 0, 0, 0,
|
||||||
|
levelWidth() / background:getWidth(),
|
||||||
|
levelHeight() / background:getHeight())
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
|
||||||
|
self.oldWidth, self.oldHeight = w, h
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
respawnPlayer = function(self, playerIdx)
|
respawnPlayer = function(self, playerIdx)
|
||||||
self.planes[playerIdx] = self.makePlanes[playerIdx]()
|
self.planes[playerIdx] = self.makePlanes[playerIdx]()
|
||||||
end;
|
end;
|
||||||
|
@ -70,6 +83,7 @@ Level = Class{
|
||||||
end;
|
end;
|
||||||
|
|
||||||
drawBackground = function(self)
|
drawBackground = function(self)
|
||||||
|
self:updateBackground()
|
||||||
love.graphics.setColor(draw_base_color)
|
love.graphics.setColor(draw_base_color)
|
||||||
love.graphics.draw(self.bgCanvas)
|
love.graphics.draw(self.bgCanvas)
|
||||||
end;
|
end;
|
||||||
|
@ -81,11 +95,11 @@ Level = Class{
|
||||||
if entity:isinstance(PhysicsEntity) then
|
if entity:isinstance(PhysicsEntity) then
|
||||||
local jump_window = 70
|
local jump_window = 70
|
||||||
local jump_amount = 50
|
local jump_amount = 50
|
||||||
while entity.body:getX() > WIDTH + jump_window do
|
while entity.body:getX() > levelWidth() + jump_window do
|
||||||
entity.body:setX(entity.body:getX() - WIDTH - jump_window - jump_amount)
|
entity.body:setX(entity.body:getX() - levelWidth() - jump_window - jump_amount)
|
||||||
end
|
end
|
||||||
while entity.body:getX() < -jump_window do
|
while entity.body:getX() < -jump_window do
|
||||||
entity.body:setX(entity.body:getX() + WIDTH + jump_window + jump_amount)
|
entity.body:setX(entity.body:getX() + levelWidth() + jump_window + jump_amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
entity:update(dt)
|
entity:update(dt)
|
||||||
|
|
|
@ -150,8 +150,8 @@ function level_state:update(dt)
|
||||||
local r = love.math.random()
|
local r = love.math.random()
|
||||||
|
|
||||||
if r <= POWERUP_POSSIBILITY * dt then
|
if r <= POWERUP_POSSIBILITY * dt then
|
||||||
local x = love.math.random(WIDTH)
|
local x = love.math.random(levelWidth())
|
||||||
local y = love.math.random(HEIGHT)
|
local y = love.math.random(levelHeight())
|
||||||
|
|
||||||
POWERUPS[love.math.random(1, #POWERUPS)](x, y, current_level)
|
POWERUPS[love.math.random(1, #POWERUPS)](x, y, current_level)
|
||||||
end
|
end
|
||||||
|
|
|
@ -144,7 +144,10 @@ end
|
||||||
|
|
||||||
function menu_state:draw()
|
function menu_state:draw()
|
||||||
love.graphics.setColor(128, 128, 128, 255)
|
love.graphics.setColor(128, 128, 128, 255)
|
||||||
love.graphics.draw(background)
|
love.graphics.draw(background, 0, 0, 0,
|
||||||
|
levelWidth() / background:getWidth(),
|
||||||
|
levelHeight() / background:getHeight())
|
||||||
|
|
||||||
|
|
||||||
local seconds, subseconds = math.modf(menuTime)
|
local seconds, subseconds = math.modf(menuTime)
|
||||||
|
|
||||||
|
|
14
settings.lua
14
settings.lua
|
@ -8,8 +8,8 @@ PIXELS_PER_METER = 8
|
||||||
GRAVITY_X = 0
|
GRAVITY_X = 0
|
||||||
GRAVITY_Y = 9.82599 * PIXELS_PER_METER
|
GRAVITY_Y = 9.82599 * PIXELS_PER_METER
|
||||||
|
|
||||||
WIDTH = 1280
|
INITIAL_WIDTH = 1280
|
||||||
HEIGHT = 768
|
INITIAL_HEIGHT = 768
|
||||||
|
|
||||||
KEYMAP = {
|
KEYMAP = {
|
||||||
[1] = {
|
[1] = {
|
||||||
|
@ -57,6 +57,16 @@ if love.filesystem.isFile("fysplane.cfg") then
|
||||||
AXISMAP = m.AXISMAP
|
AXISMAP = m.AXISMAP
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function levelWidth()
|
||||||
|
local width, height = love.window.getMode()
|
||||||
|
return width
|
||||||
|
end
|
||||||
|
|
||||||
|
function levelHeight()
|
||||||
|
local width, height = love.window.getMode()
|
||||||
|
return height
|
||||||
|
end
|
||||||
|
|
||||||
PLANE_HEALTH = 200
|
PLANE_HEALTH = 200
|
||||||
PLANE_DEFAULT_GUN = "vickers77"
|
PLANE_DEFAULT_GUN = "vickers77"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue