This is a code for rain effect created for 3D games:
Description: The code will generate points at different positions and then it will move all the points in one direction. During this, a thunder flash would appear creating beautiful image.
You will notice the ripple of the rain on an imagined plan.
Important: you should have the library loaded to excute the code.
General Variables and arrays used:
Code: Select all
DIM SHARED cose!(360), sine!(360)
DIM SHARED xrotate!, Yrotate!, Zrotate!
DIM SHARED star.Method!(1000), star.x!(1000), star.y!(1000), star.z!(1000)
DIM SHARED perspective%, x.scene%, y.scene%, z.scene%
DIM SHARED thunder%(30, 1), Thunder.Anim!, thunder.Fade%, Delayer%, blur%, Thunder.Sound%
Code: Select all
'$INCLUDE: 'future.bi'
Initi. variables:[Like cosine table array ...etc]
Code: Select all
cosine.table
kbhon
Set320x240 16
y.scene% = 10
perspective% = 220
page = 1
Frames! = 0
Thunder.Frame% = 20
Cosine Table subroutine:Main loop wrote:Frame counter:Apply Thunder effect:Code: Select all
10 Frames! = Frames! + .1
Use the star field as rain. Then, control it:Code: Select all
11 D3D.Thunder Xthender%, 30, (RND(1) * 50) - 25, (RND(1) * 50) - 15, (RND(1) * 50) - 25, (RND(1) * 50) - 15, 1 TFrames% = Frames! - (INT(Frames! / Thunder.Frame%) * Thunder.Frame%) IF INT(TFrames%) = Thunder.Frame% - 1 THEN Thunder.Anim! = 0 Xthender% = RND(1) * 320 Thunder.Frame% = INT(RND(1) * 40) + 10 END IF
Refresh the screen without flikering:Code: Select all
15 FOR blur% = 1 TO 1 20 A% = Rad%: D3d.star.field 0, 0, A%, 1 30 'IF GetKey%(78) THEN REM 40 'IF GetKey%(74) THEN REM 41 IF GetKey%(77) THEN Rad% = Rad% + 2 42 IF GetKey%(75) THEN Rad% = Rad% - 2 43 'IF GetKey%(72) THEN REM 44 'IF GetKey%(80) THEN REM 46 IF Rad% <45> 45 THEN Rad% = 45 50 IF GetKey%(1) THEN resetscreen: kbhoff: END 55 NEXT blur% 58 'future.print 1, 1, STR$(Frames!), RGB2Color(255, 255, 255), -1 59 'future.print 1, 10, STR$(INT(perspective%)), RGB2Color(255, 255, 255), -1
Flash the screen when thunder appears:Code: Select all
60 viewpage page 70 page = page + 1: IF page = 4 THEN page = 0 80 setpage page
Qbasic Programmers you know what does this do:[Main loop]Code: Select all
IF Thunder.Anim! > 0 THEN future.cls RGB2Color(thunder.Fade%, thunder.Fade%, thunder.Fade%) END IF IF Thunder.Anim! > 50 THEN future.cls 0 END IF
Code: Select all
90 GOTO 10
Code: Select all
SUB cosine.table
RA = (180 / (22 / 7))
FOR i = 0 TO 360
cose!(i) = COS(i / RA)
sine!(i) = SIN(i / RA)
NEXT i
FOR i = 1 TO 300
star.x!(i) = INT(RND(1) * 100) - 50
star.y!(i) = INT(RND(1) * 60) - 60
star.z!(i) = INT(RND(1) * 200)
NEXT i
END SUB
Code: Select all
SUB D3d.rotate (xpROT!, ypROT!, zproT!, xROT%, yROT%, zroT%)
xROT% = xROT% - (INT(xROT% / 360) * 360): IF xROT% < 0 THEN xROT% = xROT% + 360
yROT% = yROT% - (INT(yROT% / 360) * 360): IF yROT% < 0 THEN yROT% = yROT% + 360
zroT% = zroT% - (INT(zroT% / 360) * 360): IF zroT% < 0 THEN zroT% = zroT% + 360
X.X! = xpROT!
Y.X! = (cose!(xROT%) * ypROT!) - (sine!(xROT%) * zproT!)
Z.X! = (sine!(xROT%) * ypROT!) + (cose!(xROT%) * zproT!)
X.Y! = (cose!(yROT%) * X.X!) + (sine!(yROT%) * Z.X!)
Y.Y! = Y.X!
Z.Y! = (cose!(yROT%) * Z.X!) - (sine!(yROT%) * X.X!)
xrotate! = (cose!(zroT%) * X.Y!) - (sine!(zroT%) * Y.Y!)
Yrotate! = (sine!(zroT%) * X.Y!) + (cose!(zroT%) * Y.Y!)
Zrotate! = Z.Y!
END SUB
Code: Select all
SUB D3d.star.field (star.raduis.x%, star.raduis.y%, star.raduis.z%, star.speed!)
star.raduis.x% = star.raduis.x% - (INT(star.raduis.x% / 360) * 360)
star.raduis.y% = star.raduis.y% - (INT(star.raduis.y% / 360) * 360)
star.raduis.z% = star.raduis.z% - (INT(star.raduis.z% / 360) * 360)
IF star.raduis.x% < 0 THEN star.raduis.x% = star.raduis.x% + 360
IF star.raduis.y% < 0 THEN star.raduis.y% = star.raduis.y% + 360
IF star.raduis.z% <0>= 10 THEN star.speed! = 10
FOR i% = 1 TO 300
IF star.Method!(i%) = 0 THEN
star.y!(i%) = star.y!(i%) + star.speed!
D3d.rotate star.x!(i%) / 1, star.y!(i%) / 1, star.z!(i%) / 1, star.raduis.x%, star.raduis.y%, star.raduis.z%
IF Zrotate! > 5 THEN
x.star! = ((xrotate! + x.scene%) * perspective%) / (Zrotate! + z.scene%)
y.star! = ((Yrotate! + y.scene%) * perspective%) / (Zrotate! + z.scene%)
c.star% = (1 - ((Zrotate! + z.scene%) / 200)) * 255
IF (x.star! < -160 AND star.raduis.z% <180> 160 AND star.raduis.z% > 180) THEN
'x.star! = x.star! - (INT(x.star! / 160) * 160)
star.x!(i%) = (RND(1) * 240) - 120
star.y!(i%) = (-y.scene% - 90)
star.z!(i%) = (RND(1) * 190) + 10
END IF
IF Zrotate! > 5 AND Zrotate! <200> y.scene% THEN
star.Method!(i%) = 1
END IF
END IF
END IF
IF star.Method!(i%) >= 1 THEN
star.Method!(i%) = star.Method!(i%) + 1
D3d.rotate star.x!(i%) / 1, star.y!(i%) / 1, star.z!(i%) / 1, star.raduis.x%, star.raduis.y%, star.raduis.z%
IF Zrotate! + z.scene% > 5 THEN
x.center! = ((xrotate! + x.scene%) * perspective%) / (Zrotate! + z.scene%)
y.center! = ((Yrotate! + y.scene%) * perspective%) / (Zrotate! + z.scene%)
x1.star% = x.center! - ((1 - (Zrotate! + z.scene%) / 160) * star.Method!(i%))
x2.star% = x.center! + ((1 - (Zrotate! + z.scene%) / 160) * star.Method!(i%))
c.star% = (1 - (star.Method!(i%) / 10)) * 255
future.line x1.star% + 160, y.center! + 120, x2.star% + 160, y.center! + 120, RGB2Color(c.star%, c.star%, c.star%), -1
IF star.Method!(i%) >= 10 THEN
star.Method!(i%) = 0
star.x!(i%) = (RND(1) * 240) - 120
star.y!(i%) = (-y.scene% - 90)
star.z!(i%) = (RND(1) * 190) + 10
END IF
END IF
END IF
NEXT i%
END SUB
Code: Select all
SUB D3D.Thunder (xp%, yp%, x1%, y1%, x2%, y2%, Wide%)
IF Thunder.Anim! = 0 THEN
'PlayChannel 2
Dest% = ABS(y2% - y1%) / 3
thunder%(i, 0) = x1%
thunder%(i, 1) = y1%
FOR i = 1 TO 5
thunder%(i, 0) = x1% + INT(RND(1) * Wide%) - (Wide% / 2) + INT(RND(1) * 5) - (5 / 2)
thunder%(i, 1) = thunder%(i - 1, 1) + INT(RND(1) * Dest%)
Wide% = Wide% - 1: IF Wide% <0> 0 AND Thunder.Anim! < 5 THEN
thunder.Fade% = thunder.Fade% + 51: IF thunder.Fade% <0> 5 AND Thunder.Anim! < 10 THEN
thunder.Fade% = thunder.Fade% - 51: IF thunder.Fade% <0> 10 AND Thunder.Anim! < 13 THEN
thunder.Fade% = thunder.Fade% + 85: IF thunder.Fade% <0> 13 AND Thunder.Anim! < 50 THEN
thunder.Fade% = thunder.Fade% - 6: IF thunder.Fade% <0> 0 AND Thunder.Anim! < 50 THEN
FOR i = 0 TO 5
future.line xp% + thunder%(i, 0), yp% + thunder%(i, 1), xp% + thunder%(i + 1, 0), yp% + thunder%(i + 1, 1), RGB2Color(thunder.Fade%, thunder.Fade%, thunder.Fade%), -1
NEXT i
END IF
END SUB
The sample of this code is located at my site http://www.freeweb.neonamd64.com/qbas.html under the name “Rainy.zip” and “RainyB.zip” this sample is only showing how the code works.
If you are interested and explanation is needed then ask me..
I had created lots of codes during my life and I am happy to share it with you…. If anyone is interested then take it ... and send me at least PM.. I would be happy.