Ooops
February 25, 2021, 02:08:02 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bmx] Shadows by SillyPutty [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Shadows by SillyPutty [ 1+ years ago ] (Read 404 times)
BlitzBot
Jr. Member
Posts: 1
[bmx] Shadows by SillyPutty [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:40 AM »
Title :
Shadows
Author :
SillyPutty
Posted :
1+ years ago
Description :
How to draw 2D shadows
Code :
Code: BlitzMax
SuperStrict
Graphics
640
,
480
Global
xpos:
Float
Global
ypos:
Float
Global
angle:
Float
Global
Falloff:
Int
=
1000
SetClsColor
125
,
125
,
125
Function
DrawShadowCaster
(
x1:
Float
,y1:
Float
,x2:
Float
,y2:
Float
)
Local
shadowCaster:
Float
[
8
]
Local
lightAngle:
Float
lightAngle = ATan2
(
xpos-x2,ypos-y2
)
SetColor
0
,
0
,
0
shadowCaster
[
0
]
= x1
shadowCaster
[
1
]
= y1
shadowCaster
[
2
]
= x2
shadowCaster
[
3
]
= y2
shadowCaster
[
4
]
= x2-Sin
(
lightAngle
)
*Falloff
shadowCaster
[
5
]
= y2-Cos
(
lightAngle
)
*Falloff
lightAngle = ATan2
(
xpos-x1,ypos-y1
)
shadowCaster
[
6
]
= x1-Sin
(
lightAngle
)
*Falloff
shadowCaster
[
7
]
= y1-Cos
(
lightAngle
)
*Falloff
DrawPoly ShadowCaster
SetColor
255
,
255
,
255
DrawLine x1,y1,x2,y2
End
Function
While
not
KeyDown
(
KEY_ESCAPE
)
xpos = MouseX
(
)
ypos = MouseY
(
)
SetColor
255
,
255
,
0
DrawOval xpos-
5
,ypos-
5
,
10
,
10
' box
DrawShadowCaster
200
,
200
,
400
,
200
DrawShadowCaster
200
,
200
,
200
,
100
DrawShadowCaster
200
,
100
,
400
,
100
DrawShadowCaster
400
,
100
,
400
,
200
'wall
DrawShadowCaster
200
,
400
,
400
,
400
DrawLine
200
,
200
,
400
,
200
DrawLine
200
,
200
,
200
,
100
DrawLine
200
,
100
,
400
,
100
DrawLine
400
,
100
,
400
,
200
Flip
Cls
Wend
Comments :
SillyPutty(Posted 1+ years ago)
Thanks to Cyanide who gave me an example about a year ago on how to do this, since then I lost the code he gave me, but knocked this one up from what I learnt from his method. Adding it here so I dont lose the code again
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Graphics
»
[bmx] Shadows by SillyPutty [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal