Constructor CAlien::CAlien()
	m_iShipSprID = agk::CreateSprite(m_iShipImgID)
	m_iEnginePfxID = agk::CreateParticles(30.0f, 10.0f)
	
	agk::SetSpriteShape(m_iShipSprID, 2)
	
	agk::SetParticlesImage(m_iEnginePfxID, m_iParticleImgID)
	agk::SetParticlesStartZone(m_iEnginePfxID, 0.0f, 0.0f, 0.0f, 0.0f)
	agk::SetParticlesDirection(m_iEnginePfxID, 50.0f, 0.0)
	agk::SetParticlesLife(m_iEnginePfxID, 0.4f)
	agk::SetParticlesSize(m_iEnginePfxID, 16.0f)
	agk::SetParticlesAngle(m_iEnginePfxID, 20.0f)
	agk::SetParticlesFrequency(m_iEnginePfxID, 24.0f)
	agk::SetParticlesVelocityRange(m_iEnginePfxID, 0.5f, 2.0f)
	agk::AddParticlesColorKeyFrame(m_iEnginePfxID, 0.0f, agk::Random(0,255), agk::Random(0,255), 0, 255)
	agk::AddParticlesColorKeyFrame(m_iEnginePfxID, 0.4f, 255, 255, 0, 0)
	
	Raw As integer mode = agk::Random(1,4)
	
	If mode = 1 Then agk::AddParticlesForce(m_iEnginePfxID, 0.2f, 0.4f, -1500.0f, -1550.0f)
	If mode = 2 Then agk::AddParticlesForce(m_iEnginePfxID, 0.2f, 0.4f, 1500.0f, 1550.0f)
	If mode = 3 Then agk::AddParticlesForce(m_iEnginePfxID, 0.2f, 0.4f, 100.0f, 100.0f)
	If mode = 4 Then agk::AddParticlesForce(m_iEnginePfxID, 0.2f, 0.4f, -100.0f, -100.0f)
	
	this->Reset()	
End Constructor

Destructor CAlien::~CAlien()

End Destructor

Sub CAlien::Reset()
	Raw As float fX = 550.0f + agk::Random(20,600)
	Raw As float fY = float(agk::Random(100,300))
	
	Raw As float fEngineX = fX + 30.0f
	Raw As float fEngineY = fY + 10.0f
	
	fX = agk::ScreenToWorldX(fX)
	fY = agk::ScreenToWorldY(fY)
	fEngineX = agk::ScreenToWorldX(fEngineX)
	fEngineY = agk::ScreenToWorldY(fEngineY)
	
	Raw As float speed = float(agk::Random(10,20))
	m_fSpeed = speed / 10.0f
	speed = float(agk::Random(1,10))
	m_fValueA = speed / 100.0f
	m_fValueB = 0.0f
	
	agk::ClearParticlesColors(m_iEnginePfxID)
	agk::AddParticlesColorKeyFrame(m_iEnginePfxID, 0.0f, agk::Random(0,255), agk::Random(0,255), 0, 255)
	agk::AddParticlesColorKeyFrame(m_iEnginePfxID, 0.4f, 255, 255, 0, 0)
	
	agk::SetSpritePosition(m_iShipSprID, fX, fY)
	agk::SetParticlesPosition(m_iEnginePfxID, fEngineX, fEngineY)
End Sub

Sub CAlien::Update()
	Raw As float fShipX = agk::GetSpriteX(m_iShipSprID) - m_fSpeed
	Raw As float fShipY = agk::GetSpriteY(m_iShipSprID)
	Raw As float fEngineX = agk::GetParticlesX(m_iEnginePfxID) - m_fSpeed
	Raw As float fEngineY = agk::GetParticlesY(m_iEnginePfxID)
	
	m_fValueB = m_fValueB + m_fValueA
	fShipY = fShipY + agk::Cos(m_fValueB * 180.0f / 3.14f)
	fEngineY = fEngineY + agk::Cos(m_fValueB * 180.0f / 3.14f)
	
	If agk::WorldToScreenX(fEngineX) < -200 Then
		this->Reset()
		Exit Sub
	EndIf
	
	agk::SetSpritePosition(m_iShipSprID, fShipX, fShipY)
	agk::SetParticlesPosition(m_iEnginePfxID, fEngineX, fEngineY)
End Sub

Sub CAlien::GetPosition(fX As float PTR, fY As float PTR)
	If agk::GetSpriteExists(m_iShipSprID) Then
		*fX = agk::GetSpriteX(m_iShipSprID)
		*fY = agk::GetSpriteY(m_iShipSprID)
	EndIf
End Sub

Constructor CExplosion::CExplosion()
	m_iParticlePfxID = agk::CreateParticles(-1000.0f, -1000.0f)
End Constructor

Destructor CExplosion::~CExplosion()

End Destructor

