My first bit of plotting in Monkey

Community Forums/Monkey Talk/My first bit of plotting in Monkey

Blitzplotter(Posted 2015) [#1]
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



steve_ancell(Posted 2015) [#2]
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




steve_ancell(Posted 2015) [#3]
Congrat's on taking the path to Monkey-X BTW, enjoy! :)


BlitzSupport(Posted 2015) [#4]
Blimey, someone found my sadly-abandoned tutorial useful!


Blitzplotter(Posted 2015) [#5]
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