Code: Select all
level_test.collision = {
c = {x = 0, y = 3 , width = 10, height = 3}, c = {x = 0, y = 10, width = 10 , height = 2 }
}
Code: Select all
require "src/player"
require "src/gradient"
require "src/cloud"
require "src/menu"
require "src/level"
require "levelMaps/level_test"
function love.load()
world = love.physics.newWorld(0, 0)
world:setCallbacks(beginCon, endCon)
virtual_width = 1280 / 4
virtual_height = 780 / 4
window_width = virtual_width * 2
window_height = virtual_height * 2
love.window.setMode(window_width, window_height)
love.graphics.setDefaultFilter("nearest", "nearest")
menu = menu.new({{x = virtual_width / 2 - 30 / 2, y = virtual_height / 3 - 15 /2, width = 30, height = 15, selected = false, screen = "gamePlay"}, {x = virtual_width / 2 - 30 / 2, y = virtual_height / 1.5 - 15/2, width = 30, height = 15, selected = false, screen = "options"} }, {0.8, 1, 0.3, 1})
p = Player.new(0, 0)
g = gradient.new()
Clouds = {}
img = love.graphics.newImage("art/spritesheet.png")
cloudMaker()
l = Level.new(0, 0, 27, 12, 16, 16, img, level_test.map, level_test.collision, entities)
state = "start"
end
Code: Select all
Level = {}
Level.__index = Level
function Level.new(x, y, map_width, map_height,tile_width , tile_height, image, tiles, collision, entities)
local instance = setmetatable({}, Level)
instance.x = x
instance.y = y
instance.map = {}
instance.map.width = map_width
instance.map.height = map_height
instance.map.tile_width = tile_width
instance.map.tile_height = tile_height
instance.map.tiles = tiles
instance.map.spritebatch = love.graphics.newSpriteBatch(image)
instance.map.image = image
instance.map.collision = collision
instance.map.quads = {}
for y=1, instance.map.image:getHeight() / instance.map.tile_height do
for x=1, instance.map.image:getWidth() / instance.map.tile_width do
q = love.graphics.newQuad((x-1)*instance.map.tile_width, (y-1)*instance.map.tile_height, instance.map.tile_width, instance.map.tile_height, instance.map.image:getWidth(), instance.map.image:getHeight())
table.insert(instance.map.quads, q)
end
end
for y, xs in ipairs(instance.map.tiles) do
for x, value in ipairs(xs) do
if value > 0 then
print("Theres one of 4")
instance.map.spritebatch:add(instance.map.quads[value], ( x-1) * instance.map.tile_width, (y-1) * instance.map.tile_height )
end
end
end
instance.coll = {}
instance.coll.bodys = {}
instance.coll.shapes = {}
instance.coll.fixture = {}
for i, c in ipairs (instance.map.collision) do
local b = love.physics.newBody(world, c.x + instance.x - c.width / 2, c.y + instance.y - c.height / 2)
local s = love.physics.newRectangleShape(c.width * instance.map.tile_width, c.height * instance.map.tile_height)
local f = love.physics.newFixture(b, s)
table.insert(instance.coll.bodys, b)
table.insert(instance.coll.shapes, s)
table.insert(instance.coll.fixture, f)
end
return instance
end
Heres a .love