Sub CExplosion::Refresh()
	If agk::GetParticlesMaxReached(m_iParticlePfxID) = 1 Then
		agk::ClearParticlesColors(m_iParticlePfxID)
		agk::ClearParticlesForces(m_iParticlePfxID)
		m_iActive = 0
	EndIf
End Sub

Sub CExplosion::Explode(fX As float, fY As float)
	agk::ResetParticleCount(m_iParticlePfxID)
	
	agk::SetParticlesPosition(m_iParticlePfxID, fX, fY)
	
	agk::SetParticlesFrequency(m_iParticlePfxID, 250)
	agk::SetParticlesLife(m_iParticlePfxID, 1.0f)
	agk::SetParticlesSize(m_iParticlePfxID, 32)
	agk::SetParticlesStartZone(m_iParticlePfxID, -10, 0, 10, 0)
	agk::SetParticlesImage(m_iParticlePfxID, IMGID_PARTICLES)
	agk::SetParticlesDirection(m_iParticlePfxID, 20, 20.0f)
	agk::SetParticlesAngle(m_iParticlePfxID, 360.0f)
	agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.0f, 0, 0, 0, 0)
	agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.2f, agk::Random(0,100), agk::Random(100, 255), agk::Random(100,255), 255)
	agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 1.0f, 0, 100, 255, 0)
	agk::AddParticlesForce(m_iParticlePfxID, 0.2f, 0.8f, 400.0f, 0.0f)
	
	Raw As integer a = agk::Random(200,1000)
	
	If agk::Random(1,2) = 1 Then a = -a
	
	Raw As integer b = agk::Random(500, 5000)
	Raw As integer c = 0
	
	If agk::Random(1,2) = 1 Then b = -b
	
	If agk::Random(1,3) = 1 Then c = b
	
	agk::AddParticlesForce(m_iParticlePfxID, 0.6f, 1.0f, float(c), float(a))
	
	If agk::Random(1,3) = 1 Then
		agk::ClearParticlesColors(m_iParticlePfxID)
		agk::ClearParticlesForces(m_iParticlePfxID)
		
		Raw As integer col = agk::Random(1,3)
		
		If col = 1 Then
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.0f, 255, 0, 0, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.4f, 255, 100, 0, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.8f, 255, 200, 0, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 1.0f, 255, 255, 0, 0)
		ElseIf col = 2 Then
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.0f, 0, 0, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.4f, 0, 100, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.8f, 0, 200, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 1.0f, 0, 255, 255, 0)
		Else
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.0f, 0, 0, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.4f, 100, 0, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 0.8f, 200, 0, 255, 255)
			agk::AddParticlesColorKeyFrame(m_iParticlePfxID, 1.0f, 255, 0, 255, 0)
		EndIf
		
		agk::SetParticlesDirection(m_iParticlePfxID, 40.0f, 40.0f)
		
		Raw As integer up = agk::Random(200, 1000)
		
		agk::AddParticlesForce(m_iParticlePfxID, 0.2f, 0.4f, 0.0f, float(-up))
		agk::AddParticlesForce(m_iParticlePfxID, 0.4f, 1.0f, 0.0f, float(up))
	EndIf
	
	agk::SetParticlesMax(m_iParticlePfxID, 100)
End Sub

Constructor CAliens::CAliens()

End Constructor

Destructor CAliens::~CAliens()

End Destructor

Sub CAliens::CreateAlienExplosion()
	
End Sub

Sub CAliens::UpdateAliens()
	For integer i = 0 To 9
		m_AliensSprID[i].Update()
	Next
End Sub

Sub CAliens::ResetAliens()
	For integer i = 0 to 9
		m_AliensSprID[i].Reset()
	Next
End Sub

Sub CAliens::ExplodeAlien(x As float, y As float)
	Raw As integer ID = -1
	For integer i = 0 to 4
		m_ExplosionsPfxID[i].Refresh()
		If Not m_ExplosionsPfxID[i].IsActive() Then ID = 1
	Next
	
	If ID = -1 Then Exit Sub
	
	agk::PlaySound(agk::Random(SFXID_EXPLOSION1, SFXID_EXPLOSION3))
	
	m_ExplosionsPfxID[ID].Explode(x,y)
End Sub

Function CAliens::CheckCollisionWithAliens(iSprite As integer) AS CAlien PTR
	For integer j = 0 To 9
		If agk::GetSpriteColorAlpha(iSprite) > 16 Then
			If m_AliensSprID[j].CheckCollision(iSprite) Then
				Raw As float x = agk::GetSpriteX(m_AliensSprID[j].m_iShipSprID)
				Raw As float y = agk::GetSpriteY(m_AliensSprID[j].m_iShipSprID)
				Raw As float x1 = agk::WorldToScreenX(x)
				Raw As float y1 = agk::WorldToScreenY(y)
				Function = &m_AliensSprID[j]
			EndIf
		EndIf
	Next
	Function = 0L
End Function