"Arcade Loader" made with Blender

Well, ever since I started making lists and prioritizing my tasks, I’ve mysteriously been getting things accomplished left and right. (That and a bit of a temporary lay-off on the job side. You have more time when you don’t have to go to work…oh well.) In my last project (the “Custom Display Menu”) I figured out how to load non-Blender programs via Python. I had been wondering how to do that for a while, and after I learned I thought I’d tackle an idea I had a while back.

Here it is: “Arcade Loader” - complete with 4 of my favorite freeware games.

They are Windows games, but the idea is cross-platform. I used the os module instead of an operating system specific one, which I believe is referred to as making my script more “Pythonic”. Here’s the main driving script:

import os
  cont = GameLogic.getCurrentController()
  own = cont.getOwner()
  mouseOver = cont.getSensor("Over")
  leftClick = cont.getSensor("LClick")
  endGame = cont.getActuator("EndGame")
  if mouseOver.isPositive() and leftClick.isPositive():
      GameLogic.addActiveActuator(endGame, 1)

As you can see, there are two mouse sensors hooked to the Python controller to detect a mouse click (you need to use “Mouse over” and “Left Click” together to be sure that it’s your specific object being clicked). On the other end is a Game actuator set to “Quit this game”. It ends the program once the new game is loaded.

The line “os.execl(own.path)” really drives the script, though. I tried a few commands other than os.execl (I think “os.popen()” to name one) but they opened the new file as part of the same command line sequence, so when I ended the Blender Game, the new program shut down as well. You’ll notice that I stored the exact file to be executed as a property of the object calling the script (own.path). I chose to do this since I had four buttons and wanted to reuse the same script.

Actually, my final script turned out to be a bit more complicated, since the games are in subdirectories. I had to use os.getcwd() to get the current working directory, then I had to use os.chdir() to change the directory before I could use os.execl(). Trust me, me and my Python documentation had a nice night together… Ah well, I learned a lot.

Maybe someday I’ll integrate my Custom Display Menu, since all of these games (except maybe Area 2048) offer custom display/game settings either through the command line or through .ini files. I also wanted to add some cool background effects to the main menu, but I ran out of ambition…

Just as a side note, I had to replace one of the games that I was intending to include, because the .exe refused to run correctly when called from Python. (Well, Alex the Allegator had that problem, too, but I fixed it by calling a .bat that calls the .exe… didn’t work for the other game… crazy…) The game that would have made it in is called Invalid Tangram (trust me, the game is nowhere near as boring as the website), and I replaced it with Area 2048.

Well, before I forget, I should post the files:

These files do not contain .blends. They contain Windows executable files.
A zip file (16.9MB)
A rar file (15.8MB)

Out of principle I can’t boot windows again for at least another month, so I can’t try this out, but I think I understand what you did.

Your just using blender as a front end to call and run windows exe’s. Right?

I think many might think that your actually importing windows games to blender itself.

Maybe some clarification on that.

PS: Nice work. I love the textures. Did you use GIMP or PS to make them, or something else?

Clarification: It is just a front-end. No windows games were actually Blenderized in the making of this project.

Now that that’s taken care of…

I understand you not booting Windows for this. It’s not quite as useful as the last one. I had just been thinking a while back that it would be cool to make an arcade box powered by Blender, and now that I had learned some stuff, I thought I’d give it a try. Anyway, I think you can still see the principle and apply it on Linux if you ever wanted to.

BTW, I made the textures with GIMP

You do a lot of interesting stuff blendenzo, but wouldn’t Blender stay running in the background with this? It’s pretty hefty, or does it quit right after it launches?

No. Blender quits. That’s what the “EndGame” actuator does. If I really wanted to use it for an arcade application, though, I suppose Blender would have to stay running or the games would have to call the loader back up.

next step is to create a windows shell that replaces the windows explorer!!! blender SO should be the core of an os…

Is that what you did for the Blenderplayer launcher? I haven’t looked at it yet.

Yep. I just wrote the commandline out to a .bat file, then I ran it with execl() and ended the launcher.

Ragman: Yeah… we should call it BleOS… :wink:

Was the bat file necessary then? Why not just use the blenderplayer options?

I, uh… I guess I didn’t think of that.

wow , i’m intending to do a booter , … is it possiple to run an exe with command line

Do you mean from within the Blender program? Yes, that’s basically what I’ve done here. Thanks to fireside I now realize that I don’t even need to alter a .bat file with the settings, but I can just pass the command through Python like this:

os.execl("myGame.exe -p 10 10 800 600 -g blender_materials = 1")

I ran into a bit of trouble with this, though. It seems that the “os” module is not part of the “Python24.dll” file. I’m going to ask in the Python and Plugins Board how I can include the os module so that users do not have to install Python to play it.

Here is the most exciting thing that I’ve found from all of this experimenting:
You can make your intro scene and menu a runtime with Blender so that they are in .exe format. They will be licensed under the GPL, but who cares? It’s only a menu. You can keep your game as separate .blend files, but run the BlenderPlayer on them using a Python command from the menu! So you can distribute an “executable” version of your game while maintaining copyright over it. I hope that makes sense to everyone. In fact, you could even make a blank .blend file that just calls the game via Python to use as a “front-end” .exe file while maintaining copyright over the rest of your game! Maybe I’ll write an article about it later and explain myself better…

WOW :slight_smile: , God keep you blendenzo , you have a lot of good info …

Don’t leave Elysiun :slight_smile:

Can’t wait for this article

Like always you find a wow thing to keep our learning hunger going and going and…:cool:

Just don’t stop as I speak for many of us who love to learn.:smiley:

I ran into a bit of trouble with this, though. It seems that the “os” module is not part of the “Python24.dll” file. I’m going to ask in the Python and Plugins Board how I can include the os module so that users do not have to install Python to play it.
Don’t you wish they would actively link with Python and at least give all the standard libraries instead of the dll? What’s even more stupid is that in Linux they have to link with Python, so they only link with a portion of it. If someone doesn’t have python installed now days, they shouldn’t be downloading a game anyway.

You can just include the os.py in your c:/python24/lib directory with your files. If it needs something else, copy that over. Eventually, you will have everything you need. For CDO, I have a complex process to generate my executables, but for simple applications like this it shouldn’t take you too long to get all the files it needs. Actually I think os.py will be enough. Great idea for a program by the way! I actually thought about something like this as well for emulators but never did it.