Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Const SCREENX = 800
- Const SCREENY = 600
- Const SCROLLSPEED = 15
- SCREEN SCREENX,SCREENY,32,1
- FrameLimit 40
- //Initialization begins
- zoom = 100
- scrollx = 0
- scrolly = 0
- selectx = 0
- selecty = 0
- Const MAPX = 8
- Const MAPY = 4
- Dim map(MAPX,MAPY,20) //All information about map. X/Y/Data wanted
- Const MAP_TERRAIN = 0
- Const OPEN = 0
- Const PLAINS = 1
- Const FOREST = 2
- Const HILL = 3
- Const MOUNTAIN = 4
- Const LAKE = 5
- Const DESERT = 6
- Const SNOW = 7
- Const MAP_RESOURCE = 1
- Const EMPTY = 0
- Const IRON = 1
- Const DMAGIC = 2
- Const HORSE = 3
- Const MAP_VARIATION1 = 2
- Const MAP_VARIATION2 = 3
- For i = 0 To MAPX
- For j = 0 To MAPY
- Select Rand(0,7)
- Case 0
- map(i,j,MAP_TERRAIN) = OPEN
- Case 1
- map(i,j,MAP_TERRAIN) = PLAIN
- Case 2
- map(i,j,MAP_TERRAIN) = FOREST
- Case 3
- map(i,j,MAP_TERRAIN) = HILL
- Case 4
- map(i,j,MAP_TERRAIN) = MOUNTAIN
- Case 5
- map(i,j,MAP_TERRAIN) = LAKE
- Case 6
- map(i,j,MAP_TERRAIN) = DESERT
- Case 7
- map(i,j,MAP_TERRAIN) = SNOW
- End Select
- Select Rand(0,3)
- Case 0
- map(i,j,MAP_RESOURCE) = EMPTY
- Case 1
- map(i,j,MAP_RESOURCE) = IRON
- Case 2
- map(i,j,MAP_RESOURCE) = DMAGIC
- Case 3
- map(i,j,MAP_RESOURCE) = HORSE
- End Select
- map(i,j,MAP_VARIATION1) = Rand(0,19)
- map(i,j,MAP_VARIATION2) = Rand(0,19)
- Next j
- Next i
- //Initialization ends
- Repeat //Main loop begins
- ClearText
- Color cbwhite
- AddText "" + terraininfo(map(selectx,selecty,MAP_TERRAIN))
- AddText "" + resourceinfo(map(selectx,selecty,MAP_RESOURCE))
- //Selecting tiles
- If MouseHit(1) Then //Select the current Hex. Because of my inferior math skills at 2:40 AM, i used a Circle-based collision detection inside the hexes.
- clickx = MouseX()-scrollx
- clicky = MouseY()-scrolly
- For i = 0 To MAPX
- For j = 0 To MAPY
- midpointx = zoom/2 + zoom*i*3/4
- Select i Mod 2
- Case 0
- midpointy = zoom+zoom*j
- Case 1
- midpointy = zoom/2+zoom*j
- End Select
- If Distance(clickx,clicky,midpointx,midpointy) < zoom/2 Then
- selectx = i
- selecty = j
- EndIf
- Next j
- Next i
- EndIf
- //Scrolling&Zooming
- If KeyDown(cbkeyleft) Then scrollx = scrollx + SCROLLSPEED
- If KeyDown(cbkeyright) Then scrollx = scrollx - SCROLLSPEED
- If KeyDown(cbkeyup) Then scrolly = scrolly + SCROLLSPEED
- If KeyDown(cbkeydown) Then scrolly = scrolly - SCROLLSPEED
- scrolled=MouseMoveZ()
- zoombefore = zoom
- zoom = zoom + scrolled*8
- If zoom < 40 Or zoom > 200 Then
- Else
- scrollx = scrollx - scrolled*12
- scrolly = scrolly - scrolled*12
- EndIf
- If zoom < 40 Then zoom = 40
- If zoom > 200 Then zoom = 200
- If MouseDown(3) Then
- scrollx = scrollx + MouseMoveX()
- scrolly = scrolly + MouseMoveY()
- Else
- lastx=MouseMoveX()
- lasty=MouseMoveY()
- EndIf
- //Graphixs
- For i = 0 To MAPX //Draw the hexagons
- For j = 0 To MAPY
- selected = False
- If i = selectx And j = selecty Then selected = 1
- If i-1 = selectx And j = selecty Then selected = 2
- If i+1 = selectx And j = selecty Then selected = 3
- If i = selectx And j+1 = selecty Then selected = 4
- If i = selectx And j-1 = selecty Then selected = 5
- If i+1 = selectx And j-((i Mod 2)*2-1) = selecty Then selected = 6
- If i-1 = selectx And j-((i Mod 2)*2-1) = selecty Then selected = 7
- Select (i Mod 2)
- Case 0
- drawhex(i*zoom*3/4+scrollx,j*zoom+zoom/2+scrolly,zoom,selected,map(i,j,MAP_TERRAIN),map(i,j,MAP_RESOURCE),map(i,j,MAP_VARIATION1),map(i,j,MAP_VARIATION2))
- Case 1
- drawhex(i*zoom*3/4+scrollx,j*zoom+scrolly,zoom,selected,map(i,j,MAP_TERRAIN),map(i,j,MAP_RESOURCE),map(i,j,MAP_VARIATION1),map(i,j,MAP_VARIATION2))
- End Select
- Next j
- Next i
- DrawScreen
- Forever //Main loop ends
- Function drawhex(x,y,zoom,selected,land,resource,variation1,variation2) //Zoom is the lenght of every side in pixels.
- If selected = 0 Then
- Color 222,246,222
- ElseIf selected = 1 Then
- Color cbred
- Else
- Color cbgreen
- EndIf
- zoom = zoom/4
- Line zoom-1+x,0+y,zoom*3-1+x,0+y
- Line zoom*3-1+x,0+y,zoom*4-1+x,zoom*2-1+y
- Line zoom*4-1+x,zoom*2-1+y,zoom*3-1+x,zoom*4-1+y
- Line zoom*3-1+x,zoom*4-1+y,zoom-1+x,zoom*4-1+y
- Line zoom-1+x,zoom*4-1+y,0+x,zoom*2-1+y
- Line 0+x,zoom*2-1+y,zoom-1+x,0+y
- If selected > 0 Then
- For i = 0 To 3
- zoom=zoom-1
- x=x+2
- y=y+2
- Color getRGB(RED)-30,getRGB(GREEN)+25,getRGB(BLUE)+4
- Line zoom-1+x,0+y,zoom*3-1+x,0+y
- Line zoom*3-1+x,0+y,zoom*4-1+x,zoom*2-1+y
- Line zoom*4-1+x,zoom*2-1+y,zoom*3-1+x,zoom*4-1+y
- Line zoom*3-1+x,zoom*4-1+y,zoom-1+x,zoom*4-1+y
- Line zoom-1+x,zoom*4-1+y,0+x,zoom*2-1+y
- Line 0+x,zoom*2-1+y,zoom-1+x,0+y
- Next i
- EndIf
- If land = OPEN Then Color cbwhiteskin
- If land = PLAINS Then Color cblightred
- If land = FOREST Then Color cbgreen
- If land = HILL Then Color 136,136,136
- If land = MOUNTAIN Then Color cbdark
- If land = LAKE Then Color cbblue
- If land = DESERT Then Color cbdarkyellow
- If land = SNOW Then Color 240,240,255
- Circle x+zoom*2-10,y+zoom*2-10,20
- If resource <> EMPTY Then
- If resource = IRON Then Color cbsilver
- If resource = DMAGIC Then Color cbblack
- If resource = HORSE Then Color cbdarkred
- EndIf
- Circle x+zoom*2-4,y+zoom*2-4,8
- Color cbsilver
- Text x+zoom*2-20,y+zoom*2-36,""+variation1
- Text x+zoom*2-20,y+zoom*2+20,""+variation2
- End Function
- Function terraininfo(wantedinfo)
- infotxt$ = "Error"
- Select wantedinfo
- Case 0
- infotxt="Open"
- Case 1
- infotxt="Plains"
- Case 2
- infotxt="Forest"
- Case 3
- infotxt="Hill"
- Case 4
- infotxt="Mountain"
- Case 5
- infotxt="Lake"
- Case 6
- infotxt="Desert"
- Case 7
- infotxt="Snow"
- End Select
- Return infotxt
- End Function
- Function resourceinfo(wantedinfo)
- infotxt$ = "Error"
- Select wantedinfo
- Case 0
- infotxt="No resources"
- Case 1
- infotxt="Iron"
- Case 2
- infotxt="Dark Magic"
- Case 3
- infotxt="Horses"
- End Select
- Return infotxt
- End Function
Add Comment
Please, Sign In to add comment