Advertisement
Guest User

Shadow 2d

a guest
Oct 27th, 2011
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Strict
  2. Import mojo
  3.  
  4. '// By Deux
  5. '// http://www.blitzbasic.com/codearcs/codearcs.php?code=1833
  6.  
  7. Function Main%()
  8.     New myApp
  9.     Return 0
  10. End
  11.  
  12. Class myApp Extends App
  13.    
  14.     Global xpos:Float
  15.     Global ypos:Float
  16.     Global angle:Float
  17.     Global Falloff:Int = 1000
  18.     '---------------------------------------------------------------------------
  19.     Method OnCreate%()
  20.         SetUpdateRate 30
  21.         Return 0
  22.     End
  23.     '---------------------------------------------------------------------------
  24.     Method OnRender%()
  25.        
  26.         Cls(128,128,128)
  27.  
  28.         'xpos = MouseX()
  29.         'ypos = MouseY()
  30.        
  31.         SetColor 255,255,0
  32.         DrawOval xpos-5,ypos-5,10,10
  33.        
  34.         ' box
  35.         DrawShadowCaster 200,200,400,200
  36.         DrawShadowCaster 200,200,200,100
  37.         DrawShadowCaster 200,100,400,100
  38.         DrawShadowCaster 400,100,400,200
  39.        
  40.         'wall
  41.         DrawShadowCaster 200,400,400,400
  42.    
  43.         DrawLine 200,200,400,200
  44.         DrawLine 200,200,200,100
  45.         DrawLine 200,100,400,100
  46.         DrawLine 400,100,400,200
  47.         Return 0
  48.     End
  49.     '---------------------------------------------------------------------------
  50.     Method OnUpdate%()
  51.         xpos = MouseX()
  52.         ypos = MouseY()
  53.         Return 0
  54.     End
  55.     '---------------------------------------------------------------------------
  56.     Method DrawShadowCaster%(x1:Float,y1:Float,x2:Float,y2:Float)
  57.         Local shadowCaster:Float[8]
  58.         Local lightAngle:Float
  59.        
  60.         lightAngle = ATan2(xpos-x2,ypos-y2)
  61.    
  62.         SetColor 0,0,0
  63.        
  64.         shadowCaster[0] = x1
  65.         shadowCaster[1] = y1
  66.         shadowCaster[2] = x2
  67.         shadowCaster[3] = y2
  68.         shadowCaster[4] = x2-Sin(lightAngle)*Falloff
  69.         shadowCaster[5] = y2-Cos(lightAngle)*Falloff
  70.    
  71.         lightAngle = ATan2(xpos-x1,ypos-y1)
  72.    
  73.         shadowCaster[6] = x1-Sin(lightAngle)*Falloff
  74.         shadowCaster[7] = y1-Cos(lightAngle)*Falloff
  75.        
  76.         DrawPoly shadowCaster
  77.         SetColor 255,255,255
  78.         DrawLine x1,y1,x2,y2
  79.         Return 0
  80.     End
  81. End
  82.  
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement