From 5a8cc026cb6fc591795b8b8e0abec245771889bb Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 12 Oct 2007 23:01:07 +0000 Subject: Updates --- sprite.bmx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 sprite.bmx (limited to 'sprite.bmx') diff --git a/sprite.bmx b/sprite.bmx new file mode 100644 index 0000000..94ab084 --- /dev/null +++ b/sprite.bmx @@ -0,0 +1,94 @@ +' +' Provides sprite wrappers routines +' +' $Id$ +' +Import noddybox.vector + +Type TSprite + Field x:Float + Field y:Float + Field v:TVector + + ' These fields are private + ' + Field img:TImage + Field frames:Int + Field pong:Int + Field fr:Int + Field colmask:Int + Field aninmove:Int + Field animspeed:Int + Field animframe:Int + Field animframeinc:Int + + Function Create:TSprite(i:TImage,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local s:TSprite=New TSprite + + s.img=i + s.frames=i.frames.length-1 + s.fr=0 + s.colmask=col_mask + s.animframe=0 + s.animframeinc=1 + s.pong=ping_pong + s.aninmove=anim_with_delta + s.animspeed=anim_speed + + s.v=TVector.Create(0,0,0) + + s.x=0 + s.y=0 + s.v.x=0 + s.v.y=0 + + Return s + End Function + + Method ChangeAnim(anim_speed:Int,ping_pong:Int,anim_with_delta:Int) + pong=ping_pong + aninmove=anim_with_delta + animspeed=anim_speed + End Method + + Method ChangeImage(i:TImage,col_mask) + img=i + frames=i.frames.length-1 + colmask=col_mask + animframe=0 + animframeinc=1 + End Method + + Method Update() + x:+v.x + y:+v.y + + DrawImage(img,x,y,animframe) + + If (colmask<>0) + CollideImage(img,x,y,animframe,0,colmask,Self) + EndIf + + fr:+1 + + If (frames>0 And ((Not aninmove) Or v.x<>0 Or v.y<>0)) + + If (fr>animspeed) + fr=0 + + animframe:+animframeinc + + If (pong) + If (animframe=0 Or animframe=frames) + animframeinc=-animframeinc + EndIf + Else + If (animframe>frames) + animframe=0 + EndIf + EndIf + EndIf + EndIf + End Method + +End Type \ No newline at end of file -- cgit v1.2.3