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 / Turn based wargame programming "how-to" military hex maps

Author
Message
HexM
16
Years of Service
User Offline
Joined: 29th Jul 2008
Location:
Posted: 12th Aug 2008 02:49

Draws a perfect Hex with map function.

Draws a map.

Heres some more code.

I have taken a look at tutorials, and searched the web for countless hours. I understand the offsets and how they are made.

The only way I have gotten it to scroll properly is to pre-draw the map in a bitmap and scroll all the tiles as squares. Is there anyway to get this thing to scroll vertically without drawing the map ahead of time. just by displaying the hex images.

Can someone explain how this process would work. Thanks.
Terrorist Zero
18
Years of Service
User Offline
Joined: 29th Aug 2006
Location: Teh YouKai
Posted: 19th Aug 2008 01:35 Edited at: 19th Aug 2008 01:43
What I think you're trying to achieve and the way i'd do it is to include two extra variables into the draw function of your hex shapes, which would be the current player position (x,y) therefore allowing you to add those variables to alter the viewed position of the shape onscreen.

Here's an example:


Sorry for the messy code with BAD commands used
Run the code and you'll see where I'm coming from, I added in a quick function to make a line of hex shapes to make it easier to code, but this is just to demonstrate how you'd use the player's position variables to move the shapes. Notice how the two variables have been used in the DrawHex function to manipulate the drawing position each time the DrawHex function is called.

Hope it helps...

HexM
16
Years of Service
User Offline
Joined: 29th Jul 2008
Location:
Posted: 19th Aug 2008 22:26
Thanks for the code. This works. I played around with it for a while and it seems to run very slow with large maps. I guess there is no way around it, I'm just going to have to pre-draw a map and scroll it like a tile engine. Thanks.
wildbill
18
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 20th Aug 2008 15:46
Don't know why you are so hesitant to go with hex tiles. I use hex tiles and have made maps that are 1000 x 1000 hexes in size, with no loss of performance.

My hex tiles are 64X64 with the point at the top.
/\
||
\/

You need a few key functions.
TilePlotter(x,y) function:
[/code]
function TilePlotter(x,y)

ptMap.x = x*gTileWidth+(y and 1)*gTileWidth/2
ptMap.y = y*gHexRowHeight
`gHexRowHeight is a global set to 3/4 of the tile height
endfunction

ShowMapPanel() function:

function ShowMapPanel()
`set current bitmap MainDrawBitmap(0)
ink rgb(0,0,50),0
box MapPanel.left,MapPanel.top,MapPanel.right,MapPanel.bottom
` above used to clear with color the map panel
for index = 0 to gNumLayers
for mapy = 0 to gMapHeight
for mapx = 0 to gMapWidth
TilePlotter(mapx,mapy)
if TileMap(mapx,mapy,index) <> gBlank
if (ptMap.x+(MapPanel.left+gScrollX)) =< MapPanel.right and (ptMap.x+(MapPanel.left+gScrollX)) >= MapPanel.left
if (ptMap.y+(MapPanel.top+gScrollY)) =< MapPanel.bottom and (ptMap.y+(MapPanel.top+gScrollY)) >= MapPanel.top
paste image TileMap(mapx,mapy,index),ptMap.x+(MapPanel.left+gScrollX),ptMap.y+(MapPanel.top+gScrollY),1
endif
endif
endif
next mapx
next mapy
next index
`**********************Scroll Map Panel************************************************


if leftkey() = 1 and gScrollX > (((gMapWidth*gTileWidth)-screen width())*-1)
dec gScrollX,gTileWidth
endif

if rightkey()=1 and gScrollX < 0
inc gScrollX,gTileWidth
endif

if upkey() = 1 and gScrollY > (((gMapHeight*gHexRowHeight)-screen height())*-1)
dec gScrollY,(gHexRowHeight*2)
endif

if downkey()=1 and gScrollY < 0
inc gScrollY,(gHexRowHeight*2)
endif

endfunction
[code]

Hope this helps. I cannot go into as much depth as needed, because I'm at work.
HexM
16
Years of Service
User Offline
Joined: 29th Jul 2008
Location:
Posted: 21st Aug 2008 01:03
Thank you. I will try to play around some more with the code you gave me. I wrote something similar once, the reason i had to change my tactics was that, when i assigned different images to the hexes in the array. Scolling them in the x direction would work just fine, but in the y direction i was forced to scroll in increments of 2 hexes or else i would distort the map. suddenly a forest would be next to a river, then plains then back next to the river again on the 2nd hex because of the offset. So i had smooth scrolling in the x direction and i had huge jumping scrolling in the y direction in order to not distort the map.

Maybe you ran into a similar problem. lets say i had 2 images and they were in an array

World(100,100)
and each position equaled a number that was used to represent the image for the hex.

I had 2 variables I changed

if leftkey() = 1 and ShiftX > 0 then dec ShiftX
if rightkey() = 1 and ShiftX < (120 * 5)-1 then inc ShiftX
if downkey() = 1 and ShiftY < (120 * 4) - 1 then inc ShiftY
if upkey() = 1 and ShiftY > 0 then dec ShiftY

Then i drew the map that i wanted to be visable on the screen. based on those.

Drawmap(ShiftX,ShiftY)

Here is the function.


Everything looks fine until you put different terrains. Thanks in advance.
HexM
16
Years of Service
User Offline
Joined: 29th Jul 2008
Location:
Posted: 21st Aug 2008 01:17
Here is a zip file including my source and the images, run this and you will see what i mean.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 22:42:22
Your offset time is: 2024-11-24 22:42:22