class App(): 'Application Class ' def __init__(self): self.app = Interface() def loop(self): """ Main Loop """ self.app.load_main_menu() # Initiate Time self.clock = Time() while self.app._loop: # Main Loop Time Delta self.clock.grandfather() self.clock.reset() # Events for event in self.app.events(): self.app.on_event(event) # Render self.app.background() self.app.user_interface() self.app.battlefield() # Double Buffer self.app.flip() # Close Application after main loop is terminated self.app.window_close()
def __init__(self): self.position = Vector(0,0) self.image = 'exit.png' self.load_image() self.center = self.get_center() self.transparency(0) self.time = Time()
def init(self): self.image = 'player.png' self.load() self.position = Vector(0,0) self.speed = 0.35 self.shooting = False self.shot_delay = 0.15 self.direction = Vector(0,0) self.time = Time()
def __init__(self,pos,size,color,span=1,speed=1): self.particles = [] self.color = color self.speed = speed self.span = span self.position = Vector(pos[0],pos[1]) for i in range(size): self.particles.append(Vector() + Vector()) self.time = Time()
class ExitBtn(Sprite): """ Exit button object """ def __init__(self): self.position = Vector(0,0) self.image = 'exit.png' self.load_image() self.center = self.get_center() self.transparency(0) self.time = Time() def reload(self): # Fade in if self.time < 3: self.transparency(80*self.time.period()/1000.0)
class Logo(Sprite): """ Main logo object """ def __init__(self): self.image = 'logo.png' self.position = Vector(0,0) self.load_image() self.center = self.get_center() self.transparency(0) self.time = Time() def reload(self): # Fade in if self.time < 3: self.transparency(80*self.time.period()/1000.0)
class Explosion(Draw): """ Explosion object """ def __init__(self,pos,size,color,span=1,speed=1): self.particles = [] self.color = color self.speed = speed self.span = span self.position = Vector(pos[0],pos[1]) for i in range(size): self.particles.append(Vector() + Vector()) self.time = Time() def render(self): if self.time > self.span: self.destruct() for particle in self.particles: self.line(self.position+particle*self.speed*self.time.period(),self.position+particle\ *self.speed*self.time.period()*1.1,self.color) def destruct(self): Global.particles.remove(self)
class SpaceShip(Sprite): """ SpaceShip object player controlled""" def init(self): self.image = 'player.png' self.load() self.position = Vector(0,0) self.speed = 0.35 self.shooting = False self.shot_delay = 0.15 self.direction = Vector(0,0) self.time = Time() def start_shooting(self): self.shooting = True def stop_shooting(self): self.shooting = False def reload(self): if self.shooting: if self.time > self.shot_delay: self.time.reset() angle = (self._cursor.position - self.position).angle() Global.bullets += [Bullet(self.position.tupl(),angle)] if Global.score > 150000: Global.bullets += [Bullet(self.position.tupl(),angle-3)] if Global.score > 25000: Global.bullets += [Bullet(self.position.tupl(),angle+3)] elif Global.score > 50000: self.shot_delay = 0.09 elif Global.score > 10000: self.shot_delay = 0.12 if (self.position.x <= -Global.window[0]/2 and self.direction.x < 0) or \ (self.position.x >= Global.window[0]/2 and self.direction.x > 0): self.direction.x = 0 elif (self.position.y <= -Global.window[1]/2 and self.direction.y < 0) or \ (self.position.y >= Global.window[1]/2 and self.direction.y > 0): self.direction.y = 0 for terrorist in Global.enemies + Global.deathstars: if abs(terrorist.position-self.position) < 32: self.destruct() break else: self.accelerate() Global.SpaceShip_position = self.position.tupl() Global.SpaceShip_direction = ~self.direction def destruct(self): while len(Global.enemies) > 0: Global.enemies[-1].remove() while len(Global.deathstars) > 0: Global.deathstars[-1].destruct() Global.lives -= 1 if Global.lives < 1: Global.particles.append(Explosion(self.position.tupl(),200,(255,255,200),5,0.2)) self.load_main_menu() self.score = Text() << Global.score self.score.log('scores.txt') self.play('die.wav') else: Global.particles.append(Explosion(self.position.tupl(),200,(255,255,200))) self.init() self.play('die1.wav')