Strict
Import mojo
Global time:Int
Global anim_interval:Int=300
Global tor:body_part
Global leg1:body_part
Global leg2:body_part
Global shin1:body_part
Global shin2:body_part
Class body_part
Field angle:Float
Field child_list:List<body_part>
Field parent:body_part
Field matrix:Float[]
Field x:Int
Field y:Int
End Class
Class imgtest Extends App
Method OnUpdate:Int()
time=Millisecs()
If KeyDown(KEY_LEFT)
leg1.angle=leg1.angle-1
Endif
If KeyDown(KEY_RIGHT)
leg1.angle=leg1.angle+1
Endif
If KeyDown(KEY_UP)
shin1.angle=shin1.angle+1
Endif
If KeyDown(KEY_DOWN)
shin1.angle=shin1.angle-1
Endif
Return 0
End Method
Method OnRender:Int()
Cls
PushMatrix
Translate(tor.x,tor.y)
Rotate(tor.angle)
DrawCircle (0,0,30)
tor.matrix=GetMatrix()
For Local b:body_part=Eachin tor.child_list
SetMatrix(tor.matrix)
Translate(b.x,b.y)
Rotate(b.angle)
DrawRect(0,0,10,40)
b.matrix=GetMatrix()
For Local bo:body_part=Eachin b.child_list
SetMatrix(b.matrix)
Translate(bo.x,bo.y)
Rotate bo.angle
DrawRect(0,0,10,40)
Next
Next
PopMatrix
Return 0
End Method
Method OnCreate:Int()
SetUpdateRate 60
tor=New body_part
tor.x=200
tor.y=300
tor.child_list=New List<body_part>
leg1=New body_part
leg1.x=40
leg1.y=40
tor.child_list.AddLast(leg1)
leg1.child_list=New List<body_part>
shin1=New body_part
shin1.x=0
shin1.y=40
leg1.child_list.AddLast(shin1)
leg2=New body_part
leg2.x=-40
leg2.y=40
tor.child_list.AddLast(leg2)
leg2.child_list=New List<body_part>
shin2=New body_part
shin2.x=0
shin2.y=40
leg2.child_list.AddLast(shin2)
Return 0
End Method
End Class
Function Main:Int()
New imgtest
Return 0
End Function
|