Qbasic4.5 Codes 05 : Create rain, thunder effects

Discuss popular GCS tools like ZZT, Megazeux and Adventure Game Studio, as well as programming and other topics related to game design.
Post Reply
User avatar
NeonAmd64
Experienced Member
Experienced Member
Posts: 84
Joined: Mon Mar 20, 2006 7:15 pm
Location: Next to you, if not then who

Qbasic4.5 Codes 05 : Create rain, thunder effects

Post by NeonAmd64 »

Notes: if the code is too much complex and cause a Headache then leave it and go to something simple.[Don't worry. Everything will be covered in the QBasic series.I will make it simpler than this.] :)

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. :bday:

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%
I am using future library so here is an include Directive:

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
Main Program loop:
Main loop wrote:Frame counter:

Code: Select all

10 Frames! = Frames! + .1
Apply Thunder effect:

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
Use the star field as rain. Then, control it:

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%&#40;1&#41; THEN resetscreen&#58; kbhoff&#58; END
55 NEXT blur%
58 'future.print 1, 1, STR$&#40;Frames!&#41;, RGB2Color&#40;255, 255, 255&#41;, -1
59 'future.print 1, 10, STR$&#40;INT&#40;perspective%&#41;&#41;, RGB2Color&#40;255, 255, 255&#41;, -1
Refresh the screen without flikering:

Code: Select all

60 viewpage page
70 page = page + 1&#58; IF page = 4 THEN page = 0
80 setpage page
Flash the screen when thunder appears:

Code: Select all

IF Thunder.Anim! > 0 THEN
 future.cls RGB2Color&#40;thunder.Fade%, thunder.Fade%, thunder.Fade%&#41;
 END IF
IF Thunder.Anim! > 50 THEN
 future.cls 0
 END IF
Qbasic Programmers you know what does this do:[Main loop]

Code: Select all

90 GOTO 10
Cosine Table subroutine:

Code: Select all

SUB cosine.table
RA = &#40;180 / &#40;22 / 7&#41;&#41;
FOR i = 0 TO 360
cose!&#40;i&#41; = COS&#40;i / RA&#41;
sine!&#40;i&#41; = SIN&#40;i / RA&#41;
NEXT i
FOR i = 1 TO 300
star.x!&#40;i&#41; = INT&#40;RND&#40;1&#41; * 100&#41; - 50
star.y!&#40;i&#41; = INT&#40;RND&#40;1&#41; * 60&#41; - 60
star.z!&#40;i&#41; = INT&#40;RND&#40;1&#41; * 200&#41;
NEXT i
END SUB
Rotation function:[Rotate the star field]

Code: Select all

SUB D3d.rotate &#40;xpROT!, ypROT!, zproT!, xROT%, yROT%, zroT%&#41;
xROT% = xROT% - &#40;INT&#40;xROT% / 360&#41; * 360&#41;&#58; IF xROT% < 0 THEN xROT% = xROT% + 360
yROT% = yROT% - &#40;INT&#40;yROT% / 360&#41; * 360&#41;&#58; IF yROT% < 0 THEN yROT% = yROT% + 360
zroT% = zroT% - &#40;INT&#40;zroT% / 360&#41; * 360&#41;&#58; IF zroT% < 0 THEN zroT% = zroT% + 360
X.X! = xpROT!
Y.X! = &#40;cose!&#40;xROT%&#41; * ypROT!&#41; - &#40;sine!&#40;xROT%&#41; * zproT!&#41;
Z.X! = &#40;sine!&#40;xROT%&#41; * ypROT!&#41; + &#40;cose!&#40;xROT%&#41; * zproT!&#41;
X.Y! = &#40;cose!&#40;yROT%&#41; * X.X!&#41; + &#40;sine!&#40;yROT%&#41; * Z.X!&#41;
Y.Y! = Y.X!
Z.Y! = &#40;cose!&#40;yROT%&#41; * Z.X!&#41; - &#40;sine!&#40;yROT%&#41; * X.X!&#41;
xrotate! = &#40;cose!&#40;zroT%&#41; * X.Y!&#41; - &#40;sine!&#40;zroT%&#41; * Y.Y!&#41;
Yrotate! = &#40;sine!&#40;zroT%&#41; * X.Y!&#41; + &#40;cose!&#40;zroT%&#41; * Y.Y!&#41;
Zrotate! = Z.Y!
END SUB
3D Star Field as 3D Rain:[With some modification]

Code: Select all

SUB D3d.star.field &#40;star.raduis.x%, star.raduis.y%, star.raduis.z%, star.speed!&#41;
star.raduis.x% = star.raduis.x% - &#40;INT&#40;star.raduis.x% / 360&#41; * 360&#41;
star.raduis.y% = star.raduis.y% - &#40;INT&#40;star.raduis.y% / 360&#41; * 360&#41;
star.raduis.z% = star.raduis.z% - &#40;INT&#40;star.raduis.z% / 360&#41; * 360&#41;
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!&#40;i%&#41; = 0 THEN
 star.y!&#40;i%&#41; = star.y!&#40;i%&#41; + star.speed!
 D3d.rotate star.x!&#40;i%&#41; / 1, star.y!&#40;i%&#41; / 1, star.z!&#40;i%&#41; / 1, star.raduis.x%, star.raduis.y%, star.raduis.z%
 IF Zrotate! > 5 THEN
  x.star! = &#40;&#40;xrotate! + x.scene%&#41; * perspective%&#41; / &#40;Zrotate! + z.scene%&#41;
  y.star! = &#40;&#40;Yrotate! + y.scene%&#41; * perspective%&#41; / &#40;Zrotate! + z.scene%&#41;
  c.star% = &#40;1 - &#40;&#40;Zrotate! + z.scene%&#41; / 200&#41;&#41; * 255
  IF &#40;x.star! < -160 AND star.raduis.z% <180> 160 AND star.raduis.z% > 180&#41; THEN
   'x.star! = x.star! - &#40;INT&#40;x.star! / 160&#41; * 160&#41;
   star.x!&#40;i%&#41; = &#40;RND&#40;1&#41; * 240&#41; - 120
   star.y!&#40;i%&#41; = &#40;-y.scene% - 90&#41;
   star.z!&#40;i%&#41; = &#40;RND&#40;1&#41; * 190&#41; + 10
   END IF
  IF Zrotate! > 5 AND Zrotate! <200> y.scene% THEN
   star.Method!&#40;i%&#41; = 1
   END IF
  END IF
 END IF
IF star.Method!&#40;i%&#41; >= 1 THEN
 star.Method!&#40;i%&#41; = star.Method!&#40;i%&#41; + 1
 D3d.rotate star.x!&#40;i%&#41; / 1, star.y!&#40;i%&#41; / 1, star.z!&#40;i%&#41; / 1, star.raduis.x%, star.raduis.y%, star.raduis.z%
 IF Zrotate! + z.scene% > 5 THEN
  x.center! = &#40;&#40;xrotate! + x.scene%&#41; * perspective%&#41; / &#40;Zrotate! + z.scene%&#41;
  y.center! = &#40;&#40;Yrotate! + y.scene%&#41; * perspective%&#41; / &#40;Zrotate! + z.scene%&#41;
  x1.star% = x.center! - &#40;&#40;1 - &#40;Zrotate! + z.scene%&#41; / 160&#41; * star.Method!&#40;i%&#41;&#41;
  x2.star% = x.center! + &#40;&#40;1 - &#40;Zrotate! + z.scene%&#41; / 160&#41; * star.Method!&#40;i%&#41;&#41;
  c.star% = &#40;1 - &#40;star.Method!&#40;i%&#41; / 10&#41;&#41; * 255
  future.line x1.star% + 160, y.center! + 120, x2.star% + 160, y.center! + 120, RGB2Color&#40;c.star%, c.star%, c.star%&#41;, -1
  IF star.Method!&#40;i%&#41; >= 10 THEN
   star.Method!&#40;i%&#41; = 0
   star.x!&#40;i%&#41; = &#40;RND&#40;1&#41; * 240&#41; - 120
   star.y!&#40;i%&#41; = &#40;-y.scene% - 90&#41;
   star.z!&#40;i%&#41; = &#40;RND&#40;1&#41; * 190&#41; + 10
   END IF
  END IF
 END IF
NEXT i%
END SUB
A function to control the thunder effect:

Code: Select all

SUB D3D.Thunder &#40;xp%, yp%, x1%, y1%, x2%, y2%, Wide%&#41;
IF Thunder.Anim! = 0 THEN
 'PlayChannel 2
 Dest% = ABS&#40;y2% - y1%&#41; / 3
 thunder%&#40;i, 0&#41; = x1%
 thunder%&#40;i, 1&#41; = y1%
 FOR i = 1 TO 5
 thunder%&#40;i, 0&#41; = x1% + INT&#40;RND&#40;1&#41; * Wide%&#41; - &#40;Wide% / 2&#41; + INT&#40;RND&#40;1&#41; * 5&#41; - &#40;5 / 2&#41;
 thunder%&#40;i, 1&#41; = thunder%&#40;i - 1, 1&#41; + INT&#40;RND&#40;1&#41; * Dest%&#41;
 Wide% = Wide% - 1&#58; IF Wide% <0> 0 AND Thunder.Anim! < 5 THEN
 thunder.Fade% = thunder.Fade% + 51&#58; IF thunder.Fade% <0> 5 AND Thunder.Anim! < 10 THEN
 thunder.Fade% = thunder.Fade% - 51&#58; IF thunder.Fade% <0> 10 AND Thunder.Anim! < 13 THEN
 thunder.Fade% = thunder.Fade% + 85&#58; IF thunder.Fade% <0> 13 AND Thunder.Anim! < 50 THEN
 thunder.Fade% = thunder.Fade% - 6&#58; IF thunder.Fade% <0> 0 AND Thunder.Anim! < 50 THEN
 FOR i = 0 TO 5
 future.line xp% + thunder%&#40;i, 0&#41;, yp% + thunder%&#40;i, 1&#41;, xp% + thunder%&#40;i + 1, 0&#41;, yp% + thunder%&#40;i + 1, 1&#41;, RGB2Color&#40;thunder.Fade%, thunder.Fade%, thunder.Fade%&#41;, -1
 NEXT i
 END IF
END SUB
How does it go ? :sleep: I think the code is a little bit complicated. Never mind you will return to this part later. :)

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.. :love:

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. :P
Last edited by NeonAmd64 on Mon Dec 18, 2006 9:38 am, edited 1 time in total.
I am living in a black metal and I hope I die for a principle. And of course you still don't know me….
Words are coded in the two sentences above, don't try to decode it.
User avatar
Spider
Newbie
Newbie
Posts: 3
Joined: Mon Aug 28, 2006 2:34 pm
Location: Inbetween sky and land

