Sunday, March 22, 2015

Monkey-X - Beginners - Scroll Text - Code example


Here a simple example that shows you how to make a scrolltext.

Code below :

Import mojo

Class scrolltext
    Field x:Int,y:Int
    Field stext:String 'the text
    Field lx:Float 'location in the scroll
    Field scrollwidth:Int 'how many characters drawn to the screen
    Method New()
        stext="                    "
        stext+="This is a scrolltext made in Monkey-X. It is made inside a class. "
        stext+="the text will repeat itself after this text has ended.           "
    End Method
    Method update()
        'increase the scroll position
        lx+=.1
        If lx>=stext.Length Then lx=0
    End Method
    Method draw()
        'get the visible string inside dt and draw that
        Local dt:String=""
        Local sp:Int=lx
        For Local i=0 Until scrollwidth
            dt+=String.FromChar(stext[sp])            
            sp+=1
            If sp>=stext.Length Then sp=0
        Next
        SetColor 255,255,255
        DrawText dt,x,y
    End Method
End Class

Global s:scrolltext = New scrolltext

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        s.scrollwidth=20 'character the scrolltext is wide
        s.x=100
        s.y=100
    End Method
    Method OnUpdate()  
        s.update      
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        DrawText "ScrollText Example..",0,0
        s.draw
    End Method
End Class


Function Main()
    New MyGame()
End Function

Monkey-X - Screen Wipe method 5 - Circle in/out - code example


Here another screen dissolve method. I saw this one in a Zelda game.

Import mojo

Class map
    Field tilewidth:Int,tileheight:Int
    Field mapwidth:Int,mapheight:Int
    Field wmwidth:Int,wmheight:Int
    Field map:Int[][]
    Field wipemap:Int[][]
    Field wipeactive:Bool=False
    Field wipemode:String
    Field sradius:Int
    Method New(mapwidth:Int,mapheight:Int,tilewidth:Int,tileheight:Int)
        Self.tilewidth = tilewidth
        Self.tileheight = tileheight
        Self.mapwidth = mapwidth
        Self.mapheight = mapheight
        wmwidth=640/6+6
        wmheight=480/6+6
        map = New Int[mapwidth][]
        For Local i = 0 Until mapwidth
            map[i] = New Int[mapheight]
        Next
        For Local y=0 Until mapheight
        For Local x=0 Until mapwidth
            setmap(x,y,Rnd(0,5))
        Next
        Next
        wipemap = New Int[wmwidth][]
        For Local i=0 Until wmwidth
            wipemap[i] = New Int[wmheight]
        Next
    End Method    
    Method update()
        If wipemode="wipein"            
            mapcircle((wmwidth)/2,(wmheight)/2,sradius,0)
            sradius+=1            
            If sradius>wmheight Then wipemode="wipedone"
        End If
        If wipemode="wipeout"
            For Local y1=0 Until wmheight
            For Local x1=0 Until wmwidth
                wipemap[x1][y1] = 1
            Next
            Next
            sradius-=1
            mapcircle((wmwidth)/2,(wmheight)/2,sradius,0)
            If sradius < 0 Then wipemode="nothing"
        End If
    End Method
    Method initwipein()
        For Local y1=0 Until wmheight
        For Local x1=0 Until wmwidth
            wipemap[x1][y1] = 1
        Next
        Next
        wipemode="wipein"
        sradius=0
    End Method
    Method initwipeout()
        sradius=wmheight
        wipemode="wipeout"
    End Method
    Method setmap:Void(x:Int,y:Int,val:Int)
        If x>=0 And y>=0 And x<mapwidth And y<mapheight
            map[x][y] = val
        End If
    End Method
    Method drawmap:Void()
        If wipemode<>"nothing"
               For Local y1=0 Until mapheight
               For Local x1=0 Until mapwidth
                   drawtile(map[x1][y1],x1*tilewidth,y1*tileheight)
               Next
               Next        
        End If
        If wipemode="wipein"
            SetColor 0,0,0
            For Local y1=0 Until wmheight
            For Local x1=0 Until wmwidth
                If wipemap[x1][y1] = 1
                    DrawRect x1*6,y1*6,6,6
                End If
            Next
            Next        
        End If
        If wipemode="wipeout"
              SetColor 0,0,0
            For Local y1=0 Until wmheight
            For Local x1=0 Until wmwidth
                If wipemap[x1][y1] = 1
                    DrawRect x1*6,y1*6,6,6
                End If
            Next
            Next                      
        End If
    End Method
    Method mapcircle(x1:Int,y1:Int,radius:Int,val:Int)
        For Local y2=-radius Until radius
        For Local x2=-radius Until radius
            If (y2*y2+x2*x2) <= radius*radius+radius*0.8
                Local x3:Int = x1+x2
                Local y3:Int = y1+y2
                If x3>=0 And y3>=0 And x3<wmwidth And y3<wmheight
                    wipemap[x3][y3] = val
                End If
            End If
        Next
        Next
    End Method
    Method drawtile(val:Int,x1:Int,y1:Int)
        Select val
            Case 0'water
                SetColor 0,0,255
                DrawRect x1,y1,tilewidth,tileheight
            Case 1'land
                SetColor 0,200,0
                DrawRect x1,y1,tilewidth,tileheight
            Case 2'forrest
                drawtile(1,x1,y1)
                SetColor 0,255,0
                DrawOval x1+5,y1+5,tilewidth-10,tileheight/2
                SetColor 150,10,0
                DrawRect x1+12,y1+tileheight-10,tilewidth-24,tileheight/2-5
            Case 3'hill
                drawtile(1,x1,y1)
                SetColor 0,255,0
                DrawOval x1+5,y1+10,tilewidth-10,tileheight-15
                SetColor 0,200,0
                DrawRect x1,y1+tileheight/1.5,tilewidth,10
            Case 4'mountain
                drawtile(1,x1,y1)
                SetColor 200,200,200
                DrawPoly(    [Float(x1+tilewidth/2),Float(y1),
                            Float(x1+tilewidth-5),Float(y1+tileheight-5),
                            Float(x1+5),Float(y1+tileheight-5)])
        End Select
    End Method

