Example #1
0
    def __init__(self):
        self.window = pyglet.window.Window(width=const.GAME_WIDTH,
                                           height=const.GAME_HEIGHT,
                                           vsync=False,
                                           caption="Porcupyne",
                                           resizable=True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96

        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return (((x, y), (x, y + platform_height), (x + platform_width,
                                                        y + platform_height),
                     (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform(((225, 48), (400, 160), (400, 48)), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold=True),
                                     '',
                                     color=(0.5, 0.5, 0.5, 0.5),
                                     x=-150,
                                     y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [
            font.Text(ft, x=-150, y=100, color=color),
            font.Text(ft, x=-150, y=85, color=color),
            font.Text(ft, x=-150, y=70, color=color)
        ]

        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
Example #2
0
    def __init__(self):
        self.window = pyglet.window.Window(width = const.GAME_WIDTH, 
            height = const.GAME_HEIGHT, vsync = False, caption = "Porcupyne", 
            resizable = True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96
        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return ((
                (x, y), 
                (x, y + platform_height), 
                (x + platform_width, y + platform_height),
                (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform((
                (225, 48), (400, 160), (400, 48)
                ), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold = True), '', 
            color=(0.5, 0.5, 0.5, 0.5), x=-150, y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [font.Text(ft, x=-150, y=100, color = color),
                      font.Text(ft, x=-150, y=85, color = color),
                      font.Text(ft, x=-150, y=70, color = color)]
        
        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
Example #3
0
class Game(object):
    def __init__(self):
        self.window = pyglet.window.Window(width = const.GAME_WIDTH, 
            height = const.GAME_HEIGHT, vsync = False, caption = "Porcupyne", 
            resizable = True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96
        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return ((
                (x, y), 
                (x, y + platform_height), 
                (x + platform_width, y + platform_height),
                (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform((
                (225, 48), (400, 160), (400, 48)
                ), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold = True), '', 
            color=(0.5, 0.5, 0.5, 0.5), x=-150, y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [font.Text(ft, x=-150, y=100, color = color),
                      font.Text(ft, x=-150, y=85, color = color),
                      font.Text(ft, x=-150, y=70, color = color)]
        
        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

    def update(self, dt):
        self.player1.update(dt)
        self.bg.update(dt)
        
        if self.window.has_exit:
           return
        self.window.switch_to()
        self.on_draw(dt)
        self.window.flip()

    def on_draw(self, dt):
        self.window.clear()

        # This is where the code to auto-resize the window begins.

        # Set it up to draw to the whole space of the window.
        glViewport(0, 0, self.window.width, self.window.height)

        # Switch to projection matrix.
        glMatrixMode(gl.GL_PROJECTION)
        glLoadIdentity()

        # Calculate the size of our display.
        base_size = 240.0
        size_x = 0.0
        size_y = 0.0
        if (self.window.width >= self.window.height):
            size_x = base_size * (self.window.width/float(self.window.height))
            size_y = base_size
        else:
            size_x = base_size
            size_y = base_size * (self.window.height/float(self.window.width))

        # Set the orthogonal projection.
        glOrtho(-size_x/2.0, size_x/2.0, -size_y/2.0, size_y/2.0, -100, 100)

        # Switch back to model view so we can do the rest of our drawing.
        glMatrixMode(gl.GL_MODELVIEW)
        glLoadIdentity()

        # Draw stuff in the level.
        glPushMatrix()
        glTranslatef(int(-self.player1.x), int(-self.player1.y), 0.0)

        self.bg.draw()

        for platform in self.platforms:
            platform.render()

        self.player1.draw()
        if const.DRAW_SENSORS:
            for sensor in self.player1.sensors:
                sensor.render()
        
        glPopMatrix()

        # Draw HUD.
        self.fps_display.text = 'FPS: %d' % (1 / dt)
        self.fps_display.draw()

        self.debug_text[0].text = str(int(self.player1.hlock))
        self.debug_text[1].text = str(self.player1.state)
        self.debug_text[2].text = str(self.player1.rangle)
        self.debug_text[0].draw()
        self.debug_text[1].draw()
        self.debug_text[2].draw()
Example #4
0
class Game(object):
    def __init__(self):
        self.window = pyglet.window.Window(width=const.GAME_WIDTH,
                                           height=const.GAME_HEIGHT,
                                           vsync=False,
                                           caption="Porcupyne",
                                           resizable=True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96

        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return (((x, y), (x, y + platform_height), (x + platform_width,
                                                        y + platform_height),
                     (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform(((225, 48), (400, 160), (400, 48)), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold=True),
                                     '',
                                     color=(0.5, 0.5, 0.5, 0.5),
                                     x=-150,
                                     y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [
            font.Text(ft, x=-150, y=100, color=color),
            font.Text(ft, x=-150, y=85, color=color),
            font.Text(ft, x=-150, y=70, color=color)
        ]

        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

    def update(self, dt):
        self.player1.update(dt)
        self.bg.update(dt)

        if self.window.has_exit:
            return
        self.window.switch_to()
        self.on_draw(dt)
        self.window.flip()

    def on_draw(self, dt):
        self.window.clear()

        # This is where the code to auto-resize the window begins.

        # Set it up to draw to the whole space of the window.
        glViewport(0, 0, self.window.width, self.window.height)

        # Switch to projection matrix.
        glMatrixMode(gl.GL_PROJECTION)
        glLoadIdentity()

        # Calculate the size of our display.
        base_size = 240.0
        size_x = 0.0
        size_y = 0.0
        if (self.window.width >= self.window.height):
            size_x = base_size * (self.window.width /
                                  float(self.window.height))
            size_y = base_size
        else:
            size_x = base_size
            size_y = base_size * (self.window.height /
                                  float(self.window.width))

        # Set the orthogonal projection.
        glOrtho(-size_x / 2.0, size_x / 2.0, -size_y / 2.0, size_y / 2.0, -100,
                100)

        # Switch back to model view so we can do the rest of our drawing.
        glMatrixMode(gl.GL_MODELVIEW)
        glLoadIdentity()

        # Draw stuff in the level.
        glPushMatrix()
        glTranslatef(int(-self.player1.x), int(-self.player1.y), 0.0)

        self.bg.draw()

        for platform in self.platforms:
            platform.render()

        self.player1.draw()
        if const.DRAW_SENSORS:
            for sensor in self.player1.sensors:
                sensor.render()

        glPopMatrix()

        # Draw HUD.
        self.fps_display.text = 'FPS: %d' % (1 / dt)
        self.fps_display.draw()

        self.debug_text[0].text = str(int(self.player1.hlock))
        self.debug_text[1].text = str(self.player1.state)
        self.debug_text[2].text = str(self.player1.rangle)
        self.debug_text[0].draw()
        self.debug_text[1].draw()
        self.debug_text[2].draw()