Platformer Levels

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
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Platformer Levels

Post by veethree »

Hey. So i decided to try to make a platformer, and after thinking about it for a while i realized that i'll run into a few problems while making this..Here's the first one: Levels.

The problem is, I have no idea how to go about making the levels. I mean i have some ideas, but none of them are good. I did have one idea which i think could work, But i'm not sure how to execute it. I'd need some way of saving/loading tables to/from files.

I included what i have so far below , But there's basically nothing there yet..just a function that adds a platform at a random position (just a test)

EDIT: I came up with a way to do this that works pretty well. But i'm still open to suggestions..there could be a better way than mine. haha.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Platformer Levels

Post by coffee »

veethree wrote: The problem is, I have no idea how to go about making the levels. I mean i have some ideas, but none of them are good. I did have one idea which i think could work, But i'm not sure how to execute it. I'd need some way of saving/loading tables to/from files.
You need to start digging this forum. Almost everything is already answered around.
Here is a very recent topic that could help.
viewtopic.php?f=4&t=7884. If you follow my response on that thread you get a way of loading/saving maps (tables).

Also you don't seem to have something to even think load/save anything. Work first in do some jumping/plataform engine.

EDITED If you don't present your ideas even that bad, lovers can't help you much... :(
Henko
Prole
Posts: 9
Joined: Sun Jan 03, 2010 12:19 pm
Location: Wyk/Föhr, Germany
Contact:

Re: Platformer Levels

Post by Henko »

Saving tables to strings (commonly known as serialization) is actually kind of easy in Lua:

Code: Select all

function serialize(val, name, skipnewlines, depth)
	depth = depth or 0

	local tmp = string.rep(" ", depth)

	if name then tmp = tmp .. name .. " = " end

	if type(val) == "table" then
		tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")

		for k, v in pairs(val) do
			tmp =  tmp .. serialize(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
		end

		tmp = tmp .. string.rep(" ", depth) .. "}"
	elseif type(val) == "number" then
		tmp = tmp .. tostring(val)
	elseif type(val) == "string" then
		tmp = tmp .. string.format("%q", val)
	elseif type(val) == "boolean" then
		tmp = tmp .. tostring(val)
	elseif type(val) == "function" then
		tmp = tmp .. "loadstring(" .. serialize(string.dump(val)) .. ")"
	else
		tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
	end

	return tmp
end
This function creates legal Lua code that you can run at any time using loadstring().
Post Reply

Who is online

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