End Class

Global mymap:map = New map(20,14,32,32)
Global cnt:Int

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        mymap.initwipein
    End Method
    Method OnUpdate()
        mymap.update
        If Rnd(500)<2 And mymap.wipemode="wipedone" 
            mymap.initwipeout
        End If
        If mymap.wipemode="nothing"
            cnt+=1
            If cnt>100 Then
            mymap.initwipein            
            cnt=0
            End If
        End If
    End Method
    Method OnRender()
        Cls 0,0,0
        mymap.drawmap
        SetColor 255,255,255
        DrawText "Screen wipe example (circle) wipemode "+mymap.wipemode,0,0
    End Method
End Class


Function Main()
    New MyGame()
End Function

Monkey-X - Screenwipe 4 - block out/in - code example


Here a screen dissolve that I first saw in a old game called Colonization. It has blocks on the screen that dissapear/appear with time and show/hide the screen behind it.

Code below :

Import mojo

Class map
    Field tilewidth:Int,tileheight:Int
    Field mapwidth:Int,mapheight:Int
    Field map:Int[][]
    Field wipemap:Int[][]
    Field wipeactive:Bool=False
    Field wipemode:String
    Field wipetime:Int
    Method New(mapwidth:Int,mapheight:Int,tilewidth:Int,tileheight:Int)
        Self.tilewidth = tilewidth
        Self.tileheight = tileheight
        Self.mapwidth = mapwidth
        Self.mapheight = mapheight
        map = New Int[mapwidth][]
        For Local i = 0 Until mapwidth
            map[i] = New Int[mapheight]
        Next
        For Local y=0 Until mapheight
        For Local x=0 Until mapwidth
            setmap(x,y,Rnd(0,5))
        Next
        Next
        wipemap = New Int[mapwidth][]
        For Local i=0 Until mapwidth
            wipemap[i] = New Int[mapheight]
        Next
    End Method    
    Method update()
        If wipemode="wipein"            
            If Millisecs()>wipetime Then wipemode="wipedone"
        End If
        If wipemode="wipeout"
            If Millisecs()>wipetime Then wipemode="nothing"
        End If
    End Method
    Method initwipein()
        For Local y1=0 Until mapheight
        For Local x1=0 Until mapwidth
            wipemap[x1][y1] = Millisecs()+Rnd(3000)
        Next
        Next
        wipemode="wipein"
        wipetime=Millisecs()+3500
    End Method
    Method initwipeout()
        For Local y1=0 Until mapheight
        For Local x1=0 Until mapwidth
            wipemap[x1][y1] = Millisecs()+Rnd(3000)
        Next
        Next
        wipemode="wipeout"
        wipetime=Millisecs()+3500        
    End Method
    Method setmap:Void(x:Int,y:Int,val:Int)
        If x>=0 And y>=0 And x<mapwidth And y<mapheight
            map[x][y] = val
        End If
    End Method
    Method drawmap:Void()
        If wipemode<>"nothing"
            For Local y1=0 Until mapheight
            For Local x1=0 Until mapwidth
                drawtile(map[x1][y1],x1*tilewidth,y1*tileheight)
            Next
            Next        
        End If
        If wipemode="wipein"
            SetColor 0,0,0
            For Local y1=0 Until mapheight
            For Local x1=0 Until mapwidth
                If wipemap[x1][y1] > Millisecs()
                    DrawRect x1*tilewidth,y1*tileheight,tilewidth,tileheight
                End If
            Next
            Next        
        End If
        If wipemode="wipeout"
              SetColor 0,0,0
            For Local y1=0 Until mapheight
            For Local x1=0 Until mapwidth
                If wipemap[x1][y1] < Millisecs()
                    DrawRect x1*tilewidth,y1*tileheight,tilewidth,tileheight
                End If
            Next
            Next                      
        End If
    End Method
    Method drawtile(val:Int,x1:Int,y1:Int)
        Select val
            Case 0'water
                SetColor 0,0,255
                DrawRect x1,y1,tilewidth,tileheight
            Case 1'land
                SetColor 0,200,0
                DrawRect x1,y1,tilewidth,tileheight
            Case 2'forrest
                drawtile(1,x1,y1)
                SetColor 0,255,0
                DrawOval x1+5,y1+5,tilewidth-10,tileheight/2
                SetColor 150,10,0
                DrawRect x1+12,y1+tileheight-10,tilewidth-24,tileheight/2-5
            Case 3'hill
                drawtile(1,x1,y1)
                SetColor 0,255,0
                DrawOval x1+5,y1+10,tilewidth-10,tileheight-15
                SetColor 0,200,0
                DrawRect x1,y1+tileheight/1.5,tilewidth,10
            Case 4'mountain
                drawtile(1,x1,y1)
                SetColor 200,200,200
                DrawPoly(    [Float(x1+tilewidth/2),Float(y1),
                            Float(x1+tilewidth-5),Float(y1+tileheight-5),
                            Float(x1+5),Float(y1+tileheight-5)])
        End Select
    End Method

