Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (862)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Match 3 Gem Movement  (Read 1842 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771

JGO Kernel

Medals: 128
Projects: 5
Exp: 1 year

Currently inactive on forums :(

« Posted 2016-01-06 12:12:01 »

So I am in the process of creating a match 3 game for my internship and struggling to find a nice, clean way to get gems to navigate through the grid.

Currently, gems fall vertically perfectly and looks very nice. However as time went on, they wanted "obstacles" such as holes in the grid, to which gems should move around, very much like candy crush.

I can't seem to find a nice method to go about this, my plan is to use a path finding algorithm that simply navigates each gem down the way until they can no longer. We had something like this before but it causes "overlap" if you want to have gems fall async, rather than 1 column at a time (slows down user experience), so I would need to figure out the criteria that needs to be met before a gem that may cause overlap can move.

Then I thought, surely there is a better damn way of doing this? This seems overly complicated and it shouldn't be. Does anyone have any ideas? Sources? Techniques? Would appreciate any insight to this.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline VaTTeRGeR
« Reply #1 - Posted 2016-01-06 18:35:13 »

This is a difficult question depending on what level of complexity you want to achieve, it would be nice if you could provide some more information:

  • Should gems start moving at the same time, when for example a cell frees up and every gem can move one step downwards?
  • Can gems only move along the x and y axis, or also diagonally?

A first idea is to create a tag system to tag cells with "taken/not taken" / "gem exiting left/right/up/down".
Than you let your gem decide what to do by choosing a behavior.
You could create a list of behaviors that is sorted by priority. A behavior has a method to check whether it is applicable by providing the cell that the gem is on.

Example-Behavior-List (C0 is the cell the gem is currently on):
  • Fall down (cell below C0 has tag "not taken" or "gem exiting down")
  • Move left (cell left of C0 has tag "not taken" or "gem exiting left")
  • Move right (cell right of C0 has tag "not taken" or "gem exiting right")
  • ...
  • Do not move (always applicable)

You just iterate through the list and check until you reach an applicable behavior.
A gem in movement does not change his behavior until he reaches his goal.
Pages: [1]
  ignore  |  Print  

hadezbladez (2130 views)
2018-11-16 13:46:03

hadezbladez (810 views)
2018-11-16 13:41:33

hadezbladez (2103 views)
2018-11-16 13:35:35

hadezbladez (420 views)
2018-11-16 13:32:03

EgonOlsen (3453 views)
2018-06-10 19:43:48

EgonOlsen (3680 views)
2018-06-10 19:43:44

EgonOlsen (2275 views)
2018-06-10 19:43:20

DesertCoockie (3004 views)
2018-05-13 18:23:11

nelsongames (3084 views)
2018-04-24 18:15:36

nelsongames (3853 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!