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.

2D All the way! / 2D Checkers Help-Anyone?

Years of Service
User Offline
Joined: 7th Oct 2009
Posted: 7th Oct 2009 21:07
I am just learning to program with Dark GDK. I am having problem with how to code my checkers game. So far I am using two dimensional arrays to represent my board, however, I do not know how to connect the images with the two-dimensional array. As how to update my images accordingly. Also I am having trouble with how to connect the position of user\\\'s mouse click to my array. Please help me.
Pincho Paxton
Years of Service
User Offline
Joined: 8th Dec 2002
Posted: 8th Oct 2009 03:10 Edited at: 8th Oct 2009 03:14
Pseudo code... (not real code but help)

Dim Board(8,8) =(X,Y) positions.

That's your board.

Board(1,1) = 0 could be bottom left = No piece

Board(1,1) = 1 could be bottom left = black piece

Board(1,1) = 2 could be bottom left = White piece

Board(1,1) = 3 could be bottom left = black Crown

Board(1,1) = 4 could be bottom left = White Crown

You can have 1,1 top left if you like it's up to you.

You move the pieces around, and put numbers in the Board() that match where you moved the piece to. Obviously the game starts with two rows already filled. When a piece moves you have to change its old space to '0', and put a number in its new position. Checking that nothing is there, and checking if a jump is required.

From this information you should be able to get the first part of the game working.

Years of Service
User Offline
Joined: 7th Oct 2009
Posted: 8th Oct 2009 05:02
Yes, first, thank you very much for the pseudo code. I have the idea of how to program it. However, the problem is how to connect my two-dimensional array I have created to the graphics of my game. I believe I have to acquire the mouse position within the graphic and somehow relate it to my two-dimensional array. Currently I am thinking to use a function to do this, which will involve whole bunch of math and calculations of ranges. Does anyone know if there is a quicker way of doing this? or is there a special function or method in DarkGDK?
Van B
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Oct 2009 13:04
As long as PICK OBJECT is part of GDK then you are dancing...

Say your checker board was centred in the middle of the world, at 0,0,0, and it's 8x8 units wide, so 1 db unit is 1 checker tile.

Grab that 3D location!
P=Pick Object(mx,my,1,1)

Then if P is 1, then you know the mouse is over the board, and you can get the 3D position...

selx#=get pick vector x()-camera position x()
sely#=get pick vector y()-camera position y()
selz#=get pick vector z()-camera position z()

And you know that 1 db unit is 1 unit, the board is centred at 0,0,0 and if P=1 the mouse is over the board...


So by checking SELX and SELZ you have the tile under the mouse pointer, and can easily highlight it for mouse overs, using just a plain and move it around - change the colour of pieces to show the selected piece etc etc.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2023-01-29 05:23:07
Your offset time is: 2023-01-29 05:23:07