End Class

Global mymap:map = New map(20,14,32,32)

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        mymap.initwipein
    End Method
    Method OnUpdate()
        mymap.update
        If mymap.wipemode="wipedone"
            mymap.initwipeout
        End If
        If mymap.wipemode="nothing"
            mymap.initwipein            
        End If
    End Method
    Method OnRender()
        Cls 0,0,0
        mymap.drawmap
        SetColor 255,255,255
        DrawText "Screen wipe example (blocks) wipemode "+mymap.wipemode,0,0
    End Method
End Class


Function Main()
    New MyGame()
End Function

Thursday, March 19, 2015

Monkey-X - simple gui Tabber - code example



Here something I made. A tabber.

Code below :

Import mojo

Class tab
    Field x:Int,y:Int
    Field buttontext:String[10]
    Field numbuttons:Int
    Field activetab:Int=0
    Method update()
        If MouseDown(MOUSE_LEFT)
            Local x1:Int=0
            For Local i=0 Until numbuttons
                Local tw:Int = TextWidth(buttontext[i])+16
                If rectsoverlap(MouseX(),MouseY(),1,1,x+x1,y,tw,16)
                    activetab = i
                    Exit
                End If
                x1+=tw
            Next    
        End If
    End Method
    Method draw()
        Local x1:Int=0
        For Local i=0 Until numbuttons
            Local tw:Int = TextWidth(buttontext[i])+16
            Local at:Bool=False
            Local mo:Bool=False
            If activetab=i Then at=True Else at=False
            mo = rectsoverlap(MouseX(),MouseY(),1,1,x+x1,y,tw,16)
            drawbutton(x+x1,y,tw,16,at,mo)
            SetColor 255,255,255
            DrawText buttontext[i],x+x1+(tw/2),y+8,0.5,0.5
            x1+=tw
        Next
    End Method
    Method drawbutton(x:Int,y:Int,w:Int,h:Int,selected:Bool,mouseover:Bool)
        If selected = False
            If mouseover=False Then 
                SetColor 150,150,150
            Else
                SetColor 180,180,180
            End If
            DrawRect x,y,w,h
            SetColor 200,200,200
            DrawLine x,y,x+w,y
            DrawLine x,y,x,y+h
            SetColor 100,100,100
            DrawLine x,y+h,x+w,y+h
            DrawLine x+w,y,x+w,y+h
        End If
        If selected = True
            If mouseover=False Then            
                SetColor 100,100,100
            Else
                SetColor 130,130,130
            End If
            DrawRect x,y,w,h
            SetColor 50,50,50
            DrawLine x,y,x+w,y
            DrawLine x,y,x,y+h
            SetColor 70,70,70
            DrawLine x,y+h,x+w,y+h
            DrawLine x+w,y,x+w,y+h        
        End If
    End Method
    Method rectsoverlap:Bool(x1:Int, y1:Int, w1:Int, h1:Int, x2:Int, y2:Int, w2:Int, h2:Int)
        If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then Return False
        If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then Return False
        Return True
    End Method    
