sliderthing.bmx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. '
  2. ' www.sublimegames.com
  3. ' Silly picture tool by Stephen Greener (aka Shagwana)
  4. '
  5. '
  6. Strict
  7. Import MaxGUI.Drivers
  8. '_/ Consts \_______________________________________________________________________________________________________________
  9. Const iLEVEL_X_PIXEL_SIZE:Int = 32
  10. Const iLEVEL_Y_PIXEL_SIZE:Int = 32
  11. Const iLEVEL_X_SIZE:Int = 512 / iLEVEL_X_PIXEL_SIZE
  12. Const iLEVEL_Y_SIZE:Int = 512 / iLEVEL_Y_PIXEL_SIZE
  13. '_/ Includes \_______________________________________________________________________________________________________________
  14. 'Image files
  15. Incbin "sourcepic.jpg" '512x512
  16. '_/ Types \_______________________________________________________________________________________________________________
  17. Type tLevelInfo
  18. Field pImage:TImage[iLEVEL_X_SIZE,iLEVEL_Y_SIZE]
  19. Field pMapping:TImage[iLEVEL_X_SIZE,iLEVEL_Y_SIZE]
  20. Method Reset()
  21. For Local iX:Int=0 To iLEVEL_X_SIZE-1
  22. For Local iY:Int=0 To iLEVEL_Y_SIZE-1
  23. pMapping[iX,iY]=pImage[iX,iY]
  24. Next
  25. Next
  26. End Method
  27. Method Load(sFilename:String)
  28. 'Load the image
  29. Local pPixmap:TPixmap=LoadPixmap(sFilename)
  30. pPixmap:TPixmap=ConvertPixmap(pPixmap:TPixmap,PF_BGR888)
  31. For Local iX:Int=0 To iLEVEL_X_SIZE-1
  32. For Local iY:Int=0 To iLEVEL_Y_SIZE-1
  33. Local tWinPixMap:TPixmap=PixmapWindow(pPixmap:TPixmap,iX*iLEVEL_X_PIXEL_SIZE,iY*iLEVEL_Y_PIXEL_SIZE,iLEVEL_X_PIXEL_SIZE,iLEVEL_Y_PIXEL_SIZE)
  34. pImage:TImage[iX,iY]=LoadImage(tWinPixMap:TPixmap,MASKEDIMAGE) 'Chop up the image into tiles
  35. pMapping[iX,iY]=pImage:TImage[iX,iY]
  36. Next
  37. Next
  38. End Method
  39. Method Draw()
  40. SetBlend SOLIDBLEND
  41. For Local iX:Int=0 To iLEVEL_X_SIZE-1
  42. For Local iY:Int=0 To iLEVEL_Y_SIZE-1
  43. DrawImage pMapping[iX,iY],(iX*32),(iY*32)
  44. Next
  45. Next
  46. Flip
  47. End Method
  48. End Type
  49. '_/ Setup \_______________________________________________________________________________________________________________
  50. Local pMainWindow:TGadget = CreateWindow("Picture sliding thing v1.0",(GadgetWidth(Desktop())-600)/2,(GadgetHeight(Desktop())-600)/2,600,600,Null,WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
  51. Local pCanvas:TGadget = CreateCanvas(44,44,512,512,pMainWindow:TGadget)
  52. Local pLeftButton:TGadget[16]
  53. Local pRightButton:TGadget[16]
  54. Local pTopButton:TGadget[16]
  55. Local pBottomButton:TGadget[16]
  56. For Local iLoop:Int=0 To 15
  57. pRightButton[iLoop]=CreateButton("+",512+44,44+(iLoop*32),32,32,pMainWindow,BUTTON_PUSH)
  58. pLeftButton[iLoop]=CreateButton("+",44-32,44+(iLoop*32),32,32,pMainWindow,BUTTON_PUSH)
  59. pTopButton[iLoop]=CreateButton("+",44+(iLoop*32),44-32,32,32,pMainWindow,BUTTON_PUSH)
  60. pBottomButton[iLoop]=CreateButton("+",44+(iLoop*32),512+44,32,32,pMainWindow,BUTTON_PUSH)
  61. Next
  62. Global tGameLevel:tLevelInfo = New tLevelInfo
  63. tGameLevel.Load("incbin::sourcepic.jpg") 'Load it from the included file
  64. Local bQuitProgram=False
  65. '_/ Main program \_______________________________________________________________________________________________________________
  66. Repeat
  67. gccollect
  68. WaitEvent()
  69. Local pGadgetResposible:TGadget=Null
  70. Local iDir:Int=-1
  71. Local iXLine:Int=-1
  72. Local iYLine:Int=-1
  73. For Local iLoop:Int=0 To 15
  74. If EventSource()=pLeftButton[iLoop]
  75. pGadgetResposible=pLeftButton[iLoop]
  76. iXLine=-1
  77. iYLine=iLoop
  78. iDir=1
  79. EndIf
  80. If EventSource()=pRightButton[iLoop]
  81. pGadgetResposible=pRightButton[iLoop]
  82. iXLine=-1
  83. iYLine=iLoop
  84. iDir=-1
  85. EndIf
  86. If EventSource()=pTopButton[iLoop]
  87. pGadgetResposible=pTopButton[iLoop]
  88. iYLine=-1
  89. iXLine=iLoop
  90. iDir=1
  91. EndIf
  92. If EventSource()=pBottomButton[iLoop]
  93. pGadgetResposible=pBottomButton[iLoop]
  94. iYLine=-1
  95. iXLine=iLoop
  96. iDir=-1
  97. EndIf
  98. Next
  99. If pGadgetResposible<>Null
  100. 'Was a slider gadget ? ...
  101. If iYLine<>-1
  102. 'X line to scroll
  103. If iDir=1
  104. 'Scroll map one way
  105. Local pTemp:TImage=tGameLevel.pMapping[0,iYLine]
  106. For Local iP:Int=0 To iLEVEL_Y_SIZE-2
  107. tGameLevel.pMapping[iP,iYLine]=tGameLevel.pMapping[iP+1,iYLine]
  108. Next
  109. tGameLevel.pMapping[iLEVEL_X_SIZE-1,iYLine]=pTemp:TImage
  110. Else
  111. 'Scroll map the other way
  112. Local pTemp:TImage=tGameLevel.pMapping[iLEVEL_X_SIZE-1,iYLine]
  113. For Local iP:Int=iLEVEL_Y_SIZE-2 To 0 Step -1
  114. tGameLevel.pMapping[iP+1,iYLine]=tGameLevel.pMapping[iP,iYLine]
  115. Next
  116. tGameLevel.pMapping[0,iYLine]=pTemp:TImage
  117. EndIf
  118. Else
  119. 'Presume that iXLine<>-1
  120. If iDir=1
  121. 'Scroll map one way
  122. Local pTemp:TImage=tGameLevel.pMapping[iXLine,0]
  123. For Local iP:Int=0 To iLEVEL_X_SIZE-2
  124. tGameLevel.pMapping[iXLine,iP]=tGameLevel.pMapping[iXLine,iP+1]
  125. Next
  126. tGameLevel.pMapping[iXLine,iLEVEL_X_SIZE-1]=pTemp:TImage
  127. Else
  128. 'Scroll map the other way
  129. Local pTemp:TImage=tGameLevel.pMapping[iXLine,iLEVEL_Y_SIZE-1]
  130. For Local iP:Int=iLEVEL_X_SIZE-2 To 0 Step -1
  131. tGameLevel.pMapping[iXLine,iP+1]=tGameLevel.pMapping[iXLine,iP]
  132. Next
  133. tGameLevel.pMapping[iXLine,0]=pTemp:TImage
  134. EndIf
  135. EndIf
  136. 'Redraw the display cause we have moved it
  137. SetGraphics CanvasGraphics(pCanvas)
  138. Cls
  139. tGameLevel.Draw()
  140. Else
  141. 'Not one of the main game control gadgets
  142. Select EventID()
  143. Case EVENT_GADGETPAINT
  144. 'Redraw the main display
  145. SetGraphics CanvasGraphics(pCanvas)
  146. Cls
  147. tGameLevel.Draw()
  148. Case EVENT_WINDOWCLOSE
  149. 'Quit the program
  150. bQuitProgram=True
  151. End Select
  152. EndIf
  153. Until bQuitProgram=True
  154. End