Monday, December 29, 2014

Monkey-X - Draw Boxed Rectangle Code Example


Monkey can not draw Rectangles that are not filled so you need to create your own code to
draw that. Below is shown how I done this.


Code below :

Import mojo

Class MyGame Extends App
    Method OnCreate()
        SetUpdateRate(60)
    End Method
    Method OnUpdate()        
    End Method
    Method OnRender()
        Cls(0,0,0)
        SetColor(255,255,255)
        drawboxedrect(100,100,100,100)
        For Local i=0 Until 10
            drawboxedrect Rnd(100)+200,Rnd(200)+100,Rnd(50)+50,Rnd(50)+50
        Next
    End
End

Function drawboxedrect:Void(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 Function

Function Main()
    New MyGame()
End

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.