##########################################################################
#	Health.py 	Blender 2.66a
#
#	Created by Florian Voelker (iFlowProduction)
#	Games, Downloads and co. at http://iflowproduction.de
#
#	Released under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).
#	http://creativecommons.org/licenses/by-nc-sa/3.0/
#	
#	Feel free to change it for your own application(s), but leave this 
#	Header and inform others about the license.
#	If you use this code, please include this information header and don't change the license.
#
#	If you have any questions, please contact me.
#
#	Version 1.0
##########################################################################

from bge import logic
from bge import events

import sqlite3 as SQL
import sys
import GameLogic
import Rasterizer
import mathutils

import Settings
import System

# get the path to the blend directory
mainDir = GameLogic.expandPath("//")

#Activate/Deactivate the Debug and Error-visibility (1 = True/ 0 = False)
Debug = 0
Errors = 1

def onePositive(cont):
  for Keyboard in cont.sensors:
    if Keyboard.positive:
      return True

def correctHealth():
	cont = logic.getCurrentController()
	obj = cont.owner
	
	Health = obj['Health']
	
	if Health <= 0:
		obj['Health'] = 0
	if Health >= 100:
		obj['Health'] = 100
	  
def checkDeath():
	cont = logic.getCurrentController()
	obj = cont.owner
	
	Health = obj['Health']
	
	if Health <= 0:
		return 1
	else:
		return 0
	  
def Actor_HealthtoHUD_Bar():
	cont = logic.getCurrentController()
	obj = cont.owner
	
	correctHealth()
	
	if checkDeath():
		print ("Actor-Death")
		logic.restartGame()
		
	Health = obj['Health']
	
	scenelist = GameLogic.getSceneList()
	
	for s in scenelist:      
		if s.name == 'HUD':
			scene = s
	
	objList = scene.objects
	
	Bar = objList["HealthBar-Actor"]
	Bar['Health'] = Health
	
def Vehicle_HealthtoHUD_Bar():
	cont = logic.getCurrentController()
	obj = cont.owner
	
	correctHealth()
	
	if checkDeath():
		print ("Vehicle-Death")
	
	scenelist = GameLogic.getSceneList()
	
	for s in scenelist:      
		if s.name == 'HUD':
			scene = s
	
	objList = scene.objects
	
	Bar = objList["HealthBar-Vehicle"]
	Bar['Health'] = Health
