Improve My Code

BlitzMax Forums/BlitzMax Beginners Area/Improve My Code

If anyone wants to help, what I have so far is at:
(Open Test.bmx)
http://www45.brinkster.com/QuickSetup/default.htm
(Open Test.bmx)

Import "SAM.bmx" ' SAM inlcudes bobs and images and SAM
' set some local vars for use
Local RVal:Int=0
Local A:Int=0
' setup the graphics
Graphics 800,600,,0 | HARDSYNC

HideMouse
' Load images
RVal=IMGs_Add("3232.png",32,32)
' create 10 sprites that just bounce around
For A=1 To 10
	' #ToAdd,X,Y,ImgNum,SX,SY
	RVal=BOB_Add(1,32*A,32*A,A,.5,.5)
	BOB[A-1].WrapBehaviour=1
Next
' now Create a sprite that moves in a square using SAM
RVal=BOB_Add(1,100,100,20,0,0)
SAM_add()
' This is SAM (Simple Anim & Movement)
' L=Label M=Move X,Y,SX,SY J=Jump to Label 
SAM_calc("L 1:M 150,0,.5,0:M 0,150,0,.5:M 150,0,-.5,0:M 0,150,0,-.5:J 1",0,RVAL)

' loop
Repeat
	Cls
	SAM_Update()
	BOB_Update()
	BOB_Draw()
	Flip
Until KeyHit (KEY_ESCAPE)

SAM[0].Bank=Null


Let me know of any improvements...
It may also help other beginners to see it. Oh, and I noticed my images skip from 9 to 11, but thats the image not the program. I realize it's very small and simple, but I figured best to improve before it gets too big and too hard to look over.

WHAT IS IT?
It's a 2D Sprite Engine with Basic animation and movement scripting.

Be gentle, this is only my third day with BlitzMax.

I'm sort of struggling to understand what your trying to accomplish here? Can you give me any insight as to what you want to use this for. There may be a simpler way.

Altitudems:
Firstly, Does the code work on your PC?
I'm really just looking to improve what I already have (Sprite engine with scripting for movement and animation). I'm trying to make a shorthand way of controlling images. Like this:
L 1:M 150,0,.5,0:M 0,150,0,.5:M 150,0,-.5,0:M 0,150,0,-.5:J 1

That defines a path of a square, then jumps back.
L means label
M Means Move
J Means Jump (Like Goto)
And I'm going to add alot more like A for Anim that would be like this:
A (Frame#,Delay#)(Frame#,Delay#)(Frame#,Delay#)(Frame#,Delay#)

Hopefully you get the idea, some may not like this style for creating games, But I do.
Keep in mind not just one SAM object would be going as in the Example, but hundreds for all the game images.

Your code works fine as is. But I'm curious too see how it will perform with the hundreds of objects you mentioned. Don't get me wrong every programmer needs to do things their own way, but it seems to me that using your current method, there is a lot of required code to produce a simple result. Are you trying to create some kind of scriptible AI? I still think there is a simpler way to achieve the same effect. If I get some time I'll post some code.

-- For some reason your code reminds me of ZZT's OOP :)

20 lines of code is alot to have those sprites moving like that? And it's not even cleaned up. I can cleanup how the types work and get it down to 10 lines. I can see how some would find this style not their style,But I think you'd see the benefits when you have lots of objects following different paths made in SAM.

want to see how well it works with lots of sprites? Try this replace the for loop with this one:
For A=1 To 999
	' #ToAdd,X,Y,ImgNum,SX,SY
	RVal=BOB_Add(1,Rnd()*GraphicsWidth(),Rnd()*GraphicsHeight(),Rnd()*20,Rnd()+.1,.Rnd()+.1)
	BOB[A-1].WrapBehaviour=1
Next


Starting a worklog, instead of spamming here. should have done that from the start :)

Still smooth as butter on my system.

or to see more replace all the code in test.bmx with this:
mport "SAM.bmx" ' SAM  S.imple A.nimation & M.ovement
' set some local vars for use
Local RVal:Int=0
Local A:Int=0
Local Square:String="L 1:M 150,0,.5,0:M 0,150,0,.5:M 150,0,-.5,0:M 0,150,0,-.5:J 1"
Local Triangle:String="L 1:M 150,150,.5,.5:M 150,0,-.5,0:M 150,150,.5,-.5:J 1"
' setup the graphics
Graphics 800,600,,0 | HARDSYNC

HideMouse
' Load images
RVal=IMGs_Add("3232.png",32,32)
' create 10 sprites that just bounce around
For A=1 To 100
	' #ToAdd,X,Y,ImgNum,SX,SY
	RVal=BOB_Add(1,Rnd()*GraphicsWidth(),Rnd()*GraphicsHeight(),Rnd()*20,Rnd()+.1,.Rnd()+.1)
	BOB[RVal].WrapBehaviour=1
Next
' now Create a sprite that moves in a square using SAM
For A=0 To 199
	RVal=BOB_Add(1,Rnd()*GraphicsWidth(),Rnd()*GraphicsHeight(),Rnd()*20,Rnd()+.1,.Rnd()+.1)
	SAM_add()
	If A>99 Then
		SAM_calc(Triangle,A,RVAL)
	Else
		SAM_calc(Square,A,RVAL)
	End If
Next 
' loop
Repeat
	Cls
	SAM_Update()
	BOB_Update()
	BOB_Draw()
	Flip
Until KeyHit (KEY_ESCAPE)