Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Game Events and Scripting

by bladx (Chaplain)
on Jun 15, 2007 at 20:34 UTC ( #621519=perlquestion: print w/ replies, xml ) Need Help??
bladx has asked for the wisdom of the Perl Monks concerning the following question:

Edit: I think I might try going with Java for this. I was hoping to use Perl somehow, but I can't seem to find a way to have graphical output work with Flash (because of the limits,) and I don't know of any other way to dynamically show graphical output in a web browser other than with a Java applet.

So, unless there is another way to display graphics in a browser (not just output a jpg/png, etc.) I'll just try to get started with Java. (Please let me know if there is another way, as far as the graphical output in a browser goes...) Thanks for the input!


(original post below)

Hi everyone,

Background:

This is a fairly general question about game scripting. I am creating a project in Perl (just for fun,) that is a simple game world/environment.

Question:

The part I am stuck at as far as planning this project out is... the events part. This game is actually going to just be a simulation... no user input really, just something being played out on the eventual screen.

So with Perl, what I'm thinking would work (in my head,) so far is... run the game/simulation (in a Perl script,) and have each event that happens (say, a character walks across the screen...) logged as an event entry and then outputted into some file in some type of format (like XML.)

But as far as events go... does this sound like a reasonable way to make a simulation/game? The problem comes when there are multiple characters on screen. With multiple events going on per character on screen, would I just have to alternate logging events per character? That sounds confusing maybe. But I mean, how to I simultaneously log information about events that are going on in the game/simulation?

Any thoughts?

Thanks,

Andy

Comment on Game Events and Scripting
Re: Game Events and Scripting
by moklevat (Priest) on Jun 15, 2007 at 21:02 UTC
    Hi Andy.

    This response is kind of generic, but you might want to look at some examples of how others have written games in perl. I see some potentially useful examples here.

    If your simulation will be event-driven (with graphics?), I would tend to think of Perl/Tk first. However, it sounds like you may be heading toward an agent-based model. If so, the best tool may be something like NetLogo instead of perl.

      Thanks for the idea about Perl/Tk and NetLogo.

      The thing is... if this was just for a regular encapsulated simuation program, I would have used C++, I think. And that's what I was planning to do last year.

      But I'm trying to approach this type of program from another angle now. My idea is (and it's not original,) that I have a MySQL database that holds all my program's environment variables, character variables, etc. I would be using Perl just to run the simulation (but with no graphical output using the Perl script itself.) The simulation is only run once a day for a fixed length of time.

      The simulation would then output all that has happened in this program's world, events, etc. into a XML or other data type of file. Then, this is read into another Perl script that converts the actions that took place into a flash movie using SWF/Ming. The movie is exported, saved, and then I can view all that took place in a web browser.

      I don't like Flash, but after looking at Java/applets for doing real graphics programming viewable in web browsers... it seems like the majority of the internet world is using Flash for graphics lately. SO, SWF/Ming looks like what I would need. The only thing is, confining a regular programming language (like Perl) with Flash/Actionscript, one can only do so much.

      The reason I would even use Perl is just because of its availability on the server where I'm running all of this.

      The point is, it doesn't matter how fast the simulation runs because it's only generated a specific times and then outputted to a .swf file that takes care of the rest. But maybe this all isn't very possible... though it's something I'd like to try.

        You may be able to cut one step out of your proposed process by having the .swf read your xml directly. There are a lot of pointers to this on the Macromedia^wAdobe site - here's a link to a slightly less Flash-heavy page just for the heck of it.

        Not strictly Perl, but possibly worth knowing about anyway - hope that helps.

Re: Game Events and Scripting
by samtregar (Abbot) on Jun 15, 2007 at 22:08 UTC
    There are many good books about game/simulation design, although most are going to show their examples in other languages. I recommend you pick one up anyway - the concepts will be highly portable and it definitely looks like you need to do some research before starting this project!

    On the other hand, maybe all you need is a hint. Here's one - most simulations use a global loop which increments every object once per pass and then updates the screen with the results. Something like:

    my $ticks = 0; while (1) { $_->update($ticks) foreach (@objects); $screen->draw(@objects); $ticks++; }

    Each object is responsible for updating its state and exposes some kind of standard interface used by $screen to do the output (x, y, color, texture, etc). I don't know why you'd bother with XML and log files, but you could consider outputting them similar to re-drawing the screen.

    -sam

      Thanks for the hint! I remember learning a little about that in a class a long while ago... but I didn't think about how it could still apply for this type of thing as well.

      The reason why I'd even be outputting something to some type of data file... is (like I mentioned in the reply above this,) because this isn't a simulation that both runs and shows a graphical display of what is going on all that same time. I'm purposely trying to break it up into "episodes" so that when the information/data is turned into a Flash movie (or whatever is doing the graphical display side of things...) it can be a manageable size.
Re: Game Events and Scripting
by zentara (Archbishop) on Jun 16, 2007 at 11:35 UTC
      Thanks for the direction! Glib doesn't look bad, but from what I've read through so far (at least,) POE looks like it might be easier for me to use as far as what I need to be able to use it...
Re: Game Events and Scripting
by nferraz (Monk) on Jun 18, 2007 at 10:16 UTC

    Take a look on Module::Pluggable. It allows you to create plugins that are triggered under given circumstances. For instance:

    foreach my $plugin ($self->plugins) { next unless $plugin->can('handle_walk_across_the_screen'); $plugin->handle_walk_across_the_screen($character); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://621519]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-09-01 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls