```
Strict
Import mojo2
Const n:Int = 100
Global test:xy = New xy
Function Main:Int()
New Game()
Return 0
End
Class Game Extends App
Field canvas:Canvas
Field Obj:xy[n]
Method OnCreate:Int()
canvas = New Canvas() ; SetSwapInterval 1 ; SetUpdateRate 0
For Local i := 0 Until n ; Obj[i] = New xy ; initxy(Obj[i]) ; Next
Return 0
End
Method OnRender:Int()
canvas.Clear
For Local i := 0 Until n
canvas.DrawRect Obj[i].x,Obj[i].y,Obj[i].size,Obj[i].size ' Draw
Obj[i] = movexy(Obj[i]) ' Update
Next
canvas.Flush
Return 0
End
End
Class xy
Field x:Int
Field y:Int
Field vx:Int
Field vy:Int
Field size:Int
End
Function initxy:xy(p:xy)
p.size = 1 + Rnd(40) ; p.x = Rnd(640-p.size) ; p.y = Rnd(480-p.size)
p.vx = Rnd(1,4) ; If Rnd(1) >= 0.5 Then p.vx = -p.vx
p.vy = Rnd(1,4) ; If Rnd(1) >= 0.5 Then p.vy = -p.vy
Return p
End
Function movexy:xy(p:xy)
p.x = p.x + p.vx
If p.x < 0 Or p.x > (640-p.size) Then p.vx = -p.vx
p.y = p.y + p.vy
If p.y < 0 Or p.y > (480-p.size) Then p.vy = -p.vy
Return p
End
```