Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Building a Match Three game

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 3rd Mar 2018 17:04
I think I have some idea of how to do this relatively simple: Letting each sprite stay at its assigned field and faking the movement:
1) Block A is falling down to the "empty" field below
2) Once it has reached the field, it snaps back, changing to an empty sprite. The sprite assigned to the field below changes from an empty sprite to a block sprite.
I'm not sure if this is how Match Three is usually done, but I think it sounds reasonably logical.

But now I have a small problem. I have placed the blocks in a two-dimensinal array:
blocks[X, Y].spriteID
How do I detect if the mouse pointer is over one of those? I know I can run through each and every one of them and check them individually, but is there a smarter way?

puzzler2018
User Banned
Posted: 3rd Mar 2018 17:08
Maybe convert to a 1D array and use .Find("")
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 3rd Mar 2018 17:24
I have no clue what you just said! But I guess it's good advice, whatever it is ...!
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 3rd Mar 2018 19:27
I wouldn't fake the movement, I'd actually DO it.
Might be a lot easier and cleaner...


PSY LABS Games
Coders don't die, they just gosub without return
puzzler2018
User Banned
Posted: 3rd Mar 2018 19:43
If you add another type

type blockType
spriteID as Integer
memoryreference as integer
orgXpos as Float
orgYpos as Float
status as Integer // EMPTY ORDINARY FALLING SWIPING_UP SWIPING_DOWN SWIPING_LEFT SWIPING_RIGHT SWIPING_BACK_UP SWIPING_BACK_DOWN SWIPING_BACK_LEFT SWIPING_BACK_RIGHT
endtype


when create sprite - put the memory reference into it

convert the 2d to 1D

global blocks as blockType[BLOCKS_X,BLOCKS_Y]
to
global blocks as blockType[BLOCKS_X * BLOCKS_Y] // but this has to be an integer

Then when mouse goes over the sprite ,grab the memory reference that it picks up and perform a .find on the array of the memoryreference variable and i think it should return the index

that index is

BlockType[index]

and voila - you found the sprite quicker and easier

I shall try and put something up tomorrow for you - im on with Shutter Island at the moment
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 3rd Mar 2018 19:47 Edited at: 3rd Mar 2018 19:48
@PSY:

You think so? Maybe! I did notice GET THE GEMS in your signature, so you seem to have experience with tile-based movement.

A two-dimensional array just sounds so simple. Also, I won't have to bother about sending used sprite offstage. I dunno ...
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 3rd Mar 2018 19:48
Quote: "How do I detect if the mouse pointer is over one of those? I know I can run through each and every one of them and check them individually, but is there a smarter way?"


There won't be any noticeable performance impact if you do it that way, so it's perfectly fine. Alternatively you can add all the blocks to the same sprite group (SetSpriteGroup) and then use GetSpriteHitGroup(groupID, PointerX(), PointerY()) to filter hit tests to only that group for the check. This will return the sprite ID of the block that gets touched. Even going this route, you'll still have to then loop through the 2D array to locate the block that has a matching SpriteID to get its properties, but can terminate the loop as soon as the match is found instead of always looping through the complete multidimensional array. On mobile or desktop either approach is perfectly fast enough that it comes down to personal preference.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 3rd Mar 2018 23:14
Basically, you got a 2 dimensional map, like map[x,y].
You start moving a tile, and as soon as the movement is finished, you assign the ID of the moved sprite to the target tile, and a blank ID to the starting tile, or you switch IDs, depending on the game.

Looping through all tiles is more than fast enough, alternatively you can do these calculations by pure logic, as the size of the map and the size of each tile is fixed.


PSY LABS Games
Coders don't die, they just gosub without return
Zep
22
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 4th Mar 2018 08:02
I used "recursion" of a function when I made one (a match 3) 12 or so years ago in DPB.

But the file I attached to that forum post is longer exists...And I no longer have the source code...well I might have the source on a hard-drive with the project, but it is not with me at the moment.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Mar 2018 17:29
I had to lookup what a match 3 game is. Never knew that style had a name. I was doing some file backups over the weekend and just so happened to come across a program I started for this style of game. (kittens and balls of yarn) I ran it just to see what it was and it seemed to work just fine. Not sure why I stopped development or if it currently contains any bugs or not. But I'll post when I get home if you like. Or at least look at how I managed everything in it.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Mar 2018 01:23
Ok, I found my old unfinished project. It's from 5 years ago and it's in DBP, but hopefully it can show you how the basic mechanics of the game works.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-27 14:30:27
Your offset time is: 2024-11-27 14:30:27