Post by Spider »

great work Neon :), this is the most important effects to be added to a game.

But the link to your site is not working :cry: , so could you check the link, please

regards
You can lead the horse to the water, but you can't make it drink.
User avatar
NeonAmd64
Experienced Member
Experienced Member
Posts: 84
Joined: Mon Mar 20, 2006 7:15 pm
Location: Next to you, if not then who

Post by NeonAmd64 »

I am really sorry. :rolleyes:
I will fix it soon...
I am living in a black metal and I hope I die for a principle. And of course you still don't know me….
Words are coded in the two sentences above, don't try to decode it.
User avatar
NeonAmd64
Experienced Member
Experienced Member
Posts: 84
Joined: Mon Mar 20, 2006 7:15 pm
Location: Next to you, if not then who

The link is changed now.

Post by NeonAmd64 »

Ok...
Now you can download the samples of the code here, this is the link:

http://neonamd64.atspace.com/qbas.html
Or,
http://www.freewebs.com/neonamd64/qbas.html
. :)
. :)
. :)

Your speach sounds like you know programming very well.

[you didn't download the sample but you read the code]

Are you thinking of putting a plan on making a game.

Maybe I can join with you in one team and make a perfect game rather than one person... :)
Last edited by NeonAmd64 on Mon Dec 18, 2006 9:36 am, edited 1 time in total.
I am living in a black metal and I hope I die for a principle. And of course you still don't know me….
Words are coded in the two sentences above, don't try to decode it.
User avatar
Spider
Newbie
Newbie
Posts: 3
Joined: Mon Aug 28, 2006 2:34 pm
Location: Inbetween sky and land

