Ooops
March 01, 2021, 10:46:53 PM

Author Topic: [bb] RPG 2d scrolling game example by Pakz [ 1+ years ago ]  (Read 433 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : RPG 2d scrolling game example
Author : Pakz
Posted : 1+ years ago

Description : player, scrolling, multi maps, coins, doors,keys

Code :
Code: BlitzBasic
  1. AppTitle "RPG 2D scrolling multi map - cursor keys to move."
  2. Graphics 640,480,16,2
  3. SetBuffer BackBuffer()
  4.  
  5. Global editmode = False
  6. Global edittile
  7.  
  8. Global keys = 0
  9. Global gold = 0
  10.  
  11. ; map variables
  12. Global mw = 40
  13. Global mh = 30
  14. Global tw = 32
  15. Global th = 32
  16.  
  17. Global numlevels = 5
  18.  
  19. Dim map(numlevels,mw,mh)
  20. ; player variables
  21. Global pw = (tw-5)
  22. Global ph = (th-5)
  23. Global px = GraphicsWidth()/2-tw/2
  24. Global py = GraphicsHeight()/2-th/2
  25. ; scrolling variables
  26. Global mx
  27. Global my
  28. Global msx=0
  29. Global msy
  30.  
  31. ; for the multi map
  32. ;
  33. ; this is a mdimensional array
  34. ; the player location on the multi map
  35. ; is mcx (map cursor x)
  36. ; it starts at 1,1, the center of the
  37. ; multidimensional array
  38. ;
  39. Global mcx=1
  40. Global mcy=1
  41. Dim ml(3,3)
  42. ;corner maps -1 non existant
  43. ml(0,0)=-1
  44. ml(2,0)=-1
  45. ml(0,2)=-1
  46. ml(2,2)=-1
  47. ; the maps assigned
  48. ml(1,0)=1
  49. ml(1,1)=0
  50. ml(2,1)=2
  51. ml(1,2)=3
  52. ml(0,1)=4
  53.  
  54. ; Here we create/buffer the maps
  55. Dim mapimage(5)
  56. For i=0 To 5
  57.         mapimage(i) = CreateImage(mw*tw,mh*th)
  58. Next
  59. Text 0,0,"Please wait"
  60. Flip
  61.  
  62. readlevels()
  63. makemaps()
  64.  
  65. .mainloop
  66. While KeyDown(1) = False
  67.         Cls    
  68.         If KeyHit(18);key e
  69.                 If editmode=True Then editmode = False Else editmode = True
  70.         EndIf
  71.         edit
  72.         If editmode = False
  73.                 For i=0 To 4 ;speed of movement
  74.                         moveplayer
  75.                         playeritemcollision
  76.                         centermap
  77.                         switchmap()
  78.                 Next
  79.                 DrawBlock mapimage(ml(mcx,mcy)),msx,msy
  80.                 drawplayer     
  81.                 Color 255,255,255
  82.                 Text 0,0,"Use cursors to move around"
  83.                 Text 0,15,"cursor : " + mcx +","+mcy+" on map : "+ml(mcx,mcy)
  84.                 Text 320,0,"gold:"+gold+" keys:"+keys
  85.                 Text 320,15,"Press e for edit mode"
  86.         End If
  87.         Flip
  88. Wend
  89. End
  90.  
  91.  
  92. Function edit()
  93.         If editmode = True
  94.                 DrawBlock mapimage(ml(mcx,mcy)),msx,msy
  95.                 Color 20,20,20         
  96.                 Rect 0,0,GraphicsWidth(),36,True
  97.                 For x=0 To 10
  98.                         drawtile(x,0,x)
  99.                         If edittile = x
  100.                                 Color 255,0,0
  101.                                 Rect x*tw,y*th,32,32,False
  102.                         End If
  103.                         If RectsOverlap(MouseX(),MouseY(),1,1,x*tw,0,32,32)
  104.                                 Color 255,255,255
  105.                                 Rect x*tw,0,32,32,False
  106.                                 Color 0,0,0
  107.                                 Rect x*tw+1,1,30,30,False
  108.                                 If MouseDown(1) = True
  109.                                         edittile = x
  110.                                 End If
  111.                         End If
  112.                 Next
  113.                 If RectsOverlap(MouseX(),MouseY(),1,1,0,32,GraphicsWidth(),GraphicsHeight()-32)
  114.                         x1 = (MouseX()-msx)/tw
  115.                         y1 = (MouseY()-msy)/th
  116.                         If MouseDown(1) = True
  117.                                 map(ml(mcx,mcy),x1,y1)=edittile
  118.                                 updatemap x1,y1,edittile
  119.                         End If
  120.                         Color 255,255,255
  121.                         Rect x1*tw,y1*th,32,32,False
  122.                         Color 0,0,0
  123.                         Rect x1*tw+1,y1*th+1,30,30,False
  124.                 End If
  125.                 If KeyDown(205) ; right
  126.                         msx=msx-3
  127.                 EndIf
  128.                 If KeyDown(203);left           
  129.                         msx=msx+3
  130.                 End If
  131.                 If KeyDown(200);up
  132.                         msy=msy+3
  133.                 End If
  134.                 If KeyDown(208);down
  135.                         msy=msy-3
  136.                 End If
  137.         End If
  138. End Function
  139.  
  140. ; here we check if the player is
  141. ; at a border and if he can go to another map
  142. ; and set the start positions
  143. Function switchmap()
  144.         ; touches the left side of the screen
  145.         If px<5 And mcx>0
  146.                 If ml(mcx-1,mcy) <>-1
  147.                         mcx=mcx-1
  148.                         px=630-pw                      
  149.                         msx=-(mw*tw-GraphicsWidth())
  150.                         If py<10 Then py=py+10
  151.                         If py+ph>GraphicsHeight()-10 Then py=py-10
  152.                 End If         
  153.         End If
  154.         ; touches the top part of the screen
  155.         If py<5 And mcy>0
  156.                 If ml(mcx,mcy-1) <> -1
  157.                         mcy=mcy-1
  158.                         py=470-ph
  159.                         msy=-(mh*th-GraphicsHeight())
  160.                         If px<10 Then px=10
  161.                         If px+pw>GraphicsWidth()-10 Then px=px-10
  162.                 End If
  163.         End If
  164.         ; touches the right side of the screen
  165.         If px+pw>GraphicsWidth()-4 And mcx<2
  166.                 If ml(mcx+1,mcy) <> -1
  167.                         mcx=mcx+1
  168.                         px=10
  169.                         msx=0
  170.                         If py<10 Then py=10
  171.                         If py+ph>GraphicsHeight()-10 Then py=py-10
  172.                 End If
  173.         End If
  174.         ; touches the bottom of the screen
  175.         If py+ph>GraphicsHeight()-5 And mcy<2
  176.                 If ml(mcx,mcy+1) <>-1
  177.                         mcy=mcy+1
  178.                         py=10
  179.                         msy=0
  180.                         If px<10 Then px=px+10
  181.                         If px+pw>GraphicsWidth()-10 Then px=px-10
  182.                 End If
  183.         End If
  184. End Function
  185.  
  186. Function centermap()
  187.         If px<GraphicsWidth()/3 And Abs(msx)>0 Then msx=msx+1 :px=px+1
  188.         If py<GraphicsHeight()/3 And Abs(msy)>0 Then msy=msy+1 :py=py+1
  189.         If px>GraphicsWidth()/100*66
  190.                 If (Abs(msx)+GraphicsWidth()) < mw*tw
  191.                         msx=msx-1
  192.                         px=px-1
  193.                 End If
  194.         End If
  195.         If py>GraphicsHeight()/100*66
  196.                 If (Abs(msy)+GraphicsHeight()) < mh*th
  197.                         msy=msy-1
  198.                         py=py-1
  199.                 End If
  200.         End If 
  201. End Function
  202.  
  203. Function moveplayer()
  204.         Local x=0
  205.         Local y=0
  206.         If KeyDown(200) ; up
  207.                 y=-1
  208.         End If
  209.         If KeyDown(205) ; right
  210.                 x=1
  211.         End If
  212.         If KeyDown(208) ; down
  213.                 y=1
  214.         End If
  215.         If KeyDown(203) ; left
  216.                 x=-1
  217.         End If
  218.         If px+x < 0 Then x=0
  219.         If px+pw+x > GraphicsWidth() Then x=0
  220.         If py+y < 0 Then y=0
  221.         If py+ph+y > GraphicsHeight() Then y=0
  222.         If playermapcollision((px+Abs(msx))+x,py+Abs(msy)) = False
  223.                 px=px+x
  224.         End If
  225.         If playermapcollision(px+Abs(msx),py+Abs(msy)+y) = False
  226.                 py=py+y
  227.         End If
  228.  
  229. End Function
  230.  
  231. Function playermapcollision(x1,y1)
  232.         Local cx=x1/tw
  233.         Local cy=y1/th
  234.         For y2=cy-1 To cy+1
  235.         For x2=cx-1 To cx+1    
  236.                 If x2>=0 And x2<=mw And y2>=0 And y2<=mh
  237.                 mt = map(ml(mcx,mcy),x2,y2)
  238.                 If mt >= 1 And mt <= 3 Or mt = 7 ; is the map around the player a block
  239.                 If RectsOverlap(x2*tw,y2*th,tw,th,x1,y1,pw,ph)
  240.                         ;
  241.                         ; Here the player is inside a wall
  242.                         ; a value 1 on the map
  243.                         ;
  244.                         Return True
  245.                         ;
  246.                 End If
  247.                 End If
  248.                 End If
  249.         Next
  250.         Next
  251.         ; no collision occured
  252.         Return False
  253. End Function
  254.  
  255. Function playeritemcollision()
  256.         Local cx=(px+Abs(msx))/tw
  257.         Local cy=(py+Abs(msy))/th
  258.         For y2=cy-1 To cy+1
  259.         For x2=cx-1 To cx+1
  260.                 If x2>=0 And x2<=mw And y2>=0 And y2<=mh
  261.                 ; collision with coin
  262.                 If map(ml(mcx,mcy),x2,y2) = 9 ; is the map around the player a 9 value
  263.                 If RectsOverlap(x2*tw+8,y2*th+8,tw-16,th-16,px+Abs(msx),py+Abs(msy),pw,ph)
  264.                         ;
  265.                         ; Here the player touches a map item (9)
  266.                         ; We remove it from the map
  267.                         ;
  268.                         gold=gold+1
  269.                         map(ml(mcx,mcy),x2,y2) = 0
  270.                         updatemap(x2,y2,0)
  271.                 End If
  272.                 End If
  273.                 ; collision with key
  274.                 If map(ml(mcx,mcy),x2,y2) = 8 ; is the map around the player a 9 value
  275.                 If RectsOverlap(x2*tw+8,y2*th+8,tw-16,th-16,px+Abs(msx),py+Abs(msy),pw,ph)
  276.                         ;
  277.                         ; Here the player touches a map item (9)
  278.                         ; We remove it from the map
  279.                         ;
  280.                         keys=keys+1
  281.                         map(ml(mcx,mcy),x2,y2) = 0
  282.                         updatemap(x2,y2,0)
  283.                 End If
  284.                 End If
  285.                 ; collision with door
  286.                 If map(ml(mcx,mcy),x2,y2) = 7 ; is the map around the player a 9 value
  287.                 If RectsOverlap(x2*tw-1,y2*th-1,tw+2,th+2,px+Abs(msx),py+Abs(msy),pw,ph)
  288.                 If keys>0
  289.                         ;
  290.                         ; Here the player touches a map item (9)
  291.                         ; We remove it from the map
  292.                         ;
  293.                         keys=keys-1
  294.                         map(ml(mcx,mcy),x2,y2) = 0
  295.                         updatemap(x2,y2,0)
  296.                 End If
  297.                 End If
  298.                 End If
  299.  
  300.  
  301.                 End If
  302.         Next
  303.         Next
  304. End Function
  305.  
  306.  
  307. Function updatemap(x,y,t)
  308.         SetBuffer ImageBuffer(mapimage(ml(mcx,mcy)))
  309.         drawtile(x,y,t)
  310.         SetBuffer BackBuffer()
  311. End Function
  312.  
  313. Function drawplayer()
  314.         Color 0,0,255
  315.         Oval px,py,pw,ph
  316. End Function
  317.  
  318. Function makemaps()
  319.         For i=0 To numlevels
  320.         SetBuffer ImageBuffer(mapimage(i))
  321.         For y=0 To mh-1
  322.         For x=0 To mw-1
  323.                 a = map(i,x,y)
  324.                 drawtile(x,y,a)
  325.         Next
  326.         Next
  327.         Next
  328.         SetBuffer BackBuffer()
  329. End Function
  330.  
  331. Function drawtile(x,y,t)
  332.         Select t
  333.                 Case 0;nothing
  334.                         Color 0,0,0
  335.                         Rect x*tw,y*th,tw,th
  336.                 Case 1;wall
  337.                         Color 255,255,255
  338.                         Rect x*tw,y*th,tw,th,True
  339.                 Case 2;water
  340.                         Color 30,80,255
  341.                         Rect x*tw,y*th,tw,th,True
  342.                 Case 3;tree
  343.                         Color 0,255,0
  344.                         x1=x*tw
  345.                         y1=y*th
  346.                         Line x1+tw/2,y1,x1+tw,y1+th
  347.                         Line x1+tw,y1+th-1,x1,y1+th-1
  348.                         Line x1,y1+th,x1+tw/2,y1
  349.                 Case 7 ; door
  350.                         Color 150,150,150
  351.                         Rect x*tw,y*th,tw,th
  352.                 Case 8; key
  353.                         Color 200,200,0
  354.                         Oval x*tw+2,y*th+2,tw-4,th-4
  355.                         Color 255,255,255
  356.                         Text x*tw+tw/2,y*th+th/2,"K",1,1                       
  357.                 Case 9 ; gold
  358.                         Color 200,200,0
  359.                         Oval x*tw+2,y*th+2,tw-4,th-4
  360.         End Select
  361. End Function
  362.  
  363. Function readlevels()
  364.         Restore level1
  365.         For i=0 To numlevels-1
  366.                 For y=0 To mh-1
  367.                 For x=0 To mw-1
  368.                         Read a
  369.                         map(i,x,y) = a
  370.                 Next
  371.                 Next
  372.         Next
  373. End Function
  374.  
  375. .level1
  376. Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
  377. Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
  378. Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
  379. Data 0,0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,0,0,3,3,3,3,0,0,0,0,0,0,0,0
  526. Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0
  527. Data 2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0
  528. Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
  529. Data 2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3


Comments :


Dan(Posted 1+ years ago)

 great example.There is a bug, where the player cannot go through the doors.to fix this, make following change:
Code: [Select]
Global pw = (tw-5)
Global ph = (th-5)



Guy Fawkes(Posted 1+ years ago)

 INCREDIBLE! :O Is there a way to add detection of a collision sprite on another map? I sometimes warp to another map & I'm stuck in a tree. A way to edit the Data of the levels would be INCREDIBLE!Keep up the GREAT work!~GF


Pakz(Posted 1+ years ago)

 @Dan - That bug I had before (last year or so) and I had a different fix but I forgot how I did that. @Guy - I might add a simple map editor. tonight  Maybe I will add a warp key shortcut to.


Guy Fawkes(Posted 1+ years ago)

 COOOOOOOOOOOOOOOOOOOOOL! =D Keep up the GREAT work! =) I see this project going a LONG way!~GF


