help with level building

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
smokingbunny
Prole
Posts: 9
Joined: Thu Sep 18, 2014 11:58 am
Contact:

help with level building

Post by smokingbunny »

hello all,

been a bit busy of late, planning to get away from the UK but want to get some code on. and one thing i have been on and off trying to get going is a certain type of level building , thats built through 1s and 0s.
the type of level building is:

Code: Select all

thisIsALevel = {
   {1,1,1,1,1,1,1,1},
   {1,0,0,0,0,0,0,1},
   {1,0,0,1,1,0,0,1},
   {1,0,0,0,0,0,0,1},
   {1,1,1,1,1,1,1,1}
}
but i have been trying to incorporate collision to the image that is used, namely the '1' in all of this, but am running up empty, and cant figure out how. im using bump, even tried to not use it, but still running up empty.
ive searched in the forum, but im gathering my wording is wrong, since i cant remember what the name of the code above is called. i would have figured someone would of asked this question

thanks
lewis lepton
------
website
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: help with level building

Post by artofwork »

The code is called a matrix but also can be called a grid, level building is known as layers.

If you have an issue with your code either A place it in its entirety in a code tag in your post or B upload a love file
Last edited by artofwork on Mon Oct 06, 2014 8:31 pm, edited 1 time in total.
User avatar
smokingbunny
Prole
Posts: 9
Joined: Thu Sep 18, 2014 11:58 am
Contact:

Re: help with level building

Post by smokingbunny »

aye, i was trying to find what i had done before, but its missing. which is odd. but ill drum up something to show

thanks
lewis lepton
------
website
User avatar
smokingbunny
Prole
Posts: 9
Joined: Thu Sep 18, 2014 11:58 am
Contact:

Re: help with level building

Post by smokingbunny »

found an old file, which built up to what i made before going closer to collision for blocks that are 1s, but doesnt have the collision as it was before i started to put it in.
ill look further, but my computer has been really giving me problems lately and have missing a lot now. a new one is needed ;)

Code: Select all

function mapsLoad()
	mapImage = love.graphics.newImage('assets/image/level/platform01.png')
	level01 = {
		{1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
	}
end

function mapsDraw()
	for y=1, #map do
        for x=1, #map[y] do
      -- Check space and render suitable tile.
            if map[y][x] == 1 then
                love.graphics.setColor(255,255,255,255)
                love.graphics.draw(mapImage,x*32,y*32)
            end
            if map[y][x] == 0 then
                love.graphics.setColor(255,255,255,170)
                love.graphics.rectangle('fill',x*32,y*32,32,32)
            end
        end
    end
end
thanks
lewis lepton
------
website
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: help with level building

Post by artofwork »

This is a basic tutorial about creating maps and character movement

Code: Select all

http://www.love2d.org/wiki/Tutorial:Gridlocked_Player
But you can expand upon that idea by generating layers using this same system

Code: Select all

map = { -- z
		{ -- y -1
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, -- x
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, -- background layer
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, -- 1 is background
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
			{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		},
		
		{ -- y -2
			{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, -- x
			{ 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2 }, -- top layer
			{ 2, 0, 2, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 2 }, -- 2 is collision
			{ 2, 0, 2, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 2 }, -- 0 is path and top order for sprite
			{ 2, 0, 0, 2, 0, 2, 2, 2, 2, 0, 0, 0, 0, 2 },
			{ 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2 },
			{ 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2 },
			{ 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2 },
			{ 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 },
			{ 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 2 },
			{ 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2 },
			{ 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 },
			{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
		},
		
			{ -- y -3
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, -- x
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, -- empty top layer for jumping
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, -- 255 no collision
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, -- 255 is path and top order empty space
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
			{ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 },
		}

    }
I'll upload a love file to show you how this done
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: help with level building

Post by artofwork »

So I made this awhile back, I removed somethings from the original code, but i wanted to show you how to load a multi-layered map.

Although the sprite is smaller then the tiles, its the only sprite sheet I had made at the time :)
All and all it still works with the map :p
Test_Layered_Map.PNG
User avatar
smokingbunny
Prole
Posts: 9
Joined: Thu Sep 18, 2014 11:58 am
Contact:

Re: help with level building

Post by smokingbunny »

oooh. thank you very much for that, ill have a nice dig into it.

i did have a little bit of a 'spark' moment when figuring some things out, still using physics, but just stuck on the placement, or even the coding of where the physics go in the grid. if that makes sense :s
here is what i have got to, its a new file i have been working on. this is making a 2d platformer, using physics as the world, also the grid/matrix type of drawing
here is where im up to at this moment in time. i have commented where it is i need to fix, with the original, none physics block.

so in short, im trying the get physics blocks to draw on the grid.

Code: Select all

level01 = {}
function mapLoad()
	ground = {}
	ground.body = love.physics.newBody(world,64,64)
	ground.shape = love.physics.newRectangleShape(64,64)
	ground.fixture = love.physics.newFixture(ground.body,ground.shape)

	level01 = {
		{1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
	}
end

function mapDraw()
	for y=1, #map do
        for x=1, #map[y] do
            if map[y][x] == 1 then
                love.graphics.setColor(0,0,0,255)
                --THIS IS THE ORIGINAL DRAWING
--                love.graphics.rectangle('fill',x*32,y*32,32,32)

				--THIS IS THE PART WHERE I CANT GET IT TO DRAW IN THE GRID WITH PHYSICS
                love.graphics.polygon('fill',ground.body:getWorldPoints(ground.shape:getPoints()))
            end
            if map[y][x] == 0 then
                love.graphics.setColor(255,255,255,170)
                love.graphics.rectangle('fill',x*32,y*32,32,32)
            end
        end
    end
end
thanks again for your help
lewis lepton
------
website
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 1 guest