Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Bejeweled - How make it possible to remove gem when it fall.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 zamiel   Members   -  Reputation: 144

Like
0Likes
Like

Posted 11 March 2013 - 11:03 AM

<Language: ActionScript3>

 

Hi I would like to know if anyone know, the algo for removing gems when it fall on a grid. (Like bejeweled style)

With a 2D array of element it seems to be not stable.

 

 

Thanx



Sponsor:

#2 Poigahn   Crossbones+   -  Reputation: 520

Like
1Likes
Like

Posted 11 March 2013 - 06:15 PM

I do not know your language, although your problem should have an simple solution.

 

I also do not know the rules of your game. If getting an (x) number of the same type of jewel is in a row or column then do an element comparison.

 

set up a double For...Next  Loop with the number of elements in your 2D array -1

 then compare 1 element to the next and if they are the same then increment a counter also set a starter element.

  When when reach to elements that do not equal each other exit your loop,  Check your counter.  If the counter is => the minimum number then goto a sub-routine to delete those elements and fill them in with the elements from above.

 

  If I sat down for 30 minutes I could provide you with the algorithym,  But where is the fun in that. 

 

  If you get stuck. Contact me and I will see what I can do.

 

Good Luck.


Your Brain contains the Best Program Ever Written : Manage Your Data Wisely !!


#3 metsfan   Members   -  Reputation: 654

Like
0Likes
Like

Posted 12 March 2013 - 12:34 PM

I dont see why you think a 2D array would be unstable.  2D arrays are exactly how grids are represented in games.  If you prefer some additional encapsulation. you could use a managed container like a dynamic array.  Additionally, each element in the 2D array could be some kind of "GridCell" class, which contains information about the grid.    You should also create a wrapper class around your 2D grid array which will manage it for you, which has operations such as "dropRow", "dropColumn", "checkForMatches", ect.  Best of luck.


Edited by metsfan, 12 March 2013 - 12:37 PM.


#4 zamiel   Members   -  Reputation: 144

Like
0Likes
Like

Posted 13 March 2013 - 08:37 PM

metsfan

<I dont see why you think a 2D array would be unstable.  2D arrays are exactly how grids are represented in games.>

 

It's because when I destroy a gems the space inside become null but other gems when they fall and goes in that case,

 

 

Poigahn

 

For now I coded all the games. All the Gems are unable to click while they fall. But I want a system more dynamic.

 



#5 CC Ricers   Members   -  Reputation: 816

Like
0Likes
Like

Posted 14 March 2013 - 01:41 PM

metsfan

<I dont see why you think a 2D array would be unstable.  2D arrays are exactly how grids are represented in games.>

 

It's because when I destroy a gems the space inside become null but other gems when they fall and goes in that case,

 

The 2D array would represent the relative location of the gems in terms of gameplay, but it shouldn't be tied to the actual screen location of the gems. This separation is necessary so that you can do animations while the array is updating.

 

Suppose you clear 3 gems in a column. Your array will now have three zero values (empty areas) in one column, and the algorithm to update the array would be, for every zero value that is in a row below a non-zero value (gems), trade their places. To do this in one pass, you start from the 2nd to bottom row going up and horizontally. Afterwards all your empty spots will be on the top. Then you simply fill these zero spots with random values for new gems.


My development blog: Electronic Meteor

#6 blueshogun96   Crossbones+   -  Reputation: 1105

Like
0Likes
Like

Posted 14 March 2013 - 03:44 PM

I also have never really used action script either, but I have done something similar to a bejeweled clone.  It took me a while to get the blocks to fall properly, but I did manage with a 1D array treated as a 2D array to keep things simple.  Unfortunately, the fine tuned source code was on my old macbook which was stolen about 6 months ago, so I have to redo the changes I made on it.  Fortunately, I remember what I was doing wrong.

 

I'll have to dig up the source on my Notebook PC if you'd like to see.

 

Shogun.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png

 

"Yo mama so fat, she can't be frustum culled." - yoshi_lol


#7 zamiel   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 March 2013 - 06:15 PM

blueshogun96

This could be very interessing to see what you've done. Thanx
 

CC Ricers

Thanx for the tips. I'll give it a try right now.



#8 slicer4ever   Crossbones+   -  Reputation: 3987

Like
0Likes
Like

Posted 14 March 2013 - 08:52 PM

use a 2D array(or 1D treated as 2D with an stride).  anyway, what i'd do for bejewed is:

 

when a gem is destroyed, instantly update the tile(or gem) list so that internally everything is represented correctly, and you have no null spaces.

 

now then, each tile should also contain a draw position, do not change this value when you are updating the list, just make sure it's retained when you swap tiles around.

 

so, now, even though a gem is destroyed, internally the grid looks correct, however when drawn, the gem should appear as if it's in it's old position, now, on each update tick, move that draw position where it's suppose to be on the grid, this should create the illusion of the gem falling. 

 

in theory this system can be used for anything, if you want new gems to drop from above the camera, when adding a new gem to the array, simply set the draw position above the camera.  when you swap gems around, you could either instantly set the correct position, or you can just let the gem move to where it's suppose to.


Edited by slicer4ever, 14 March 2013 - 08:53 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#9 TheChubu   Crossbones+   -  Reputation: 4793

Like
0Likes
Like

Posted 15 March 2013 - 09:20 AM

You don't need to "destroy" the gem per-se. Just make some state that represents if there is a gem or not. Like an enum of "Empty" "BlueGem" "GreenGem" etc.

 

Removing a gem would set the 2D array at that position to "Empty" state.

 

If you draw it you check the 2D array and say, if BlueGem -> draw(BlueGemTile) and such. You don't need to tie in your representation of the state of the game (grid of gems) to your visual representation of it (tiles, board, score number, etc). That means that you don't need to represent the "falling" on your grid of gems, just represent it on the visual side (the "falling" tiles), and when it stops "falling", update the actual jewel position on your data grid.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#10 CC Ricers   Members   -  Reputation: 816

Like
0Likes
Like

Posted 15 March 2013 - 12:32 PM

For the falling movement, determine a "target position" for each of the gems, which are just keyframes for the screen position where the animation ends. Here is where you can use your updated 2D array to find target positions. For example if each gem is 50x50 pixels you would want a gem that's stored at [2, 3] in the array to be 100, 150 when it's in play.

 

Draw the new gems somewhere off the screen or outside the grid, just in the same horizontal position as the row they will fall in. Then keep moving them down until they reach or are past the vertical position. After all gems are in place, the game continues as normal. Then you can re-check for more matches, which is how you would handle combos, cascades, etc.


My development blog: Electronic Meteor

#11 zamiel   Members   -  Reputation: 144

Like
0Likes
Like

Posted 19 March 2013 - 06:49 AM

Thanx a lot for all the idea. I'll change my GameEngine with that.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS