```
Strict
Import mojo2
Function Main:Int()
New Game()
Return 0
End
Class Game Extends App
Field canvas:Canvas
' Field a:xy = New xy ' Create simple variable of type xy
Field indices:xy[100] ' Create array of type xy
Method OnCreate:Int()
' Inits
For Local i := 0 To 99 ; indices[i] = New xy ; Next ' Init Array
canvas = New Canvas() ' Init canvas
SetSwapInterval 1
SetUpdateRate 0
' Continue init array
For Local i := 0 To 99
indices[i] = initxy(indices[i])
Next
Return 0
End
Method Update:Int()
Return 0
End
Method OnRender:Int()
canvas.Clear
' Loop all objects
For Local i := Eachin indices
canvas.DrawRect i.x,i.y,16,16 ' Draw
i = movexy(i) ' Update
Next
' For Local i := 0 To 99
' canvas.DrawRect indices[i].x,indices[i].y,16,16 ' Draw
' indices[i] = movexy(indices[i]) ' Update
' Next
canvas.Flush
Return 0
End
End
Class xy
Field x:Int
Field y:Int
Field vx:Int
Field vy:Int
End
Function initxy:xy(p:xy)
p.x = Rnd(640)
p.y = Rnd(480)
p.vx = Rnd(1,2)
If Rnd(1) >= 0.5 Then p.vx = -p.vx
p.vy = Rnd(1,2)
Return p
End
Function movexy:xy(p:xy)
p.x = p.x + p.vx
If p.x < 0 Or p.x >= 640 Then p.vx = -p.vx
p.y = p.y + p.vy
If p.y < 0 Or p.y >= 480 Then p.vy = -p.vy
Return p
End
```