Archiv der Kategorie: Monkey X

Monkey: multitouch demo

Strict
Import mojo

Function Main:Int()
    New MyApp
    Return 0
End

Class MyApp Extends App
    Method OnCreate:Int()
        SetUpdateRate(120)
        Return 0
    End

    Method OnUpdate:Int()
        Return 0
    End

    Method OnRender:Int()
        Cls(0,0,0)
        Local dy:Int = 30
        For Local i:Int = 0 To 31
            If TouchDown(i) Then
                If i Mod 2 = 0 Then
                    SetColor(255,0,0)
                Else
                    SetColor(0,0,255)
                End
                DrawCircle(TouchX(i),TouchY(i),50)
                SetColor(255,255,255)
                DrawText(""+i, 10, dy)
                DrawText(""+Int(TouchX(i)), 40, dy)
                DrawText(""+Int(TouchY(i)), 80, dy)
                dy+=20
            End
        End
        DrawText("idx",10,10)
        DrawText("x",40,10)
        DrawText("y",80,10)
        Return 0
    End
End

Monkey: fantomEngine – using text object as a button

Strict

#rem
   Script:      touchTest.monkey
   Description:   Sample Script fantomEngine to display the use of touch events 
   Author:       Michael
#end

Import fantomEngine
Global g:game

'***************************************
Class game Extends App
   Field eng:engine
   Field font1:ftFont
   '------------------------------------------
   Method CreateObjects:Int()

      'Create a box
      Local b:ftObject = eng.CreateBox(100,50,eng.canvasWidth/2,eng.canvasHeight/2-150)
      'Set TouchMode to bounding box(2)    ... 1=Circle
      b.SetTouchMode(2)
      b.SetName("Box")

      'Create a circle
      Local c:ftObject = eng.CreateCircle(50,eng.canvasWidth/2,eng.canvasHeight/2)
      c.SetTouchMode(1)
      c.SetName("Circle")

      'Create a text
      Local t:ftObject = eng.CreateText(font1,"This is a clickable text", eng.canvasWidth/2,eng.canvasHeight/2+150,1)
      t.SetTouchMode(2)
      t.SetName("Text")

      Return 0
   End
   '------------------------------------------
   Method OnCreate:Int()
      SetUpdateRate(60)

      'Store the engine instance
      eng = New engine

      'Load the font bitmap
      font1 = eng.LoadFont("bo_font")             '<========== please change this to a font that you have

      'Create the objects
      CreateObjects()
      Return 0
   End

   '------------------------------------------
   Method OnUpdate:Int()
      Local d:Float = Float(eng.CalcDeltaTime())/60.0
      eng.Update(Float(d))
      'check if you have a touch hit and then do a touch check.
      If TouchHit(0) Then   eng.TouchCheck()
      Return 0
   End

   '------------------------------------------
   Method OnRender:Int()
      Cls
      eng.Render()
      Return 0
   End
End  

'***************************************
Class engine Extends ftEngine
   '------------------------------------------
   Method OnObjectTouch:Int(obj:ftObject, touchId:Int)
      Print ("Object "+obj.GetName()+" was hit!")
      Return 0
   End
End

'***************************************
Function Main:Int()
   g = New game
   Return 0
End

Monkey: a base script for the fantomEngine

Strict

#rem
    Script:     baseScript.monkey
    Description:    Base Script fantomEngine 
    Author:         Michael Hartlef
    Version:      1.0
#end

Import fantomEngine
Global g:game

'***************************************
Class game Extends App
    Field eng:engine
    Field isSuspended:Bool = False
    '------------------------------------------
    Method OnCreate:Int()
        SetUpdateRate(60)
        eng = New engine
        Return 0
    End
    '------------------------------------------
    Method OnUpdate:Int()
        Local d:Float = Float(eng.CalcDeltaTime())/60.0
        If isSuspended = False Then
            eng.Update(Float(d))
        Endif
        Return 0
    End
    '------------------------------------------
    Method OnRender:Int()
        Cls
        eng.Render()
        Return 0
    End
    '------------------------------------------
    Method OnResume:Int()
        isSuspended = False
        SetUpdateRate(60)
        Return 0
    End
    '------------------------------------------
    Method OnSuspend:Int()
        isSuspended = True
        SetUpdateRate(5)
        Return 0
    End
End