Dan(Posted 1+ years ago)

 @pakz i guess the bug is up to the steps which the circle need to move from one position to another.So if the circle is not 100% at the empty space, it wont go through.You can go through the door with your original example, you will need to use 2 keys (down/up and left if the door is at the left side).but if you try to position the circle directly at the door, and then press left, it doesnt work (here). so i made the circle a bit smaller.


Guy Fawkes(Posted 1+ years ago)

 Any luck Pakz? =)~GF


Pakz(Posted 1+ years ago)

 I have not had any time yet Guy. Also, a map editor would require a save/load feature. Do you think you could do that on your own? Or should I just put in the code for you to enable? The code archives have no file inclusion. That is why I have the data statements in.


Guy Fawkes(Posted 1+ years ago)

 Put the code in to enable would be awesome! =)Thanks Pakz!~GF


Andy_A(Posted 1+ years ago)

 PakzYou can include ****small**** files (.zip, .png, .jpg) indirectly.<a href="http://www.blitzmax.com/codearcs/codearcs.php?code=3026" target="_blank">http://www.blitzmax.com/codearcs/codearcs.php?code=3026[/url]


Pakz(Posted 1+ years ago)

 Thanks Andy :)@Dan - I changed the code, the player is now smaller.@Guy - I have added a simple editor. Press e for edit mode. Still need to add save and load feature.


