Slick Forums

Discuss the Slick 2D Library
It is currently Mon Apr 21, 2014 1:17 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed May 07, 2008 11:54 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Tommy asked how the in game tutorial in putty worked:
Quote:
Would you mind to explain how you create such a tutorial level where you offer explanation texts and expect certain mouse clicks or actions on certain game objects? And that over many click/explanation/click/explanation steps! Puzzles me a bit.
Do you use a certain ingame mode for the tutorial or can this happen in the default "game engine" and thus be part of any level (like hints or special information breaks)?


So, here it is. The in game tutorial can be used anywhere and is part of the core "engine". The guide is referred to as the "Directions" which are built up of "Node" objects, each node representing a step in the instructions. Bad naming I know, was rushing.

Every action (select, mouse over, merge, split etc) in the game is controlled from the InGameState. Each action takes the form:

Code:
if (directions.vetoMerge(int x, int y)) {
    return;
}

// do normal merge action stuff here


Every user input is first validated by the directions object. It has the power of "veto", the ability to decide that the action/event can not go ahead as normal.

The Directions class is a list of nodes and proxies each veto call (one for each event/action) onto the "current" Node. This node makes the decision. The node interface looks a bit like this:

Code:
package org.newdawn.putty.directions;

public interface Node {
   
   public String getText();
   
   public boolean vetoMouseClick(int x, int y);
   
   public boolean vetoSelection(int x, int y);
   
   public boolean vetoOver(int x, int y);
   
   public boolean vetoRemoveOrCancel(int x, int y);
   
   public boolean vetoComplete();
   
   public boolean complete();
   
   public int[] getHighlight();
   
   public void reset();
}


The different implementations control different types of step in the directions. So I have a ClickNode that vetos everthing except a mouse click. When it gets asked about a mouse click it marks itself as completed, lets the click go ahead. The completed flag moves the Directions onto the next node. Another example is the over node, which waits until the use moves the mouse over a given location (prevents everything else).

The other bits in the Node interface (and likewise in the directions interface) support the visual representation and the reuse of the directions. getHighlight() specifies which location if any should be highlighted for the user. getText() defines what Frank (the tutorial guide) will say. Finally, reset() resets the state of the node so the directions can be used again.

The last bit is that the directions themselfs are described in a little XML dialect with a factory to produce the right sort of node. Standard pattern stuff. For completeness here's what the XML looks like:

Code:
<directions>
   <direction type="click">
Oh, a new player, how entertaining! I'm Frank your guide to the putty
 world, it's time to learn how to play. Remember
 you can press R at any time to restart the level and press escape to
 select a different one. Click the mouse to continue...
   </direction>
   <direction type="select" x="12" y="15">
First thing, lets learn how to merge putty together. Once merged, putty
 can move and morph into other shapes. First click
 the highlighted putty to start the merge.
   </direction>
   <direction type="select" x="13" y="15">
The next step is to select the putty that we're going to merge with. Move
 the mouse over the highlighted square. The selection
 changes colour to show that the merge is possible. Click the mouse on
 this square to complete the merge.
   </direction>
   <direction type="click">
Excellent work! Maybe you're going to be good at this after all. Next, lets
 look at moving the putty around by changing it's
 shape using a morph. Click the mouse to continue...
   </direction>
</directions>


Hope this is clear,

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 11:15 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
Great stuff!

After I read it the third time all over I got it now :D
That is a pretty cool approach which also covers a lot of related stuff (highlighting the area to be selected for example).

Is this a common mechanism or did you made this up on your own?

Sometimes I'm asking myself "Why isn't there a site where I can find solutions / suggestions / pseudo implementations for those common game developer issues?"

Does someone know such a site? Or are there recommended books? Like those Game programming Gems?

Anyway, thanks Kev for this great explanation! I learned a lot!

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 12:19 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Just made it up, it only took a few minutes to code and check out. Visuals took a bit longer tbh.

In this case it's just following the strategy pattern, a bit of a factory pattern and the composite pattern.

Gang of Four book is pretty useful for the pure patterns, but I suppose the rest is just practice.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 6:27 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
So I am certainly missing the practice as the GOF book is on my desk at work for years now (and I read it!) :wink:

Note to self: must steal more hours, must code more games...

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 08, 2008 4:14 am 
Offline

Joined: Sun Jun 08, 2008 4:11 am
Posts: 5
I find it interesting that you made a lot of these informative posts on the forum, but yet they have not been compiled to a wiki of sorts. This forum has a plenthora of information which could be made more accessible. I'm a complete newbie, and from what I've seen Slick looks amazing. It's just hard to get started using it. It's a good thing there's a small community available. :D


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 08, 2008 9:05 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
You're welcome to put it on the Wiki if you think its worth it - or post it somewhere else. I just answer the questions I'm asked and write the code. Thats plenty for me to do :)

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group