Post by Spider »

Now you can download the samples of the code here, this is the link:
Thanks for the samples. :thumbsup:
Your speach sounds like you know programming very well.
..............

Are you thinking of putting a plan on making a game.
I am already working on an adventure game.
Maybe I can join with you in one team and make a perfect game rather than one person...
hold on... hold on friend..... you might have better skills than mine... but you are unknown for me..... it is a good idea :thumbsup: ... but I am sorry.... we need to know each other.
You can lead the horse to the water, but you can't make it drink.
User avatar
NeonAmd64
Experienced Member
Experienced Member
Posts: 84
Joined: Mon Mar 20, 2006 7:15 pm
Location: Next to you, if not then who

Post by NeonAmd64 »

Ok... take your time. :)

Beside that you can download the Tanks Challenge demo game that I had done to see what I had done with my partner BATtech. B)

You can test the game if you want to. Click on the link below:
http://www.dosgames.com/forum/viewtopic.php?t=8201

Anyway, I will continue on posting the codes and I will try to give a good explanation about it.

I hope it will help the forum in such a way. :)
I am living in a black metal and I hope I die for a principle. And of course you still don't know me….
Words are coded in the two sentences above, don't try to decode it.
User avatar
Icedragon
Lord of Gaming
Lord of Gaming
Posts: 232
Joined: Sun Mar 21, 2004 4:18 am