AdamStrange(Posted 1+ years ago)

 here's a blitzmax version with some error checking and deeper water added plus some minor interface changes
Code: [Select]

Graphics 640,480

Global editmode = False
Global edittile

Global keys = 0
Global gold = 0
global totalgold:int = 0

' map variables
Global mw = 40
Global mh = 30
Global tw = 32
Global th = 32

Global numlevels = 5

global map:int[numlevels, mw, mh]

' player variables
Global pw = (tw-5)
Global ph = (th-5)
Global px = GraphicsWidth()/2-tw/2
Global py = GraphicsHeight()/2-th/2
' scrolling variables
Global mx
Global my
Global msx=0
Global msy

' for the multi map
'
' this is a mdimensional array
' the player location on the multi map
' is mcx (map cursor x)
' it starts at 1,1, the center of the
' multidimensional array
'
Global mcx=1
Global mcy=1

global ml[3, 3]

'corner maps -1 non existant
ml[0,0]=-1
ml[2,0]=-1
ml[0,2]=-1
ml[2,2]=-1
' the maps assigned
ml[1,0]=1
ml[1,1]=0
ml[2,1]=2
ml[1,2]=3
ml[0,1]=4


setblend alphablend

readlevels()
makemaps()

'.mainloop
While KeyDown(1) = False and not(AppTerminate())
Cls
If KeyHit(KEY_E)'key e
If editmode=True Then editmode = False Else editmode = True
EndIf
edit
If editmode = False
For i=0 To 4 'speed of movement
moveplayer
playeritemcollision
centermap
switchmap()
Next

