Very simple game, maybe interesting level editor

Hi everybody fellow blenderers!

i’m submitting a very simple (and not original at all) game concept, but maybe the way it creates the game levels is a bit more interesting…

i did it to experiment with the BGE and take my very first steps in Python

since the game is a 2D maze, with 3D visuals i was looking for a simple way to design levels, and come out with the idea to parse a bitmap image to create the maze structure starting from pre-built blocks, this way you can use The Gimp as a level editor

at the moment the image parser looks for:

black to put a wall
white to put a path
full red for the starting point
full green for the goal
blu for placing a simple ai BOT, going round the maze (thanx KILLER for this)

obviously there are still a few millions colors that can be used for other elements of the gameplay (and i also have a few ideas)

the elements of the game are on layer 20, but if i have time, i’d like to load all the assets when i generate the maze; there should also be a list for matching the color of the pixel with the filename of the game elements…

to create a maze, just unpack the archive and launch the “levelCreate” script, be sure to have layer 1 & 11 visible then go to the “camera” space and press “p”, hope everything works fine in win, since i’m an Ubuntu user

the “game” (it’s just a concept 'cause nothing happens) uses GLSL and Blender 2.48, 'cause a wanted to experiment also with that, no idea of the way it looks without it

ok, too many words for such a basic thing, goodbye everybody, any feedback or suggestion will be appreciated

P.S. since i just realized it’s not possible to attach archives, here’s the link to the thing:

http://papftp.selfip.net/download/aMaze.zip

How are you planning to return the color values? I think it would be better to make a blender level editor. Somwhere around here I have a level editor… hmmm… going to have to search for it =) (It was in one of the blender mags, not sure what issue)

Your script looks good, I like the concept of level creation by reading an image. Nice simple textures that look clean.

If I try to open the blend, it autoruns it as a game in which nothing happens. (I see no objects, I simply see the frame rate and other such data against a gray background. Is that what it is expected to do at the moment?

my idea is to create levels the simplest way, without coding an editor, i have no need to return color values, i just have to read it from a bitmap

You might want to remake it so it generates the level at runtime (and pack images and stuff or use local file paths, all the image connections were lost), as is I had to open from blender to avoid autorun, reconnect all the images, then run the script with alt-p. You could easily have gotten the same result with a for loop and an add object actuator, without the player having to do any work. You would, however, have to re-write pretty much the entire script…

I like the concept, and the graphical part is very solid. The controls were a bit slippery, but I doubt that was your focus.

@Almost
this is weird, i can open the .blend file and the engine doesn’t start automatically, maybe it’s a windows thing

anyway, of course you just see a gray background, you need to run the script in order to generate the level

please let me know if there’s a workaround for the autostart

@Captain Oblivion

i’m an absolute beginner in Python scripting and BGE, any suggestion is welcome, can you be more precise, please

How are you going to get python to read the colors of the bitmap?

a few lines from his python script…

newImg = Image.Load(mainPath+levelFilename)

width = newImg.getMaxXY()[0]
height = newImg.getMaxXY()[1]

for x in range(width):
(indent) for y in range(height):

if newImg.getPixelI(x,y) == [0, 0, 0, 255]:

elif newImg.getPixelI(x,y) == [255, 255, 255, 255]:

Alright, I got it to run this time. I did as Captain had said, and opened blender first, then opened the file within blender. (before I had been trying to open the blend directly by clicking on it in a file viewer).

It works well, and watching the tiles as they are created entertains me.

What Captain Oblivion was saying is that instead of executing a script to create all of the objects, you can within the game use an add object actuator to create the objects after the player presses P to play the game. It would work on the same concepts, but the specific methods of doing it would vary. (import blender and most of the other imports would be replaced with import GameLogic and then manipulation of objects within that.

EDIT:
Well, I had time on my hands so I tried to create something in similar manner. I don’t know how to load an image with GameLogic python, so I did it with text, my own way. :slight_smile:makealevel.blend (278 KB)

I have simple movement and level creation. Added a player to roll around, much as you have done. No goal or destination, although that wouldn’t be too difficult.

@Almost

very good, it works very well also with text, gamelogic is very powerful, but i’m not used to its methods, that’s my biggest drawback at the moment, expecially planning to create a few bots that can help or obstacolate the player

for example, i’d like to add a bot that once it’s touched makes the camera zoom out for a few seconds, to help the player find the way

but the most important thing would be to externalize all assets, so that it’s possible to edit every aspect of the game on its own and have the main blend file acting as a collector

i think the main problem for this would be how to locate and append to the current scene an object (or better a group) from anoter scene, can anyone point me to some useful piece of script about that matter?

The great thing about using GameLogic is that you can load triggers and outputs (sensors and actuators) in case you don’t know the gamelogic module that well here’s a little example (it could be a solution for you zoom out bot)


cont = GameLogic.getCurrentController()
own = cont.getOwner()
mysensor = cont.getSensor("MySensorName")
myactuator = cont.getActuator("MyActuatorName")
if mysensor.isPositive():
       GameLogic.addActiveActuator(myactuator,1)

Basically when you trigger something with a sensor to make an actuator react you run addActiveActuator and type the variable name, if you type a 1 after it it means it’ll be positive (run normal) if you use a 0 it will disable the actuator.

Not sure if you already knew that or I’m wasting my time, just a friendly tip :wink:

tips are welcome KILLER, but i can’t figure out how to use this for the camera zoom out, i was simply thinking about triggering an animation curve to make the camera go backwards then put it back in place

What you should do is make an IPO. The best way would be to go into camera view and select the camera, insert frame ([i] > loc) then go to the frame you want it to end and hit G > Z, Z (hit z twice to get the local orientation) and move your mouse back and forth till you get the right position. Then you’ll want to setup the IPO actuator with the playback type and start and end frames. To get python trigger this name your IPO block something like “myanimation” now attack the brick to the python block and enter these python lines (make sure you have a sensor)


cont = GameLogic.getCurrentController()
own = cont.getOwner()
sensor = cont.getSensor("mysensor")
myanimation = cont.getActuator("myanimation")
if sensor.isPositive():
    GameLogic.addActiveActuator(myanimation,1)

that would be the easiest way to set it up.

having a bit of spare time, today i’ve devoted one our to the “externalization” process, now the assets are loaded from disk when level is created, this is great so you can edit the objects in blender on their own, much better expecially in case of team work

blender+python=pieceOfCake… really couldn’t imagine i could to this in just one hour

next step creation of “ZoomOut” object

updated archive
http://papftp.selfip.net/download/aMaze.zip

bye

Did you try my method of zooming? It should work just fine.

not yet, killer, it’s my next goal

ok, i did the bot that goes around the screen and makes the camera zoom Out… i also spent some time giving it a bit of a skin… i’m posting a screenshot

the bot works with a Near Sensor, that when detects the Player triggers a message for the GameCamera, the GameCamera reacts playing an IPO that zooms it out

sorry KILLER, i’ve found it easier this way

next things i 'd like to work on:

  • reading colors and filenames from an array, so that’s easy to add elements witout touching the main script
  • create a lifecycle for the BOTS (spawn, death, respawn) anybody ever done this via the game logic? any suggestion?

updated files are in:

http://papftp.selfip.net/download/aMaze.zip

bye everybody

Attachments