shadowimage.bmx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ' Rockets rotating and casting alpha-blended, pseudo light-sourced shadows on each other...
  2. MAXNUM = 500
  3. Graphics 640, 480, 32
  4. AutoImageFlags MASKEDIMAGE
  5. SetMaskColor 255, 0, 255
  6. rocket = LoadImage ("gfx/boing.png",MASKEDIMAGE|MIPMAPPEDIMAGE)
  7. grass = LoadImage ("gfx/grass.png")
  8. MidHandleImage rocket
  9. scale# = 0.5
  10. trans# = 0.5
  11. NUM = MAXNUM
  12. Local x [NUM], y [NUM]
  13. Local xs [NUM], ys [NUM]
  14. Local ang# [NUM], angstep# [NUM]
  15. For loop = 0 To NUM - 1
  16. x [loop] = Rand (0, GraphicsWidth () - 1)
  17. y [loop] = Rand (0, GraphicsHeight () - 1)
  18. xs [loop] = Rand (1, 5)
  19. ys [loop] = Rand (1, 5)
  20. ang [loop] = Rand (0, 359)
  21. angstep [loop] = Rnd (1, 5)
  22. Next
  23. NUM = 1
  24. Repeat
  25. Cls
  26. If KeyHit (KEY_RIGHT) Or MouseHit (2)
  27. If NUM < MAXNUM Then NUM = NUM + 1
  28. Else
  29. If KeyHit (KEY_LEFT) Or MouseHit (1)
  30. If NUM > 1 Then NUM = NUM - 1
  31. EndIf
  32. EndIf
  33. mx = MouseX ()
  34. my = MouseY ()
  35. SetScale scale, scale
  36. SetRotation 0
  37. TileImage grass
  38. For loop = 0 To NUM - 1
  39. x [loop] = x [loop] + xs [loop]
  40. y [loop] = y [loop] + ys [loop]
  41. If x [loop] < 0 Or x [loop] > GraphicsWidth () - 1
  42. xs [loop] = -xs [loop]; x [loop] = x [loop] + xs [loop]
  43. angstep [loop] = -angstep [loop]
  44. EndIf
  45. If y [loop] < 0 Or y [loop] > GraphicsHeight () - 1
  46. ys [loop] = -ys [loop]; y [loop] = y [loop] + ys [loop]
  47. angstep [loop] = -angstep [loop]
  48. EndIf
  49. ang [loop] = ang [loop] + angstep [loop]
  50. If ang [loop] > 360 - angstep [loop] Then ang [loop] = 0
  51. SetRotation ang [loop]
  52. offx = -(mx - x [loop]) / 8
  53. offy = -(my - y [loop]) / 8
  54. DrawShadowedImage rocket, x [loop], y [loop], offx, offy, trans
  55. Next
  56. SetScale 1, 1
  57. DrawShadowText "Use left/right cursors or mouse buttons to add/remove rockets", 20, 20
  58. DrawShadowText "Move mouse to change light direction", 20, 40
  59. DrawShadowText "Number of rockets: " + NUM, 20, 80
  60. Flip
  61. Until KeyHit (KEY_ESCAPE)
  62. End
  63. Function DrawShadowText (t$, x, y)
  64. SetRotation 0
  65. SetColor 0, 0, 0
  66. DrawText t$, x + 1, y + 1
  67. SetColor 255, 255, 255
  68. DrawText t$, x, y
  69. End Function
  70. Function DrawShadowedImage (image, x#, y#, xoff#, yoff#, level#)
  71. SetBlend ALPHABLEND
  72. SetColor 0, 0, 0
  73. SetAlpha level
  74. DrawImage image, x + xoff, y + yoff
  75. SetBlend MASKBLEND
  76. SetColor 255, 255, 255
  77. SetAlpha 1
  78. DrawImage image, x, y
  79. End Function