drawmap(ml(mcx,mcy), msx,msy)

setalpha 0.2
setcolor 0,0,0
drawrect 0,0,640,30
setalpha 1

drawplayer

setColor 0,0,0
drawText "Use cursors to move around",1,1
drawText "cursor : " + mcx +","+mcy+" on map : "+ml(mcx,mcy), 1,16
drawText "gold:"+gold+" of "+totalgold+"   keys:"+keys, 321,1
drawText "Press e for edit mode", 321,16
setColor 240,240,150
drawText "Use cursors to move around",0,0
drawText "cursor : " + mcx +","+mcy+" on map : "+ml(mcx,mcy), 0,15
drawText "gold:"+gold+" of "+totalgold+"   keys:"+keys, 320,0
drawText "Press e for edit mode", 320,15
End If

delay 10
Flip
Wend
End

Function drawmap(level:int, xo:int, yo:int)
For y=0 To mh-1
For x=0 To mw-1
a = map[level,x,y]
drawtile(x,y,a, xo, yo)
Next
Next
End Function

function rectsOverlap:int(x1,y1,w1,h1, x2,y2,w2,h2)
w1 :+ x1
h1 :+ y1
w2 :+ x2
h2 :+ y2

if w1 < x2 then return false
if x1 > w2 then return false

if h1 < y2 then return false
if y1 > h2 then return false

return true
end function

Function edit()
If editmode = True
drawmap(ml(mcx,mcy), msx,msy)

setColor 20,20,20
drawRect 0,0,GraphicsWidth(),36
For x=0 To 10
drawtile(x,0,x)
If edittile = x
setColor 255,0,0
drawRect x*tw,y*th,32,32
End If
If RectsOverlap(MouseX(),MouseY(),1,1,x*tw,0,32,32)
setColor 255,255,255
drawRect x*tw,0,32,32
setColor 0,0,0
drawRect x*tw+1,1,30,30
If MouseDown(1) = True
edittile = x
End If
End If
Next
If RectsOverlap(MouseX(),MouseY(),1,1,0,32,GraphicsWidth(),GraphicsHeight()-32)
x1 = (MouseX()-msx)/tw
y1 = (MouseY()-msy)/th
If MouseDown(1) = True
map(ml(mcx,mcy),x1,y1)=edittile
updatemap x1,y1,edittile
End If
setColor 255,255,255
drawRect x1*tw+msx,y1*th+msy,32,32
setColor 0,0,0
drawRect x1*tw+1+msx,y1*th+1+msy,30,30
End If
If KeyDown(KEY_RIGHT) ' right
msx=msx-3
EndIf
If KeyDown(KEY_LEFT)'left
msx=msx+3
End If
If KeyDown(KEY_UP)'up
msy=msy+3
End If
If KeyDown(KEY_DOWN)'down
msy=msy-3
End If
End If
End Function

