Example #1
0
def create(game):
    mat = gl.Material('player')

    def rand_color():
        import random
        return gl.col3f(random.random(), random.random(), random.random())

    mat.ambient = rand_color()  #gl.col3f(0.2, 0.2, 0.2)
    #mat.diffuse = gl.col3f('black')
    #mat.specular = gl.col3f('black')
    mat.opacity = .5
    mesh = gl.Spheref(gl.vec3f(0), 1).drawable(game.renderer)
    light = game.renderer.new_light(
        gl.PointLightInfo(
            gl.vec3f(0, 8, -1),
            gl.Color3f("#888"),
            gl.Color3f("#333"),
        ))
    player = game.entity_manager.create('player')
    player.add_component(
        Transform(gl.matrix.translate(gl.mat4f(), gl.vec3f(0, .9, 0)),
                  name='position'), )
    player.add_component(Bindable(light, name='light'))
    player.add_component(Bindable(mat, name='material'))
    player.add_component(Drawable(mesh))
    #def change_colors(ev, delta):
    #    mat.ambiant = rand_color()
    #player.add_component(Controller(change_colors, ['tick']))
    return player
Example #2
0
def create(game):
    mat = gl.Material('ground')
    mat.ambient = gl.col3f('black')
    mat.diffuse = gl.col3f('brown')
    mat.specular = gl.col3f('gray')
    mat.shininess = 1000
    mat.shading_model = gl.material.ShadingModel.gouraud
    mat.add_texture("ground.bmp", gl.TextureType.ambient, gl.TextureMapping.uv,
                    gl.StackOperation.add, gl.TextureMapMode.wrap,
                    gl.BlendMode.basic)
    mesh = gl.Mesh()
    mesh.mode = gl.DrawMode.quads
    size = 40
    step = 1.0 / size
    for i in (i / size for i in range(size)):
        x = i
        for j in (i / size for i in range(size)):
            y = 1.0 - j
            mesh.kind = gl.ContentKind.vertex
            mesh.append(gl.vec3f(x, y, 0))
            mesh.append(gl.vec3f(x, y - step, 0))
            mesh.append(gl.vec3f(x + step, y - step, 0))
            mesh.append(gl.vec3f(x + step, y, 0))
            mesh.kind = gl.ContentKind.tex_coord0
            mesh.append(gl.vec2f(i, j))
            mesh.append(gl.vec2f(i, j + step))
            mesh.append(gl.vec2f(i + step, j + step))
            mesh.append(gl.vec2f(i + step, j))
            mesh.kind = gl.ContentKind.normal
            mesh.append(gl.vec3f(0, 0, 1))
            mesh.append(gl.vec3f(0, 0, 1))
            mesh.append(gl.vec3f(0, 0, 1))
            mesh.append(gl.vec3f(0, 0, 1))
    light = game.renderer.new_light(
        gl.PointLightInfo(
            gl.vec3f(0, 2, -1),
            gl.Color3f("#888"),
            gl.Color3f("#333"),
        ))
    ground = game.entity_manager.create("ground")
    ground.add_component(
        cubeapp.game.entity.component.Transform(
            gl.matrix.rotate(
                gl.matrix.translate(gl.matrix.scale(gl.mat4f(), gl.vec3f(20)),
                                    gl.vec3f(-.5, 0, 0)), units.deg(-90),
                gl.vec3f(1, 0, 0))))
    ground.add_component(cubeapp.game.entity.component.Bindable(mat))
    ground.add_component(cubeapp.game.entity.component.Drawable(mesh))
    return ground
Example #3
0
def create(game, x, z):
    mat = gl.Material('player')
    mat.ambient = gl.col3f('#100')
    mat.diffuse = gl.col3f('#f55')
    mat.specular = gl.col3f('#f00')
    mat.shininess = .5
    mat.shading_model = gl.material.ShadingModel.gouraud

    mesh = gl.Spheref(gl.vec3f(0), 1).drawable(game.renderer)

    entity = game.entity_manager.create('Darkling')
    transform = entity.add_component(
        Transform(gl.matrix.translate(gl.mat4f(), gl.vec3f(x, 1, z))))
    entity.add_component(Bindable(mat))
    entity.add_component(Drawable(mesh))
    return entity