'***************************************
Class engine Extends ftEngine
    '------------------------------------------
    Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject)
        Return 0
    End
    '------------------------------------------
    Method OnObjectTimer:Int(timerId:Int, obj:ftObject)
        Return 0
    End
    '------------------------------------------
    Method OnObjectTouch:Int(obj:ftObject, touchId:Int)
        Return 0
    End
    '------------------------------------------
    Method OnObjectTransition:Int(transId:Int, obj:ftObject)
        Return 0
    End
    '------------------------------------------
    Method OnObjectUpdate:Int(obj:ftObject)
        Return 0
    End
    '------------------------------------------
    Method OnLayerTransition:Int(transId:Int, layer:ftLayer)
        Return 0
    End
    '------------------------------------------
    Method OnLayerUpdate:Int(layer:ftLayer)
        Return 0
    End
End

'***************************************
Function Main:Int()
    g = New game
    Return 0
End

 

Monkey: drawing a diffusion effect

'******************************************************************
'* Diffusion Example
'* Author: Richard R Betson
'* Date: 11/25/11
'* Language: Monkey
'* Target: HTML5              
'******************************************************************
' Linsence - Public Domain
'******************************************************************
' Web Site - <a href="http://redeyeware.uphero.com" target="_blank">http://redeyeware.uphero.com</a>
'******************************************************************
' Canvas Wrapper Mod by Impixi - <a href="http://www.monkeycoder.co.nz/Community/posts.php?topic=1885" target="_blank">http://www.monkeycoder.co.nz/Community/posts.php?topic=1885</a>
'******************************************************************

Import monkey
Import mojo
Import canvaswrapper

Global flag=0
Global clra:Int
Global ang_index_1:Int[360],ang_index_2:Int[360],ang_index_3:Int[360],ang_index_4:Int[360]

Function Main()
  New Diffusion
End Function

Class Diffusion Extends App
Field imd:ImageData

Global fps,fp,fps_t
Global mapx:Int[77900]
Global mapx1:Int[77900]
Global mapx2:Int[77900]
Global mapx3:Int[77900]
Global mapx4:Int[77900]

Global clrr:Int[77900]
Global clrb:Int[77900]

Global clrr1:Int[77900]
Global clrb1:Int[77900]

Global ii
Global fxsel_ttl
Global fxsel

Global fred:Int=1,fblue:Int=2
Global qtext:String="Highest Quality",qt:Int=3,widetext:String=""

Global xa:Int=1,xb:Int=319,ya:Int=1,yb:Int=239

  Method OnCreate()
    fxsel_ttl=Millisecs()+16000
    SetUpdateRate(60)
    SetLookUp()
    imd = xCanvas.CreateImageData(640,480)'640,480)
Local i2:Int
  For i2=0 To 359
    ang_index_1[i2]=(160 + (Sin(i2)*40) )
    ang_index_2[i2]=(120 + (Cos(i2)*40) )
    ang_index_3[i2]=(160 + (-Sin(i2)*40) )
    ang_index_4[i2]=(120 + (-Cos(i2)*40) )
  Next

  End Method

  Method OnUpdate()
    If KeyHit(KEY_F1)
    For Local y=0 To 240
      'Local y1:Int=320 *y
      For Local x= 0 To 320
        xCanvas.SetImageDataPixel(imd, x*2,(y*2), 0, 0, 0, 255)
        xCanvas.SetImageDataPixel(imd, (x*2)+1,(y*2) ,0, 0, 0, 255)
        xCanvas.SetImageDataPixel(imd, (x*2),((y*2)+1), 0, 0, 0, 255)
        xCanvas.SetImageDataPixel(imd, ((x*2)+1),((y*2)+1) ,0, 0, 0, 255)
      Next
    Next
