How to draw levels with images!

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Banoticus
Citizen
Posts: 60
Joined: Wed Apr 04, 2012 4:01 pm
Location: London

How to draw levels with images!

Post by Banoticus »

Have you ever been sick of writing - 1, 4, 1, 0, 0, 0, 0, 6, - to draw your levels. Because i am!
There has to be a simpler way.
How about using an image's colours for different blocks. A block-A pixel.
Can you please tell me how this is done so i can add it to my game Platformer X.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: How to draw levels with images!

Post by Santos »

Another Kind of World does this.

Check out world.lua and the levels directory. Here's an excerpt from world.lua:

Code: Select all

for x = 0, self.width-1 do
	for y = 0, self.height-1 do
		red, green, blue, alpha = self.baseImg:getPixel(x, y)
		if red == 255 and green == 0 and blue == 0 then
			love.graphics.draw(self.gfxNormal, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 0 and green == 255 and blue == 0 then
			love.graphics.draw(self.gfxTop, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 255 and green == 255 and blue == 0 then
			love.graphics.draw(self.gfxUnder, x*8*self.scale, y*8*self.scale, 0, 3, 3)
		elseif red == 0 and green == 255 and blue == 255 then
...
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: How to draw levels with images!

Post by T-Bone »

There are tons of ways to solve this. I tend to create level editors in my games to get total control. Typically, I let the editor write automated lua code to files containing the data for each level.
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: How to draw levels with images!

Post by Nsmurf »

well, i am currently using a system where i have a level .txt file that looks something like this:
111
101
111
(^that would be a box)

and it gets read into an array, where i use it in my game and in love.draw()
(love.draw renders the level)

if you want some code i can post some.

is this what you want?
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
awhite92
Prole
Posts: 21
Joined: Thu Jul 26, 2012 4:25 am

Re: How to draw levels with images!

Post by awhite92 »

i like how "another kind of world" did it, so im working on my own version, ill create a new thread when its gotten anywhere.
saved by a scholarship..
redesigned my "avatar"
User avatar
awhite92
Prole
Posts: 21
Joined: Thu Jul 26, 2012 4:25 am

Re: How to draw levels with images!

Post by awhite92 »

this is what i made, let me know if it helps! although its pretty rough
Drawing Maps With Images
saved by a scholarship..
redesigned my "avatar"
B-Man99
Prole
Posts: 36
Joined: Wed Jul 25, 2012 10:51 pm
Location: Right behind you. I know you looked. Heck, even I looked

Re: How to draw levels with images!

Post by B-Man99 »

Stabyourself.net's OrthoRobot does this fantastically. Not sure how... its open source though, just like Mari0
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests