Esempio n. 1
0
    def __init__(self, app, game):
        self._app = app
        self.cam = camera.Camera(origin=[0, -30, 60],
                                 target=[0, 0, 0],
                                 up=[0, 1, 0],
                                 fov=50,
                                 screen_width=app.window_width,
                                 screen_height=app.window_height,
                                 near=0.1,
                                 far=1000)
        self.phrases = phrasebook.PhraseBook('resources/phrases/all.phr')

        # Level state
        self.timer = util.Timer()
        self.money = 0
        self.state = Level.State.build
        self._target = None
        self._phase = 0
        self._towers = []
        self.enemies = []
        self.waves = []
        self.tower_creator = None

        # Map/graphics etc.
        self._min_coords = None
        self._max_coords = None
        self.tiles = None
        self.base = None
        self.load()

        self._vao = None
        self._vbo = None
        self._shader = glutils.ShaderInstance(
            self._app, 'level2.vs',
            'level2.fs', [('transMatrix', GL.GL_FLOAT_MAT4,
                           self.cam.trans_matrix_as_array()),
                          ('colourIn', GL.GL_FLOAT_VEC4, [1, 1, 1, 1])])
        self._build_vertex_arrays()

        self._picking_texture = glutils.PickingTexture(app.window_width,
                                                       app.window_height)
        self._picking_shader = glutils.ShaderInstance(
            app, 'level.vs', 'picking.fs', [[
                'transMatrix', GL.GL_FLOAT_MAT4,
                self.cam.trans_matrix_as_array()
            ], ['colourIn', GL.GL_FLOAT_VEC4, [0, 0, 0, 0]]])
        self.picking_draw()

        self._hud = hud.Hud(app, self)
Esempio n. 2
0
    def __init__(self, app, x, y):
        self._app = app
        self._vao = glutils.VertexArray()
        self._vbo = glutils.VertexBuffer()
        self.x = x
        self.y = y

        self._shader = glutils.ShaderInstance(
            app, 'ortho.vs', 'test.fs',
            [('screenDimensions', GL.GL_FLOAT_VEC2, [app.window_width,
                                                     app.window_height]),
             ('translate', GL.GL_FLOAT_VEC2, [0, 0])])

        data = [x - Button.SIZE / 2, y - Button.SIZE / 2,
                x - Button.SIZE / 2, y + Button.SIZE / 2,
                x + Button.SIZE / 2, y + Button.SIZE / 2,
                x + Button.SIZE / 2, y - Button.SIZE / 2]

        with self._vao.bind():
            self._vbo.bind()
            data_array = numpy.array(data, numpy.float32)
            GL.glBufferData(GL.GL_ARRAY_BUFFER,
                            data_array.nbytes, data_array,
                            GL.GL_STATIC_DRAW)
            GL.glEnableVertexAttribArray(0)
            GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, GL.GL_FALSE, 8, None)
Esempio n. 3
0
 def __init__(self, app, font, text, x, y, height, align=Text.Align.left):
     super().__init__(font, text, x, y, height, align)
     self._shader = glutils.ShaderInstance(
         app, 'ortho.vs',
         'texture.fs', [('screenDimensions', GL.GL_FLOAT_VEC2,
                         [app.window_width, app.window_height]),
                        ('texUnit', GL.GL_INT, 0)])
Esempio n. 4
0
    def __init__(self, app, cam, coords, height, colour):
        """Construct a (hexagonal) tile.

        coords is a vector containing the horizontal coordinates of the tile,
        using axial coordinates.
        height is the number of stacks in the tile.
        """
        self.coords = coords
        self.height = height
        self.colour = colour
        self.path_next = None
        self.tower = None

        self._shader = glutils.ShaderInstance(
            app, 'level.vs', 'level.fs',
            [('transMatrix', GL.GL_FLOAT_MAT4, cam.trans_matrix_as_array()),
             ('colourIn', GL.GL_FLOAT_VEC4, None)])
        self._hex = glutils.Hex(vector.Vector(self.x, self.y, 0), Tile.SIZE,
                                Tile.DEPTH, height)

        self.outline_colour = colour
        self.face_colour = copy.copy(self.outline_colour)
        self.face_colour.s = self.face_colour.s / 2

        # Dictionary of waves, keyed by the level phase in which they appear.
        self.waves = {}

        # Whether the tile is a 'slow movement' tile.
        self.slow = False
Esempio n. 5
0
    def __init__(self, app, coords):
        self._shader = glutils.ShaderInstance(
            app, 'ortho.vs', 'level.fs',
            [('screenDimensions', GL.GL_FLOAT_VEC2,
              (app.window_width, app.window_height)),
             ('colourIn', GL.GL_FLOAT_VEC4, [1, 1, 1, 1])])

        self._vao = glutils.VertexArray()
        self._vbo = glutils.VertexBuffer()
        self.coords = coords
        data = [coords.x + _ColourButton.SIZE / 2,
                coords.y - _ColourButton.SIZE / 2,
                coords.x + _ColourButton.SIZE / 2,
                coords.y + _ColourButton.SIZE / 2,
                coords.x - _ColourButton.SIZE / 2,
                coords.y + _ColourButton.SIZE / 2,
                coords.x - _ColourButton.SIZE / 2,
                coords.y - _ColourButton.SIZE / 2]
        with self._vao.bind():
            self._vbo.bind()
            data_array = numpy.array(data, numpy.float32)
            GL.glBufferData(GL.GL_ARRAY_BUFFER,
                            data_array.nbytes, data_array,
                            GL.GL_STATIC_DRAW)
            GL.glEnableVertexAttribArray(0)
            GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, GL.GL_FALSE, 8, None)
Esempio n. 6
0
    def __init__(self, app, cam, tile, origin, z):
        self.health = Base.START_HEALTH
        self.tile = tile

        self._shader = glutils.ShaderInstance(
            app, 'level.vs', 'level.fs',
            [('transMatrix', GL.GL_FLOAT_MAT4, cam.trans_matrix_as_array())])
        self._hex = glutils.Hex(vector.Vector(tile.x, tile.y, 0),
                                Tile.SIZE * 0.8, Tile.DEPTH, 2)
Esempio n. 7
0
 def __init__(self, app, level, tile, colour):
     self._shader = glutils.ShaderInstance(
         app, 'level.vs',
         'level.fs', [('transMatrix', GL.GL_FLOAT_MAT4,
                       level.cam.trans_matrix_as_array()),
                      ('colourIn', GL.GL_FLOAT_VEC4, colour)])
     self._hex = glutils.Hex(vector.Vector(tile.x, tile.y, tile.top),
                             0.5,
                             2,
                             stacks=4)
Esempio n. 8
0
    def __init__(self,
                 app,
                 cam,
                 font,
                 text,
                 x,
                 y,
                 height,
                 align=Text.Align.left):
        super().__init__(font, text, x, y, height, align)

        self._shader = glutils.ShaderInstance(
            app, 'phrase_text.vs', 'phrase_text.fs',
            [('transMatrix', GL.GL_FLOAT_MAT4, cam.trans_matrix_as_array()),
             ('origin', GL.GL_FLOAT_VEC3, None),
             ('screenDimensions',
              GL.GL_FLOAT_VEC2, [app.window_width, app.window_height]),
             ('texUnit', GL.GL_INT, 0),
             ('inColour', GL.GL_FLOAT_VEC3, [1, 1, 1])])
Esempio n. 9
0
    def __init__(self, app, level, tile, speed, move_pause, value, damage,
                 colour, health=1, words=1,
                 wordlength=phrasebook.PhraseBook.SHORT_PHRASE):
        # TODO:temp
        self.prev_time = 0
        self.prev_origin = vector.Vector(0, 0, 0)

        self._app = app
        self._level = level
        self._tile = tile

        # Phrase variables
        self._words = words
        self._wordlength = wordlength
        self.phrase = None

        # Movement variables
        self.origin = vector.Vector(tile.x, tile.y, tile.top)
        self.prev_tile = None
        self.current_tile = tile
        self.next_tile = tile.path_next
        self._speed = speed
        self._move_pause = move_pause
        self._start_pos = None
        self._end_pos = None
        self._move_start = 0
        self._move_end = 0

        # Graphics variables
        self._shader = glutils.ShaderInstance(
            app, 'level.vs', 'level.fs',
            [('transMatrix', GL.GL_FLOAT_MAT4, None),
             ('colourIn', GL.GL_FLOAT_VEC4, colour)])
        self._hex = glutils.Hex(vector.Vector(0, 0, 0), 0.5, 1)

        self.health = health
        self.damage = damage
        self.unlink = False
        self.value = value

        # Initial setup
        self._setup_move(level.timer)
        self._setup_phrase()