Turning functions into methods help

BlitzMax Forums/BlitzMax Beginners Area/Turning functions into methods help

QuickSilva(Posted 2004) [#1]
Hi all,

Ok this OO stuff is real new to me (and many others I`m sure) and although I think I`m getting it I still have one small question. I want to add the following function to the players type as I have done with the UpdatePlayers() and DrawPlayers() functions (which are now methods) but I am a little unsure how to add it. Any help would be great.

Jason.

Function CreatePlayer(x,y,sp,si)
	Local p:players

	p=New players
	p.x=x
	p.y=y
	p.sp=sp
	p.si=si
	
	ListAddLast plist,p
 
	pcount=pcount+1
End Function

Type players
	Field x 
	Field y  
	Field sp
	Field si
	
	Method UpdatePlayers()
		If KeyDown(KEY_LEFT)  Then x=x-sp
		If KeyDown(KEY_RIGHT) Then x=x+sp
	End Method

	Method DrawPlayers()
		SetColor 255,100,0  
		DrawRect x,y,si,si
		SetColor 255,255,255
	End Method
End Type



VIP3R(Posted 2004) [#2]
What are the forum codes?


QuickSilva(Posted 2004) [#3]
Thanks VIP3R, updated my post.

Jason.


Perturbatio(Posted 2004) [#4]



QuickSilva(Posted 2004) [#5]
Excellent, thanks Perturbatio :)

Jason.