My first bit of plotting in Monkey
Community Forums/Monkey Talk/My first bit of plotting in Monkey
| ||
You need the image from here, thanks to James Boyd for his excellent tutorial. 'http://www.hi-toro.com/boing.png' Import mojo Global plot_x:Int = 10 Global plot_y:Int = 10 Global inc:Int = 1 Global count=0 Global speed_var:Float [110] ' a hundred speeds Global value:Float Global x:Int Function Main () 'populate the speed_var array with dummy data For x=0 To 100 If x<=52 value=value+3.0 Print value Else value=value-3.0 Print value Endif speed_var [x]=value Next New Game End Class Game Extends App Field player:Image Field x:Float Field y:Float Method OnCreate () player = LoadImage ("boing.png") SetUpdateRate 60 End Method OnUpdate () If KeyDown (KEY_LEFT) Then x = x - 4 If KeyDown (KEY_RIGHT) Then x = x + 4 If KeyDown (KEY_UP) Then y = y - 4 If KeyDown (KEY_DOWN) Then y = y + 4 'change the speed_var variable being used count=count+1 If count>=100 Then count=0 plot_x=count plot_y=speed_var [count] End Method OnRender () Cls 64, 96, 128 DrawImage player, x, y 'plot the red rectangle SetColor(255,0,0) DrawRect(plot_x,plot_y,16,16) End End |
| ||
Bollock me if you must, but your code will be a whole lot more readable if you do this. ;)Import mojo Global plot_x:Int = 10 Global plot_y:Int = 10 Global inc:Int = 1 Global count=0 Global speed_var:Float [110] ' a hundred speeds Global value:Float Global x:Int Function Main () 'populate the speed_var array with dummy data For x=0 To 100 If x<=52 value=value+3.0 Print value Else value=value-3.0 Print value Endif speed_var [x]=value Next New Game() End Class Game Extends App Field player:Image Field x:Float Field y:Float Method OnCreate () player = LoadImage ("boing.png") SetUpdateRate 60 End Method OnUpdate () If KeyDown (KEY_LEFT) Then x = x - 4 If KeyDown (KEY_RIGHT) Then x = x + 4 If KeyDown (KEY_UP) Then y = y - 4 If KeyDown (KEY_DOWN) Then y = y + 4 'change the speed_var variable being used count=count+1 If count>=100 Then count=0 plot_x=count plot_y=speed_var [count] End Method OnRender () Cls 64, 96, 128 DrawImage player, x, y 'plot the red rectangle SetColor(255,0,0) DrawRect(plot_x,plot_y,16,16) End End |
| ||
Congrat's on taking the path to Monkey-X BTW, enjoy! :) |
| ||
Blimey, someone found my sadly-abandoned tutorial useful! |
| ||
Steve, thanks for the feedback - I was coding under pressure - was meant to be watchin a sitcom with the family and I was in '5 more mins to crack this' mode ;) @BlitzSupport, oh yeah, very useful - thank you! This blog also helped: http://www.blitzbasic.com/Community/posts.php?topic=103806#1273936 |