End Class

Global t:tab = New tab

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        t.x = 50
        t.y = 32
        t.buttontext[0] = "City 1"
        t.buttontext[1] = "City 2"
        t.buttontext[2] = "City 3"
        t.buttontext[3] = "City 4"
        t.buttontext[4] = "City 5"
        t.buttontext[5] = "City 6"
        t.numbuttons = 6
    End Method
    Method OnUpdate()        
        t.update
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        DrawText "Simple Tabber, press mouse on buttons to switch screens",0,0
        DrawText "Tab Selected : "+t.activetab,t.x+100,t.y+100
        t.draw
        
    End Method
End Class


Function Main()
    New MyGame()
End Function

Monday, March 16, 2015

Monkey-X - Basic List view/selector - code example


Here a simple listview for selecting items from a list.

Code below :

Import mojo

Global selecteditem:String=""

Class listview
    Field x:Int,y:Int
    Field w:Int=200
    Field h:Int=300
    Field item:String[100]
    Field pos:Int=0
    Field selected:Int=0
    Field itemcount:Int=100    
    Field vscrollerpos:Int=0
    Field keydelay:Int=0
    Field active:Bool=True
    Method setitemname(item:String,pos:Int)
        For Local i=0 Until itemcount
            If i = pos
                Self.item[i] = item
            End If
        Next
    End Method
    Method update()
        If active=False Then Return
        'keys
        If Millisecs()>keydelay
            If KeyDown(KEY_DOWN)
                selected+=1
                If selected > itemcount-1 Then selected = itemcount-1
                If selected > pos + (h-64)/15
                    pos+=1
                    If pos>itemcount-((h-64)/15) Then pos = itemcount-((h-64)/15)
                End If
                keydelay = Millisecs() + 60
            End If
            If KeyDown(KEY_UP)
                selected-=1
                If selected < 0 Then selected = 0
                If selected < pos 
                    pos-=1
                    If pos<0 Then pos=0
                End If
                keydelay = Millisecs() + 60
            End If    
        End If
        ' mouse on items
        Local i:Int=0
        Local exitloop:Bool=False
        While exitloop=False
            If MouseHit(MOUSE_LEFT)
            If rectsoverlap(MouseX(),MouseY(),1,1,x+10,y+20+i*15,w-32-20,15)
                selected = i+pos
                If selected > itemcount-1 Then selected=itemcount-1
            End If
            End If
            i+=1
            If i+pos>itemcount Then exitloop = True
            If i*15 > h-64 Then exitloop = True
        Wend
        'update vscroller
        vscrollerpos = pos*((h-96)/itemcount)
        If MouseDown(MOUSE_LEFT)
        If rectsoverlap(MouseX(),MouseY(),1,1,x+w-32,y+31,32-10,h-96)
            pos = (MouseY()-y-32)/((h-96)/itemcount)
            If pos>itemcount-((h-64)/15) Then pos = itemcount-((h-64)/15)
            If pos<0 Then pos = 0        
        End If
        End If
        '
        'update v scroll buttons
        If MouseDown(MOUSE_LEFT)
            If rectsoverlap(MouseX(),MouseY(),1,1,x+w-32,y+10,32-10,20)
                pos-=1
                If pos<0 Then pos=0
            End If
            If rectsoverlap(MouseX(),MouseY(),1,1,x+w-32,y+h-64,32-10,20)
                pos+=1
                If pos>itemcount-((h-64)/15) Then pos = itemcount-((h-64)/15)
            End If
        End If
        'Select using enter key
        If KeyHit(KEY_ENTER)        
            selecteditem=item[selected]
            active = False
        End If
        'Cancel select using esc
        If KeyHit(KEY_ESCAPE)
            selecteditem="Nothing"
            active=False            
        End If
        '
        ' Update ok cancel buttons
        If MouseHit(MOUSE_LEFT)
            'ok
            If rectsoverlap(MouseX(),MouseY(),1,1,x+10,y+h-32,w/2.2,32-8)
                selecteditem=item[selected]
                active = False
            End If
            'cancel
            If rectsoverlap(MouseX(),MouseY(),1,1,x+w/2,y+h-32,w/2.2,32-8)
                ' code here        
                selecteditem="Nothing"
                active=False
            End If
        End If
    End Method
    Method draw()
        If active=False Then Return
        SetColor 200,200,200
        DrawRect x,y,w,h
        SetColor 0,0,0
        DrawRect x+10,y+10,w-20,h-20
        SetColor 255,255,255
        Local i:Int=0
        Local exitloop:Bool=False
        While exitloop=False
            If selected = i+pos Then 
                drawboxedrect x+10,y+20+i*15-1,w-32-20,15
            End If
            DrawText item[i+pos],x+20,y+20+i*15            
            i+=1
            If i+pos>itemcount-1 Then exitloop = True
            If i*15 > h-64 Then exitloop = True
        Wend
        drawbutton(x+10,y+h-32,w/2.2,32-8,"Ok")
        drawbutton(x+w/2,y+h-32,w/2.2,32-8,"Cancel")
        drawbutton(x+w-32,y+10,32-10,20,"<")
        drawbutton(x+w-32,y+h-64,32-10,20,">")
        drawvscroller(x+w-32,y+31,32-10,h-96)
    End Method
    Method drawvscroller(x:Int,y:Int,w:Int,h:Int)
        SetColor 255,255,255
        drawboxedrect(x,y,w,h)
        DrawRect x+1,y+vscrollerpos,w-2,38
    End Method
    Method drawbutton(x:Int,y:Int,w:Int,h:Int,text:String)
        SetColor 200,200,200
        DrawRect x,y,w,h
        SetColor 0,0,0
        DrawRect x+2,y+2,w-4,h-4
        SetColor 255,255,255
        DrawText text,x+w/2,y+h/2,0.5,0.5
    End Method
    Method drawboxedrect(x:Int,y:Int,w:Int,h:Int)
        DrawLine x,y,x+w,y
        DrawLine x,y,x,y+h
        DrawLine x,y+h,x+w,y+h
        DrawLine x+w,y,x+w,y+h
    End Method
    Method rectsoverlap:Bool(x1:Int, y1:Int, w1:Int, h1:Int, x2:Int, y2:Int, w2:Int, h2:Int)
        If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then Return False
        If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then Return False
        Return True
    End    Method
