Procedural Cave/Map Generation Experiment

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Procedural Cave Generation Experiment

Post by Robin »

Awesome!
Help us help you: attach a .love.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Procedural Cave Generation Experiment

Post by BlackBulletIV »

Thanks a lot! :)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Procedural Cave/Map Generation Experiment

Post by BlackBulletIV »

I've added another .love file, which generates maps with land/water, etc. See the main post for more details.
User avatar
schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

Re: Procedural Cave Generation Experiment

Post by schme16 »

kikito wrote: PS: I don't know many people from Australia. Is your accent from Victoria?
BlackBulletIV wrote:
It's not the highly-posh British-like accent (is Victorian what you call it?) that was around during the earlier nineties. I'm actually not sure what it is. It's definitely not the aussie ocker accent. The accent isn't from Victoria I believe, as I've been up and down the east coast (Queensland, New South Wales, and currently Victoria).
As a Queenslander I can say that his accent is much like my own, it isn't a specific Victorian dialect, Australians tend to have a fairly uniform accent, with only small variation between states/territories, unless you're a bogan :cry:
My Development Diary - http://shanegadsby.info
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Procedural Cave Generation Experiment

Post by Taehl »

BlackBulletIV wrote:Ah ok, that explains (that number would apply to shapes too, as I tested it by using a single body too). Yeah I'd appreciate a snippet, not sure whether I'll use cave generation in a game for a while though.

Custom physics wouldn't go well if you wanted to do complex stuff like stacks of falling boxes, joint systems and the like; the only feasible way then would be to load/unload small sections of map.
I had to have each block separate in Underlife because adding and removing tiles is a core gameplay mechanic. Or maybe I was just doing it wrong, who knows. Stacking boxes and stuff is possible without Box2D, but you'd need your own Lua-based physics for it (like Hardon Collider or something. My own Fizz isn't suited to stacking).

Here's the physics I use in Underlife at the moment (it needs slight tweaking and a good bit of refinement, but it works quite well for me):

Code: Select all

-- pc is the player object, which has (amongst other things) variables x, y (coordinates), xv, yv (velocity), facing (-1 or 1, pc is facing left or right)
local p = pc

-- check for key input
local w,a,s,d,j = love.keyboard.isDown("w"), love.keyboard.isDown("a"), love.keyboard.isDown("s"), love.keyboard.isDown("d"), love.keyboard.isDown(" ")

if map[math.round(p.x)] and map[math.round(p.x)][math.ceil(p.y+.01)] then	-- touching the ground
	p.yv = p.yv + (j and -.2 or 0)	-- jumping
	p.xv = p.xv + (a and -.8 or d and .8 or 0)*dt	-- running
	p.xv = p.xv*(1-dt*6)	-- horizontal friction
end
if p.xv<.15 and p.xv>-.15 then p.xv = p.xv + (a and -.2 or d and .2 or 0)*dt end	-- limited air control
p.yv = math.min(p.yv + .6*dt, 1)	-- falling

p.x,p.y = p.x+p.xv, p.y+p.yv	-- add velocity to coordinates
p.facing = p.xv<-.04 and -1 or p.xv>.04 and 1 or p.facing	-- determine if pc is facing left or right

-- check for collision with tiles
-- tiles are in form of map[x][y] = tile (or nil if there's no tile there). No decimals. No numbers skipped between touching tiles.
-- please note, in Underlife, the pc is two tiles tall, one tile wide
if map[math.round(p.x)] and map[math.round(p.x)][math.ceil(p.y)] then p.y,p.yv = math.ceil(p.y)-1,0 end
if map[math.round(p.x)] and map[math.round(p.x)][math.floor(p.y-1)] then p.y,p.yv = math.floor(p.y)+1,0 end
if map[math.floor(p.x)] and (map[math.floor(p.x)][math.round(p.y)] or map[math.floor(p.x)][math.round(p.y-1)]) then p.x,p.xv = math.floor(p.x)+1,0 end
if map[math.ceil(p.x)] and (map[math.ceil(p.x)][math.round(p.y)] or map[math.ceil(p.x)][math.round(p.y-1)]) then p.x,p.xv = math.ceil(p.x)-1,0 end
An important part of how it works is that I store tiles like this:

Code: Select all

map={
	1={ 2=tile, 3=tile, 4=tile, },
	2={ 1=tile, },
	3={ 1=tile, 4=tile, 5=tile, },
	4={ 1=tile, 5=tile, },
	5={ 2=tile, 3=tile, 4=tile, 5=tile, },
}
So to tell if there's a tile on the left of the pc, for example, I need only round the pc's coordinates, subtract 1 from x, and see if map has that coordinate. Doing it this way ensures that I can have as many tiles as I want without slowing down my collision checks.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Procedural Cave Generation Experiment

Post by BlackBulletIV »

Taehl wrote:...
Thanks for that.

I know that stacks of boxes and stuff is certainly doable in Lua, it's just that it would be reinventing the wheel, and in a slower environment.
schme16 wrote:
kikito wrote: PS: I don't know many people from Australia. Is your accent from Victoria?
BlackBulletIV wrote:
It's not the highly-posh British-like accent (is Victorian what you call it?) that was around during the earlier nineties. I'm actually not sure what it is. It's definitely not the aussie ocker accent. The accent isn't from Victoria I believe, as I've been up and down the east coast (Queensland, New South Wales, and currently Victoria).
As a Queenslander I can say that his accent is much like my own, it isn't a specific Victorian dialect, Australians tend to have a fairly uniform accent, with only small variation between states/territories, unless you're a bogan :cry:
Bogan sounds a bit like an ocker from the description. There are also more skewed accents like many from the country, pronouncing "like" as "lyke", "life" and "lyfe", and a number of other weird sounding stuff. Julia Gillard also has a rather strange accent.
User avatar
schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

Re: Procedural Cave Generation Experiment

Post by schme16 »

BlackBulletIV wrote:Julia Gillard also has a rather strange accent.
I'm willing to blame that on her being originally a pom :P
My Development Diary - http://shanegadsby.info
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Procedural Cave/Map Generation Experiment

Post by BlackBulletIV »

The English have a pretty nice accent (excluded cockney and an over-done royalty-like accent), so she must've unfortunately got her accent mixed up between the two, with possibly some New Zealand thrown in.
User avatar
middlerun
Citizen
Posts: 64
Joined: Tue Nov 25, 2008 4:31 am
Location: Sydney, Australia
Contact:

Re: Procedural Cave/Map Generation Experiment

Post by middlerun »

Isn't she from Wales? They have pretty funny accents.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Procedural Cave/Map Generation Experiment

Post by BlackBulletIV »

Wouldn't have a clue of their accents.
Post Reply

Who is online

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