summaryrefslogtreecommitdiff
path: root/sprite.bmx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2007-10-12 23:01:07 +0000
committerIan C <ianc@noddybox.co.uk>2007-10-12 23:01:07 +0000
commit5a8cc026cb6fc591795b8b8e0abec245771889bb (patch)
tree156b1291e3379bfe0d67718be5ed98c43cc4fd8f /sprite.bmx
parentf6b1934a27375bb633e70757d672eae1e3485f5a (diff)
Updates
Diffstat (limited to 'sprite.bmx')
-rw-r--r--sprite.bmx94
1 files changed, 94 insertions, 0 deletions
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