Example #4
0
def create(shape, entity_manager):
    mat = gl.Material('power')
    mat.ambient = gl.col3f('#888')
    mat.diffuse = gl.col3f('#000')
    mat.specular = gl.col3f('#000')
    #mat.shininess = 0
    #mat.shading_model = gl.material.ShadingModel.gouraud
    mat.add_color(
        gl.ShaderParameterType.vec3,
        gl.StackOperation.add
    )
    mesh = gl.Mesh()
    mesh.mode = gl.DrawMode.quads
    mesh.kind = gl.ContentKind.vertex
    mesh.append(gl.vec3f(0, 0, 0))
    mesh.append(gl.vec3f(0, 1, 0))
    mesh.append(gl.vec3f(1, 1, 0))
    mesh.append(gl.vec3f(1, 0, 0))
    mesh.kind = gl.ContentKind.color
    mesh.append(gl.col3f('red'))
    mesh.append(gl.col3f('green'))
    mesh.append(gl.col3f('green'))
    mesh.append(gl.col3f('red'))
    mesh.kind = gl.ContentKind.normal
    mesh.append(gl.vec3f(0, 0, 1))
    mesh.append(gl.vec3f(0, 0, 1))
    mesh.append(gl.vec3f(0, 0, 1))
    mesh.append(gl.vec3f(0, 0, 1))
    power = entity_manager.create('power', shape = shape)

    transform = power.add_component(Transform(power_matrix(shape)))
    power.add_component(Bindable(mat))
    power.add_component(Drawable(mesh))

    refill = Controller(Refill(power))

    def start_power(ev, delta):
        power.add_component(refill)
    power.add_component(Controller(start_power, ['start-power']))

    def stop_power(ev, delta):
        power.remove_component(refill)
        power.shape.h = 1
        transform.node.value = power_matrix(power.shape)
    power.add_component(Controller(stop_power, ['stop-power']))

    return power
Example #5
0
def create(game, size, border, tile_width, tile_height, rows):
    mat = gl.Material('ground')
    mat.ambient = gl.col3f('#888')
    mat.diffuse = gl.col3f('#000')
    mat.specular = gl.col3f('#000')
    #mat.shininess = 0
    #mat.shading_model = gl.material.ShadingModel.gouraud
    mat.add_color(
        gl.ShaderParameterType.vec3,
        gl.StackOperation.add
    )
    coords = []
    colors = []
    indices = list(range(size.x * size.y * 4))
    for i in range(size.x):
        x = i * tile_width + border
        for j in range(size.y):
            y = j * tile_height + border
            coords.extend([
                gl.vec3f(x, y, 0),
                gl.vec3f(x, y + tile_height, 0),
                gl.vec3f(x + tile_width, y + tile_height, 0),
                gl.vec3f(x + tile_width, y, 0),
            ])
            colors.extend([
                gl.col3f('#356712'),
                gl.col3f('#356712'),
                gl.col3f('#356712'),
                gl.col3f('#356712'),
            ])
    ground_vb = game.renderer.new_vertex_buffer([
        gl.make_vba(
            gl.ContentKind.vertex,
            coords,
            gl.ContentHint.static_content
        ),
        gl.make_vba(
            gl.ContentKind.color,
            colors,
            gl.ContentHint.static_content
        )
    ])
    ground_ib = game.renderer.new_index_buffer(
        gl.make_vba(
            gl.ContentKind.index,
            indices,
            gl.ContentHint.static_content
        )
    )
    # Set initial color
    #colors_attr = ground_vb[1]
    #colors_attr[0] = gl.col3f('blue')
    #colors_attr[1] = gl.col3f('blue')
    #ground_vb.reload(1)

    board = game.entity_manager.create(
        'board',
        ib = ground_ib,
        vb = ground_vb,
        size = size,
        tile_height = tile_height,
        tile_width = tile_width,
        border = border,
        rows = rows,
        event_manager = game.event_manager,
    )
    transform = board.add_component(
        Transform(
            gl.matrix.translate(
                #gl.matrix.scale(
                   gl.mat4f(),
                #    gl.vec3f(size, size, 1)
                #),
                gl.vec3f(-.5, -.5, 0)
            )
        )
    )
    board.add_component(Bindable(mat))
    board.add_component(Drawable(DrawGround(board, len(indices))))
    board.add_component(Controller(CellManager(board = board)))

    return board