Okay, so I'm getting to grips with my first Bmax code, and after struggling with the examples on the forum I finally understand what all the fuss is about OO coding.
However I've got completely stuck now. I decided to write a simple robotron style shooter, and things were progressing nicely.
In the following code "being" is my basetype for all things in the game (player, shot and grunt at the moment), So I'd though It'd be nice and easy to override compare method to use the .y variable to z sort all the images
However as soon as I dare override the compare method my delete being code (in workall() setup by killbeing()) completely fails and deletes all manner of random beings.
I though it was due to the list sorting messing up my killlist links, but removing the actual sort command made no difference. It seems the very existance of a new compare method causes my code to fail, without compare ever being called and I can't figure out why.
So I'm obviously unsure of exactly how compare is used. can you guys point me in the right way.
Download the source here:
http://www.zen65317.zen.co.uk/simon/MST3K.zip
and here's a listing of the being code
However I've got completely stuck now. I decided to write a simple robotron style shooter, and things were progressing nicely.
In the following code "being" is my basetype for all things in the game (player, shot and grunt at the moment), So I'd though It'd be nice and easy to override compare method to use the .y variable to z sort all the images
However as soon as I dare override the compare method my delete being code (in workall() setup by killbeing()) completely fails and deletes all manner of random beings.
I though it was due to the list sorting messing up my killlist links, but removing the actual sort command made no difference. It seems the very existance of a new compare method causes my code to fail, without compare ever being called and I can't figure out why.
So I'm obviously unsure of exactly how compare is used. can you guys point me in the right way.
Download the source here:
http://www.zen65317.zen.co.uk/simon/MST3K.zip
and here's a listing of the being code
' make a base type for all creatures Type being ' constants for creatures in game Const CRhero=1 ' CReature hero Const CRgrunt=2 ' Basic badguy Const CRtank=3 Const SHbasic=50 ' basic lazer Global list:TList ' nblist is a list of pointers to every being to be worked on Global killlist:TList ' Anything on this list will get removed from beings Field x#,y#,z# Field xspd#,yspd# Field spd# ' general speed stuff moves Field image Field scalex#,scaley#,alpha#,rot# ' scale, alpha, rotation Field blend 'blendtype (ie. ALPHABLEND) Field r,g,b ' tint information Field lastshot,shotdelay ' frames since lastshot and min frames between shots Field kind ' Type of being see BNGxxx consts Function Draw() If list=Null Then Return For Local b:being=EachIn list SetBlend(b.blend) ; SetScale(b.scalex,b.scaley) SetColor(b.r,b.g,b.b) ; DrawImage b.image,b.x,b.y Next End Function Function workall() If list=Null Then Return ' code move everything For Local b:being=EachIn list b.work() ' increment the universal timers b.lastshot=b.lastshot+1 Next ' got their positions? cool now draw em SortList(list,True) ' collide ' react If killlist<>Null For Local b:being=EachIn killlist list.remove(b) Next ClearList(killlist) EndIf End Function Method work() Abstract ' overide compare to for use with sortlist Method Compare:Int(o:Object) Return Sgn(y-being(o).y) End Method ' set up master list and default details Method initbeing(kind,x,y,image,scx#,scy#) If list=Null Then list=New TList Self.image=image self.x=x ; self.y=y self.scalex=scx ; self.scaley=scy self.blend=MASKBLEND self.r=255 ; self.g=255 ; self.b=255 self.shotdelay=2 ListAddLast list,Self End Method Method killbeing() If killlist=Null Then killlist=New TList ListAddLast killlist,Self End Method End Type