'This BMX file was edited with BLIde ( http://www.blide.org )



Function BackGround()
	Stars.CreateStars(StarsImg1, 0, 0, 6)
	Stars.CreateStars(StarsImg1, 0, 0, 1)
End Function


Function UpdateEntities(list:TList)
        For Local entity:TEntity=EachIn list
                entity.Update
				hohoh = hohoh + 1
        Next
		For Local entity2:TEnemy = EachIn SEnemys
                entity2.Update
				hohoh = hohoh + 1
        Next
End Function

Function RemoveEntities(list:TList)
	For Local entity0:TEnemy = EachIn SEnemys
                entity0.remove
        Next

	For Local entity:TEntity = EachIn list
                entity.remove
        Next
End Function


Function PlayerGUI()
		SetAlpha(0.5)
		SetColor(50, 200, 50)
		DrawRect(0, height - height * 0.1, width, 5)
		SetAlpha(0.2)
		SetColor(50, 50, 50)
		DrawRect(0, height - height * 0.1, width, height * 0.1)

	
	
		Local u
		Local b
		SetColor(255, 0, 0)
		SetAlpha(0.9)
		
		For u = 0 To PlayerLink.maxarmor
		   If (u < PlayerLink.showarmor) Then
		   	  DrawRect(50 + (u * 3) + (u * ((width * 0.3 - PlayerLink.maxarmor * 3) / PlayerLink.maxarmor)), height - 80, ((width * 0.3 - PlayerLink.maxarmor * 3) / PlayerLink.maxarmor), 30)
		   End If
		Next
		SetColor(0, 0, 255)
		For u = 0 To PlayerLink.maxEnrgy
		   If (u < PlayerLink.showEnergy) Then
		   	  DrawRect(50 + (u * 3) + (u * ((width * 0.3 - PlayerLink.maxEnrgy * 3) / PlayerLink.maxEnrgy)), height - 30, ((width * 0.3 - PlayerLink.maxEnrgy * 3) / PlayerLink.maxEnrgy), 30)
		   End If
		Next
		SetAlpha(0.85)
		SetColor(255, 255, 255)
		SetImageFont(BoxFont)
		DrawText "Score: " + ShowScore, width / 2 - 150, 20
		SetImageFont(ArtFont)
		DrawText "W e a p o n: " + WeaponyUp, width - 200, 40
		DrawText "A r m o r: " + ArmoryUp, width - 200, 90
		DrawText "E n e r g y: " + EnergyUp, width - 200, 140
		SetImageFont(StandartFont)
		SetAlpha(1)
		Local y
		For y = 0 To 3
			DrawText(ChatMessages[y], 1000, height * 0.9 + 15 + 20 * y)
		Next
End Function

            

Function Distance:Float(x1, y1, x2, y2)
	Return Sqr(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)))
End Function


Function DamageExplosion:Float(x1, y1, x2, y2, maxdist, health:Float, dmg:Float)
	Local ret:Float = 0
	Local dist:Float = Distance(x1, y1, x2, y2)
	If (dist < maxdist)
		ret = (maxdist - dist) * maxdist / dmg
	End If

	Return (health - ret)
End Function



Type ScoreEffect Extends TEntity
	Field x, y
	Field score
	Field time, maxtime
	Field font:TImageFont
	Field Rc, Gc, Bc
	
	Function CreateEffect:ScoreEffect(x, y, score, time, font:TImageFont, Rc, Gc, Bc)
		Local eff:ScoreEffect = New ScoreEffect
		eff.x = x
		eff.y = y
		eff.score = score
		eff.maxtime = time
		eff.Gc = Gc
		eff.Rc = Rc
		eff.Bc = Bc
		eff.font = font
		eff.AddLast(SEntities)
	EndFunction
	
	Method Update()
		time = time + 1
		If time > maxtime Then
			Self.remove()
		End If
		
		SetColor(Rc, gc, Bc)
			SetImageFont(font)
				DrawText score, x, y - time
			SetImageFont(StandartFont)
		SetColor(255,255,255)
	End Method
	
End Type



Type TBonus Extends TEntity
	Field x, y
	Field energy, armor, weapony, armory, energyup2
	Field img:TImage
	
	Function CreateBonus:TBonus(x, y, img:TImage, armor, energy, wep = 0, ar = 0, enr = 0)
		Local bonus:TBonus = New TBonus
		bonus.x = x
		bonus.y = y
		bonus.img = img
		bonus.armor = armor
		bonus.energy = energy
		bonus.energyup2 = enr
		bonus.armory = ar
		bonus.weapony = wep
		
		bonus.AddLast(SEntities)
	End Function
	
	Method Update()
		y = y + 2
		If (y > height)
			Self.remove()
		End If
		
		char:Player = PlayerLink
		If (ImagesCollide(img, x, y, 0, PlayerLink.img, PlayerLink.x, PlayerLink.y, 0)) Then
			  Self.remove()
			  char.Energy = char.Energy + energy
			  char.armor = char.armor + armor
			  char.maxarmor = char.maxarmor + armory
			  char.maxEnrgy = char.maxEnrgy + energyup2
			  WeaponyUp = WeaponyUp + weapony
			  ArmoryUp = ArmoryUp + armory
			  EnergyUp = EnergyUp + energyup2
			  If armory > 0 Then
			  		ChatMess("Теперь ваш щит работает лучше!")
			  EndIf
			  If weapony > 0 Then
			  		ChatMess("Оружие усилено!")
			  EndIf
			  If energyup2 > 0 Then
			  		ChatMess("Двигатель улчшен!")
			  EndIf
			  If armor > 0 Then
			  		ChatMess("Щит починен!")
			  EndIf
			  If energy > 0 Then
			  		ChatMess("Мы подобрали энерго-батарею!")
			  EndIf
			  
		EndIf
		
		SetScale(0.5, 0.5)
		DrawImage(img, x, y)
		SetScale(1, 1)
	End Method
End Type


Function ChatMess(str:String)
	ChatMessages[0] = ChatMessages[1]
	ChatMessages[1] = ChatMessages[2]
	ChatMessages[2] = ChatMessages[3]
	ChatMessages[3] = str
End Function