"""Senso
Author: onpon4
Start Date: 6/13/2010
Completion Date: 6/14/2010
Version: 0.0.1

Description:
    In this game, two players try to destroy each other's moving "targets".
    Whoever destroys the other's targets first wins. Bullets which
    collide with each other are destroyed.

    While this is happening, a ball bounces around the screen. This ball
    works in much the same way as in Pong; it bounces off each player
    object in the same fasion. The players are also allowed to shoot
    the ball with bullets, which causes the ball to bounce in the other
    direction.

    The player objects have 10 "health" and 3 "lives" each. If the player
    is hit by an enemy bullet, 1 health is lost. If health reaches zero or
    if the ball reaches that player's side, 1 life is lost. If lives reaches
    zero, the game is over and the other player wins.

"""

VERSION = (0,0,1,0)

import pygame, sys
from pygame.locals import *

class Game(object):
    def __init__(self, gamesize=(640,480), bgcolor=(0,0,0), lncolor=(0,200,0)):
        pygame.init()

        self.rect = Rect((0,0),gamesize)

        #Window
        self.window = pygame.display.set_mode(self.rect.size)        
        pygame.display.set_caption('Deep Defense')

        #Background
        self.background = pygame.Surface(self.rect.size).convert()
        self.background.fill(bgcolor)
        pygame.draw.line(self.background, lncolor, \
                         (self.rect.size[0]//2,0), \
                         (self.rect.size[0]//2,self.rect.size[1]), 3)
        self.window.blit(self.background, (0,0))
        pygame.display.update()

        #Misc
        self.sprites = pygame.sprite.RenderUpdates()
        self.clock = pygame.time.Clock()
        pygame.event.set_allowed([QUIT, KEYDOWN, KEYUP])

        self.p1 = Player(0,0,(100,100),lncolor,0,(8,64),(16,8))
        self.sprites.append(self.p1)

        self.run()

    def run(self):
        while 1:
            self.time_passed = self.clock.tick(60) / 1000.
            self.ev_handle()
            pygame.display.set_caption('Deep Defense (%d FPS)' % self.clock.get_fps())

            #Redraw
            self.sprites.clear(self.window, self.background)
            self.sprites.update()
            dirty = self.sprites.draw(self.window)
            pygame.display.update(dirty)

    def ev_handle(self):
        for event in pygame.event.get():
            if event.type == QUIT \
               or (event.type == KEYDOWN and event.key == K_ESCAPE):
                self.quit()

            elif event.type == KEYDOWN:
                pass

            elif event.type == KEYUP:
                pass

    def quit(self):
        pygame.quit()
        sys.exit()

class Player(pygame.sprite.Sprite):
    def __init__(self, player, control, position, color=(0,200,0), flip=0, size=(4,32), gunsize=(4,4)):
        pygame.sprite.Sprite.__init__(self)
        self.player = player
        self.rect = Rect(position,size)

        self.sprite = pygame.Surface(size[0]+gunsize[0],max(size[1],gunsize[1])).convert()
        pygame.draw.rect(self.sprite, color, ((0,0),size))
        pygame.draw.polygon(self.sprite, color, \
                            [(size[0],(size[1]//2)-(gunsize[1]//2)), \
                             (size[0],(size[1]//2)+(gunsize[1]//2)), \
                             (size[0]+gunsize[0],size[1]//2)])
        pygame.transform.flip(self.sprite, flip, 0)

    def update(self):
        pass

class Bullet(pygame.sprite.Sprite):
    pass

class Target(pygame.sprite.Sprite):
    pass

if __name__ == '__main__':
    game = Game((640,480), (0,0,0), (0,200,0))
