Procedural 3D level generation with Blocks

Procedural 3D level generation with Blocks

Postby ginkgo » 11 Jun 2010, 00:38

Hello :)

I'm the developer of Blocks and Pink Pony.

Blocks is a minimalist 3D Jump n' Run in the Style of Super Mario 64. The whole level is composed of cuboid blocks which can be pushed around and even animated to form floating platforms. The purpose of a level is to get into the next level. For this you have to collect marbles and get to the goal. You can watch a video of the game in action here.

I recently released a new Bug-Fix version of Blocks. Among the changes are bug-fixes, some small tweaks and finally support for the catalyst drivers.

The newest version on SVN has a cool, new feature. I created a simple python library for generating level files. This makes it very easy to create a new Level:

I originally generated the levels in the C++ Source code, but the constant recompilation can get very tedious. We switched to an XML-Level format, but this turned out to be way to verbose and low level to be of any use.

Here is a short demonstration of a simple generated level file:

{l Code}: {l Select All Code}
from blocks import Level, hsv

# Create level
level = Level()

# Set level properties
level.set_player_position(50,50,50)
level.set_light(25, 50, 100)
level.set_music("data/music/04 - Crystal Cavern.ogg")

# Add a solid base
level.add_fixed_block('red', (40, 49, 40),  (20, 1, 20))

# Add a stack of movable blocks
for y in range(0, 10):
    level.add_normal_block(hsv(0, y/10.0, 1),
                           (98-50, 100+y-50, 104-50),
                           (4, 1, 2))

# One marble
level.add_marble('turquoise', (46, 50, 50))
# An exit to another level. Entering this would load the 'levels/Castle.xml' level file.
level.add_goal('Castle', 1, (54, 50, 50))

# Floating text
level.add_text("This is a \n test", (50, 52, 45),
              size=1.5, angle=180, alignment='center',
              color='orange')

# Create animated block
actionBlock = level.add_action_block('blue', (35, 45, 35), (5,5,5))
actionBlock.add_x_move(25, 5.0)
actionBlock.add_z_move(25, 5.0)
actionBlock.add_x_move(-25, 5.0)
actionBlock.add_z_move(-25, 5.0)
actionBlock.add_restart(0)

# Write to file
level.write('levels/TestLevel.xml')


When executed, this script creates a level file which can be loaded with Blocks. The above would look like the following:
testlevel.png
testlevel.png (94.79 KiB) Viewed 6461 times


Since you have a full programming language at your service you can let your imagination run wild.
imagelevel.png
imagelevel.png (152.03 KiB) Viewed 6461 times

I created this level by loading an image with python and converting every pixel into a block. This only took about 25 lines of code.

You create links between level files by simply adding an exit with the name of the other level. Blocks will search for a file with this name in the levels folder. You can also create more than one exit per level to create complex interconnected worlds.

So, I invite anyone who is interested to check out the latest SVN revision and go crazy.

The library is lacking documentation at the moment, so just ask if you need help with anything.
ginkgo
 
Posts: 15
Joined: 14 Dec 2009, 17:10

Re: Procedural 3D level generation with Blocks

Postby TheAncientGoat » 11 Jun 2010, 08:12

Blocks has always looked like an awesome game to me, it would be really cool to see it packaged and put on Playdeb or something like that :)

How about making an in-game level editor? Maybe quite a bit of work, but that's pretty much pre-requisite if you want lots of people to make levels... The next step would be a nice mechanism to share levels, but I guess that might be a bit too much work, I tend to want to make everyone re-make syntensity XD
User avatar
TheAncientGoat
Community Moderator
 
Posts: 518
Joined: 27 Dec 2009, 19:06

Re: Procedural 3D level generation with Blocks

Postby TheAncientGoat » 11 Jun 2010, 08:40

Btw, I tried compiling to no success, I keep on getting
{l Code}: {l Select All Code}
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o source/base/BlkLoop.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/base/BlkLoop.cpp
In file included from source/base/BlkLoop.h:23,
                 from source/base/BlkLoop.cpp:20:
source/base/../BlkCommon.h:24:21: error: GL/glfw.h: No such file or directory
scons: *** [source/base/BlkLoop.o] Error 1
scons: building terminated because of errors.
User avatar
TheAncientGoat
Community Moderator
 
Posts: 518
Joined: 27 Dec 2009, 19:06

Re: Procedural 3D level generation with Blocks

Postby ginkgo » 11 Jun 2010, 08:53

You have to install GLFW. You need several libraries for building the game.

As far as i remember these are: glfw, openexr, openal, freealut, ftgl, ogg/vorbis. Seems like I missed GLFW in the INSTALL file.
ginkgo
 
Posts: 15
Joined: 14 Dec 2009, 17:10

Re: Procedural 3D level generation with Blocks

Postby charlie » 11 Jun 2010, 09:46

I really need to try out Blocks... looks great!
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

Re: Procedural 3D level generation with Blocks

Postby TheAncientGoat » 11 Jun 2010, 17:46

ginkgo {l Wrote}:You have to install GLFW. You need several libraries for building the game.

As far as i remember these are: glfw, openexr, openal, freealut, ftgl, ogg/vorbis. Seems like I missed GLFW in the INSTALL file.


Ah, that wasnt in the install docs :) Still fails to build though

{l Code}: {l Select All Code}
 scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o source/base/BlkLoop.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/base/BlkLoop.cpp