'Cls    
      qt=qt+1
      If qt>5 Then qt=0
      If qt=0 Then qtext="Low Quality"
      If qt=1 Then qtext="Med Quality"
      If qt=2 Then qtext="Med-High Quality"
      If qt=3 Then qtext="Highest Quality"
      If qt=4 Then qtext="1/4 Screen H-Quality" 
      If qt=5 Then qtext="1/4 Screen x 4 H-Quality"
    Endif

    If KeyHit(KEY_F2)
      For Local y=0 To 240
        'Local y1:Int=320 *y
        For Local x= 0 To 320
          xCanvas.SetImageDataPixel(imd, x*2,(y*2), 0, 0, 0, 255)
          xCanvas.SetImageDataPixel(imd, (x*2)+1,(y*2) ,0, 0, 0, 255)
          xCanvas.SetImageDataPixel(imd, (x*2),((y*2)+1), 0, 0, 0, 255)
          xCanvas.SetImageDataPixel(imd, ((x*2)+1),((y*2)+1) ,0, 0, 0, 255)
        Next
      Next

      If widetext=""
        ya=60
        yb=180
        widetext="WIDE -"
      Else
        ya=1
        yb=239
        widetext=""
      Endif
    Endif

    If fxsel_ttl<millisecs() fxsel="" fxsel_ttl="Millisecs()+14000" if="">4 Then fxsel=0
      Select fxsel
      Case 0
        fred=1
        fblue=2

      Case 1
        fred=50
        fblue=4
      Case 2
        fred=3
        fblue=3
      Case 3
        fred=2
        fblue=4
      Case 4
        fred=3
        fblue=4
    End Select

    Endif 

  End Method

  Method OnRender()

    fps=fps+1
    If fps_t<millisecs() fp="(fps)" fps_t="1000+Millisecs()" fps="0" endif="" ii="" if="">359 Then ii=0

    Local x2:Int=ang_index_1[ii]
    Local y2:Int=ang_index_2[ii]
    Local x3:Int=ang_index_3[ii]
    Local y3:Int=ang_index_4[ii]

    'Draw Line
    LineB(160,120,x2,y2)
    LineB(160,120,x3,y3)

    For Local zz=0 To 100
      Local xz=Int(Rnd(50))+135
      Local yz=Int(Rnd(50))+95
      clrb1[ ( 320 *yz ) +xz ]=255

    Next

    For Local y=ya To yb
        Local y2:Int=(320 *y)
      For Local x= xa To xb 
        Local y1:Int=y2+x
        'Apply mapping via lookup table
        If fxsel=0
        clrr[  y1  ] = clrr1[ mapx[ y1 ] ]
        clrb[  y1  ] = clrb1[ mapx[ y1 ] ]
        Else If fxsel=1
        clrr[  y1   ] = clrr1[ mapx1[ y1  ] ]
        clrb[  y1   ] = clrb1[ mapx1[ y1  ] ]
        Else If fxsel=2
        clrr[  y1   ] = clrr1[ mapx2[ y1  ] ]
        clrb[  y1   ] = clrb1[ mapx2[ y1  ] ]
        Else If fxsel=3
        clrr[  y1   ] = clrr1[ mapx3[ y1  ] ]
        clrb[  y1   ] = clrb1[ mapx3[ y1  ] ]
        Else If fxsel=4
        clrr[  y1   ] = clrr1[ mapx4[ y1  ] ]
        clrb[  y1   ] = clrb1[ mapx4[ y1  ] ]
        Endif

      Next
    Next

Local sumr,sumb,b,r

    For Local y=ya To yb
      Local y1:Int=320 *y
      Local yn1:Int=y*2
      For Local x= xa To xb
        Local yn2:Int=y1+x
        'Blur Image and Fade Color

        r=clrr[yn2]
        sumr = ((r*4) + clrr[ yn2+1   ] + clrr[ yn2-1   ] + clrr[ ( y1-1 ) + x   ] + clrr[ ( y1+1 ) + x   ] ) Shr 3 

        b=clrb[yn2]
        sumb = ((b*4) + clrb[ yn2+1   ] + clrb[ yn2-1   ] + clrb[ ( y1-1 ) + x   ] + clrb[ ( y1+1 ) + x   ] ) Shr 3

        r=sumr-fred
        b=sumb-fblue

        If r<0 then="" r="" if="">255 Then r=255
        If b<0 then="" b="" if="">255 Then b=255

        clrr1[ yn2 ]=r
        clrb1[ yn2 ]=b

        Local xn1:Int=x*2

        If qt=0
            xCanvas.SetImageDataPixel(imd, xn1,yn1, r, 0, b, 255)         
          Else If qt=1
            xCanvas.SetImageDataPixel(imd, xn1,yn1, r, 0, b, 255)         
            xCanvas.SetImageDataPixel(imd, xn1,yn1+1, r, 0, b, 255)
          Else If qt=2
            xCanvas.SetImageDataPixel(imd, xn1,yn1, r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, xn1+1,yn1 ,r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, xn1,yn1+1, r, 0, b, 255)         
          Else If qt=3
            xCanvas.SetImageDataPixel(imd, xn1,yn1, r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, xn1+1,yn1 ,r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, xn1,yn1+1, r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, xn1+1,yn1+1 ,r, 0, b, 255)
          Else If qt=4
            xCanvas.SetImageDataPixel(imd, x,y, r, 0, b, 255)
          Else If qt=5
            xCanvas.SetImageDataPixel(imd, x,y, r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, (x+319),y ,r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, x,(y+239), r, 0, b, 255)
            xCanvas.SetImageDataPixel(imd, (x+319),(y+239) ,r, 0, b, 255)
          Endif

