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.

Newcomers DBPro Corner / Need help with chess-like game

Author
Message
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Oct 2009 00:56
This image will probably explain my problem best:

http://img8.imageshack.us/img8/4862/losg.jpg

Say, the player is the green box. Red boxes are walls (cannot go through). Player can move 6 boxes (light gray area).

How on earth I can make somekind of check where you can move your player. I tried this many times and my brains are exploding. I'm just doo dumb to come up with any reasonable solution?

Somekind of array perhaps? Please help me on this!

PS. I know the basics of arrays, I'v already made my own working tilemap editor, but this is something else...
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 27th Oct 2009 18:23
Yes, for this situation, I think a double-dimensioned array would be best.

Your level is 15x15 cells it looks like? Then I would just create a 15x15 array, and store a different integer value depending on what type of cell it is (0 for empty, 1 for solid wall, etc).

For collision, you just need to get the position of the cell that the player is standing in, and then checking the value of the array at that spot. So for example, the player is on cell "PlX" and "PlZ", you'd check "if MapArray(PlX, PlZ) = 1" to see if the player is standing on a solid block.

If the player is standing on a solid block, then you reposition the player back to their last-known position.
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Oct 2009 20:18
Okay, thank you. But I'll think I just didnt myselft clear.

I'v already have done what you described.

I forgot to say that the game is turn based. And player (the green box) can move 6 squares to any direction from players position.

I'm wondering how I can check which of the squares are ok to move. Hmmm... difficult to explain.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Oct 2009 22:29
You just take the players position in the array and:

Add 6 to x coordinate for right moves
Subtract 6 from x coordinate for left moves
Add 6 to y coordinate for down moves
Subtract 6 from y coordinate for up moves
Add 6 to x and y coordinates for lower right moves
Subtract 6 from x and y coordinates for upper left moves
Add 6 to y and subtract 6 from x to get upper right moves
Subtract 6 from x and add 6 to y to get lower left moves

jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Oct 2009 23:13
Yes yes, but I didnt mean that either. Thanks anyway.

I'll put more clear images later. Sorry for being unclear, difficult to write in english, what I mean.
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 28th Oct 2009 07:42
Are you saying you want to limit the player to a maximum move of six spaces each turn? Like, for example, one turn you can move up two spaces and then right four spaces?

If that's what you're looking for then for any given move, compare the X and Y position of the requested move to the player's current position. Then do a check like: "if (abs(playerX-moveX) + abs(playerY-moveY) <= 6)", then the move is legal (the player can get to that move in six or less steps).

Sorry if that's still not what you're looking for, I'll see if I can offer any suggestions when you get a picture of what you're trying to do.
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 28th Oct 2009 11:58
Yes, coming close!

I use old Space Crusade as example here:

The commander (selected) can move 6 spaces too, like in my game.

http://img17.imageshack.us/img17/8109/scmove1.jpg

And when I select move, the game calculates all spaces where the selected commander unit can move during this turn.

http://img136.imageshack.us/img136/7279/scmove2.jpg

This is not gonna be easy, as the game have to calculate the moves around the walls.

I'm not expecting to anyone make me full code, but somekind of hint on what technique to use.
gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 28th Oct 2009 21:04 Edited at: 28th Oct 2009 21:12
Ok then, I see your issue now.

Ok, one way to do this, would be to devise a recursive flood-fill algorithm starting at your player. The flood fill would keep track of "depth", which is essentially the number of steps it would take to reach a specific point. The flood fill would end once the depth exceeds the maximum number of steps the player could walk (6 in your case).

Keep in mind if you did this method, you'd need an extra array (or add another dimension to your map array) that keeps track of which spaces in the flood fill have been visited (this will essentially be an array storing which spaces are legal moves).

Something like the following code might work (note again I'm assuming that a mapArray(x,y) value of 0 is a "walkable" cell, and 1 is a solid "unwalkable" cell):



Then, anytime you want to generate a list of legal moves for the player, you'd call: "FloodFill(playerX, playerY, 0, 6)"

You could then check the array "floodFillVisited(x, y)" to see if any given x,y space is a move the player can access in no more than six steps, without walking through obstacles.
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 28th Oct 2009 21:32
Thank you!

I'll try to study this.
Mulderman
20
Years of Service
User Offline
Joined: 8th Jan 2004
Location: C:\\
Posted: 30th Oct 2009 14:46
I also recommend you to read DarkBasic Pro Game Programming 2nd edition book.


At the end of the book it has tutorial about similar game called battle Checkers.

Maybe you can get some help from there also.
I don't play such games but i thought i should mention this.

New GTA2 Map Editor :: http://www.gta2madness.co.cc

Login to post a reply

Server time is: 2024-09-28 12:20:53
Your offset time is: 2024-09-28 12:20:53