Always wanted weather for your game?
Always thought you could do it yourself?
Tried the weather from the old forms and aren't happy with it's results?
You've come to the right place! This is from Konfuze's source, or whatever they wanna call it now..(Elysium... Diamond..?) Anyways...
Don't add this unless you've saved your code.
Level of Dificulty: 1/5(Just C&P and Understand...)
First, and foremost, back up your code.
Second, Open the Server.
This is the only thing you have to add.
Change
Code:
' Lets change the weather if its time to
If WeatherSeconds >= 60 Then
i = Int(Rnd * 3)
If i <> GameWeather Then
GameWeather = i
Call SendWeatherToAll
End If
WeatherSeconds = 0
End If
To read
Code:
' Lets change the weather if its time to
If WeatherSeconds >= 18600 / 2 Then
i = Int(Rnd * 3)
If i <> GameWeather Then
GameWeather = i
Call SendWeatherToAll
Call PutVar(FileName, "Weather", "Weather", Trim(GameWeather))
End If
WeatherSeconds = 0
End If
That just checks for half a day(12 hours, irl) and changes the weather randomly.
Also, uncomment this line
Code:
WeatherSeconds = WeatherSeconds + 1
That's important. Keeps the time for weather.
Now, close the server. You're done with it. (AHMAGAWD, THAT WAS EASY!!1)
Next, open the client. Open modDirectX.
Put this in there
Code:
Sub BltWeather()
Dim i As Long
Call DD_BackBuffer.SetForeColor(RGB(0, 0, 200))
If GameWeather = WEATHER_RAINING 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
ElseIf GameWeather = WEATHER_SNOWING Then
For i = 1 To MAX_RAINDROPS
If DropSnow(i).Randomized = False Then
If frmMirage.tmrSnowDrop.Enabled = False Then
BLT_SNOW_DROPS = 1
frmMirage.tmrSnowDrop.Enabled = True
If frmMirage.tmrSnowDrop.Tag = "" Then
frmMirage.tmrSnowDrop.Interval = 200
frmMirage.tmrSnowDrop.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
'actually blt the rain
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
'declare snow tile
rec.top = 0
rec.Bottom = rec.top + PIC_Y
rec.Left = 0
rec.Right = rec.Left + PIC_X
'actualy blt the snow
For i = 1 To MAX_RAINDROPS
If Not ((DropSnow(i).X = 0) Or (DropSnow(i).Y = 0)) Then
DropSnow(i).X = DropSnow(i).X + DropSnow(i).Speed
DropSnow(i).Y = DropSnow(i).Y + DropSnow(i).Speed
Call DD_BackBuffer.BltFast(DropSnow(i).X + DropSnow(i).Speed, DropSnow(i).Y + DropSnow(i).Speed, DD_SnowSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
If (DropSnow(i).X > (MAX_MAPX + 1) * PIC_X) Or (DropSnow(i).Y > (MAX_MAPY + 1) * PIC_Y) Then
DropSnow(i).Randomized = False
End If
End If
Next i
' If it's raining, make the screen randomly flash white
If GameWeather = WEATHER_RAINING Then
If Int((100 - 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
End Sub
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
Sub ClearSnowDrop(ByVal RDNumber As Long)
On Error Resume Next
DropSnow(RDNumber).X = 0
DropSnow(RDNumber).Y = 0
DropSnow(RDNumber).Speed = 0
DropSnow(RDNumber).Randomized = False
End Sub
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
Sub RNDSnowDrop(ByVal RDNumber As Long)
Start:
DropSnow(RDNumber).X = Int((((MAX_MAPX + 1) * PIC_X) * Rnd) + 1)
DropSnow(RDNumber).Y = Int((((MAX_MAPY + 1) * PIC_Y) * Rnd) + 1)
If (DropSnow(RDNumber).Y > (MAX_MAPY + 1) * PIC_Y / 4) And (DropSnow(RDNumber).X > (MAX_MAPX + 1) * PIC_X / 4) Then GoTo Start
DropSnow(RDNumber).Speed = Int((10 * Rnd) + 6)
DropSnow(RDNumber).Randomized = True
End Sub
That just blts the weather, plain and simple. If it's raining, it draws random lines. If it's snowing, it gets snow from a file(this one!
Snow GFX) and blits it randomly on the screen. Also, if it's raining, It makes it go boom. xD
Now, you have the snow tile. HOW TEH HELLZ R WE GONNA PUT IT ON TEH GAME, LOL!
Simple. Just in the General Declaration part, put this
Code:
Public DD_SnowSurf As DirectDrawSurface7
Si, tis all you need. Now, go to InitSurfaces...
I'm not sure how the blank mirage does it... But, we're not noobs... Load the picture you downloaded onto the surface you declared.
If you have trouble with this, feel free to leave me a PM or IM me on a messenger.
Anyways, onwards!
Client side, put this in the declaration section of modTypes
Code:
Public MAX_RAINDROPS As Long
Public BLT_RAIN_DROPS As Long
Public DropRain() As DropRainRec
Public BLT_SNOW_DROPS As Long
Public DropSnow() As DropRainRec
Public RainIntensity As Byte
Also add this to the 'TypeRec' Area up there(anywhere before it is declared)
Code:
Type DropRainRec
x As Long
y As Long
Randomized As Boolean
Speed As Byte
End Type
One last thing to change. Then we gotta do a bit of programming for ourselves.
Find
Code:
If Lcase(Parse(0)) = "weather" Then
In handle data or something similar and replace that whole statement with this:
Code:
If (LCase(Parse(0)) = "weather") Then
If Val(Parse(1)) = WEATHER_RAINING And GameWeather <> WEATHER_RAINING Then
Call AddText("You see drops of rain falling from the sky above!", frmMirage.txtChat, BrightGreen)
End If
If Val(Parse(1)) = WEATHER_SNOWING And GameWeather <> WEATHER_SNOWING Then
Call AddText("You see snow falling from the sky above!", frmMirage.txtChat, BrightGreen)
End If
If Val(Parse(1)) = WEATHER_NONE Then
If GameWeather = WEATHER_RAINING Then
Call AddText("The rain beings to calm.", frmMirage.txtChat, BrightGreen)
ElseIf GameWeather = WEATHER_SNOWING Then
Call AddText("The snow is melting away.", frmMirage.txtChat, BrightGreen)
End If
End If
GameWeather = Val(Parse(1))
RainIntensity = 100
If MAX_RAINDROPS <> RainIntensity Then
MAX_RAINDROPS = RainIntensity
ReDim DropRain(1 To MAX_RAINDROPS) As DropRainRec
ReDim DropSnow(1 To MAX_RAINDROPS) As DropRainRec
End If
End If
One more thing to do.
In Sub GameLoop Add
Code:
If InEditor = False Then
If GameWeather <> WEATHER_NONE Then
Call BltWeather
End If
End If
Right under
Code:
' Blit out tile layer fringe
For Y = 0 To MAX_MAPY
For X = 0 To MAX_MAPX
Call BltFringeTile(X, Y)
Next X
Next Y
Now, weather's almost done! Open frmMirage, and make Two Timers and set them to these values.
Timer1Name: tmrRainDrop
Enabled: False
Interval: 100
Timer2Name: tmrSnowDrop
Enabled: False
Interval: 100
For the timers, this is the code you want for them. Do not double click the timers to open the code window. Just right click on the form and click on 'View Code'
Add these to the bottom
Code:
Private Sub tmrRainDrop_Timer()
If BLT_RAIN_DROPS > RainIntensity Then
tmrRainDrop.Enabled = False
Exit Sub
End If
If BLT_RAIN_DROPS > 0 Then
If DropRain(BLT_RAIN_DROPS).Randomized = False Then
Call RNDRainDrop(BLT_RAIN_DROPS)
End If
End If
BLT_RAIN_DROPS = BLT_RAIN_DROPS + 1
If tmrRainDrop.Interval > 30 Then
tmrRainDrop.Interval = tmrRainDrop.Interval - 10
End If
End Sub
Private Sub tmrSnowDrop_Timer()
If BLT_SNOW_DROPS > RainIntensity Then
tmrSnowDrop.Enabled = False
Exit Sub
End If
If BLT_SNOW_DROPS > 0 Then
If DropSnow(BLT_SNOW_DROPS).Randomized = False Then
Call RNDSnowDrop(BLT_SNOW_DROPS)
End If
End If
BLT_SNOW_DROPS = BLT_SNOW_DROPS + 1
If tmrSnowDrop.Interval > 30 Then
tmrSnowDrop.Interval = tmrSnowDrop.Interval - 10
End If
End Sub
And that should be it. If you have any problems whatsoever, or if I'm missing anything, please tell me. This is as easy as I could get it, ripped from Elysium to work for MSE.
Sorry I can't explain what any of it does. I don't understand DirectX too well to do so. Maybe someone else could explain?