' here we check if the player is
' at a border and if he can go to another map
' and set the start positions
Function switchmap()
' touches the left side of the screen
If px<5 And mcx>0
If ml(mcx-1,mcy) <>-1
mcx=mcx-1
px=630-pw
msx=-(mw*tw-GraphicsWidth())
If py<10 Then py=py+10
If py+ph>GraphicsHeight()-10 Then py=py-10
End If
End If
' touches the top part of the screen
If py<5 And mcy>0
If ml(mcx,mcy-1) <> -1
mcy=mcy-1
py=470-ph
msy=-(mh*th-GraphicsHeight())
If px<10 Then px=10
If px+pw>GraphicsWidth()-10 Then px=px-10
End If
End If
' touches the right side of the screen
If px+pw>GraphicsWidth()-4 And mcx<2
If ml(mcx+1,mcy) <> -1
mcx=mcx+1
px=10
msx=0
If py<10 Then py=10
If py+ph>GraphicsHeight()-10 Then py=py-10
End If
End If
' touches the bottom of the screen
If py+ph>GraphicsHeight()-5 And mcy<2
If ml(mcx,mcy+1) <>-1
mcy=mcy+1
py=10
msy=0
If px<10 Then px=px+10
If px+pw>GraphicsWidth()-10 Then px=px-10
End If
End If
End Function

Function centermap()
If px<GraphicsWidth()/3 And Abs(msx)>0 Then
msx=msx+1
px=px+1
end if
If py<GraphicsHeight()/3 And Abs(msy)>0 Then
msy=msy+1
py=py+1
end if
If px>GraphicsWidth()/100*66
If (Abs(msx)+GraphicsWidth()) < mw*tw then
msx=msx-1
px=px-1
End If
End If
If py>GraphicsHeight()/100*66
If (Abs(msy)+GraphicsHeight()) < mh*th then
msy=msy-1
py=py-1
End If
End If
End Function

Function moveplayer()
Local x=0
Local y=0
If KeyDown(KEY_UP) ' up
y=-1
End If
If KeyDown(KEY_RIGHT) ' right
x=1
End If
If KeyDown(KEY_DOWN) ' down
y=1
End If
If KeyDown(KEY_LEFT) ' left
x=-1
End If
If px+x < 0 Then x=0
If px+pw+x > GraphicsWidth() Then x=0
If py+y < 0 Then y=0
If py+ph+y > GraphicsHeight() Then y=0

local collide:int = playermapcollision((px+Abs(msx))+x,py+Abs(msy))
if collide = 0 then
px=px+x
else if collide = 2 and rand(0,100) < 40 then px=px+x
End If

collide = playermapcollision(px+Abs(msx),py+Abs(msy)+y)
if collide = 0 then
py=py+y
else if collide = 2 and rand(0,100) < 40 then py=py+y
End If

End Function

Function playermapcollision(x1,y1)
Local cx=x1/tw
Local cy=y1/th
For y2=cy-1 To cy+1
For x2=cx-1 To cx+1
If x2 >= 0 And x2 < mw And y2 >= 0 And y2 < mh then
mt = map[ml(mcx,mcy),x2,y2]

If mt = 1 or mt = 2 or mt = 3 Or mt = 4 or mt = 7 then ' is the map around the player a block
If RectsOverlap(x2*tw,y2*th,tw,th,x1,y1,pw,ph)
' Here the player is inside a wall
' a value 1 on the map
Return mt
End If
End If
End If
Next
Next
' no collision occured
Return 0
End Function

Function playeritemcollision()
Local cx=(px+Abs(msx))/tw
Local cy=(py+Abs(msy))/th
For y2=cy-1 To cy+1
For x2=cx-1 To cx+1
If x2 >= 0 And x2 < mw And y2 >= 0 And y2 < mh then
' collision with coin
If map(ml(mcx,mcy),x2,y2) = 9 then ' is the map around the player a 9 value
If RectsOverlap(x2*tw+8,y2*th+8,tw-16,th-16,px+Abs(msx),py+Abs(msy),pw,ph) then
' Here the player touches a map item (9)
' We remove it from the map
gold=gold+1
map(ml(mcx,mcy),x2,y2) = 0
updatemap(x2,y2,0)
End If
End If

' collision with key
If map(ml(mcx,mcy),x2,y2) = 8 then' is the map around the player a 9 value
If RectsOverlap(x2*tw+8,y2*th+8,tw-16,th-16,px+Abs(msx),py+Abs(msy),pw,ph) then
' Here the player touches a map item (9)
' We remove it from the map
keys=keys+1
map(ml(mcx,mcy),x2,y2) = 0
updatemap(x2,y2,0)
End If
End If

' collision with door
If map(ml(mcx,mcy),x2,y2) = 7 then' is the map around the player a 9 value
If RectsOverlap(x2*tw-1,y2*th-1,tw+2,th+2,px+Abs(msx),py+Abs(msy),pw,ph) then
If keys > 0 then
' Here the player touches a map item (9)
' We remove it from the map
keys=keys-1
map(ml(mcx,mcy),x2,y2) = 0
updatemap(x2,y2,0)
End If
End If
End If

End If
Next
Next
End Function


Function updatemap(x,y,t)
drawtile(x,y,t)
End Function

Function drawplayer()
setColor 0,0,255
drawOval px,py,pw,ph
End Function

Function makemaps()
For i=0 To numlevels-1
For y=0 To mh-1
For x=0 To mw-1
a = map[i,x,y]
drawtile(x,y,a)
Next
Next
Next
End Function

