#
###
# Application: Pycadia
# File:        game_state.py
# Description: Pycadia GameState and other minor classes
# 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 sin, cos, sqrt, pi
from random import Random
import pygame
from pygame.locals import *
import config

class GameState:
    def __init__(self, constants):
        #
        self.constants = constants
        #trig tables
        self.sin_table=[]
        self.cos_table=[]
        self.make_sin_cos_tables()
        self.rnd = Random()
        self.rnd.seed()
        #get config
        sCfgFile, self.config = config.PycadiaConfig()
        #set screen
        self.screen = pygame.display.set_mode(constants.SCREENRECT.size, constants.SCREEN_FLAGS)
        
    #utility functions
    def make_sin_cos_tables(self):
        """calculate sine lookup table"""
        radian = 0.0
        pi2 = 2 * pi
        for i in range(self.constants.NUMBER_OF_DEGREES+1):
            self.sin_table.append(sin(radian))
            radian += pi2 / self.constants.NUMBER_OF_DEGREES
    
        # calculate cosine lookup table
        radian = 0
        for i in range(self.constants.NUMBER_OF_DEGREES+1):
            self.cos_table.append(cos(radian))
            radian += pi2 / self.constants.NUMBER_OF_DEGREES
    
    def SIN(self, angle):
        """sine lookup function"""
        return self.sin_table[int(angle)]
    
    def COS(self, angle):
        """cosine lookup function"""
        return self.cos_table[int(angle)]

        
class Point:
    """an x,y co-ordinate class"""
    def __init__(self, p):
        self.x = p[0]
        self.y = p[1]

        
class DummyJoy:
    """dummy class for non-existant joysticks"""
    def get_button(self, button):
        return 0
    def get_axis(self, axis):
        return 0