g++ -o source/base/BlkScene.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/base/BlkScene.cpp
g++ -o source/base/BlkScreen.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/base/BlkScreen.cpp
g++ -o source/blocks/BlkActionBlock.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/blocks/BlkActionBlock.cpp
g++ -o source/blocks/BlkFixedBlock.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/blocks/BlkFixedBlock.cpp
g++ -o source/blocks/BlkNormalBlock.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/blocks/BlkNormalBlock.cpp
g++ -o source/cameras/BlkDirectionalLightCamera.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/cameras/BlkDirectionalLightCamera.cpp
g++ -o source/cameras/BlkPlayerCamera.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/cameras/BlkPlayerCamera.cpp
g++ -o source/cameras/BlkSpotLightCamera.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/cameras/BlkSpotLightCamera.cpp
g++ -o source/cameras/BlkTitleCamera.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/cameras/BlkTitleCamera.cpp
g++ -o source/effects/BlkDepthOfField.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/effects/BlkDepthOfField.cpp
g++ -o source/fbo/BlkDeferredFBO.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/fbo/BlkDeferredFBO.cpp
g++ -o source/fbo/BlkDepthFBO.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/fbo/BlkDepthFBO.cpp
g++ -o source/fbo/BlkTexture2DFBO.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/fbo/BlkTexture2DFBO.cpp
g++ -o source/font/BlkFtglOutlineFont.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/font/BlkFtglOutlineFont.cpp
In file included from source/font/BlkFtglOutlineFont.cpp:20:
source/font/BlkFtglOutlineFont.h:24:23: error: FTGL/ftgl.h: No such file or directory
In file included from source/font/BlkFtglOutlineFont.cpp:20:
source/font/BlkFtglOutlineFont.h:30: error: ISO C++ forbids declaration of 'FTFont' with no type
source/font/BlkFtglOutlineFont.h:30: error: expected ';' before '*' token
source/font/BlkFtglOutlineFont.cpp: In constructor 'Blk::FtglOutlineFont::FtglOutlineFont(std::string)':
source/font/BlkFtglOutlineFont.cpp:28: error: 'font' was not declared in this scope
source/font/BlkFtglOutlineFont.cpp:28: error: expected type-specifier before 'FTGLPolygonFont'
source/font/BlkFtglOutlineFont.cpp:28: error: expected ';' before 'FTGLPolygonFont'
source/font/BlkFtglOutlineFont.cpp: In destructor 'virtual Blk::FtglOutlineFont::~FtglOutlineFont()':
source/font/BlkFtglOutlineFont.cpp:35: error: 'font' was not declared in this scope
source/font/BlkFtglOutlineFont.cpp: In member function 'virtual Blk::Drawable* Blk::FtglOutlineFont::use(std::string, Imath::V3f, float, float, Imath::Color4f, Imath::V2f)':
source/font/BlkFtglOutlineFont.cpp:45: error: 'font' was not declared in this scope
scons: *** [source/font/BlkFtglOutlineFont.o] Error 1
scons: building terminated because of errors.
User avatar
TheAncientGoat
Community Moderator
 
Posts: 518
Joined: 27 Dec 2009, 19:06

Re: Procedural 3D level generation with Blocks

Postby qubodup » 12 Jun 2010, 02:08

TheAncientGoat {l Wrote}:Ah, that wasnt in the install docs :) Still fails to build though

{l Code}: {l Select All Code}
g++ -o source/font/BlkFtglOutlineFont.o -c -I/usr/include -I/usr/include/OpenEXR -I/usr/include/freetype2 -Isource -Iexternal/GLee -Iexternal/tinyxml source/font/BlkFtglOutlineFont.cpp
In file included from source/font/BlkFtglOutlineFont.cpp:20:
source/font/BlkFtglOutlineFont.h:24:23: error: FTGL/ftgl.h: No such file or directory
In file included from source/font/BlkFtglOutlineFont.cpp:20:

Hope that your distribution provides ftgl and install it :)
User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

Re: Procedural 3D level generation with Blocks

Postby TheAncientGoat » 12 Jun 2010, 07:43

Ah, I had to install the dev libs, silly goat
User avatar
TheAncientGoat
Community Moderator
 
Posts: 518
Joined: 27 Dec 2009, 19:06

Re: Procedural 3D level generation with Blocks

Postby qubodup » 12 Jun 2010, 13:25

TheAncientGoat {l Wrote}:Ah, I had to install the dev libs, silly goat

Does It Work Now YouSillyGoat? :kiss:
User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

Re: Procedural 3D level generation with Blocks

Postby TheAncientGoat » 12 Jun 2010, 14:45

Indeed. Veeeery nice, should definitely be up there on the list of "well polished foss games"/"foss games that match commercial quality". Hard though
User avatar
TheAncientGoat
Community Moderator
 
Posts: 518
Joined: 27 Dec 2009, 19:06

Re: Procedural 3D level generation with Blocks

Postby ginkgo » 12 Jun 2010, 15:26

I'm glad you like it. :)

Unless I do a complete rewrite of the game, I'm afraid an in-game level-editor won't happen. The source is simply too crufty to strap on something like that.

What I might do is create a standalone editor with pygame or something like that. But we have to see.

I did some experimenting with the level-library.
Here's a generated maze:

maze.png
ginkgo
 
Posts: 15
Joined: 14 Dec 2009, 17:10

Re: Procedural 3D level generation with Blocks

Postby svenskmand » 17 Jul 2010, 01:04

This looks awesome :), and the graphics is very nice too, I especially like the lighting and the focus which gives a unsharp look in the distance (picture above). One thing though the guy you control should have some more smooth animations, but very nice, will it be part of a PPA so it can be installed on Ubuntu? (aka and easy install)
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest