Tanks Game Server Code
For both the tanks game as well as the jigsaw puzzle game server code, we used Adobe Flash* to render the images and animations on the shared screen. This section describes how we dealt with interfacing the game framework to Flash, followed by an example of accepting a player's request to move a tank forward.
It should be noted that while many games built on this framework may use Adobe Flash, the game framework code does not mandate the use of Flash.
Interfacing the Game Framework to Flash
While Flash afforded us many comforts in animating the game, it posed one primary challenge: the game framework provides a JavaScript/PHP interface, not a Flash interface. Therefore, our main challenge was how to get player creation and action commands from JavaScript/PHP into Flash. This trick here is to export a few Flash ActionScript functions and make those available to the game server's JavaScript. The game server's JavaScript interacts with the PHP code through HTTP POSTs/GETs. To make this concrete, in the game's action script code we exported calls to various functions as shown in Figure 7.
// set up all external calls
ExternalInterface.addCallback( "addTank", this, addTank );
ExternalInterface.addCallback( "removeTank", this, removeTank );
ExternalInterface.addCallback( "commandTank", this, commandTank );
ExternalInterface.addCallback( "newGame", this, newGame );
ExternalInterface.addCallback( "restartGame", this, restartGame );
Figure 7 - Exporting ActionScript Functions.
Once the ActionScript interfaces are exported, we can call them by packaging up an XML string representing the ActionScript function to call along with its arguments and calling the Flash object's “CallFunction” method, as show in Figure 8.
var _invoke = function( cmdName, args ) {
var _cmd_str = [
'
'" returntype="javascript">',
'' + _toXML(args) +
'',
''].join('');
return _flashRef.CallFunction( _cmd_str );
}
Figure 8 - Calling ActionScript from JavaScript.
Once we can call ActionScript from JavaScript, we are left with the simple task of mapping player commands into ActionScript calls, as is shown in Figure 9 for moving a tank forward.
react: function( opts ) {
var cmd = '';
var params = '';
var _message = '';
switch( parseInt(opts.type) ) {
…
case 2: // move
cmd = 'commandTank';
params = [ opts.source_id, 0,
opts.message ].join('_');
break;
…
}
if( cmd != '' ) {
var _ret = _invoke( cmd, params );
}
},
Figure 9 - JavaScript player action command parsing
Conclusions and Future Work
We've presented a new usage model for multiplayer games that takes advantage of players being in a single location looking at a shared view of the game and controlling the game with mobile devices. We explained important aspects of the game framework we developed to implement this usage model borrowing ideas and technologies such as AJAX from the web development world. We presented a detailed walk through of a game built on this framework.
The last thing we'll do is to make our code available to the public and let you have a go at this usage model that we've applied to games but can be extended to the other areas. The next steps are yours - take the code and make your own games or applications. Again, the code is available for download via Intel's website (email address required) or via Gamasutra. There is also a video available here with more information.
Remember that games are just one example of the usage model. A number of future directions are possible for this work:
- Porting
existing games to use this framework and usage model
- Developing
new games -- or even new game genres -- based on this usage model
- Focus
on improving performance and response time
- Focusing
more on graphics capabilities of the server that are not possible on the
client
- Trying
this out in more and more locations, with more and more players at a time
- Trying
this for non-game usages: audience polls, group creativity, and whatever
else you can think of
We are excited to see and hear where this technology goes. We would love to hear from you about your uses of this code. Please contact us!
|
http://video.google.com/videoplay?docid=-1651221202388387390
ProjectorGames has been almost exactly the same idea for some 5 years now - and we're for hire ;-)
It's hard to tell from the video, but it looks like you have multiple XBox controllers hooked up to a USB hub, is that right? If so, I would say the ability to use any Internet capable device as a controller is an important difference (along with the fact that we're giving away code).
However, I wish we had known about your work while we were working on this article. I'm still interested in comparing notes & sharing work. Is there any place we can learn more about the technology behind your work?
Thanks,
--Scott
We've tried a number of different ways of getting people's input up to the main screen, including DS, PSP, mobile phones + bluetooth. Internet-enabled devices isn't something we tried, simply because people almost never have these at LANs (or they have massive alienware laptops that will singe their laps)
As for technology, well, the PG system is a custom game engine, built around a DirectX renderer, and has support for lots of abstract controllers, player naming, cross-event scoringkeeping, but there's nothing overly original there - all the cool stuff's in the game design. Feel free to grab me at djarcas@hotmail.com if you'd like to ask anything else tho.
Did I mention we were for hire for lan parties and corporate events? ;-)
I think we have a great pairing here. You say "all the cool stuff's in the game design" and we know our games are nothing special...indeed the games we created are just to show the usage model and the technology we used to hook it all together.
With more and more "mobile Internet devices" in the world every day, at some point it might be worth you checking out putting your games on our code (which we're giving away).
And I'll definitely keep you in mind for parties and corporate events. :)
--Scott
I'm trying to get this to work, but I keep getting an error that says that the MDB2.php file was not found and then it gives me a fatal error. I have it uploaded at www.brandonbarnes.us/game/index.php . I noticed in the readme that it required Apache 2, but my server is only running 1.3.41. Could this be the problem, or am I totally wrong?
Thanks!
The reason the README file lists Apache 2 as a requirement is because I had Apache 2 installed when developing this project. I would say it couldn't hurt to try it on Apache 2 if you can. However, the error you are getting seems to be related to the MDB2 PEAR package. What version of MDB2 do you have installed? I used version 2.4.0.
Thanks for trying it out...I would like to help you get this working.
Can you shoot me an email at freelance.brandon@yahoo.com ? I would love to get this working.
I've got the MDB2 PEAR package installed, but it still doesn't recognize it, so I'm wondering what else it could be.
Thanks!