Block editing with platformer engine

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Rhinoceros
Prole
Posts: 35
Joined: Mon Jun 11, 2012 2:59 am
Location: Under the Floorboards

Block editing with platformer engine

Post by Rhinoceros »

Hi.

I'm using this to make a Harvest Moon clone for practice.

What I'm wondering is: how do I make squares editable by the player? I'm assuming it would have something to do with a table

the map:

Code: Select all

	{ 48, 36, 'Intro',
	'711111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111000000011111121000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'1110000000p0000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111111111111111111111111111111111111111111111111'..
	'111111111111111111111111111111111111111111111111'..
	'111111111111111111111111111111111111111111111111'},
"1"s are impassable blocks, "0"s are passable blocks, the "2" is a door, the "p" is the player starting position, "f"s are the blocks that I need to be editable.
That 7 up there is just a anchor for the map texture.

How would I link each f to a variable or table point? And how would I get the player to move to a square and change it?
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Block editing with platformer engine

Post by Wojak »

You are storing 2-dimensional map and some other variables in one 1-dimensional table, I would suggest something like this:

Code: Select all

intromap = { 
	val1 = 48, 
	val2 = 36, 
	id = 'Intro',
	tilemap = {
                        {7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,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,0,0,0,0,0,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,0,0,0,0,0,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,0,0,0,0,0,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,0,0,0,0,0,0,0,1,1,1,1,1,1,2,1,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,p,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                       {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                       {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,1,1,1},
                        {1,1,1,0,0,0,0,0,0,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,0,0,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,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}
                      }
}
now you can access any field by:

Code: Select all

intromap.tilemap[coordinateY][coordinateX]
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Block editing with platformer engine

Post by coffee »

Rhinoceros wrote:Hi.

I'm using this to make a Harvest Moon clone for practice.

What I'm wondering is: how do I make squares editable by the player? I'm assuming it would have something to do with a table

the map:

Code: Select all

	{ 48, 36, 'Intro',
	'711111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111111111111111111110000011111111111111111111111'..
	'111000000011111121000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'1110000000p0000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000ffffffffffffffffffffffffffffffffff00111'..
	'111000000000000000000000000000000000000000000111'..
	'111000000000000000000000000000000000000000000111'..
	'111111111111111111111111111111111111111111111111'..
	'111111111111111111111111111111111111111111111111'..
	'111111111111111111111111111111111111111111111111'},
"1"s are impassable blocks, "0"s are passable blocks, the "2" is a door, the "p" is the player starting position, "f"s are the blocks that I need to be editable.
That 7 up there is just a anchor for the map texture.

How would I link each f to a variable or table point? And how would I get the player to move to a square and change it?
Well for a beginner you probably didn't choose the easiest of map grid formats because now you are totally dependent of yellowafterlife engine. To change values in the map isn't so direct and need string manipulation. Unfortunately I think he didn't make an editor for exemplify but you have implemented functions to change blocks. Check level.lua for level.plot(x, y, what) -Changes block at given coordinates- so I guess that you can use it for map changes.
Now you only need to add a mouse x/y coords > map translator. You can use specific parts of mouse coords detection for example here
viewtopic.php?f=4&t=9392&p=58153
Remember that you can't use much more of the remaining code in that example because the map system is different (uses a more direct approach).

EDITED: Ninja'ed by Wojak.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Block editing with platformer engine

Post by Robin »

If you want to use Wojak's solution (which is a good one), you need to add this line to the very top:

Code: Select all

local f = 2 -- or 'f' or something else
You see, f is nil by default, which can cause problems later on.
Help us help you: attach a .love.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Block editing with platformer engine

Post by coffee »

I'm divided what suggest. Depend of Rhinoceros intentions and needs (and now decision). If you want more quickly do a platform game would de better stick with yellowafterlife engine and add a level editor. But for learning yes, it should be better start from scratch/back to basics like wojak propose. Well, you could also ask if yellowafterlife can't add some basic level editor to his engine.
User avatar
Rhinoceros
Prole
Posts: 35
Joined: Mon Jun 11, 2012 2:59 am
Location: Under the Floorboards

Re: Block editing with platformer engine

Post by Rhinoceros »

Alright, I'll try the table and subtable map.

Thanks, guys.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Block editing with platformer engine

Post by kikito »

Strings are easier to handle when manually editing the map - you have less keys to touch, and less "noise" (you don't have apostrophes, comas or curly brackets). On the other hand, the 2d array is easier to manipulate once you have it.

To me, the solution is clear: use a string to specify the initial map easily, and then immediately transform the string into a 2d array for easy manipulation.

Here, give this a look:

https://github.com/kikito/love-tile-tut ... 1d-strings
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 74 guests