Post by Icedragon »

Looks good.

I only know a little QBasic so i dont fully understand it, but i get what all the commands are.
**********
Icedragon
**********
User avatar
NeonAmd64
Experienced Member
Experienced Member
Posts: 84
Joined: Mon Mar 20, 2006 7:15 pm
Location: Next to you, if not then who

Post by NeonAmd64 »

That’s Great.... :thumbsup:

And If any question about the details is needed then I am happy to answer. :)
You can ask any time you want.

Anyway nice to meet you Icedragon
I am living in a black metal and I hope I die for a principle. And of course you still don't know me….
Words are coded in the two sentences above, don't try to decode it.
User avatar
legaloneforever
Expert
Expert
Posts: 143
Joined: Mon Mar 05, 2018 10:50 pm

Post by legaloneforever »

Remember I am giving these methods out on behalf of my two parents mom Huong Thi Thuyen Vu and my dad Nguyen Binh Thuy! They have a stable job hopefully however they say I can only give out the executable. I am just a kid in the family. While I give out my proprietary methods I collect welfare because no one would give back. But you see that is the beauty. I die like Jesus Christ "The King of Programming!" When I live I live because of my parents giving me food and shelter to survive!!!! I am 44 years old and I could have went out to make a living but I spend 100% of my time on my hobby like my family (mom Huong Thi Thuyen Vu; dad Nguyen Binh Thuy; siss Nguyen Khoa Thuyen and Nguyen Khoa Thi and myself Nguyen Khoa Tien and my white friends want). I just play and everyone gets to see how the techniques of the King of Programming does it through following The Holy Bible forever and ever from now on gleans# I am The King of Programming through Jesus Christ; if you doubt me look at all the sources I have given out for free since I started and could have made money from. If you doubt I am The King of Programming through Jesus Christ then stick around. There is living life left in me so you see miracles through Jesus Christ my own saving grace and my family's grace forever and ever from now on gleamings.
User avatar
legaloneforever
Expert
Expert
Posts: 143
Joined: Mon Mar 05, 2018 10:50 pm

Post by legaloneforever »

If you want to know how to be the best you can be in anything you owe my two parents because they say J E S U S!
Post Reply