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 / Drawing Hexes more elegantly and adding the offset in DBC

Author
Message
Valliant
20
Years of Service
User Offline
Joined: 12th Mar 2004
Location: Redmond, Washington
Posted: 4th Apr 2004 02:12 Edited at: 4th Apr 2004 02:15
Howdys folks,

I am trying to draw a hex overlay for a 2d Wargame.

Right now I'm using what I'm sure is about the most kludgy way to draw the Hexes, then I'm trying to grab that image as a texture to apply to the matrix.

There are a couple problems I'm running into:

1) I can't tell if the texture is being applied to the matrix properly, if I take out the matrix creation stuff, the hexes line up the same. The end goal is to provide a background for the Hexes to overlay, and I'm not sure that using a matrix is best for this.

2) The hexes aren't lining up right, I can't seem to get the offset correct.

3) When the Hexes hit the outter edge of the screen (Right and Bottom) they distort, is there a way to just say "Draw till you hit the right and bottom boundaries of the screen size"?

4) How do I make the hex an object? The Sprites I'm using are sized to the hexes, but for some units I need to register when they are 2 - 7 hexes away. I haven't really looked at collision too much yet, I'm really just trying to get the gameboard drawn and be able to move even just one sprite on it right now.

Can anyone think of a better way to do this? Is any of this code salvagable or am missing by a texas mile? Is there a Hexbased editor out there that I haven't found?

Code Attached

edit: I just noticed theres a commentline I accidentally left in before the sub. I originally hoped to use a function but couldn't get it to work really well so took it out. I just forgot to remove the comment discribing the parameters I expected.
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 4th Apr 2004 03:03 Edited at: 4th Apr 2004 03:06
Well, that was screwy. I got an repeating octogon pattern. You do know that hexagons have six sides, yes?

Just for giggles, check out the attached code. It fixes your drawing routine, turns it back into a function, and adds some handy code you might need later.
--
TAZ

Amit has some articles on hexagons that you might want to read:
http://www-cs-students.stanford.edu/~amitp/gameprog.html

Valliant
20
Years of Service
User Offline
Joined: 12th Mar 2004
Location: Redmond, Washington
Posted: 4th Apr 2004 03:22
Thanks Zircher!

Well if you got the repeating octogons it worked I didn't get much further than that before I realized I was doing something wrong.

Of course you are correct that hexes are only 6 sides. I was basing my octogons off an old boardgame map I had which used the octogon model, I just generically called them hexes.

I checked out the code, it's pretty much exactly what I was looking for except I can't get it to compile in DBC.

The two items so far that are causing it to barf are:
1) Line 44 - The function "as integer" isn't recognized.
2) Line 51 - y = (r * 24 + (( c mod 2)*12))+StartPointY.

For the first I just remove the "as integer" portion, for the second I suspect its the "(( c mod 2)*12))" thats causing it to balk.

I am not sure what "mod" does so I wasn't able to make a change on the DBC side.

Instead I just downloaded the trial of DBP and ran it
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 4th Apr 2004 06:21 Edited at: 4th Apr 2004 06:25
DBC does not have MOD? That bites. Mod is short for modulus aka % in C/C++. It is the 'remainder operator'. If you say 15 mod 10, you get back something from 0 to 9, in this case 5. So, ? mod 2 will return 0 or 1, basically an even/odd number detector which is real handy for hex grids since either the even or odd column has to be offset down a half hex.
--
TAZ

Without mod, you going to have maintain a variable or flag that toggles back and forth between 0 and 1 every time a new column is started. You can then use that as part of your DrawHex function.

for Columns = 1 to 43
for Rows=1 to 23
DrawHex(Columns, Rows)
next Rows
if offsetHex = 0 then offsetHex = 1 else offsetHex = 0
next Columns

The use offsetHex instead of (c mod 2)

Login to post a reply

Server time is: 2024-09-22 04:38:03
Your offset time is: 2024-09-22 04:38:03