Saturday, September 26, 2015

Monkey-X - GetDate Seconds to Rnd Seed - code example

To not get the same random behaviour each time you start the game you can set the seed to use the GetDate current second.

Import mojo

Global color:Int[] = New Int[3]

Class MyApp Extends App
    Method OnCreate()
        ' here 
        Local date := GetDate()
        ' set the random seed to
        ' current second
        Seed = date[5]
        color[0] = Rnd(255)
        color[1] = Rnd(255)
        color[2] = Rnd(255)                
    End Method

    Method OnUpdate()
    End Method
    Method OnRender()
        Cls 0,0,0
        SetColor 255,255,255
        DrawText "Monkey-X different random seed each time.",10,10
        For Local i=0 Until 3
            SetColor color[i],0,0
            DrawRect i*DeviceWidth()/3,0,DeviceWidth()/3,DeviceHeight()
    End Method
End Class

Function Main()
    New MyApp
End Function

No comments:

Post a Comment