playMaker

Author Topic: Creating a win state  (Read 2761 times)

semie

  • Playmaker Newbie
  • *
  • Posts: 21
Creating a win state
« on: May 30, 2013, 11:31:07 PM »
Hi all,

I need some advice/direction on how to go about adding a win state to my game.
i have a 3x3 cube game that I want to add a win state to if three materials match.

The materials are added at random on each click. How do I identify if there are 3 across, down or diagonal??

See link for demo.

https://dl.dropboxusercontent.com/u/130092092/Skillshare/CrateSpin/My%20Game%20Builds.html

Cheers
Lindsay

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Creating a win state
« Reply #1 on: May 30, 2013, 11:43:56 PM »
Hmm thats a tough one, I can't really think of anything i like off the top of my head... FlyingRobot is doing a Match 3 ( http://hutonggames.com/playmakerforum/index.php?topic=3908.0 ) so he'll likely have better input on this type of thing... You could PM him? Probably going to be a while before you can buy his kit for this.

Personally, since there are only have 9 squares I would be okay with setting up a unique FSM for each block that checks the material value of the neighbor blocks for matches in each possible success direction. But, this is quite a hack for lack of a better solution.

You could create colliders for each possible direction, use the colliders to get the objects it hits and send events to check the material, if they're all the same throw a success. Its a mess this way though, there is definitely a better, dynamic way to do it than a hack like this. Frankly I never realized it was this complicated until I started thinking about it. Maybe The Robo will reveal his secrets on this ;)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a win state
« Reply #2 on: May 31, 2013, 02:18:09 AM »
Hi,

just a map, so that it's easier to understand my explanations:

1 2 3
4 5 6
7 8 9

 in this particular case, I would try the following:

 everytime the user click on a cube, you check that cube, this is your starting point.

1: check around that cube, if it doesn't find a similar cube, forget the winning check
2: if it did find similar adjacent cubes, check the opposite direction of them adjacent cubes, if you find a similar cube on the opposite, you have a winning combination. If you are on 4 and 1 is identical, you want to check 7
3: number 2 is not enough, you also need to look in the same direction ahead of an adjacent cube, ( if you start on 1, and 2 is similar, you want to check 3 right away)


Now, to navigate within such arrays, can be tricky mathematically. You might find easier to reference your cubes using xy references:

11 21 31
12 22 32
13 23 33

this way if you are on 22 and wants to check the item below, you stay want to go on item 2(y+1). Much easier to navigate like that. So each of your gameObject should have their indexes in a variables, say "row" and "column" for example, for the center cube would have row:2 column:2


bye,

 Jean

semie

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Creating a win state
« Reply #3 on: May 31, 2013, 04:25:14 AM »
Thanks for that Jean, I now understand the theory behind it but have no idea as to how to implement that into practice or in this case what actions from within Playmaker would I use.

My programming skills are very, very basic at this point. Not chasing a tutorial on this issue but a starting point as I am unsure as to how I reference or ID the different materials or cubes and or then do the checking.

Would I be looking at the Game object compare action? Am I even close??

Edit: After looking further at this along with Jeans example I am of the thought that arrays could be used to store the materials? and then the array id could be called to compare if 3 of the same id's in a row exist?
Cheers
Lindsay
« Last Edit: June 02, 2013, 05:08:34 PM by semie »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a win state
« Reply #4 on: June 03, 2013, 02:11:04 AM »
Hi,

 you'll need a lot more actually. Let me work on a sample, I'll get back to you.

bye,

 Jean

semie

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Creating a win state
« Reply #5 on: June 04, 2013, 06:53:40 AM »
Thanks Jean, I appreciate your support with this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a win state
« Reply #6 on: June 05, 2013, 08:55:55 AM »
Hi,

 ok, updated arrayMaker with a new sample scene "Three In a row", it's basically the same set up, 9 cubes, and as you click you get random colors, it then automatically check for winning combinations.

 study this, this is definitly kind of advanced, because the fsm that checks for winning contains a fair number of states, but basically it's cut down into checking rows, then columns, then diagonal, so don't be put off by the fsm size.

 come back to me if you have trouble understanding the processes.

https://hutonggames.fogbugz.com/default.asp?W715

Bye,

 Jean