Function drawtile(x,y,t, xo:int = 0, yo:int = 0)
Select t
Case 0'nothing
setColor 0,0,0
drawRect x*tw + xo,y*th + yo,tw,th
Case 1'wall
setColor 255,255,255
drawRect x*tw + xo,y*th + yo,tw,th
Case 2'water
setColor 30,140,255
drawRect x*tw + xo,y*th + yo,tw,th
Case 3'tree
setColor 0,255,0
x1=x*tw + xo
y1=y*th + yo
drawLine x1+tw/2,y1,x1+tw,y1+th
drawLine x1+tw,y1+th-1,x1,y1+th-1
drawLine x1,y1+th,x1+tw/2,y1
Case 4'deepwater
setColor 30,100,245
drawRect x*tw + xo,y*th + yo,tw,th
Case 7 ' door
setColor 150,150,150
drawRect x*tw + xo,y*th + yo,tw,th
Case 8' key
setColor 180,120,00
drawOval x*tw+2 + xo,y*th+2 + yo,tw-4,th-4
setColor 255,255,255
drawText "K",x*tw + (tw/3.4) + xo, y*th + (th/3.4) + yo

Case 9 ' gold
setColor 230,200,0
drawOval (x*tw+2) + xo, (y*th+2) + yo, tw-4, th-4
End Select
End Function

Function readlevels()
' Restore level1
print numlevels
For i=0 To numlevels-1
For y=0 To mh-1
For x=0 To mw-1
Readdata a
map[i, x,y] = a
if a = 9 then totalgold :+ 1
Next
Next
Next
End Function

'.level1
defdata 0,0,0,0,0,0,0,0,0,0,0,0,2,2,4,2,2,2,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
defdata 0,0,0,0,0,0,0,2,2,2,2,2,4,4,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
defdata 0,0,0,0,0,0,2,4,4,4,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
defdata 0,0,0,0,0,2,4,4,2,2,2,2,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4,4,4,4,4,4,4,4,4,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3



Guy Fawkes(Posted 1+ years ago)

 Here's the same thing, translated into Blitz3D :: [code]
Graphics3D ( 800, 600, 0, 2 )

Global editmode = False
Global edittile

Global keys = 0
Global gold = 0
Global totalgold = 0

; map variables
Global mw = 40
Global mh = 30
Global tw = 32
Global th = 32

Global numlevels = 5

Dim map ( numlevels, mw, mh )

; player variables
Global pw = ( tw - 5 )
Global ph = ( th - 5 )
Global px =  GraphicsWidth ( ) / 2 - tw / 2
Global py = GraphicsHeight ( ) / 2 - th / 2

; scrolling variables
Global mx
Global my
Global msx = 0
Global msy

; For the multi map
;
; this is a mdimensional array
; the player location on the multi map
; is mcx ( map cursor x )
; it starts at 1, 1, the center of the
; multidimensional array
;
Global mcx = 1
Global mcy = 1

Dim ml ( 3, 3 )

;corner maps  - 1 non existant
ml ( 0, 0 ) =  -1
ml ( 2, 0 ) =  -1
ml ( 0, 2 ) =  -1
ml ( 2, 2 ) =  -1

; the maps assigned
ml ( 1, 0 ) = 1
ml ( 1, 1 ) = 0
ml ( 2, 1 ) = 2
ml ( 1, 2 ) = 3
ml ( 0, 1 ) = 4

readlevels ( )

makemaps ( )

;.mainloop
While Not KeyDown ( 1 )

   Cls

      ;key e
      If KeyHit ( 18 ) Then editmode = 1 - editmode

      edit ( )
   
         If editmode = False
      
            For i = 0 To 4 ;speed of movement
      
               moveplayer ( )
      
                  playeritemcollision ( )
         
                  centermap ( )
      
               switchmap ( )
      
            Next
            
               drawmap ( ml ( mcx, mcy ), msx, msy )
   
                  Color 0, 0, 0
            
                  Rect 0, 0, 640, 30
               
               drawplayer ( )

            Color 0, 0, 0

               Text "Use cursors to move around", 1, 1
         
                  Text "cursor : " + mcx + ", " + mcy + " on map : " + ml ( mcx, mcy ), 1, 16
         
               Text "gold:" + gold + " of " + totalgold + "   keys:" + keys, 321, 1
      
            Text "Press e for edit mode", 321, 16
      
            Color 240, 240, 150
      
               Text "Use cursors to move around", 0, 0
         
                  Text "cursor : " + mcx + ", " + mcy + " on map : " + ml ( mcx, mcy ), 0, 15
         
               Text "gold:" + gold + " of " + totalgold + "   keys:" + keys, 320, 0
      
            Text "Press e for edit mode", 320, 15
      
         EndIf
   
      Delay 10

   Flip

Wend

End

Function drawmap ( level, xo, yo )

   For y = 0 To mh - 1

      For x = 0 To mw - 1

         a = map ( level, x, y )

         drawtile ( x, y, a, xo, yo )

      Next

   Next

End Function

