Print Page | Close Window

My Weather system

Printed From: Mirage Source
Category: Tutorials
Forum Name: Temporary Archive (Read Only)
Forum Discription: Temporary 3.0.3 archive tutorials, will be deleted when converted.
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=182
Printed Date: 20 December 2006 at 5:52pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: My Weather system
Posted By: Sync
Subject: My Weather system
Date Posted: 11 February 2006 at 3:20pm
This takes me a bit of work to make, and was realy drifter about releasing this or not... But I will :wink:
This is not a simple tut, you need to change a lot of things so it will realy work great. I will explain line by line.
This weather system is NOT hard to be maded by your selves, but I know that most of you dont have "time" :roll:  to make it.
It works like this: it random a x and y 4 each drop of rain and blt them all like lines. Then it makes x + 1 and y + 1 lots of times, so if the x > max_map_x or y > max_map_y it ReRandom the x and y. Ok lets start...

OBVIOUSLY Client Side...(1st)

1st lets make it so the drops of rain stay in the memory so we can use it other time:
In mod types, in the Declarations, add a new type. Lets call it DropRainRec:
Type DropRainRec

End Type

Now lets make the x and y variables in the new type, important thing of the drop of rain  :wink: . Make them as long, both.
Now add 2 public variables: MAX_RAINDROPS and BLT_RAIN_DROPS.
Now lets make a public var(DropRain)
Public DropRain() As DropRainRec

This will make it so when we type DropRain we can use the types we defined before in Type DraopRainRec.
Now that the program is able to record this info in the memory, lets make it random the x and y values.
Lets make a new Sub in modGameLogic. Lets call it BltWeather. And lets make it so it receivs the info of witch weather it have to blt.
Our sub should looks like this:
Sub BltWeather()
End Sub

Great! Now that we named the sub, lets make the code in it :P
add 2 variables: WeatherTemp(Byte) and I(Long).
Add this to:
If WeatherType = WEATHER_THUNDER Then
    WeatherTemp = WEATHER_RAIN
Else
    WeatherTemp = WeatherType
End If

This make it so if its thundering it is raing too(nice efect 8) )
Now lets set the color of our lines(Rain Drops). To make thislets change the ForeColor of of the BackBuffer. I like my Rain white so I set the ForeColor to white. Here is the code to make this:
Call DD_BackBuffer.SetForeColor(RGB(255, 255, 255))
Self explanatory.
Now we need to randomize the x and y. To make this, I maded a litle sub, here it is:
Sub RNDRainDrop(ByVal RDNumber As Long)
Start:
    DropRain(RDNumber).X = Int((((MAX_MAPX + 1) * PIC_X) * Rnd) + 1)
    DropRain(RDNumber).Y = Int((((MAX_MAPY + 1) * PIC_Y) * Rnd) + 1)
    If (DropRain(RDNumber).Y > (MAX_MAPY + 1) * PIC_Y / 4) And (DropRain(RDNumber).X > (MAX_MAPX + 1) * PIC_X / 4) Then GoTo Start
    DropRain(RDNumber).Speed = Int((10 * Rnd) + 6)
    DropRain(RDNumber).Randomized = True
End Sub

DropRain(RDNumber).X = Int((((MAX_MAPX + 1) * PIC_X) * Rnd) + 1)

This will store the X value in 1 DropRain. The number is a random number(min = 1, max = (MAX_MAPX + 1) * PIC_X) this means that it will random a X in the Screen.

DropRain(RDNumber).Y = Int((((MAX_MAPY + 1) * PIC_Y) * Rnd) + 1)

Same as before but now for Y, not X.

If (DropRain(RDNumber).Y > (MAX_MAPY + 1) * PIC_Y / 4) And (DropRain(RDNumber).X > (MAX_MAPX + 1) * PIC_X / 4) Then GoTo Start

This is to make the random number stays in the up and left of the screen. The drop of rain will be in diagonal line from up letf to down righ, got it?

DropRain(RDNumber).Speed = Int((10 * Rnd) + 6)

This line random a Speed for this drop of rain. From 6 to 10.

DropRain(RDNumber).Randomized = True

This line makes this drop of rain be "done" so it can be blited on the screen.

WOWOWOW! WAIT A SEC! We didnt define Speed nor Randomized! So lets define them! Go back to Type DropRainRec and add this 2 new vars: Randomized(Boolean) and Speed(Byte).
Ok this part is done. But this sub we maded a min ago is never being called so lets call it!
Go back to BltWeather sub and lets make it call the random function. Add this to the code:
    If WeatherType = WEATHER_RAIN Or WeatherType = WEATHER_THUNDER Then
        For I = 1 To MAX_RAINDROPS
             If DropRain(I).Randomized = False Then
                 If frmMirage.tmrRainDrop.Enabled = False Then
                     BLT_RAIN_DROPS = 1
                     frmMirage.tmrRainDrop.Enabled = True
                     If frmMirage.tmrRainDrop.Tag = "" Then
                           frmMirage.tmrRainDrop.Interval = 200
                           frmMirage.tmrRainDrop.Tag = "123"
                     End If
                 End If
             End If
        Next I
    Else
        If BLT_RAIN_DROPS > 0 And BLT_RAIN_DROPS <= RainIntensity Then
             Call ClearRainDrop(BLT_RAIN_DROPS)
        End If
        frmMirage.tmrRainDrop.Tag = ""
    End If

