background.bmx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. '===============================================================================
  2. ' Little Shooty Test Thing
  3. ' Code & Stuff by Richard Olpin ([email protected])
  4. '===============================================================================
  5. ' Background.bmx
  6. '
  7. ' Module for tilemapped background layer
  8. '
  9. '===============================================================================
  10. Global bgtileset, bgwidth=256
  11. Global skyfade, cloud
  12. Global direction=1
  13. Global map:Int[6,1000,2]
  14. Global worldpos
  15. '==============================================================================
  16. ' Init BG
  17. '==============================================================================
  18. Function CreateBG()
  19. bgtileset=LoadAnimImage:TImage("gfx/hill_1.png",256,256,0,9, MASKEDIMAGE )
  20. skyfade=LoadAnimImage:TImage("gfx/sky32.png",32,32,0,48 )
  21. cloud = LoadImage:TImage("gfx/bigcloud.png")
  22. RandomMap()
  23. EndFunction
  24. '==============================================================================
  25. ' Note:
  26. '==============================================================================
  27. Function RenderBackground( worldx, worldy)
  28. Local sframe,soffset,lx
  29. Local layerpos, mappos, offset
  30. '-------------------------------
  31. ' Sky
  32. '-------------------------------
  33. SetBlend ALPHABLEND
  34. SetAlpha 1
  35. SetRotation 0
  36. SetScale 1,1
  37. If y_offset<0 Then y_offset=0
  38. If y_offset>600 Then y_offset=600
  39. sframe = Int(y_offset/32) ; If sframe>24 Then sframe=24
  40. soffset = y_offset Mod 32
  41. For x = 0 To WIDTH Step 32
  42. For y=0 To 18
  43. DrawImage skyfade,x,(y*32)-soffset,sframe+y
  44. Next
  45. Next
  46. '-------------------------------
  47. ' Clouds
  48. '-------------------------------
  49. SetBlend ALPHABLEND
  50. SetAlpha 0.25
  51. DrawImage cloud,sky_pos, 100
  52. '-------------------------------
  53. ' Hills
  54. '-------------------------------
  55. SetAlpha 1
  56. ' layerpos = scaled from worldpos for parallax
  57. ' map_pos = offset into Map
  58. ' offset = shift for
  59. layerpos = worldpos/8
  60. mappos = Int(layerpos/bgwidth)
  61. offset = layerpos Mod bgwidth
  62. For x = 0 To 5
  63. DrawImage bgtileset,(x*bgwidth)-offset,380-(y_offset/12), map[5,mappos+x,0]
  64. Next
  65. layerpos = worldpos/6
  66. mappos = Int(layerpos/bgwidth)
  67. offset = layerpos Mod bgwidth
  68. For x = 0 To 5
  69. DrawImage bgtileset,(x*bgwidth)-offset,430-(y_offset/11), map[4,mappos+x,0]
  70. Next
  71. layerpos = worldpos/4
  72. mappos = Int(layerpos/bgwidth)
  73. offset = layerpos Mod bgwidth
  74. For x = 0 To 5
  75. DrawImage bgtileset,(x*bgwidth)-offset,480-(y_offset/10), map[3,mappos+x,0]
  76. Next
  77. layerpos = worldpos/2
  78. mappos = Int(layerpos/bgwidth)
  79. offset = layerpos Mod bgwidth
  80. For x = 0 To 5
  81. DrawImage bgtileset,(x*bgwidth)-offset,530-(y_offset/9), map[2,mappos+x,0]
  82. Next
  83. '----------------------------------
  84. ' Layer 1 Hills with collisions
  85. '----------------------------------
  86. SetAlpha 1
  87. mappos = Int(worldpos/bgwidth)
  88. offset = worldpos Mod bgwidth
  89. For x = 0 To 5
  90. DrawImage bgtileset,(x*bgwidth)-offset,480, map[1,mappos+x,0]
  91. ' CollideImage bgtileset,(x*bgwidth)-offset,480, map[1,mappos+x,0],0,2
  92. Next
  93. End Function
  94. '===============================================================================
  95. ' Description:
  96. '
  97. ' Quick hack to test the concept. Need to sort this out fully.
  98. '
  99. '===============================================================================
  100. Function MoveBg()
  101. sky_pos = sky_pos - (scroll_speed/32)
  102. If sky_pos<-256 Then sky_pos=1000
  103. worldpos=worldpos + scroll_speed
  104. End Function
  105. '==============================================================================
  106. ' Random Map
  107. '
  108. ' Test function only to randomise map data
  109. '==============================================================================
  110. Function RandomMap()
  111. Local h=0, l=0,pos=0
  112. For h=0 To 5
  113. pos=0
  114. While pos<980
  115. '--------------------------
  116. ' Hill
  117. map(h,pos,0)=1 ' Hill ramp up
  118. pos:+1
  119. l=Rand(5)
  120. If h=1 Then l=Rand(10)
  121. If h=5 Then l=Rand(20)
  122. While l>0
  123. map(h,pos,0)=Rand(2,7)
  124. pos:+1
  125. l:-1
  126. Wend
  127. map(h,pos,0)=8 ' Hill ramp down
  128. pos:+1
  129. '--------------------------
  130. ' Gap
  131. l=Rand(3)
  132. While l>0
  133. If pos<1000 map(h,pos,0)=0
  134. pos:+1
  135. l:-1
  136. Wend
  137. Wend
  138. Next
  139. End Function
  140. '===============================================================================
  141. ' END OF FILE
  142. '===============================================================================