From 5a8cc026cb6fc591795b8b8e0abec245771889bb Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 12 Oct 2007 23:01:07 +0000 Subject: Updates --- players.bmx | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 players.bmx (limited to 'players.bmx') diff --git a/players.bmx b/players.bmx new file mode 100644 index 0000000..cda263a --- /dev/null +++ b/players.bmx @@ -0,0 +1,123 @@ +' +' Actor objects +' +' $Id$ +' +Import "sprite.bmx" + +Type TActor Abstract + ' These fields are public + ' + Field sprite:TSprite + + ' These fields are private + ' + Field m_bullets:TList + Field m_bullet:TImage + Field m_bullet_del:Int + Field m_init_del:Int + Field m_bullet_speed:Float + + Method InitActor(img:TImage,bullet:TImage,bullet_del:Int,bullet_speed:Float,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + sprite=TSprite.Create(img,anim_speed,ping_pong,anim_with_delta,col_mask) + + m_bullet=bullet + m_bullets=CreateList() + m_bullet_del=bullet_del + m_init_del=bullet_del + m_bullet_speed=bullet_speed + + sprite.x=0 + sprite.y=0 + sprite.v.x=0 + sprite.v.y=0 + End Method + + Method Centre() + sprite.x=GraphicsWidth()/2 + sprite.y=GraphicsHeight()/2 + sprite.v.x=0 + sprite.v.y=0 + End Method + + Method Update() + sprite.Update() + + For Local s:TSprite=EachIn m_bullets + s.Update() + Next + End Method + + Method AddBullet(x:Int,y:Int) + Local dx:Int=x-sprite.x + Local dy:Int=y-sprite.y + + If (dx=0 And dy=0) + Return + EndIf + + If m_bullet_del=0 + m_bullet_del=m_init_del + + If (m_bullets.Count()>50) + m_bullets.RemoveFirst() + EndIf + + Local s:TSprite=TSprite.Create(m_bullet,2,False,False,0) + + s.x=sprite.x + s.y=sprite.y + + s.v.x=dx + s.v.y=dy + + s.v.Normalise() + s.v.Scale(m_bullet_speed) + + m_bullets.AddLast(s) + Else + m_bullet_del:-1 + EndIf + End Method +End Type + + +Type TPlayer Extends TActor + ' These fields are public + ' + Field lives:Int + + Function Create:TPlayer(img:TImage,bullet:TImage,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local p:TPlayer=New TPlayer + + p.InitActor(img,bullet,10,4,anim_speed,ping_pong,anim_with_delta,col_mask) + p.lives=3 + + Return p + End Function + + Method NewGame() + Centre() + lives=3 + m_bullets.Clear() + m_bullet_del=m_init_del + End Method + + Method ResetPosition() + sprite.x=GraphicsWidth()/2 + sprite.y=GraphicsHeight()/2 + sprite.v.x=0 + sprite.v.y=0 + End Method +End Type + +Type TEnemy Extends TActor + Function Create:TEnemy(img:TImage,bullet:TImage,bullet_del:Int,bullet_speed:Float,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int) + Local p:TEnemy=New TEnemy + + p.InitActor(img,bullet,bullet_del,bullet_speed,anim_speed,ping_pong,anim_with_delta,col_mask) + + Return p + End Function +End Type + -- cgit v1.2.3