Ejemplo n.º 1
0
 def __init__(self, game):
     self._game = game
     self._starting_position = PVector(game.resolution.x / 2,
                                       game.resolution.y / 4)
     # Line spacing: a vertical vector, based on the resolution
     self._line_spacing = PVector(0, game.resolution.y) / 20
     # Font size based on resolution
     self._fontsize = int(game.resolution.modulo / 40)
     self._animate_glow = animator(math.pi * 2, .05)
     self._options = {
         'main menu': (
             ('play game', '_play'),
             ('help', '_help'),
             ('exit', '_exit_game'),
         ),
         'in-game menu': (
             ('back to game', '_back_to_game'),
             ('exit', '_exit_game'),
         ),
         'help': (
             ("Space - fire thruster\nRight click - Yaw control\n" +
              "g - Toggle landing gears\nb - Beep\nMouse wheel - zoom\n" +
              "Ctrl-mouse-wheel - faster zoom", None),
             ('back', '_back_to_main_menu'),
         ),
     }
     self._selected_option = 0
     self._text = """StarOrbit Menu\n\n\n"""
     self.mode = 'main menu'
Ejemplo n.º 2
0
 def _set_fullscreen(self):
     """Set fullscreen mode"""
     surf = self._display_s = pygame.display.set_mode(
         (0, 0), pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
         | pygame.OPENGL)
     Gloss.full_screen = True
     self.resolution = PVector(surf.get_size())
     self._background = pygame.image.load('space_dim.jpg')
     self._background = pygame.transform.smoothscale(
         self._background, self.resolution)
     self.changed_scale = True
     self._presolution = PVector(self.resolution)
Ejemplo n.º 3
0
def parse_args():
    """Parse CLI args"""
    parser = OptionParser()
    parser.add_option("-f",
                      "--fullscreen",
                      dest="fullscreen",
                      action="store_true",
                      help="fullscreen",
                      default=False)
    parser.add_option("-r",
                      "--framerate",
                      dest="framerate",
                      action="store_true",
                      help="display FPS",
                      default=False)
    parser.add_option("--no-sound",
                      dest="sound",
                      action="store_false",
                      help="Disable sound",
                      default=True)
    parser.add_option("-x",
                      "--x-resolution",
                      dest="resolution",
                      help="resolution",
                      default=800)

    (options, args) = parser.parse_args()
    rx = options.resolution
    if rx:
        options.resolution = PVector(int(rx), int(int(rx) / 4.0 * 3))
    return options, args
Ejemplo n.º 4
0
 def _draw_bottom_right_text(self, text, y):
     """Draw gray metrics"""
     self._font.draw(text,
                     scale=1,
                     position=self._presolution - PVector(y, 15),
                     color=gloss.Color(1, 1, 1, .5),
                     letterspacing=0,
                     linespacing=-25)
Ejemplo n.º 5
0
 def _rotate_ship(self):
     """Fire side thrusters to rotate ship"""
     if self._ship.propellent:
         mpos = pygame.mouse.get_pos()
         thrust = self._ship.gcenter.on_screen - PVector(mpos)
         self._ship.set_target_angle(thrust.normalized())
     else:
         pass  #TODO: add error sound
Ejemplo n.º 6
0
 def __init__(self, obj, attr, pos_f, color, len_f=.3, vmax=1):
     res = game.resolution
     self._attr = attr
     self._maxlen = len_f * res.y
     self._obj = obj
     self._stopleft = PVector(res.x * pos_f, res.y - 10)
     self._value_max = float(vmax)
     self._value = 1
     self._color = color
Ejemplo n.º 7
0
 def _change_resolution(self, resolution):
     """Change screen resolution"""
     self.resolution = resolution
     Gloss.screen_resolution = resolution.tup
     self._display_s = pygame.display.set_mode(
         resolution, pygame.RESIZABLE | pygame.DOUBLEBUF | pygame.OPENGL)
     self._background = pygame.image.load('space_dim.jpg')
     self._background = pygame.transform.smoothscale(
         self._background, resolution)
     self.changed_scale = True  #FIXME: remove changed_scale everywhere
     self._presolution = PVector(self.resolution)
