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.

DarkBASIC Professional Discussion / Function to find specific tile piece in a grid of randomized tiles...

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 4th Aug 2010 13:52
Hi all,

This is hard to explain but... you know those puzzles where you have to form a picture by moving tiles in a grid? 1 grid would be empty and you can move tiles onto that empty grid and you keep moving tiles onto empty grids until you solve the puzzle.

For example, the following puzzle involves the player having to arrange the numbers in order:

http://www.ccs.neu.edu/jpt/fhs/FifteenPuzzle-01/FifteenPuzzleSmall.jpg

Now I've made a similar game where it is a 3x3 grid with tiles that are given a random colour in the beginning of the game. But they are moved by moving the entire column or row. Both methods ultimately end up changing a tile's initial position on the grid.

Basically, Tile number 1 that started in Row 1 and Column 1 may end up in Row 3 and Column 2.

Now I need to make a function that can grab the tile number in a certain row and column.

Does anyone know how to do this? I can't wrap my head around how to make this function.

Thanks.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 4th Aug 2010 19:21
If your not already using an array to store the tile information then you should be. With an array grabbing the tile number is simply knowing which row and column you want.

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 04:11
Yeah, I have an array for the tiles like tile(n).obj.

But I still don't quite know how to make the function that can grab a tile from a specified row and column.

It's probably something obvious but I can't grasp it. I know it has something to do with this:



But I don't know what to insert into that function to grab the tile.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th Aug 2010 06:31
Do you have a way that you can paste the images? Maybe you should be using a 2d array?


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Aug 2010 08:44 Edited at: 5th Aug 2010 08:45
Quote: "tile(n).obj"


It sounds like your over complicating it with a UDT. I needs to be as Neuro Fuzzy mentioned. A 2D array is much easier to work with in this case.



DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 14:45
A 2D array? I never made a 2D array before o.O

I'm even having slight difficulty understanding how your code works Grog =/

But in terms of 2D array, do you mean instead use sprites to represent the tiles?
Mugen Wizardry
User Banned
Posted: 5th Aug 2010 14:49
Dim myarray(x,y)

replace x,y with 2,2

that's how it works

it will count up to 2

or whatever is in the parentheses-1

so it starts with 0 that means 1

1 that means 2

etc..

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 15:07
Hmm... Ok... so the dim grid(2,2) is basically saying that there are 3 "boxes", each with 3 "boxes" so like 3 rows, each row with 3 columns right?

So to make this game, I should use sprites and move the sprites and use the grid system to fetch which "grid" that sprite is in and therefore that becomes the "specific tile"? =/

Because colour is involved in my game. Sorry, my brain is really tired. I'm trying to work on it now though.
Mugen Wizardry
User Banned
Posted: 5th Aug 2010 15:14
in a way, yes.

the x,y could be the coordinates of the box, OR the box itself. it depends what you want.

if you want to make a full-fledged 2d rpg, i think you should try rpgmaker xp

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 15:18
No, I just want to make a game similar to the one where I posted a link of an existing game.

It just involves the player moving rows and columns to form an image. I just needed a function that can grab the current tile number from a specified row and column. For example, if Row 3 and Column 5 contains Tile #12, then do something.
Mugen Wizardry
User Banned
Posted: 5th Aug 2010 15:23
here



CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Aug 2010 15:27
Quote: "I just needed a function that can grab the current tile number from a specified row and column. For example, if Row 3 and Column 5 contains Tile #12, then do something. "


Something like this?

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 15:30
Umm... what's the difference between yours and Grog's? Aside putting the set up in functions?

The problem with the current code here is that the tiles aren't moving, so it's easy to grab the number of the tile.

But my game has not only the tiles moving (therefore changing their row and column number), but each tile are randomly coloured in the beginning of the game.

Unless I'm missing something with the codes...?
Mugen Wizardry
User Banned
Posted: 5th Aug 2010 15:31
call gg's function in a loop

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 5th Aug 2010 15:39
This is probably easier if I actually posted my code.

Anywhos, this is the current game as it stands. Please note that I am not a programmer so my coding won't be clean or efficient:



If you press the directional keys, you move the row or column that the white box is in. What I wanted was something to happen when 3 of the same coloured cube are in a row.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Aug 2010 19:23 Edited at: 5th Aug 2010 19:28
Quote: "This is probably easier if I actually posted my code."


I really hate working with 3D so I took some of your code and made it 2D. The colors of the PossibleColours() array are stored in the Grid() array to make each box. When you hit the arrow keys it moves the column or row in the Grid array based on where the player is in the Grid.



DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 6th Aug 2010 04:56
Oh wow nice. I'm still trying to understand how your code works though since I mostly work with 3D. I'm also trying to make it so that no more than 3 of the same colour can be used (i.e. there should be no more than 3 red squares).

Thanks very much for that. If I can understand your code I can stick with 2D ^^

Login to post a reply

Server time is: 2026-07-25 07:37:22
Your offset time is: 2026-07-25 07:37:22