#
###
# Application: Pycadia
# File:        sacuer.py
# Description: pycadia Saucer 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.
#
import pygame
from pygame.locals import *

from game_state import Point
from actor import Actor
import gd_objects

class Saucer(pygame.sprite.Sprite, Actor):
    """a u.f.o. class"""
    def __init__(self, consts, rnd, size, xxx, yyy):
        Actor.__init__(self, consts, gd_objects.saucerRectSize)
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.name = "saucer"
        self.size = size
        self.verts = gd_objects.saucerVerts
        self.lines = gd_objects.saucerLines
        if size == 2:
            #normal size
            self.scale = gd_objects.saucerScale
            self.brightness = consts.NORM_BRIGHT
        elif size == 1:
            #small
            self.scale = gd_objects.saucerScale * 0.7
            self.brightness = consts.NORM_BRIGHT + 50
        self.visible=1
        self.spin_deg = 0
        self.mass = 2
        self.initial_speed = (rnd.random() * 2.5) + 1.0
        start_pos = self.pos = Point((0, 0))
        self.pos.x = self.rect.centerx = xxx
        self.pos.y = self.rect.centery = yyy
        self.speed = Point((0.0, self.initial_speed))
        self.hits = 0
        self.move_timer = 0 
        self.fps = consts.FRAMES_PER_SEC
        self.rnd = rnd
        self.alive = 1
        self.firing = 0

    def update(self):
        """move saucer"""
        #change dir every n secs
        self.move_timer -= 1
        if self.move_timer <= 0:
            self.move_timer = 1.5 * self.fps
            new_dir = self.rnd.randrange(225 * 4, 315 * 4, 1)
            self.speed = Point((0.0, self.initial_speed)) 
            self.speed = self.rotate_point(self.speed, float(new_dir))
        #calc pos
        self.pos.x += self.speed.x
        self.pos.y += self.speed.y
        temp_x = self.pos.x - self.rect.centerx
        temp_y = self.pos.y - self.rect.centery
        self.check_position_limits()
        #redraw
        self.rect.move_ip(temp_x, temp_y)
        self.draw_obj()

