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



Type Player Extends TEntity
	Field armor:Float
	Field maxarmor:Float, showarmor:Float
	Field weaponID
	Field x
	Field y
	Field speed
	Field img:TImage
	Field reload:Float, maxreload:Float
	Field reload2:Float, maxreload2:Float
	Field Energy:Float
	Field maxEnrgy:Float, showEnergy:Float
	
	Function CreatePlayer:Player(img:TImage, x, y, speed = 5, armor:Float = 100, weaponID = 0, enrg = 100)
        Local char:Player = New Player
		char.img = img
		char.x = x
		char.y = y
		char.speed = speed
		char.armor = armor
		char.maxarmor = armor
		char.showarmor = armor
		char.weaponID = weaponID
		char.AddLast SEntities
		char.maxreload = WeaponSlot1.ReloadTime
		If WeaponSlot2 <> Null Then
		char.maxreload2 = WeaponSlot2.ReloadTime
		EndIf
		char.maxEnrgy = enrg
		char.Energy = char.maxEnrgy
		PlayerLink = char 
	End Function
				
	Method Update()
		'===============Movements=========
			
		If (KeyDown(KeyUp1) Or KeyDown(KeyUp2)) Then
			 y = y - speed
		ElseIf (msys <> 0)
			Local speeed2 = msys / 2
			
			 y = y + speeed2
		EndIf
		If (KeyDown(KeyDown1) Or KeyDown(KeyDown2)) Then
			 y = y + speed
		EndIf
		If (KeyDown(KeyLeft1) Or KeyDown(KeyLeft2)) Then
			 x = x - speed
		ElseIf (msxs <> 0)
			Local speeed = msxs / 2
		
			 x = x + speeed
		EndIf
		If (KeyDown(KeyRight1) Or KeyDown(KeyRight2)) Then
			 x = x + speed
		EndIf
		
		'Upgrades
		If WeaponyUp = 5 Then
			WeaponSlot1 = BigBulletLauncher
		End If
		
		If WeaponyUp = 10 Then
			  WeaponySlot2 = IonLauncher
		EndIf
		
		If WeaponyUp = 15 Then
			WeaponSlot1 = IonLaser
		EndIf
		
		If WeaponyUp = 20 Then
			  WeaponySlot2 = PlasmaGun
		EndIf
		
		If WeaponyUp = 25 Then
			  WeaponySlot1 = WaweLauncher
		EndIf
		
		If WeaponyUp = 30 Then
			  WeaponySlot2 = RocketLauncher
		EndIf
		
		
		'SHOOT
		If (((KeyDown(KeyEnter1) Or KeyDown(KeyEnter2) Or MouseDown(MOUSE_LEFT)) And reload = maxreload And Energy > WeaponSlot1.Energy) And WeaponSlot1 <> Null) Then
			 Bullet.CreateBullet(WeaponSlot1.img, x, y - 20, WeaponSlot1.speed, WeaponSlot1.damage, 1, 0, WeaponSlot1.scalex, WeaponSlot1.scaley)
			 
			 reload = 0
			 Energy = Energy - WeaponSlot1.Energy
			 ShootChannel:TChannel = CueSound(LaserSound)
			 SetChannelVolume(ShootChannel, 0.1 * Sound)
			 ResumeChannel(ShootChannel)
		Else
		Energy = Energy + 0.04 + 0.01 * EnergyUp
		EndIf
		If (((KeyDown(KeySecAttack1) Or KeyDown(KeySecAttack2) Or MouseDown(MOUSE_RIGHT)) And reload2 = maxreload2 And Energy > WeaponSlot2.Energy) And WeaponSlot2 <> Null) Then
			 Bullet.CreateBullet(WeaponSlot2.img, x, y - 20, WeaponSlot2.speed, WeaponSlot2.damage, 1, 0, WeaponSlot2.scalex:Float, WeaponSlot2.scaley:Float)
			 reload2 = 0
			 Energy = Energy - WeaponSlot2.Energy
			 ShootChannel2:TChannel = CueSound(LaserSound2)
			 SetChannelVolume(ShootChannel2, 0.2 * Sound)
			 ResumeChannel(ShootChannel2)
		EndIf
		
		'Energy
		If (Energy > maxEnrgy) Then
			Energy = maxEnrgy
		End If
		If (Energy < 0) Then
			Energy = 0
		End If
		
		'Armor
		 If (armor > maxarmor) Then
			armor = maxarmor
		End If
		If (armor < 0) Then
			armor = 0
			FlushKeys()
			GameLevel = -1
			MenuLevel = 10
			init = 0
			RemoveEntities SEntities
			LocScore = 0
		End If
		
		
		
		'RELOADING
		If (reload < maxreload) Then
			reload = reload + 0.1
		EndIf
		If (reload > maxreload) Then
			reload = maxreload
		End If
		
		If (reload2 < maxreload2) Then
			reload2 = reload2 + 0.1
		EndIf
		If (reload2 > maxreload2) Then
			reload2 = maxreload2
		End If
		
		
		'FIX POSITION
		If (x < 0) Then
			  x = 0
		EndIf
		If (y < 0) Then
			  y = 0
		EndIf
		If (x > width - img.width) Then
			  x = width - img.width
		EndIf
		If (y > height) Then
			  y = height
		EndIf
		
		
				
		'SHOW ARMOR MAGIC
		If (showarmor <> armor) Then
			If (showarmor > armor)
				showarmor = showarmor - 0.7
			Else
				showarmor = showarmor + 0.7
			EndIf
		End If
		'SHOW ENERGY MAGIC
		If (showEnergy <> Energy) Then
			If (showEnergy > Energy)
				showEnergy = showEnergy - 0.7
			Else
				showEnergy = showEnergy + 0.7
			EndIf
		End If
		  			  
		
		DrawImage(img, x, y)
		
		
		
		'Score draw
		
		HideMouse
		
	End Method
	
End Type