Function edit ( )

   If editmode = True

      drawmap ( ml ( mcx, mcy ), msx, msy )
      
      Color 20, 20, 20      

      Rect 0, 0, GraphicsWidth ( ), 36

      For x = 0 To 10

         drawtile ( x, 0, x )

            If edittile = x
   
               Color 255, 0, 0
   
               Rect x * tw, y * th, 32, 32
   
            EndIf

         If RectsOverlap ( MouseX ( ), MouseY ( ), 1, 1, x * tw, 0, 32, 32 )

            Color 255, 255, 255

               Rect x * tw, 0, 32, 32
   
                  Color 0, 0, 0
   
               Rect x * tw + 1, 1, 30, 30

            If MouseDown ( 1 ) = True Then edittile = x

         EndIf

      Next

      If RectsOverlap ( MouseX ( ), MouseY ( ), 1, 1, 0, 32, GraphicsWidth ( ), GraphicsHeight ( ) - 32 )

         x1 = ( MouseX ( ) - msx ) / tw

            y1 = ( MouseY ( ) - msy ) / th
   
               If MouseDown ( 1 ) = True
      
                  map ( ml ( mcx, mcy ), x1, y1 ) = edittile
      
                     updatemap x1, y1, edittile
                  
                  FlushMouse ( )
      
               EndIf
   
            Color 255, 255, 255
   
            Rect x1 * tw + msx, y1 * th + msy, 32, 32

         Color 0, 0, 0

         Rect x1 * tw + 1 + msx, y1 * th + 1 + msy, 30, 30

      EndIf

      If KeyDown ( 200 ) Then msy = msy + 3

         If KeyDown ( 208 ) Then msy = msy - 3
   
         If KeyDown ( 203 ) Then msx = msx + 3

      If KeyDown ( 205 ) Then msx = msx - 3

   EndIf

End Function

; here we check If the player is
; at a border And If he can go To another map
; And set the start positions
Function switchmap ( )

   ; touches the Left side of the screen
   If px < 5 And mcx > 0
      If ml ( mcx - 1, mcy ) <> - 1
         mcx = mcx - 1
         px = 630 - pw         
         msx =  - ( mw * tw - GraphicsWidth ( ) )
         If py < 10 py = py + 10
         If py + ph > GraphicsHeight ( ) - 10 py = py - 10
      EndIf      
   EndIf
   ; touches the top part of the screen
   If py < 5 And mcy > 0
      If ml ( mcx, mcy - 1 ) <> - 1
         mcy = mcy - 1
         py = 470 - ph
         msy =  - ( mh * th - GraphicsHeight ( ) )
         If px < 10 px = 10
         If px + pw > GraphicsWidth ( ) - 10 px = px - 10
      EndIf
   EndIf
   ; touches the Right side of the screen
   If px + pw > GraphicsWidth ( ) -4 And mcx < 2
      If ml ( mcx + 1, mcy ) <> -1
         mcx = mcx + 1
         px = 10
         msx = 0
         If py < 10 py = 10
         If py + ph > GraphicsHeight ( ) - 10 py = py - 10
      EndIf
   EndIf
   ; touches the bottom of the screen
   If py + ph > GraphicsHeight ( ) - 5 And mcy < 2
      If ml ( mcx, mcy + 1 ) <> -1
         mcy = mcy + 1
         py = 10
         msy = 0
         If px < 10 px = px + 10
         If px + pw > GraphicsWidth ( ) - 10 px = px - 10
      EndIf
   EndIf
End Function

Function centermap ( )
   If px < GraphicsWidth ( ) / 3 And Abs ( msx ) > 0 Then
      msx = msx + 1
      px = px + 1
   EndIf
   If py < GraphicsHeight ( ) / 3 And Abs ( msy ) > 0 Then
      msy = msy + 1
      py = py + 1
   EndIf
   If px > GraphicsWidth ( ) / 100 * 66
      If ( Abs ( msx ) + GraphicsWidth ( ) ) < mw * tw Then
         msx = msx - 1
         px = px - 1
      EndIf
   EndIf
   If py > GraphicsHeight ( ) / 100 * 66
      If ( Abs ( msy ) + GraphicsHeight ( ) ) < mh * th Then
         msy = msy - 1
         py = py - 1
      EndIf
   EndIf   
End Function

Function moveplayer ( )

   Local x = 0
   Local y = 0

   If KeyDown ( 200 ) Then y = y - 1
   If KeyDown ( 208 ) Then y = y + 1
   If KeyDown ( 203 ) Then x = x - 1
   If KeyDown ( 205 ) Then x = x + 1

   If px + x < 0 Then x = 0
   If px + pw + x > GraphicsWidth ( ) Then x = 0
   If py + y < 0 Then y = 0
   If py + ph + y > GraphicsHeight ( ) Then y = 0

   Local collide = playermapcollision ( ( px + Abs ( msx ) ) + x, py + Abs ( msy ) )

   If collide = 0
      px = px + x
   ElseIf collide = 2 And Rand ( 0, 100 ) < 40
      px = px + x
   EndIf

   collide = playermapcollision ( px + Abs ( msx ), py + Abs ( msy ) + y )

   If collide = 0

      py = py + y

   ElseIf collide = 2 And Rand ( 0, 100 ) < 40

      py = py + y

   EndIf

End Function

Function playermapcollision ( x1, y1 )

   Local cx = x1 / tw

      Local cy = y1 / th
   
         For y2 = cy - 1 To cy + 1
      
            For x2 = cx - 1 To cx + 1   
      
               If x2 >= 0 And x2 < mw And y2 >= 0 And y2 < mh
      
                  mt = map ( ml ( mcx, mcy ), x2, y2 )
      
                  ; Is the Map around the Player a Block?
                  If mt = 1 Or mt = 2 Or mt = 3 Or mt = 4 Or mt = 7
      
                     If RectsOverlap ( x2 * tw, y2 * th, tw, th, x1, y1, pw, ph )
      
                        ; Here the Player is inside a Wall
      
                           ; A value 1 on the Map
      
                        Return mt
      
                     EndIf
      
                  EndIf
      
               EndIf
      
            Next
      
         Next

      ; No Collision Occured

   Return 0

