' ' Actor objects ' ' $Id$ ' Strict 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