November 21, 2017, 03:56:16 PM

Author Topic: [bb] Topdown scrolling map by Pakz [ 1+ years ago ]  (Read 160 times)

Offline BlitzBot

  • Newbie
  • *
  • Posts: 0
[bb] Topdown scrolling map by Pakz [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Topdown scrolling map
Author : Pakz
Posted : 1+ years ago

Description :

I think this might interest some. A big map randomly created where a player can be moved through with the cursor keys. The map scrolls.
Could be the start of an rpg.


Code :
Code: BlitzBasic
  1. ; Topdown movement scrolling map by Rudy van Etten
  2. ;
  3. ;
  4.  
  5. Graphics 640,480,32,2
  6. SetBuffer BackBuffer()
  7. SeedRnd 1
  8. AppTitle "Use cursor keys to move the map"
  9. Global tilewidth = 8
  10. Global tileheight =8
  11. Global playerwidth = tilewidth
  12. Global playerheight = tileheight
  13. Global mapwidth = 512
  14. Global mapheight = 512
  15. Dim map(mapwidth,mapheight)
  16. Global mapx = 256
  17. Global mapy = 256
  18. Global playerx = mapx + ((GraphicsWidth()/tilewidth)/2)
  19. Global playery = mapy + ((GraphicsHeight()/tileheight)/2)
  20.  
  21. ; Make lines with pasways that goes a little bit wavy
  22. x = 0
  23. y = 0
  24. While y=<mapheight-5
  25.         y=y+3
  26.         While x=<mapwidth              
  27.                 If Rand(5) = 1 Then
  28.                         If m1<2
  29.                                 m1 = m1 + 1
  30.                                 Else
  31.                                 m1 = m1 -1
  32.                         End If
  33.                 End If
  34.                 If Rand(10) < 8
  35.                         map(x,y+m1) = 1
  36.                 End If
  37.                 x=x+1          
  38.         Wend
  39.         x=0
  40. Wend
  41.  
  42. ; Make open spaces
  43. For i=0 To 200
  44.         x1 = Rand(0,mapwidth)
  45.         y1 = Rand(0,mapheight)
  46.         rad = Rand(10,30)
  47.         For y2 = -rad To rad
  48.         For x2 = -rad To rad
  49.                 If (y2*y2+x2*x2) <= rad*rad+rad*0.8
  50.                         x3 = x1+x2
  51.                         y3 = y1+y2
  52.                         If Rand(10) < 8
  53.                         If x3=>0 And x3<=mapwidth And y3>=0 And y3<=mapheight
  54.                                 map(x3,y3) = 0
  55.                         End If
  56.                         End If
  57.                 End If
  58.         Next
  59.         Next
  60. Next
  61.  
  62. ; Make the borders
  63. For y=0 To mapheight
  64.         map(0,y) = 1
  65.         map(mapwidth,y) = 1
  66. Next
  67. For x=0 To mapwidth
  68.         map(x,0) = 1
  69.         map(x,mapheight) = 1
  70. Next
  71.  
  72.  
  73. ; Make sure the player location is not a wall
  74. map(playerx,playery) = 2
  75.  
  76. ; Main game loop
  77. Global mytimer = CreateTimer(15)
  78. While KeyDown(1) = False
  79.         WaitTimer mytimer
  80.         Cls
  81.         drawmap()
  82.         ; up
  83.         If KeyDown(200) And map(playerx,playery-1) = 0 Then
  84.                 map(playerx,playery) = 0
  85.                 playery = playery - 1
  86.                 mapy = mapy - 1
  87.                 map(playerx,playery) = 2
  88.         End If
  89.         ; down
  90.         If KeyDown(208) And map(playerx,playery+1) = 0 Then
  91.                 map(playerx,playery) = 0
  92.                 playery = playery + 1
  93.                 mapy = mapy + 1
  94.                 map(playerx,playery) = 2
  95.         End If
  96.         ; left
  97.         If KeyDown(203) And map(playerx-1,playery) = 0
  98.                 map(playerx,playery) = 0
  99.                 playerx = playerx - 1
  100.                 mapx = mapx - 1
  101.                 map(playerx,playery) = 2
  102.         End If
  103.         ; right
  104.         If KeyDown(205) And map(playerx+1,playery) = 0
  105.                 map(playerx,playery) = 0
  106.                 playerx = playerx + 1
  107.                 mapx = mapx + 1
  108.                 map(playerx,playery) = 2
  109.         End If
  110.  
  111.         Flip
  112. Wend
  113. End
  114.  
  115. Function drawmap()
  116.         For y=0 To GraphicsHeight()/tileheight
  117.         For x=0 To GraphicsWidth()/tilewidth
  118.                 tx = mapx + x
  119.                 ty = mapy + y
  120.                 If tx => 0  And tx <= mapwidth And ty => 0 And ty <= mapheight
  121.                         If map(tx,ty) = 1
  122.                                 Color 255,255,255
  123.                                 Rect x*tilewidth,y*tileheight,tilewidth,tileheight,True
  124.                         End If
  125.                         If map(tx,ty) = 2
  126.                                 Color 255,0,0
  127.                                 Rect x*tilewidth,y*tileheight,tilewidth,tileheight,True
  128.                         End If
  129.                        
  130.        
  131.                 End If
  132.         Next
  133.         Next
  134. End Function


Comments :


azcoca(Posted 1+ years ago)

 Cool.