"""game_hud.py

   This is the main hud for the game, there are really only three elements

   Adventures on Planet Zephulor by Aaron Hachez. 

   All code, artwork, and sound copyright 2003, Aaron Hachez.

   ----------------------------------------------------------------------------------------

   This file is part of "Adventures on Planet Zephulor".

   A copy of the GNU General Public License should be included with any
   redistribution of this program in a file named "COPYING.txt".

   "Adventures on Planet Zephulor" is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   "Adventures on Planet Zephulor" is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with "Adventures on Planet Zephulor"; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   ----------------------------------------------------------------------------------------

   "Adventures on Planet Zephulor" uses the following libraries:

   PyGame
   SDL

   Both are at the time of this writing, licensed under the GNU LGPL. Please see
   the included file LGPL for details 
"""

import myimg
import pygame
from pygame.locals import *

class hud:

    hearth = 16
    heartw = 16

    bulleth = 16
    bulletw = 16

    eheartw = 16
    ehearth = 16

    hx = 0
    hy = 0

    bx = 0
    by = 0

    ehx = 0
    ehy = 0

    sx = 0
    sy = 0

    hlvl = 0
    blvl = 0
    ehlvl = 0

    # The player's score
    pscore = 0

    font = pygame.font.Font(None, 24)

    def __init__(self):
        pass

    def load(self, heartfile, (hx, hy), bulletfile, (bx,by), eheartfile, (ehx,ehy), (sx,sy)):
        """Load the image file for the hearts (life) and for bullet (power)"""

        # The text for the score
        # Setup default
        newtxt = "Score: 000 "
        text = self.font.render(newtxt, 1, (210, 210, 210))
        # Get size to create surface
        text_rect = text.get_rect()

        self.scoreimage = pygame.Surface(( text_rect[2], text_rect[3] ))
        self.scoreimage = self.scoreimage.convert()
        self.scoreimage.fill((200, 0, 0))
        self.scoreimage.set_colorkey((200, 0, 0), RLEACCEL)

        self.heartimage = myimg.loadimage(heartfile, colorkey=-1)
        self.bulletimage = myimg.loadimage(bulletfile, colorkey=-1)
        self.eheartimage = myimg.loadimage(eheartfile, colorkey=-1)

        # Determine width and height of each
        self.hearth = self.heartimage.get_width()
        self.heartw = self.heartimage.get_height()
        self.bulletw = self.bulletimage.get_width()
        self.bulleth = self.bulletimage.get_height()
        self.ehearth = self.eheartimage.get_width()
        self.eheartw = self.eheartimage.get_height()

        self.hx = hx
        self.hy = hy
        self.bx = bx
        self.by = by
        self.ehx = ehx
        self.ehy = ehy
        self.sx = sx
        self.sy = sy

    def update(self, hlvl, blvl):
        """Update current levels"""

        self.hlvl = hlvl
        self.blvl = blvl

        newtxt = "Score: " + `self.pscore`

        self.scoreimage.fill((200, 0, 0))

        # Update the score
        text = self.font.render(newtxt, 1, (210, 10, 10))

        self.scoreimage.blit(text, (0,0))

        return(self.pscore)

    def draw(self, screen):
        """Draw the hud items to the screen, hlvl hearts, and blvl bullets"""

        screen.blit(self.scoreimage, (self.sx, self.sy) )

        for i in range(self.hlvl):
            offset = i * self.heartw
            screen.blit(self.heartimage, (self.hx + offset, self.hy) )

        for i in range(self.blvl):
            offset = i * self.bulletw
            screen.blit(self.bulletimage, (self.bx + offset, self.by) )

        for i in range(self.ehlvl):
            offset = i * self.eheartw
            screen.blit(self.eheartimage, (self.ehx + offset, self.ehy) )

mainhud = hud()
