コード例 #1
0
    def __init__(self, grid_size):

        # Basics variables set up
        self.total_grid = grid_size
        self.grid_unit = 2 / self.total_grid
        self.alive = True
        self.last_mov = "Up"
        self.theta = pi / 2
        self.next_segment = None
        self._rotations = {
            "Up": pi / 2,
            "Left": pi,
            "Down": 3 * pi / 2,
            "Right": 2 * pi
        }

        # Creation of basic figure of the Snake
        gpu_body_quad = es.toGPUShape(
            bs.createTextureQuad(
                "/home/fabiwave/PycharmProjects/T1C-poke-snake/T1/MVC/Models/Images/snake.png"
            ), GL_REPEAT, GL_NEAREST)

        # Creation of the body
        body = sg.SceneGraphNode("Body")
        body.transform = tr.uniformScale(1)
        body.childs += [gpu_body_quad]

        # Translation delta for adjustment of the snake in the grid
        self.t_delta = 0
        if self.total_grid % 2 == 0:
            self.t_delta = self.grid_unit / 2

        # Get together all the parts of the Snake
        snake = sg.SceneGraphNode('snake')
        snake.transform = tr.matmul([
            tr.scale(self.grid_unit, self.grid_unit, 0),
            tr.translate(0, 0, 0)
        ])
        snake.childs += [body]

        # Addition the snake to the scene graph node
        transform_snake = sg.SceneGraphNode('snakeTR')
        transform_snake.childs += [snake]

        # Designation of the previous snake as the model of this class
        self.model = transform_snake
        self.pos_x = self.t_delta
        self.pos_y = self.t_delta

        # Translation of the snake to the center position
        self.model.transform = tr.matmul([
            tr.translate(self.t_delta, self.t_delta, 0),
            tr.rotationZ(pi / 2)
        ])
コード例 #2
0
 def update_pos(self, new_dir="Up"):
     rotation = self.rotate(new_dir)
     translation = tr.translate(self.pos_x, self.pos_y, 0)
     self.model.transform = tr.matmul([translation, rotation])
     if self.next_segment is not None:
         self.next_segment.continue_move()
         self.next_segment.set_last_move(self.last_mov)
コード例 #3
0
 def move_to_last(self, pos, previous_dir):
     if previous_dir == "Right":
         self.set_position(pos[0] - self.grid_unit, pos[1])
     elif previous_dir == "Left":
         self.set_position(pos[0] + self.grid_unit, pos[1])
     elif previous_dir == "Down":
         self.set_position(pos[0], pos[1] + self.grid_unit)
     elif previous_dir == "Up":
         self.set_position(pos[0], pos[1] - self.grid_unit)
     self.last_mov = previous_dir
     rotation = self.rotate(self.last_mov)
     translation = tr.translate(self.pos_x, self.pos_y, 0)
     self.model.transform = tr.matmul([translation, rotation])
コード例 #4
0
ファイル: End.py プロジェクト: fabiwave/PokeSnake-2D
    def __init__(self):
        # Creation of basic figure of the end scene
        gpu_background_quad = es.toGPUShape(
            bs.createTextureQuad(
                "/home/fabiwave/PycharmProjects/T1C-poke-snake/T1/MVC/Models/Images/end.png"
            ), GL_REPEAT, GL_NEAREST)
        end_scene = sg.SceneGraphNode("End")
        end_scene.transform = tr.uniformScale(1)
        end_scene.childs += [gpu_background_quad]

        # Translation and scale of the end scene
        end_scene.transform = tr.matmul(
            [tr.scale(1.25, 1, 0), tr.translate(0, 0, 0)])

        # Designation of the previous background as the model of this class
        self.model = end_scene
コード例 #5
0
    def __init__(self, grid_size):

        # Basics variables set up
        self.total_grid = grid_size
        self.grid_unit = 2 / self.total_grid

        # Creation of basic figure of the Wall
        gpu_brick_quad = es.toGPUShape(
            bs.createTextureQuad("/home/fabiwave/PycharmProjects/T1C-poke-snake/T1/MVC/Models/Images/bush.png"),
            GL_REPEAT, GL_NEAREST)

        # Creation of the a generic brick node
        brick = sg.SceneGraphNode("Brick")
        brick.transform = tr.matmul(
            [tr.scale(self.grid_unit, self.grid_unit, 0), tr.translate(0, 0, 0)])
        brick.childs += [gpu_brick_quad]

        # Translation delta for adjustment of the wall in the grid
        t_delta = self.grid_unit / 2
        wall_children = []
        i = -1 + t_delta

        # Creation of a generic wall
        while i < 1:
            new_brick = sg.SceneGraphNode("Brick " + str(i))
            new_brick.transform = tr.translate(1 - t_delta, i, 0)
            new_brick.childs += [brick]
            wall_children.append(new_brick)
            i += self.grid_unit

        a_wall = sg.SceneGraphNode("Wall")
        a_wall.transform = tr.identity()
        a_wall.childs += wall_children

        # Creation of a fort with 4 walls
        fort = sg.SceneGraphNode("Fort")
        fort.transform = tr.identity()
        walls = []
        for i in range(0, 4):
            wall = sg.SceneGraphNode("Wall " + str(i))
            wall.transform = tr.rotationZ(i * pi / 2)
            wall.childs += [a_wall]
            walls.append(wall)
        fort.childs += walls

        # Designation of the previous fort as the model of this class
        self.model = fort
