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 / Need help creating a 2D grid

Author
Message
dark_dragon
16
Years of Service
User Offline
Joined: 25th Jun 2010
Location: Scarborough, Ontario
Posted: 7th Aug 2010 15:16
Hi all......I am trying to create a 2D grid like battle map with each grid unit being Hexagon shape. I searched the forums but couldnt find anything similar to what I am looking for.

If your not sure what I am looking for check the image I have attached

Any help would be great.

Don't judge a book by its cover.
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 7th Aug 2010 18:09
It's quite easy if you think of a hexagonal board as simple a grid with every other row offset - like this:



You can store information about the map just like you would with a square grid. Things get just a tad more complicated when checking what hexes are adjacent to which other ones.

dark_dragon
16
Years of Service
User Offline
Joined: 25th Jun 2010
Location: Scarborough, Ontario
Posted: 8th Aug 2010 00:09
Hi BMac.

Would I need to draw the hexagons by hand? or can DBP generate the map for me using certain commands?

I am REALLY new to Dark Basic Pro lol

Don't judge a book by its cover.
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 8th Aug 2010 03:40
Code Snippets has a function to make a 3D hexagon: http://forum.thegamecreators.com/?m=forum_view&t=113330&b=6

If you're doing this in 2D, yes, you'll want to draw a hexagon by hand. You can then load that image and paste it over and over again with a FOR loop to draw the board.

Since you're new, have you looked at some of the tutorials in the Newcomer's Corner? They will help you answer most of your questions.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 8th Aug 2010 06:46
dark dragonl if you're really really new to dark basic, you should check out the tutorials first.

You should at least know about for loops and two dimensional arrays before trying something like this.

and... what do you mean "draw the hexagons by hand"? You could create it in image editing software, then load the image with transparency as a sprite or something (you'd need ta make sure its a regular hexagon), or you could draw it using the line or some other 2d drawing command.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Aug 2010 05:17
You could make a hexagon shaped model in a 3d package. Should be fairly simple.

http://s6.bitefight.org/c.php?uid=103081
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Aug 2010 06:35
Here's a bit of code that makes a flat hexagon object for you...



BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 9th Aug 2010 06:39
@Rick - Cool, but slightly wasteful of polygons.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Aug 2010 07:52 Edited at: 9th Aug 2010 07:55
@BMacZero - yah, I know. You can get it down to 4 tri's for a flat one, or 16 for one with a base.

I've attached a model that can be used with this...



Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Aug 2010 07:54 Edited at: 9th Aug 2010 07:55
Oh, here's what it looks like...



dark_dragon
16
Years of Service
User Offline
Joined: 25th Jun 2010
Location: Scarborough, Ontario
Posted: 10th Aug 2010 15:09 Edited at: 10th Aug 2010 15:11
@Rich Dersheimer - Thanks a lot that is exactly what I am looking for.....I will be checking that code over later today.


Sorry I haven't responded until now I was away for a couple of days.

Don't judge a book by its cover.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 10th Aug 2010 19:53 Edited at: 10th Aug 2010 19:54
dark_dragon - I've put a better version in this thread, but the polys made with code in DBPro are sometimes hard to texture, so it might be easier for you to just make the hexes in a 3D modeling program. You could even use something as simple as Google Sketchup.

Here's a hex tile I made in Sketchup...



dark_dragon
16
Years of Service
User Offline
Joined: 25th Jun 2010
Location: Scarborough, Ontario
Posted: 11th Aug 2010 12:29
Rich Dersheimer - I just checked out your code in that other thread.

Its a pretty intense piece of code. I think Neuro Fuzzy may be right, I should learn about the basics first, this project I want to work on is far beyond my skill level, even professional coders that have been coding for 20 years would find this game a challenge.

Though I am excited about doing this project, I wont be able to get anything done if I don't know what I am doing.

Maybe I should try a "Space Invaders" type game first and work my way up lol.

Don't judge a book by its cover.

Login to post a reply

Server time is: 2026-07-25 07:02:16
Your offset time is: 2026-07-25 07:02:16