#
###
# Application: Pycadia
# File:        asteroid.py
# Description: pycadia Asteroid 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 Asteroid(pygame.sprite.Sprite, Actor):
    """a spinning rock"""
    def __init__(self, consts, rnd, size, xxx, yyy):
        Actor.__init__(self, consts, (14*size, 14*size))
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.name = "asteroid"
        self.size = size
        self.verts = gd_objects.asteroidVerts
        self.lines = gd_objects.asteroidLines
        self.scale = gd_objects.asteroidScale * size
        self.visible = 1
        self.spin_deg = 0
        self.spin_rate = rnd.randrange(-10, 10, 1)
        self.mass = 2
        self.brightness = consts.NORM_BRIGHT
        initial_dir = rnd.randrange(0, consts.NUMBER_OF_DEGREES, 1)
        initial_speed = rnd.random() * 3
        self.speed = Point((0.0, initial_speed))
        start_pos = self.pos = Point((0, 0))
        self.pos.x = self.rect.centerx = xxx
        self.pos.y = self.rect.centery = yyy
        self.speed = self.rotate_point(self.speed, float(initial_dir))
        self.hits = 0

    def update(self):
        """move asteroid"""
        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.spin_deg += self.spin_rate
        self.check_spin_limits()
        #redraw
        self.rect.move_ip(temp_x, temp_y)
        self.draw_obj()

