def start_pyasteroids(): random.seed() import sys from OpenGL.GLUT import glutInit glutInit(sys.argv) app = QApplication(argv) # Game state Player() # Load the config files in memory ConfigManager() # Add the custom fonts to the Qt database FontManager() # Creates the window (GLWidget is created there) win = AsteroidsMainWindow() # Pop-up the window win.show() # Faster processing try: import psyco except: print 'You currently do not have the Psyco module in your PYTHONPATH.' print 'It is highly advisable to install it for a much better gaming performance.' print 'Official site: http://psyco.sourceforge.net/' # Gives control to Qt app.exec_()
def __init__(self): if (SoundManager.instance is None): SoundManager.instance = self else: return SoundClass = None self.play_func = None self.stop_func = None self.available = True if (QSound.isAvailable()): SoundClasse = QSound self.play_func = pyqt_play_sound self.stop_func = pyqt_stop_sound else: try: import pygame pygame.init() pygame.mixer.set_num_channels(12) SoundClass = pygame.mixer.Sound self.play_func = pygame_play_sound self.stop_func = pygame_stop_sound except: QMessageBox.warning(None,'PyAsteroids - Sound', 'This platform does not provide sound facilites through Qt nor PyGame. \ Sound is disabled') self.available = False return self.sounds = {} for sec in ConfigManager.getSections('sounds'): self.sounds[sec] = {} for audio_descr in ConfigManager.getOptions('sounds', sec): file, vol = map(str.strip, ConfigManager.getVal('sounds',sec,audio_descr).split('||')) vol = float(vol) sound = SoundClass(file) if (not (SoundClass is QSound)): sound.set_volume(vol) self.sounds[sec][audio_descr] = sound
def __init__(self, level_number, level): self.level_number = level_number self.info = {} self.fields = set() self.level = level self.player_state = Player.get_instance() cfg = Config('interface', 'Settings') font_name = cfg.get('field_font') font_size = cfg.get('field_font_sz') self.field_font = FontManager.getFont(font_name) self.field_font.setPointSize(font_size) self.field_color = QColor.fromRgb(*cfg.get('field_color')) for f_name in ConfigManager.getOptions('interface', 'Fields'): s = ConfigManager.getVal('interface', 'Fields', f_name) s = map(str.strip, s.split('||')) img = QImage('resources/images/'+s[0]) img_pos = QPoint(*eval(s[1])) info_rect = QRect(*eval(s[2])) scale = float(s[3]) if (len(s) >= 5): font = QFont(self.field_font) font.setPointSize(int(s[4])) else: font = self.field_font img_w, img_h = img.width(), img.height() img_rect = QRect( img_pos.x(), img_pos.y(), int(img_w*scale), int(img_h*scale) ) self.info[f_name] = '' self.fields.add(Field(f_name, img, img_rect, info_rect, font)) self.radar = Radar.from_config('E-Radar', self) self.missile = GuidedMissile.from_config('GuidedMissile', self)
from sys import argv from PyQt4.QtGui import QApplication from util.config import ConfigManager from editor.main_window import EditorMainWindow if __name__ == '__main__': ConfigManager() app = QApplication(argv) win = EditorMainWindow() win.show() app.exec_()
from math import * from OpenGL.GL import * from OpenGL.GLU import * from util.config import ConfigManager from physics.vector3d import Vector3d _fovy = float(ConfigManager.getVal('game','OpenGL','y_field_of_view')) _z_near = float(ConfigManager.getVal('game','OpenGL','z_near')) _z_far = float(ConfigManager.getVal('game','OpenGL','z_far')) def default_perspective(width, height, x = 0, y = 0): glViewport(x,y,width,height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(_fovy,float(width)/height,_z_near,_z_far) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glClear(GL_DEPTH_BUFFER_BIT) def custom_ortho_projection(x, y, left, right, bottom, top): w = abs(left - right) h = abs(top - bottom) glViewport(x,y,w,h)
from math import * from OpenGL.GL import * from OpenGL.GLU import * from util.config import ConfigManager from physics.vector3d import Vector3d _fovy = float(ConfigManager.getVal('game', 'OpenGL', 'y_field_of_view')) _z_near = float(ConfigManager.getVal('game', 'OpenGL', 'z_near')) _z_far = float(ConfigManager.getVal('game', 'OpenGL', 'z_far')) def default_perspective(width, height, x=0, y=0): glViewport(x, y, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(_fovy, float(width) / height, _z_near, _z_far) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glClear(GL_DEPTH_BUFFER_BIT) def custom_ortho_projection(x, y, left, right, bottom, top): w = abs(left - right) h = abs(top - bottom)