End Function

Function playeritemcollision ( )

   Local cx = ( px + Abs ( msx ) ) / tw

   Local cy = ( py + Abs ( msy ) ) / th

   For y2 = cy - 1 To cy + 1

      For x2 = cx - 1 To cx + 1

         If x2 >= 0 And x2 < mw And y2 >= 0 And y2 < mh

            ; Collision with Coin

               ; Is the Map around the Player a 9 value?

            If map ( ml ( mcx, mcy ), x2, y2 ) = 9

               If RectsOverlap ( x2 * tw + 8, y2 * th + 8, tw - 16, th - 16, px + Abs ( msx ), py + Abs ( msy ), pw, ph )

                  ; Here the player touches a map item ( 9 )

                     ; We remove it from the map

                  gold = gold + 1

                     map ( ml ( mcx, mcy ), x2, y2 ) = 0

                  updatemap ( x2, y2, 0 )

               EndIf

            EndIf
            
               ; Collision with Key

                  ; Is the Map around the Player an 8 value?
   
               If map ( ml ( mcx, mcy ), x2, y2 ) = 8
   
                  If RectsOverlap ( x2 * tw + 8, y2 * th + 8, tw - 16, th - 16, px + Abs ( msx ), py + Abs ( msy ), pw, ph )
   
                     ; Here the player touches a map item ( 9 )

                        ; We remove it from the map
   
                           keys = keys + 1
   
                        map ( ml ( mcx, mcy ), x2, y2 ) = 0
   
                     updatemap ( x2, y2, 0 )
   
                  EndIf
   
               EndIf
            
            ; Collision with Door

               ; Is the Map around the Player a 7 value?

            If map ( ml ( mcx, mcy ), x2, y2 ) = 7

               If RectsOverlap ( x2 * tw - 1, y2 * th - 1, tw + 2, th + 2, px + Abs ( msx ), py + Abs ( msy ), pw, ph )

                   If keys > 0

                     ; Here the Player touches a map item ( 9 )

                        ; We remove it from the map
   
                           keys = keys - 1

                        map ( ml ( mcx, mcy ), x2, y2 ) = 0

                     updatemap ( x2, y2, 0 )

                  EndIf

               EndIf

            EndIf
   
         EndIf

      Next

   Next

End Function

Function updatemap ( x, y, t )

   drawtile ( x, y, t )

End Function

Function drawplayer ( )

   Color 0, 0, 255

   Oval px, py, pw, ph

End Function

Function makemaps ( )

   For i = 0 To numlevels - 1

      For y = 0 To mh - 1

         For x = 0 To mw - 1

            a = map ( i, x, y )

            drawtile ( x, y, a )

         Next

      Next

   Next

End Function

Function drawtile ( x, y, t, xo = 0, yo = 0 )

   Select t

      ;Nothing
      Case 0

         Color 0, 0, 0

         Rect x * tw + xo, y * th + yo, tw, th

      ;Wall

      Case 1

         Color 255, 255, 255

         Rect x * tw + xo, y * th + yo, tw, th

      ;Water

      Case 2

         Color 30, 140, 255

         Rect x * tw + xo, y * th + yo, tw, th

      ;Tree

      Case 3

         Color 0, 255, 0

            x1 = x * tw + xo
   
               y1 = y * th + yo
      
               DrawLine x1 + tw / 2, y1, x1 + tw, y1 + th
   
            DrawLine x1 + tw, y1 + th - 1, x1, y1 + th - 1

         DrawLine x1, y1 + th, x1 + tw / 2, y1

      ;Deep Water

      Case 4

         Color 30, 100, 245

         Rect x * tw + xo, y * th + yo, tw, th

      ; Door

      Case 7

         Color 150, 150, 150

         Rect x * tw + xo, y * th + yo, tw, th

      ; Key

      Case 8

         Color 180, 120, 00
   
            Oval x * tw + 2 + xo, y * th + 2 + yo, tw - 4, th - 4
      
            Color 255, 255, 255
   
         Text x * tw + ( tw / 3.4 ) + xo, y * th + ( th / 3.4 ) + yo, "K"

      ; Gold

      Case 9

         Color 230, 200, 0
   
         Oval ( x * tw + 2 ) + xo, ( y * th + 2 ) + yo, tw - 4, th - 4

   End Select

End Function

Function readlevels ( )

;   Restore level1

   Print numlevels

   For i = 0 To numlevels - 1

      For y = 0 To mh - 1

         For x = 0 To mw - 1

            Read a

               map ( i, x, y ) = a

            If a = 9 Then totalgold = totalgold + 1

         Next

      Next

   Next

End Function

.level1
Data 0,0,0,0,0,0,0,0,0,0,0,0,2,2,4,2,2,2,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,2,2,2,2,2,4,4,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,2,4,4,4,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,2,4,4,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1
Data 0,0,0,2,2,4,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,8,0,1,1,1,1,1,1,1
Data 2,2,2,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,1,1,1,1,1,1,1
Data 4,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,0,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