This part of the code will call the random function only if its raining for each rain drop. lets make a timer make this things looks better so in frmMirage add a timer caled tmrRainDrop(Enabled = False, Interval = 100). Double click it and add this code:
    If BLT_RAIN_DROPS > RainIntensity Then
        tmrRainDrop.Enabled = False
        Exit Sub
    End If
    If DropRain(BLT_RAIN_DROPS).Randomized = False Then
        Call RNDRainDrop(BLT_RAIN_DROPS)
    End If
    BLT_RAIN_DROPS = BLT_RAIN_DROPS + 1
    If tmrRainDrop.Interval > 30 Then
        tmrRainDrop.Interval = tmrRainDrop.Interval - 10
    End If

This timer will call the random sub only if its needed and remove from its own Interval 10(only if Interval > 30
Now lets add some Variables
Find:
Public GameWeather As Long

and under it add:
Public RainIntensity As Long

This is the intensity of the rain, like a slow rain or hard rain 8)

We are missing 1 sub, so add this:
Sub ClearRainDrop(ByVal RDNumber As Long)
On Error Resume Next
    DropRain(RDNumber).X = 0
    DropRain(RDNumber).Y = 0
    DropRain(RDNumber).Speed = 0
    DropRain(RDNumber).Randomized = False
End Sub

This sub Clear the Rain so it can be Rerandomed

At this part of the tut, NOTHING will realy hapen, we need to blit this info in the screen, in the format of lines. Go to sub BltWeather and add this:
    For I = 1 To MAX_RAINDROPS
        If Not ((DropRain(I).X = 0) Or (DropRain(I).Y = 0)) Then
             DropRain(I).X = DropRain(I).X + DropRain(I).Speed
             DropRain(I).Y = DropRain(I).Y + DropRain(I).Speed
             Call DD_BackBuffer.DrawLine(DropRain(I).X, DropRain(I).Y, DropRain(I).X + DropRain(I).Speed, DropRain(I).Y + DropRain(I).Speed)
             If (DropRain(I).X > (MAX_MAPX + 1) * PIC_X) Or (DropRain(I).Y > (MAX_MAPY + 1) * PIC_Y) Then
                 DropRain(I).Randomized = False
             End If
        End If
    Next I

This will blit for each rain drop  a line and add the speed of it. Think a little. If something is slow and little its becouse its far from you, if its fast and big its near you. That is what I tried to make, and I guess I made the efect good. If the drop of rain if out of the screen it sets Randomized to False, so it will ReRandom the place where it should go.

Now we should add the thing that makes the Thunder(TNX TO MUFFLES!)
    ' If it's thunder, make the screen randomly flash blue
    If WeatherType = WEATHER_THUNDER Then
        If Int((60 - 1 + 1) * Rnd) + 1 = 8 Then
             DD_BackBuffer.SetFillColor RGB(255, 255, 255)
             Call DD_BackBuffer.DrawBox(0, 0, (MAX_MAPX + 1) * PIC_X, (MAX_MAPY + 1) * PIC_Y)
        End If
    End If


Now, replace the hole: ' :: Weather packet ::
with:

    If (LCase(Parse(0)) = "weather") Then
        GameWeather = Val(Parse(1))
        RainIntensity = Val(Parse(2))
        If MAX_RAINDROPS <> RainIntensity Then
             MAX_RAINDROPS = RainIntensity
             ReDim DropRain(1 To MAX_RAINDROPS) As DropRainRec
        End If
    End If


As least we need to make the server handle this info. Easy, easy. Save your client project and open the server project.

in modGeneral find:
Public GameWeather As Long

under that add:
Public RainIntensity As Long

Find this:
GameWeather = WEATHER_NONE

and under it add:
RainIntensity = 50


Replace the hole Sub SendWeatherTo(ByVal index As Long) with:
Sub SendWeatherTo(ByVal index As Long)
Dim Packet As String
    If RainIntensity <= 0 Then RainIntensity = 1
    Packet = "WEATHER" & SEP_CHAR & GameWeather & SEP_CHAR & RainIntensity & SEP_CHAR & END_CHAR
    Call SendDataTo(index, Packet)
End Sub

In frmServer add a Scroll and name it scrlRainIntensity(min = 1, max = 50), add a label and call it lblRainIntensity
Double click scrlRainIntensity and add this code:
    lblRainIntensity.Caption = Val(scrlRainIntensity.Value)
    RainIntensity = scrlRainIntensity.Value


I guess its done! Any Question or bug, Post it here! :D



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info