1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
Strict Import mojo Interface IUpdateable Method OnUpdate:Int() End Interface IRenderable Method OnRender:Int() End Class AbstractEntity Abstract Global cw:Int Global ch:Int Method New (cw:Int, ch:Int) Self.cw = cw; Self.ch = ch; End End Class Ball Extends AbstractEntity Implements IUpdateable, IRenderable Field x:Int Field y:Int Field xs:Int Field ys:Int Method New () Self.x = 0 Self.y = 0 Self.xs = 1 Self.ys = 1 End Method New (cw:Int, ch:Int) Super.New(cw, ch) Self.x = 0 Self.y = 0 Self.xs = 1 Self.ys = 1 End Method OnUpdate:Int() Self.x += xs Self.y += ys If Self.x > Self.cw-16 Or Self.x < 0 Self.xs =- Self.xs End If Self.y > Self.ch-16 Or Self.y < 0 Self.ys =- Self.ys End Return 0 End Method OnRender:Int() DrawCircle Self.x, Self.y, 16 Return 0 End End Class Pad Extends AbstractEntity Implements IUpdateable, IRenderable Field x:Int Field y:Int Field xs:Int Method New () Self.x = 0 Self.y = ch - 16 Self.xs = 1 End Method New (cw:Int, ch:Int) Super.New(cw, ch) Self.x = 0 Self.y = ch - 16 Self.xs = 1 End Method OnUpdate:Int() Self.x += xs If Self.x > Self.cw-64 Or Self.x < 0 Self.xs =- Self.xs End Return 0 End Method OnRender:Int() DrawRect Self.x, Self.y, 64, 8 Return 0 End End Class game Extends App Field ball:Ball Field pad:Pad Method OnCreate:Int() SetUpdateRate(60) ball = New Ball(DeviceWidth(), DeviceHeight()) pad = New Pad() Return 0 End Method OnUpdate:Int() ball.OnUpdate() pad.OnUpdate() Return 0 End Method OnRender:Int() Cls 0,0,0 ball.OnRender() pad.OnRender() Return 0 End End Function Main:Int() New game Return 0 End |