Ejemplo n.º 8
0
    def __init__(self, gcenter, thrust):
        self.gcenter = gcenter
        tex = gloss.Texture("smoke.tga")

        wind = PVector(game.zoom * 48, 0)
        wind.angle_cw_degs = degrees(180) - thrust.angle_cw_degs
        wind = wind.round_tup

        self._ps = gloss.ParticleSystem(
            tex,
            onfinish = self._finished,
            position = gcenter.on_screen.tup,
            name = "smoke",
            initialparticles = 20,
            particlelifespan = 190,
            growth = .8,
            wind = wind,
            minspeed = .1,
            maxspeed = 10,
            minscale = game.zoom * .05,
            maxscale = game.zoom * .1,
            startcolor = Color(1, 1, 1, 1),
            endcolor = Color(1, 1, 1, 0),
        )
Ejemplo n.º 9
0
    def __init__(self, gcenter, thrust):
        self.gcenter = gcenter
        tex = gloss.Texture("smoke.tga")

        wind = PVector(game.zoom * 48, 0)
        wind.angle_cw_degs = degrees(180) - thrust.angle_cw_degs
        wind = wind.round_tup

        self._ps = gloss.ParticleSystem(
            tex,
            onfinish=self._finished,
            position=gcenter.on_screen.tup,
            name="smoke",
            initialparticles=20,
            particlelifespan=190,
            growth=.8,
            wind=wind,
            minspeed=.1,
            maxspeed=10,
            minscale=game.zoom * .05,
            maxscale=game.zoom * .1,
            startcolor=Color(1, 1, 1, 1),
            endcolor=Color(1, 1, 1, 0),
        )
Ejemplo n.º 10
0
 def draw(self):
     gloss.Gloss.draw_box(
         position=self._stopleft.tup,
         width=self._value * self._maxlen,
         height=5,
         color=self._color,
     )
     gloss.Gloss.draw_box(
         position=self._stopleft,
         width=1,
         height=5,
         color=self._color,
     )
     gloss.Gloss.draw_box(
         position=self._stopleft + PVector(self._maxlen, 0),
         width=1,
         height=5,
         color=self._color,
     )
Ejemplo n.º 11
0
    def __init__(self, ship, cw=True):
        self.gcenter = ship.gcenter
        self._tex = gloss.Texture("smoke.tga")
        self._ps = []  # Running particle systems

        # Distance of the RCS thrusters from the ship center
        gdelta_front = GVector(3.5, 0)
        gdelta_front.angle_cw_degs = degrees(180) - ship._angle
        gdelta_rear = GVector(4, 0)
        gdelta_rear.angle_cw_degs = degrees(0) - ship._angle

        wind_front = PVector(100, 0)
        wind_rear = PVector(200, 0)

        if cw:
            wind_front.angle_cw_degs = degrees(270) - ship._angle
            wind_rear.angle_cw_degs = degrees(90) - ship._angle
        else:
            wind_front.angle_cw_degs = degrees(90) - ship._angle
            wind_rear.angle_cw_degs = degrees(270) - ship._angle

        self._create_particles(ship.gcenter + gdelta_front, wind_front)
        self._create_particles(ship.gcenter + gdelta_rear, wind_rear)
Ejemplo n.º 12
0
    def __init__(self, ship, cw=True):
        self.gcenter = ship.gcenter
        self._tex = gloss.Texture("smoke.tga")
        self._ps = [] # Running particle systems

        # Distance of the RCS thrusters from the ship center
        gdelta_front = GVector(3.5, 0)
        gdelta_front.angle_cw_degs = degrees(180) - ship._angle
        gdelta_rear = GVector(4, 0)
        gdelta_rear.angle_cw_degs = degrees(0) - ship._angle

        wind_front = PVector(100, 0)
        wind_rear = PVector(200, 0)

        if cw:
            wind_front.angle_cw_degs = degrees(270) - ship._angle
            wind_rear.angle_cw_degs = degrees(90) - ship._angle
        else:
            wind_front.angle_cw_degs = degrees(90) - ship._angle
            wind_rear.angle_cw_degs = degrees(270) - ship._angle

        self._create_particles(ship.gcenter + gdelta_front, wind_front)
        self._create_particles(ship.gcenter + gdelta_rear, wind_rear)
Ejemplo n.º 13
0
 def _center(self, line):
     """ """
     w = self._font.font.size(line)[0]
     return PVector(w / 2, 0)
Ejemplo n.º 14
0
 def gvector(self):
     """Equivalent GVector"""
     pv = PVector(*self.tup) - game._screen_center + game.gcamera.pvector
     gv = pv / game.zoom
     return GVector(*gv.tup)
Ejemplo n.º 15
0
 def in_pixels(self):
     """Equivalent vector measured in pixes"""
     scaled = self * game.zoom
     return PVector(scaled.tup)