End Class

Global l:listview = New listview

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        l.itemcount=100
           For Local i=0 Until l.itemcount
               l.setitemname(String(i),i)
           Next
       l.x=100
       l.y=50
    End Method
    Method OnUpdate()        
        l.update
        If l.active = False And Rnd(100)<2 
            l.active = True
            l.x = Rnd(50,320)
            l.y = Rnd(50,100)
        End If
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        l.draw
        DrawText "Use Mouse and enter and curs up/down for listview",0,0
        DrawText "Selected item :"+selecteditem,0,15
    End Method
End Class


Function Main()
    New MyGame()
End Function

Thursday, March 12, 2015

Monkey-X - Simple RPG Shop screen - code example


Here a example of a rpg shop window. You can buy and sell swords and shields.

Code below :

Import mojo

Class player
    Field inventory:String[] =     [    "Wooden Sword","Wooden Shield"]
    Field gold:Int=362
End Class

Class shop
    Field items:String[] =     [    "Wooden Sword","Iron Sword",
                                "Steel Sword","Wooden Shield",
                                "Iron Shield","Steel Shield"]
    Field prices:Int[] =    [    10,20,30,15,30,40]
    Field buyarrowindex:Int=0
    Method update()
        ' navigate through the screen
        If KeyHit(KEY_DOWN)
            buyarrowindex+=1
        End If
        If KeyHit(KEY_UP)
            buyarrowindex-=1
        End If
        ' keep arrow inside options
        If buyarrowindex < 0 Then buyarrowindex = 0
        If buyarrowindex > 7 Then buyarrowindex = 7
        If KeyHit(KEY_ENTER)            
            If buyarrowindex < 6 'in the buy part of the screen
                If hastomanyitems()=False
                    buyitem(items[buyarrowindex])
                End If
            End If
            If buyarrowindex > 5 ' if in the sell part ot screen
                sellitem(buyarrowindex-6)
            End If
        End If
    End Method
    Method draw()
        SetColor 255,255,255
        PushMatrix()
        Scale 10,10
        Translate 50,50
        Rotate 45
        Translate -50,-50
        DrawText "Shop",35,-10
        PopMatrix()
        PushMatrix()
        Scale 2,2
        DrawText "Weapon",340/2,32
        DrawText "Price",550/2,32
        For Local y=0 Until items.Length
            If buyarrowindex = y
            DrawText ">",230/2,32+15+y*15
            End If
            DrawText "Buy",250/2,32+15+y*15
            DrawText items[y],340/2,32+15+y*15
            DrawText prices[y],550/2,32+15+y*15
        Next
        DrawText "Player gold",20,200/2+32+15
        DrawText p.gold,20,200/2+64
        DrawText "Player carying",340/2,200/2+32+15
        For Local y=0 Until p.inventory.Length
            If buyarrowindex - 6 = y
                DrawText ">",230/2,200/2+y*15+64
            End If
            DrawText "Sell",250/2,200/2+y*15+64
            DrawText p.inventory[y],340/2,200/2+y*15+64
            DrawText sellprice(p.inventory[y]),550/2,200/2+y*15+64
        Next
        PopMatrix()
    End Method
    Method sellitem:Void(index:Int)        
        p.gold += sellprice(p.inventory[index])
        p.inventory[index] = ""
    End Method
    Method buyitem:Void(item:String)
        If p.gold >= itemprice(item) Then 
            If p.inventory[0] = "" Then 
                p.inventory[0] = item
            Else
                p.inventory[1] = item
            End If
            p.gold -= itemprice(item)
        End If
    End Method
    Method itemprice:Int(item:String)
        For Local i=0 Until items.Length
            If item = items[i] Then Return prices[i]
        Next
    End Method
    Method hastomanyitems:Bool()
        If p.inventory[0] <> "" And p.inventory[1] <> "" Then Return True
        Return False
    End Method
    Method sellprice:Int(item:String)
        For Local i=0 Until items.Length
            If items[i] = item Then Return prices[i]/3
        Next
        Return 0
    End Method
End Class

Global p:player = New player
Global s:shop = New shop

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
    End Method
    Method OnUpdate()
        s.update
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255        
        s.draw
        DrawText "Use arrow up/down and enter.",320,0,0.5,0
    End Method
End Class


Function Main()
    New MyGame()
End Function

Monkey-X - Beginners - List Count - code example


Here code that shows how to use the Count command.

Code below :

Import mojo

Global mylist:List<Int> = New List<Int>

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(60)
        mylist.AddLast(10)
        mylist.AddLast(20)
    End Method
    Method OnUpdate()   
        If Rnd(100)<2 Then mylist.AddLast(Rnd(0,100))     
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        DrawText "List Count example.",0,0
        DrawText "Number of items in list : " + mylist.Count,0,15
    End Method
End Class


Function Main()
    New MyGame()
End Function