Next
Next

    xCanvas.DrawImageData imd, 0, 0
    DrawText("Hit F1/F2 Change Qualtity-Size/Wide Screen: "+widetext+" "+qtext,10,440)
    DrawText("HTML5 Diffusion - Richard Betson, <a href="http://redeyeware.uphero.com" target="_blank">http://redeyeware.uphero.com</a> - FPS:"+fp,10,460)

  End Method

  Function LineB(x1,y1,x2,y2)
    'Ported
    'Bresenham Line Algorithm 
    'Source - GameDev.Net - Mark Feldman
    'Public Domain

    Local deltax = Abs(x2 - x1)
    Local deltay = Abs(y2 - y1) 

    Local numpixels,d,dinc1,dinc2,xinc1,xinc2,yinc1,yinc2,x,y,i

    If deltax >= deltay 
      numpixels = deltax + 1
      d = (2 * deltay) - deltax
      dinc1 = deltay Shl 1
      dinc2 = (deltay - deltax) Shl 1
      xinc1 = 1
      xinc2 = 1
      yinc1 = 0
      yinc2 = 1
    Else
      numpixels = deltay + 1
      d = (2 * deltax) - deltay
      dinc1 = deltax Shl 1
      dinc2 = (deltax - deltay) Shl 1
      xinc1 = 0
      xinc2 = 1
      yinc1 = 1
      yinc2 = 1
    Endif

    If x1 > x2
      xinc1 = -xinc1
      xinc2 = -xinc2
    Endif

    If y1 > y2
      yinc1 = -yinc1
      yinc2 = -yinc2

    Endif

    x = x1
    y = y1

    For i = 1 To numpixels 

      If d < 0
        d = d + dinc1
        x = x + xinc1
        y = y + yinc1
      Else
        d = d + dinc2
        x = x + xinc2
        y = y + yinc2
      Endif

      'Draw line 
      If x>xa And x<xb and="" y="">ya And y<yb clrr1="" 320="" y="0" x="0" endif="" next="" end="" function="" method="" setlookup="" local="" ang="0" for="" lui="0" to="" 4="" 240="" rad="" abs="" y-120="" if="">0
          rad= Sqrt(rad)
        Else
          rad=0
        Endif
        If rad=0 Then rad=1

        Local dx#=((x-160)/(rad))
        Local dy#=((y-120)/(rad))
        If lui=1
          rad= ( ( (  ((Sin(rad*.2)*29.5) ) * (  ((Cos(rad*.81)*9.5) ) ) ) )   )

          dx=(dx*Cos(ang) - dy*Sin(ang))
          dy=(dy*Cos(ang) + dx*Sin(ang))

          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx1[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
        Endif

        If lui=2
          'Free Float
          ang=1
          rad= 1-( ( rad- (Sin(rad*900)*-Cos(rad*900)*.5 )*3.1415926 ) *  (-Cos((3.1415926) ) )*.9  )
          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)
          x1= ( x1*Cos(ang) - y1*Sin(ang) )
          y1= ( x1*Sin(ang) + y1*Cos(ang) )

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx2[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1
        Endif

        If lui=3
          rad= rad-(  (Sin(rad*PI)*3)- ((Cos(rad*PI)*3) )  )

          dx=(dx*Cos(ang) - dy*Sin(ang))
          dy=(dy*Cos(ang) + dx*Sin(ang))

          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx3[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1

        Endif
        If lui=0
          ang=-3

          Local yq:Int=y
          If yq<=120
          rad= rad-(  (Sin(yq))    )
          rad= rad-(  (Cos(yq)) )
          Else
          rad= rad-(  (Sin((240-yq)) )    )
          rad= rad-(  (Cos((240-yq)) )    )
          Endif

          dx=(dx*Cos(ang) - dy*Sin(ang))
          dy=(dy*Cos(ang) + dx*Sin(ang))

          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1

        Endif
        If lui=39
          'Orb
          rad= 2-( ( rad- (Sin(rad)*(Cos(rad)) )*3.1415926 ) *  (-Cos((3.1415926) ))*.97  )
          dx=(dx*Cos(ang) - dy*Sin(ang))
          dy=(dy*Cos(ang) + dx*Sin(ang))

          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx3[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1
        Endif
        If lui=4
          'Swirl
           ang=-3
          rad= 1-( ( rad- (Sin(rad)*-Cos(rad)*.9 )*3.1415926 ) *  (-Cos((3.1415926) ) )*.9  )
          dx=(dx*Cos(ang) - dy*Sin(ang))
          dy=(dy*Cos(ang) + dx*Sin(ang))

          Local x1=Int(dx*rad)+(160)
          Local y1=Int(dy*rad)+(120)

          If y1<1 then="" y1="" if="">240 Then y1=240
          If x1<1 then="" x1="" if="">320 Then x1=320

          mapx4[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1
      Endif

      Next
    Next
  Next

  End Method

End Class

Monkey: drawing a mosaic

Import mojo
Global sprite:MyApp

Function Main()
    sprite = New MyApp()
End Function

Class TColor
    Field r:Int,g:Int,b:Int
    Method Color()
        SetColor r,g,b
    End Method

    Method Set(rgb$)
        Self.r=255*(rgb[0]-48)/7
        Self.g=255*(rgb[1]-48)/7
        Self.b=255*(rgb[2]-48)/7
    End Method
End Class

Class MyApp Extends App
    Field pixel:Int[256]
    Field palette:TColor[16]

    Method OnCreate()
        SetUpdateRate 50

        For Local col:Int=0 To 15
            palette[col]=New TColor
            palette[col].Set "000333555777300520742764003025247467020040160370"[col*3..col*3+3]
        Next

        For Local t:Int=0 To 255
            pixel[t]=Rnd(16)
        Next
    End Method

    Method OnRender()
        Local i:Int
        For Local y:Int=0 To 15
            For Local x:Int=0 To 15
                palette[pixel[i]].Color
                DrawRect x*16,y*16,16,16
                i=i+1
            Next
        Next
    End Method

    Method OnUpdate()
    End Method
End Class

Monkey: drawing a starfield

Import mojo
Global stars:Starfield,mx:Float,my:Float

Function Main()
    stars = New Starfield()
End Function

Class TStar
    Field x:Float,y:Float,z:Float
    Method Init()
        x=Rnd(-100,100)
        y=Rnd(-100,100)
        z=Rnd(-100,100)
    End Method

    Method Update()
        z-=1
        x+=mx
        y+=my
        If z<=-100 z+=200
        If x<=-100 x+=200
        If y<=-100 y+=200
        If x>= 100 x-=200
        If y>= 100 y-=200
    End Method

    Method Draw()
        Local i:Int=z+121
        Local px:Int=x*450/(z+151)
        Local py:Int=y*350/(z+151)
        SetColor 255-i,255-i,255-i
        DrawRect 320+px,240+py,1,1
    End Method
End Class

Class Starfield Extends App
    Field star:TStar[1024]
    Method OnCreate()
        SetUpdateRate 50
        For Local t:Int=0 To star.Length-1
            star[t]=New TStar
            star[t].Init
        Next
    End Method

    Method OnUpdate()
        mx=(MouseX()-320)/50
        my=(MouseY()-240)/50
        For Local t:Int=0 To star.Length-1
            star[t].Update
        Next
    End Method

    Method OnRender()
        Cls 0,0,0
        For Local t:Int=0 To star.Length-1
            star[t].Draw
        Next
    End Method
End Class

Monkey: minimum base script for the diddy framework

Strict

Import mojo
Import diddy

Global titleScreen:TitleScreen

Function Main:Int()
        game = New MyGame()
        Return 0
End

Class MyGame Extends DiddyApp
        Method OnCreate:Int()
                Super.OnCreate()
                titleScreen = New TitleScreen
                titleScreen.PreStart()
                Return 0
        End
End

Class TitleScreen Extends Screen
        Method New()
                name = "Title"
        End

        Method Start:Void()
                game.screenFade.Start(50, false)
        End

        Method Render:Void()
                Cls
                DrawText "TITLE SCREEN!", SCREEN_WIDTH2, SCREEN_HEIGHT2, 0.5, 0.5
                DrawText "Click to Play!", SCREEN_WIDTH2, SCREEN_HEIGHT2 + 20, 0.5, 0.5
                DrawText "Escape to Quit!", SCREEN_WIDTH2, SCREEN_HEIGHT2 + 40, 0.5, 0.5
        End

        Method Update:Void()
                If KeyHit(KEY_ESCAPE)
                        game.screenFade.Start(50, true)
                        game.nextScreen = game.exitScreen
                End
        End
End

Monkey: class example with extends, implements and abstract

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

Monkey: particle class

Import mojo

Class Particle
    Global ParticleList:List<particle> = New List<particle>
    Field x:Float,y:Float,a:Float = 1,r:Int
    Field ox:Int,oy:Int
    Field img:Image
    Field dx:Float,dy:Float, da:Float
    Field maxdistance:Int
    Field speed:Float
    Field dir:Int
    Field fade:Int
    Field z:Int

    Method Create:Particle(_x:Int, _y:Int, _img:Image, _dir:Int = 0, _speed:Float = 0, frames:Int = 1, _fade:Int = False, _autorot:Int = False, _z:Int = 0)
        ParticleList.AddLast(Self)
        z = _z
        x = _x
        y = _y
        ox = _x
        oy = _y
        img = _img
        speed = _speed
        dir = _dir
        dx = Sin(dir) * speed
        dy = -Cos(dir) * speed
        da = 1.0 / frames
        maxdistance = frames
        If dir And _autorot
            r = -dir - 180
        End If

        If _fade
            fade = True
        End If
    End Method

    Method Update()
        x+=dx
        y+=dy
        If fade a-=da

        maxdistance-=1
        If maxdistance <= 0 Or a <= 0
            Destroy()
        End If

        If x > VDeviceWidth() Or x < 0 - img.Width Or y > VDeviceHeight() Or y < 0 - img.Height
            Destroy()
        End If
    End Method
    Method Draw()
        SetAlpha a
        DrawImage img,x,y,r,1,1
        SetAlpha 1
    End Method

    Method SetPAlpha(alpha:Float)
        a = alpha
    End Method

    Method SetPRotation(rot:Int)
        r = rot
    End Method

    Method Destroy()
        ParticleList.Remove(Self)
    End Method

    Method AddX(_x:Int)
        x+= _x
    End Method

    Method AddY(_y:Int)
        y+= _y
    End Method

    Method SetDirection(_dir:Int)
        dir = _dir
    End Method

    Method SetSpeed(_speed:Float)
        speed = _speed
    End Method

End

Function ParticleExplosion(_x:Float, _y:Float, image:Image, n:Int, frames:Int, speed_multiplyer:Float = 0, ar:Int = False, _z:Int = 0)
    Local speed:Float

    For Local i:Int = 1 To n
        Local dir:Int = Rnd(0, 359)

        If speed_multiplyer
            speed = Rnd(0.08*speed_multiplyer, 1.5*speed_multiplyer)
        Else
            speed = Rnd(0.08, 1.5)
        End If

        Local part:Particle = New Particle()
        part.Create(_x, _y, image, dir, speed, frames - 10 + Rnd((frames*1.40)), True, ar, _z)
    Next

End Function

Function EmitParticle(_x:Float, _y:Float, image:Image, frames:Int, fade:Int = True, dir:Int = 0, speed:Float = 0, ar:Int = False, _z:Int = 0)

    Local part:Particle = New Particle()
    part.Create(_x, _y, image, dir, speed, frames, fade, ar, _z)

End Function

Function ParticleCount:Int()
    Return Particle.ParticleList.Count()
End Function

Function ClearParticles()
    Particle.ParticleList.Clear()
End Function

Function ClearParticlesZ(z:Int = 0)
    For Local delp:Particle = Eachin Particle.ParticleList
        If delp.z = z
            Particle.ParticleList.Remove(delp)
        End If
    Next
End Function

Function UpdateParticlesZ(z:Int = 0, forcex:Float = 0, forcey:Float = 0)   
    For Local UpdateP:Particle = Eachin Particle.ParticleList
        If UpdateP.z = z
            UpdateP.Update()
            If forcex UpdateP.x+=forcex
            If forcey UpdateP.y+=forcey
        End If
    Next
End Function
Function DrawParticlesZ(z:Int = 0) 
    For Local UpdateP:Particle = Eachin Particle.ParticleList
        If UpdateP.z = z
            UpdateP.Draw()
        End If
    Next
End Function

Monkey: box2d falling boxes

'----Includes----'
Import box2d.dynamics.b2world

'----Test Zone----'
Function Main()
  New Box2DLoop()
End Function

'----Main Loop----'
Class Box2DLoop Extends App

  Field _world:b2World

  Field RATIO:Float = 8

  Field _nextCrateIn:Int

  '--Main Methods----'

  Method OnCreate()

    ' 1. Set Up World
    setupWorld()
    ' Create Walls and Floors
    createWallsAndFloor()
    setupDebugDraw()
    _nextCrateIn = 0

    'Display Setup
    SetUpdateRate(60)

  End Method

  Method setupDebugDraw:Void()

      'Box2D Debug Settings       'Delete this section if you dont need to see the physical process in graphics.
    Local dbgDraw :b2DebugDraw = New b2DebugDraw()      

        dbgDraw.SetDrawScale(10.0)
        dbgDraw.SetFillAlpha(0.3)
        dbgDraw.SetLineThickness(1.0)
        dbgDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit)'| b2DebugDraw.e_pairBit)
        _world.SetDebugDraw(dbgDraw)

  End
  Method OnRender()
    Cls    

    _world.DrawDebugData()

  End Method

  Method OnUpdate()

    _world.TimeStep(1.0 /30,10,10)
    _world.ClearForces()

    _nextCrateIn = _nextCrateIn - 1

    If _nextCrateIn  <=0 And _world.m_bodyCount < 80 Then
      addARandomCrate()
      _nextCrateIn = 10
    Endif

  End Method

  Method setupWorld()

    ' Define gravity
    Local gravity:b2Vec2 = New b2Vec2(0,9.8)

    ' Ignore Sleeping Objects
    Local ignoresleeping:Bool = True

    _world = New b2World(gravity,ignoresleeping)

  End

  Method addARandomCrate()
    Local fd:b2FixtureDef = New b2FixtureDef()
    Local sd:b2PolygonShape = New b2PolygonShape()
    Local bd:b2BodyDef = New b2BodyDef();
    bd.type = b2Body.b2_Body

    fd.friction = 0.8
    fd.restitution = 0.3
    fd.density = 0.7
    fd.shape = sd

    sd.SetAsBox(randomInt(5,40) / RATIO, randomInt(5, 40) / RATIO)

    bd.position.Set(randomInt(15,530) / RATIO, randomInt(-100, -10) / RATIO)
    bd.angle = randomInt(0,360) * 3.14 / 180

    Local b:b2Body = _world.CreateBody(bd)
    b.CreateFixture(fd)

  End

  Method randomInt:Int(lowVal:Int, highVal:Int)

    If (lowVal <= highVal)

      Return lowVal + Floor(Rnd() * (highVal - lowVal + 1))

    Endif
  End

  Method createWallsAndFloor:Void()

    Local sd:b2PolygonShape = New b2PolygonShape()
    Local fd:b2FixtureDef = New b2FixtureDef()
    Local bd:b2BodyDef = New b2BodyDef()
    bd.type = b2Body.b2_staticBody

    sd.SetAsArray([New b2Vec2(0,0),New b2Vec2(550/RATIO,0), New b2Vec2(550/RATIO,10/RATIO), New b2Vec2(0,10/RATIO)])

    fd.friction = 0.5
    fd.restitution = 0.3
    fd.density = 0.0
    fd.shape = sd

    bd.position.Set(0,560/RATIO)

    Local b:b2Body = _world.CreateBody(bd)
    b.CreateFixture(fd)

    Local sdwall:b2PolygonShape = New b2PolygonShape()
    Local fdwall:b2FixtureDef = New b2FixtureDef()
    Local bdwall:b2BodyDef = New b2BodyDef()   
    bd.type = b2Body.b2_staticBody

    fdwall.friction =  0.5
    fdwall.restitution = 0.3
    fdwall.density = 0
    fdwall.shape = sdwall
    sdwall.SetAsBox(5/RATIO,390/RATIO)

    bdwall.position.Set(5/RATIO,195/RATIO)

    Local leftwall:b2Body = _world.CreateBody(bdwall)
    leftwall.CreateFixture(fdwall)

    bdwall.position.Set(545/RATIO,195/RATIO)

    Local rightwall:b2Body = _world.CreateBody(bdwall)
    rightwall.CreateFixture(fdwall)

  End
End Class