コード例 #6
0
ファイル: Apple.py プロジェクト: fabiwave/PokeSnake-2D
    def __init__(self, grid_size):
        # Basics variables set up
        self.total_grid = grid_size
        self.grid_unit = 2 / self.total_grid

        # Basic color shapes
        gpu_center_vertical_quad = es.toGPUShape(
            bs.createColorQuad(240 / 255, 85 / 255, 94 / 255))
        gpu_center_horizontal_quad = es.toGPUShape(
            bs.createColorQuad(240 / 255, 85 / 255, 94 / 255))
        gpu_berry_part_quad = es.toGPUShape(
            bs.createColorQuad(240 / 255, 85 / 255, 94 / 255))
        gpu_leaf_quad = es.toGPUShape(
            bs.createColorQuad(160 / 255, 235 / 255, 73 / 255))

        # We create a center vertical body for the body
        berry_center_vertical_body = sg.SceneGraphNode("VerticalBerry")
        berry_center_vertical_body.transform = tr.scale(5 / 9, 0.8, 1)
        berry_center_vertical_body.childs += [gpu_center_vertical_quad]

        # We create a center horizontal body for the body
        berry_center_horizontal_body = sg.SceneGraphNode("HorizontalBerry")
        berry_center_horizontal_body.transform = tr.scale(9 / 9, 0.2, 1)
        berry_center_horizontal_body.childs += [gpu_center_horizontal_quad]

        # We create a generic berry part
        berry_part = sg.SceneGraphNode("GenericBerry")
        berry_part.transform = tr.scale(7 / 9, 0.2, 1)
        berry_part.childs += [gpu_berry_part_quad]

        # We create the specific down part of the berry
        berry_part_down = sg.SceneGraphNode('BerryDown')
        berry_part_down.transform = tr.translate(0, -1.5 / 9, 0)
        berry_part_down.childs += [berry_part]

        # We create the specific down part of the berry
        berry_part_up = sg.SceneGraphNode('BerryUp')
        berry_part_up.transform = tr.translate(0, 1.5 / 9, 0)
        berry_part_up.childs += [berry_part]

        # We create a generic leaf
        leaf = sg.SceneGraphNode('Leaf')
        leaf.transform = tr.scale(1.5 / 9, 1.5 / 9, 1)
        leaf.childs += [gpu_leaf_quad]

        # We create the first leaf
        leaf_1 = sg.SceneGraphNode('Leaf1')
        leaf_1.transform = tr.translate(1 / 9, 4 / 9, 0)
        leaf_1.childs += [leaf]

        # We create the second leaf
        leaf_2 = sg.SceneGraphNode('Leaf2')
        leaf_2.transform = tr.translate(-1 / 9, 4 / 9, 0)
        leaf_2.childs += [leaf]

        # We create the second leaf
        leaf_3 = sg.SceneGraphNode('Leaf3')
        leaf_3.transform = tr.translate(0, 3 / 9, 0)
        leaf_3.childs += [leaf]

        # Translation delta for adjustment of the snake in the grid
        self.t_delta = 0
        if self.total_grid % 2 == 0:
            self.t_delta = self.grid_unit / 2

        # We put together all the parts of the Apple
        apple = sg.SceneGraphNode('apple')
        apple.transform = tr.matmul([
            tr.scale(self.grid_unit, self.grid_unit, 0),
            tr.translate(0, 0, 0)
        ])
        apple.childs += [
            berry_center_vertical_body, berry_center_horizontal_body,
            berry_part_down, berry_part_up, leaf_1, leaf_2, leaf_3
        ]

        # We add the apple to the scene graph node
        transform_apple = sg.SceneGraphNode('appleTR')
        transform_apple.childs += [apple]

        # Designation of the previous apple as the model of this class
        half_grid = int((self.total_grid - 2) / 2)
        if self.total_grid % 2 == 0:
            half_grid = half_grid - 1

        random_x = randint(-half_grid, half_grid)
        random_y = randint(-half_grid, half_grid)

        self.model = transform_apple
        self.pos_x = self.t_delta + (random_x * self.grid_unit)
        self.pos_y = self.t_delta + (random_y * self.grid_unit)

        # Translation of the Apple to the random position
        self.model.transform = tr.translate(
            self.t_delta + (random_x * self.grid_unit),
            self.t_delta + (random_y * self.grid_unit), 0)