Page 1 of 1

Advice to prepare for level design

Posted: Mon Apr 02, 2012 10:19 pm
by aliceandsven
Hello,

I desperately need advice on how I should prepare and set-up my code and things for the future when I start creating the images for the ground and platforms and make a variety of terrain patterns and levels. For instance, if there's some way to make a floor entity, that can have it's width or height scaled up or down, and repeat certain "tiles" as needed. I'm also wondering if it can assign "crust" tiles to the outer edges while repeating the inside tiles, or if I should make separate entities for the floor that I want to be scalable and for the crust.

Right now I have nothing but a global "yFloor" variable that shows the height of one floor because I've been perpetually confused by relating boxes to each other :?

Also... differentiating between different classes of objects (player, projectile, enemy, floor, etc) and coding different results for each of their collisions.

I think I have the start of something like this, as you can see the game prints the player object's name and it's class ("player").

Here's my code

Re: Advice to prepare for level design

Posted: Tue Apr 03, 2012 1:17 am
by Refpeuk
I find your question confusing, but what I think you're trying to do is simply organize all the objects in your game. If that's the case then I use a really simple table system for objects.

I write this assuming you don't want to do a tilemap, if you do this can help: https://love2d.org/wiki/Tutorial:Tile-based_Scrolling
The tilemap only organizes the level, though.

For objects that can be anywhere I just use this table system:

Code: Select all

objects = {}
objectdat = {}
function objects:new (id, type, x, y)
  objectdat[id] = {}
  objectdat[id].type = type  --I use this to correspond to a texture id for drawing (texture table created in a similar way)
  objectdat[id].x = x
  objectdat[id].y = y
end

function objects:drawall()  -- assuming you have ordered your object ids from 1 - n, let n = objecttotal
  for i = 1, objecttotal do
    love.graphics.draw(textures[objectdat[i].type], objectdat[i].x, objectdat[i].y)
  end
end
. . . and variations on this.

You can loop through them all in the same way you draw them when you solve for collisions if you put the collision object in the objectdat[id] subtable.

And I apologize if this wasn't what you were asking for, though it seems like it is . . . hope it helps.