Here's my contribution done in Brutus2D. We have night-time, fog, rain and wind. Press space to switch effect. The wind slowly changes from side to side.
Download an image to use as background and place it in the same folder as the source code. The image name must be environment.jpg. Here's a link to an example image.
' Environmental effects. 3. jun 2007
' u9 4T kallnet D0T fo
Option explicit
randomize
key.initialize
Dim filename
filename = "Environment.jpg"
Dim background
graphics.initialize 10, 10
background = graphics.loadimage( filename )
Dim width, height
width = graphics.getwidth( background )
height = graphics.getheight( background )
graphics.terminate
graphics.initialize width, height
graphics.settitle "Press space to change effect"
background = graphics.loadimage( filename )
Dim font
font = graphics.createfont( "Courier New", 22, True )
Dim particleImage, overlay, curEffect, nextEffect, startTime, effectTime, wind
ReDim effect (4)
effect(0) = "none"
effect(1) = "night"
effect(2) = "fog"
effect(3) = "rain"
effect(4) = "wind"
ReDim paricles( 100, 4 ) ' The second dimensions are: x, y, dx, dy
curEffect = 0
nextEffect = 0
startTime = system.gettime ' Timer used for transitions
particleImage = graphics.createimage( 1, 1 )
overlay = graphics.createimage( width, height )
graphics.renderimage overlay
makeEffect
Do
Dim key_down, key_up
key_up = False
If key.pressed( vk_space ) Then
key_down = True
ElseIf key_down Then
key_down = False
key_up = True
End If
' Key released, so change environmental effect
If key_up Then
nextEffect = (nextEffect + 1) Mod (UBound( effect ) + 1)
startTime = system.gettime
End If
' Make transition
If system.gettime > startTime+255 And nextEffect <> curEffect Then
curEffect = nextEffect
makeEffect
startTime = system.gettime
End If
' Update effects
doEffect
graphics.clear
graphics.setimage background
' Fade in
If nextEffect = curEffect Then
graphics.setalpha overlay, min( 255, system.gettime - startTime )
' Fade out
Else
graphics.setalpha overlay, max( 0, 255+startTime - system.gettime )
End If
graphics.setimage overlay
graphics.settext effect(curEffect), 10, 10, font, argb(255,255,255,255)
graphics.display
Loop until key.pressed( vk_escape ) Or key.pressed( vk_windowx )
key.terminate
graphics.terminate
Sub makeEffect()
' no effect
If effect(curEffect) = "none" Then
graphics.renderimage overlay
graphics.clear argb( 0, 0, 0, 0 )
graphics.rendernormal
' night effect
ElseIf effect(curEffect) = "night" Then
graphics.renderimage overlay
graphics.clear argb( 190, 0, 0, 0 )
graphics.rendernormal
' fog effect
ElseIf effect(curEffect) = "fog" Then
graphics.renderimage overlay
graphics.clear argb( 200, 180, 180, 180 )
graphics.rendernormal
' rain effect
ElseIf effect(curEffect) = "rain" Then
graphics.renderimage overlay
graphics.clear argb( 0, 0, 0, 0 )
graphics.clear
graphics.rendernormal
effectTime = system.gettime
ElseIf effect(curEffect) = "wind" Then
wind = cos( system.gettime / 1000 )
End If
End Sub
Sub doEffect()
' no effect
If effect(curEffect) = "none" Then
' night effect
ElseIf effect(curEffect) = "night" Then
' fog effect
ElseIf effect(curEffect) = "fog" Then
' rain and wind effect
ElseIf effect(curEffect) = "rain" Or effect(curEffect) = "wind" Then
If effectTime < system.gettime Then
effectTime = effectTime + 70
If effect(curEffect) = "wind" Then
wind = cos( system.gettime / 5000 )
Else
wind = -0.2
End If
graphics.renderimage overlay
graphics.clear
Dim angle, alpha, x, y, length, i
angle = pi * 3 / 2 + wind/2
For i = 0 To (graphics.getscreenwidth * graphics.getscreenheight)/(40^2)
x = rnd * graphics.getscreenwidth
y = rnd * graphics.getscreenheight
length = rnd * 20
alpha = length / 20 * 155 + 100
graphics.setline x, y, x+cos(angle)*length, y-sin(angle)*length, argb(alpha,200,220,255)
Next
graphics.rendernormal
End If
End If
End Sub