Finite-state machines

9 views
Skip to first unread message

Chris McCormick

unread,
Aug 7, 2011, 2:09:52 AM8/7/11
to jsgam...@googlegroups.com
Hi all,

It is now trivially easy to implement entities which are finite-state machines with jsGameSoup. Some examples of entities that could be modelled as finite-state machines:

* A non-player character which wanders around and then starts chasing the player once they come in range.
* A door which switches between closed, opening (animated), and open states.
* A spacecraft under player control which has an proximity-triggered docking procedure.

<http://mccormick.cx/news/entries/finite-state-machines-in-jsgamesoup>

Cheers,

Chris.

-------------------
http://mccormick.cx

Atom Gape

unread,
Aug 7, 2011, 4:47:32 AM8/7/11
to jsgam...@googlegroups.com
2011/8/7 Chris McCormick <ch...@mccormick.cx>


It is now trivially easy to implement entities which are finite-state machines with jsGameSoup.

This seems to be really cool! Actually I'm working on a very simple game to test the capabilities of jsgamesoup and I missed this functionality. I've used variables to follow states until now; it was OK but not really convenient. Do you plan to implement state changes based on timing, e.g. the enemy chills down after a minute anyway? (Yeah I can use counters for this. I've tried it and worked OK.)

By the way, I've noticed the screenshot of an isometric-like alignment (water, little islands and one player) in your post; is that an actual game you're working on? Seems really great so if you'd have some spare time to create a tutorial for that, it'd be really great. I don't know how to create games like that so I started with a top-view alignment. I'd like to create that quasi-isometric view if I could. I'm really interested on how do you generate the "tiles" like that and moreover how do you handle the collisions? In my little game I worked hard to create a routine that can tell which side of the objects was hit; in an isometric view it seems to be even more hard.

BR,

A.G.

Chris McCormick

unread,
Aug 17, 2011, 9:07:57 AM8/17/11
to jsgam...@googlegroups.com
Hi,

I'm travelling at the moment but will post a proper reply to this when i get home. Some good ideas in here i would like to implement in jsGameSoup.


Cheers,

Chris.
-------------------
http://mccormick.cx

Atom Gape <atom...@gmail.com> wrote:
--bcaec547ca45a3572904a

Chris McCormick

unread,
Aug 19, 2011, 10:14:10 PM8/19/11
to jsgam...@googlegroups.com
Hello,

On Sun, Aug 07, 2011 at 10:47:32AM +0200, Atom Gape wrote:
> 2011/8/7 Chris McCormick <ch...@mccormick.cx>
> > It is now trivially easy to implement entities which are finite-state
> > machines with jsGameSoup.
>

> Do you plan to implement state changes based on timing, e.g. the
> enemy chills down after a minute anyway? (Yeah I can use counters for this.
> I've tried it and worked OK.)

I have now implemented a new method on jsGameSoup called "schedule" which lets you specify a number of frames and a callback which gets run that number of frames in the future.

If you specifically want time-based callbacks you might as well use the setTimeout() function which is built into Javascript.

<http://mccormick.cx/projects/jsGameSoup/jsdocs/symbols/JSGameSoup.html#schedule>
<http://mccormick.cx/projects/jsGameSoup/tests/schedule.html>

> By the way, I've noticed the screenshot of an isometric-like alignment
> (water, little islands and one player) in your post; is that an actual game
> you're working on? Seems really great so if you'd have some spare time to
> create a tutorial for that, it'd be really great.

That was a Ludum Dare entry I wrote a while back but I never finished it off - just the graphics. It did not actually use jsGameSoup as I had not yet written the sprite engine, but I pulled the code for the sprite engine in from that demo. With that kind of thing the important part is the drawing order of the elements. You want to draw the lowest elements and the elements furthest back from the screen first. You can use the 'priority' property of your jsGameSoup entities to ensure this.

> I don't know how to create
> games like that so I started with a top-view alignment. I'd like to create
> that quasi-isometric view if I could. I'm really interested on how do you
> generate the "tiles" like that and moreover how do you handle the
> collisions? In my little game I worked hard to create a routine that can
> tell which side of the objects was hit; in an isometric view it seems to be
> even more hard.

In terms of collisions you can use circular collisions and when drawing multiply by some factor that changes the circles into the side-on ovals.

Incidentally, I am working on a new module for jsGameSoup which will be able to import tiled TMX format maps:

<http://www.mapeditor.org/>

I am trying to make this very quick and easy for game developers so you can basically create a map in the tool and then instantly pull it into your game.

Atom Gape

unread,
Aug 22, 2011, 5:10:06 PM8/22/11
to jsgam...@googlegroups.com


2011/8/20 Chris McCormick <ch...@mccormick.cx>
Hello,


I have now implemented a new method on jsGameSoup called "schedule" which lets you specify a number of frames and a callback which gets run that number of frames in the future.

That sounds cool, I'll try it out if I can find a little time.
 
With that kind of thing the important part is the drawing order of the elements. You want to draw the lowest elements and the elements furthest back from the screen first. You can use the 'priority' property of your jsGameSoup entities to ensure this.
In terms of collisions you can use circular collisions and when drawing multiply by some factor that changes the circles into the side-on ovals.

Thanks! Unfortunately I have no experience on game development at all, I've just started some very simple scenarios but I'll obviously use these advices. :)

Incidentally, I am working on a new module for jsGameSoup which will be able to import tiled TMX format maps:

<http://www.mapeditor.org/>
 

Wow it really blowed my mind. :) After my holiday I'm going to try some more serious stuff. :-)

Thanks,

A.G.

Chris McCormick

unread,
Aug 22, 2011, 10:04:32 PM8/22/11
to jsgam...@googlegroups.com
Hi,

On Mon, Aug 22, 2011 at 11:10:06PM +0200, Atom Gape wrote:
> 2011/8/20 Chris McCormick <ch...@mccormick.cx>


> Incidentally, I am working on a new module for jsGameSoup which will be able
> > to import tiled TMX format maps:
> >
> > <http://www.mapeditor.org/>
>
> Wow it really blowed my mind. :) After my holiday I'm going to try some more
> serious stuff. :-)

Oh I think I forgot to mention in my first email that this will support the type of isometric views you were asking about in your original email.

<http://images.mapeditor.org/tiled-qt-screenshot-4.png>

I want to get both the side/top view an isometric views working. Will post more here when it is working.

Have fun!

Reply all
Reply to author
Forward
0 new messages