#
###
# Application: Pycadia
# File:        shot.py
# Description: pycadia Shot class
# Copyright (c) 2002-2003   Andy Balcombe <http://www.anti-particle.com>
###
#
# This program 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.
#
# This program 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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

#from math import sqrt, pi
import pygame
from pygame.locals import *

from game_state import Point
from actor import Actor
import gd_objects

class Shot(pygame.sprite.Sprite, Actor):
    """player / saucer missiles"""
    def __init__(self, consts, player, initial_spin_deg, shot_life):
        Actor.__init__(self, consts, (1,1))
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.verts = gd_objects.missileVerts
        self.lines = gd_objects.missileLines
        self.scale = gd_objects.missileScale
        self.visible=1
        self.spin_deg = 0
        self.mass = 0.25
        self.life = shot_life
        #calc start pos
        start_pos = self.pos = Point((0,15))
        start_pos = self.rotate_point( start_pos, float(initial_spin_deg) )
        self.pos.x = self.rect.centerx = player.rect.centerx + start_pos.x
        self.pos.y = self.rect.centery = player.rect.centery + start_pos.y
        #set speed
        self.speed = Point((0.0, consts.SHOT_SPEED))
        self.speed = self.rotate_point( self.speed, float(initial_spin_deg) )
        #include player speed 
        self.speed.x = self.speed.x + player.speed.x
        self.speed.y = self.speed.y + player.speed.y
        #shot is just a white spot, so fill image with white
        r=self.image.fill((255,255,255))

    def update(self):
        """move shots"""
        self.pos.x += self.speed.x
        self.pos.y += self.speed.y
        self.calc_sun_gravity()
        temp_x = self.pos.x - self.rect.centerx
        temp_y = self.pos.y - self.rect.centery
        self.check_position_limits()
        self.life=self.life-1
        #redraw
        self.rect.move_ip(temp_x, temp_y)
        if self.life <= 0:
            self.kill()

