Exemple #1
0
    def replace_tile(self):
        _ = self.selected_map_tile
        _u = self.selected_map_tile_up
        if self.selected_new_tile:
            try:
                if self.selected_new_tile not in self.seen_tiles:

                    image = self.img_loader.load_image(
                        ALL_IMAGES[self.selected_new_tile])
                    self.seen_tiles[self.selected_new_tile] = image
            except KeyError:
                pass
        if _ == _u and _:
            try:
                if self.selected_new_tile and self.selected_map_tile:
                    self.tile_map[_[0], _[1]] = Wall(
                        self.seen_tiles[self.selected_new_tile], _[0], _[1])
                    self.map_array[_[1]][_[0]] = self.selected_new_tile
                self.selected_map_tile = None
            except KeyError:
                pass
        elif _ != _u and _u and _:
            try:
                for i in range(min(_[0], _u[0]), max(_[0], _u[0]) + 1):
                    for j in range(min(_[1], _u[1]), max(_[1], _u[1]) + 1):
                        if self.selected_new_tile and self.selected_map_tile:
                            self.tile_map[i, j] = Wall(
                                self.seen_tiles[self.selected_new_tile], i, j)
                            self.map_array[j][i] = self.selected_new_tile
                self.selected_map_tile = None
                self.selected_map_tile_up = None
            except KeyError:
                pass
            except TypeError:
                pass
def newGame():
    #holds initial level value
    global levelCount
    levelCount = 1

    wall = Wall()
    #builds wall of bricks
    wall.buildWall(gameDisplay, ballRect, ballDirection, levelCount)

    #creates new lists to avoid bugs
    global newBrickList
    global newRecList
    global newColorList
    global newHitList
    global newPowerList
    newBrickList = wall.brickList
    newRecList = wall.recList
    newColorList = wall.colorList
    newHitList = wall.hitList
    newPowerList = wall.powerList

    #resets intial life value
    lifeCount = 3

    #resets bricksBroken
    global bricksBroken
    bricksBroken = 0

    #resets startTime
    global startTime
    startTime = time.time()

    resetBall()

    py.display.flip()
def levelFive():
    wall = Wall()
    gameDisplay.fill((0,0,0))
    #builds wall of bricks
    global levelCount
    wall.buildWall(gameDisplay, ballRect, ballDirection, 5)

    #creates new lists to avoid bugs
    global newBrickList
    global newRecList
    global newColorList
    global newHitList
    global newPowerList
    newBrickList = wall.brickList
    newRecList = wall.recList
    newColorList = wall.colorList
    newHitList = wall.hitList
    newPowerList = wall.powerList

    resetBall()

    #resets bricksBroken
    global bricksBroken
    bricksBroken = 0

    #resets startTime
    global startTime
    startTime = time.time()

    py.display.flip()
    global play
    play = True
Exemple #4
0
    def draw_map(self, level):
        for row in range(len(level)):
            for y in range(len(level[row])):
                for col in range(len(level[row][y])):
                    character = level[row][y][col]
                    x_pos = 810 - (col * 15)
                    y_pos = 90 + (row * 15)

                    if character == "0":
                        self.vertical_wall.add(Wall(self.screen, x_pos, y_pos))
                    if character == "H":
                        self.horizontal_wall.add(
                            Wall(self.screen, x_pos, y_pos))
                    if character == "S":
                        self.shield.add(Shield(self.screen, x_pos, y_pos))
                    if character == "+":
                        self.power_group.add(
                            Power(self.screen, x_pos - 12, y_pos - 12))
                    if character == "N":
                        self.node_group.add(NodeGroup(x_pos + 15, y_pos + 15))
                    if character == "@":
                        self.portal_groupO.add(
                            PortalO(self.screen, x_pos, y_pos))
                    if character == "$":
                        self.portal_groupB.add(
                            PortalB(self.screen, x_pos, y_pos))
 def create_wall(self, pos=[24, 49, 16, 298]):
     mywal = Wall(self.canv, pos)
     for i in mywal.get_coords()[0]:
         if not mywal.get_coords()[1]:
             walls['horizontal'].append(i)
         else:
             walls['vertical'].append(i)
Exemple #6
0
 def initWalls(self):
     wall = Wall(0, 0, 1, 20)
     self.addWall(wall)
     wall = Wall(760, 0, 1, 20)
     self.addWall(wall)
     wall = Wall(0, 0, 20, 1)
     self.addWall(wall)
     wall = Wall(0, 760, 20, 1)
     self.addWall(wall)
Exemple #7
0
    def loadLevel(self, levelMatrix):
        offset = self.offset
        tileSize = self.tileSize

        for y in range(len(levelMatrix)):
            for x in range(len(levelMatrix[y])):
                if levelMatrix[y][x] == self.WALL:
                    wall = Wall((self.x_offset + x * tileSize + offset,
                                 self.y_offset + y * tileSize + offset),
                                self.WALL_IMAGE)
                    for corner in wall.getWallCorners():
                        self.wallSprites.add(corner)
                elif levelMatrix[y][x] == self.STONE_WALL:
                    stoneWall = GameObject(
                        (self.x_offset + x * tileSize + offset,
                         self.y_offset + y * tileSize + offset),
                        self.STONE_WALL_IMAGE)
                    self.stoneWallSprites.add(stoneWall)
                elif levelMatrix[y][x] == self.GRASS:
                    grass = GameObject((self.x_offset + x * tileSize + offset,
                                        self.y_offset + y * tileSize + offset),
                                       self.GRASS_IMAGE)
                    self.grassSprites.add(grass)
                elif levelMatrix[y][x] == self.WATER:
                    water = GameObject((self.x_offset + x * tileSize + offset,
                                        self.y_offset + y * tileSize + offset),
                                       self.WATER_IMAGE)
                    self.waterSprites.add(water)
                elif levelMatrix[y][x] == self.FLOOR:
                    floor = GameObject((self.x_offset + x * tileSize + offset,
                                        self.y_offset + y * tileSize + offset),
                                       self.FLOOR_IMAGE)
                    self.floorSprites.add(floor)
                elif levelMatrix[y][x] == self.FRAME:
                    frame = GameObject((self.x_offset + x * tileSize + offset,
                                        self.y_offset + y * tileSize + offset),
                                       self.FRAME_IMAGE)
                    self.frameSprites.add(frame)
                elif levelMatrix[y][x] == self.PLAYER:
                    images = (self.PLAYER_IMAGE_UP, self.PLAYER_IMAGE_DOWN,
                              self.PLAYER_IMAGE_LEFT, self.PLAYER_IMAGE_RIGHT)
                    self.playerRespPoint = (self.x_offset + x * tileSize +
                                            offset, self.y_offset +
                                            y * tileSize + offset)
                    self.player = MovingObjects.Tank(self.playerRespPoint,
                                                     images,
                                                     self.CREATING_TANK_IMAGES,
                                                     self.BIG_BUM_IMAGES,
                                                     tileSize, 4)
                    self.playerSprite = pygame.sprite.RenderPlain(self.player)
                elif levelMatrix[y][x] == self.BASE:
                    self.base = GameObject(
                        (self.x_offset + x * tileSize + offset,
                         self.y_offset + y * tileSize + offset),
                        self.BASE_IMAGE)
                    self.baseSprite = pygame.sprite.RenderPlain(self.base)
    def gen_board(self):

        # fill board with elements

        board = [[None for x in range(16)] for y in range(9)]

        for cord in WALLS:
            board[cord[0]][cord[1]] = Wall(cord[0], cord[1])

        for cord in INNER:
            board[cord[0]][cord[1]] = Piece(cord[0], cord[1])

        for cord in UPSIDE:
            board[cord[0]][cord[1]].upside = True

        for x in board:
            for y in x:
                if type(y) == Piece and y.upside: y.up = NOGO
                if type(y) == Piece and not y.upside: y.down = NOGO

        for cord in SHELF:
            board[cord[0]][cord[1]] = Blank(cord[0], cord[1])

        # color elements

        for cord in SP_WALLS:
            e = board[cord[0]][cord[1]]
            col = random.choice(COL)
            e.left = col
            e.right = col
            board[cord[0]][cord[1] - 1].right = col
            board[cord[0]][cord[1] + 1].left = col

        for cord in INNER:
            e = board[cord[0]][cord[1]]
            col = [random.choice(COL) for i in range(4)]
            if e.up == BLANK:
                e.up = col[0]
                board[cord[0] - 1][cord[1]].down = col[0]
            if e.left == BLANK:
                e.left = col[1]
                board[cord[0]][cord[1] - 1].right = col[1]
            if e.down == BLANK:
                e.down = col[3]
                board[cord[0] + 1][cord[1]].up = col[3]
            if e.right == BLANK:
                e.right = col[2]
                board[cord[0]][cord[1] + 1].left = col[2]

        self.set_wall_color(board)

        self.__board = board
Exemple #9
0
def create_map1(MainGame):
    for i in [-1, 0, 1]:
        wall = Wall("img/wall/walls.gif", SCREEN_WIDTH / 2 - 30 + i * 60, SCREEN_HEIGHT - 120, 1)
        MainGame.wall_list.append(wall)
    for i in [-1, 1]:
        wall = Wall("img/wall/walls.gif", SCREEN_WIDTH / 2 - 30 + 60 * i, SCREEN_HEIGHT - 60, 1)
        MainGame.wall_list.append(wall)
    walls_list = []
    list1 = [1, 3, 5, 7, 9, 11]
    list2 = [4, 4, 3, 3, 4, 4]
    list3 = [1, 1, 2.5, 2.5, 1, 1]
    wall1 = Wall("img/wall/wall_net_h.gif", 0, SCREEN_HEIGHT/2, 0)
    wall2 = Wall("img/wall/wall_net_h.gif", SCREEN_WIDTH-60, SCREEN_HEIGHT/2, 0)
    for i in range(2):
        wall = Wall("img/wall/walls.gif", 120+60*i, SCREEN_HEIGHT/2, 1)
        MainGame.wall_list.append(wall)
    for i in range(2):
        wall = Wall("img/wall/walls.gif", SCREEN_WIDTH-240-60*i, SCREEN_HEIGHT/2, 0)
        MainGame.wall_list.append(wall)
    for i in range(6):
        wall_list = create_wall(70 * list1[i], 0, list2[i])
        walls_list.extend(wall_list)
    for i in range(6):
        wall_list = create_wall(70 * list1[i], SCREEN_HEIGHT - 60*4-60*list3[i], 4)
        walls_list.extend(wall_list)
    wall3 = Wall("img/wall/walls_net.gif", 6*70, 120, 0)
    wall4 = Wall("img/wall/walls.gif", SCREEN_WIDTH/2-30, SCREEN_HEIGHT/2+30, 1)
    walls_list.extend([wall1, wall2, wall3, wall4])
    MainGame.wall_list.extend(walls_list)
Exemple #10
0
    def __init__(self, center, width, height, type="none"):
        self.__center = center
        self.__width = width
        self.__height = height
        self.__top_left = Vector(self.__center.x - self.__width / 2,
                                 self.__center.y - self.__height / 2)
        self.__top_right = Vector(self.__center.x + self.__width / 2,
                                  self.__center.y - self.__height / 2)
        self.__bot_left = Vector(self.__center.x - self.__width / 2,
                                 self.__center.y + self.__height / 2)
        self.__bot_right = Vector(self.__center.x + self.__width / 2,
                                  self.__center.y + self.__height / 2)
        self.__walls = [
            Wall(self.__top_left, self.__top_right, "N"),
            Wall(self.__top_right, self.__bot_right, "E"),
            Wall(self.__bot_right, self.__bot_left, "S"),
            Wall(self.__bot_left, self.__top_left, "W")
        ]
        self.__type = type
        self.__characters = []
        self.__neighbours = {"N": None, "E": None, "S": None, "W": None}
        self.__doors = {}
        self.__enemies = []

        self.__tileset = simplegui.load_image(
            "https://i.imgur.com/a55akyp.png")
        self.__wall_sprite_size = (32, 32)
        self.__wall_sprite_pos_dict = {
            "N": (16, (64 + self.__wall_sprite_size[1] / 2)),
            "E": ((32 + self.__wall_sprite_size[0] / 2),
                  (64 + self.__wall_sprite_size[1] / 2)),
            "S": ((96 + self.__wall_sprite_size[0] / 2),
                  (64 + self.__wall_sprite_size[1] / 2)),
            "W": ((64 + self.__wall_sprite_size[0] / 2),
                  (64 + self.__wall_sprite_size[1] / 2))
        }
        self.__corner_sprite_pos_dict = {
            "NW": ((128 + 16), (64 + 16)),
            "NE": (16, (96 + 16)),
            "SE": ((32 + 16), (96 + 16)),
            "SW": ((64 + 16), (96 + 16))
        }
        self.__door_sprite_size = (64, 32)
        self.__door_sprite_pos = ((128),
                                  (128 + self.__door_sprite_size[1] / 2))

        if (type == "end"):
            self.__ladder_pos = ((96 + 16), (96 + 16))
            self.__ladder_size = (32, 32)
            self.__level_door = Door("C", self.__center)
Exemple #11
0
    def __init__(self):
        super().__init__()

        walls = [[0, 0, 20, 780, WHITE],
                 [780, 0, 20, 250, WHITE],
                 [780, 350, 20, 250, WHITE],
                 [20, 0, 760, 20, WHITE],
                 [20, 580, 760, 20, WHITE],
                 [20, 260, 150, 20, BLUE],
                 [20, 360, 150, 20, BLUE],
                 [200, 150, 150, 20, BLUE],
                 [200, 450, 150, 20, BLUE],
                 [350, 150, 20, 160, BLUE],
                 [350, 310, 20, 160, BLUE],
                 [450, 20, 20, 160, BLUE],
                 [450, 410, 20, 160, BLUE]]

        entrance = [[780, 250, 20, 100, YELLOW]]

        complete = []

        enemies = [[500, 190, 70, 70, WHITE],
                   [600, 390, 70, 70, WHITE],
                   [700, 590, 70, 70, WHITE]]

        collectables = [[375, 150, 50, 50, YELLOW],
                        [550, 380, 50, 50, YELLOW],
                        [400, 400, 50, 50, YELLOW]]

        for item in entrance:
            entrance = Wall(item[0], item[1], item[2], item[3], item[4])
            self.entrance_list.add(entrance)

        for item in walls:
            wall = Wall(item[0], item[1], item[2], item[3], item[4])
            self.wall_list.add(wall)

        for item in enemies:
            enemy = Enemy(item[0], item[1], item[2], item[3], item[4])
            self.enemy_list.add(enemy)

        for item in collectables:
            collectable = Collectable(item[0], item[1], item[2], item[3], item[4])
            self.collectable_list.add(collectable)

        for item in complete:
            exit = Complete(item[0], item[1], item[2], item[3], item[4])
            self.exit_list.add(exit)
Exemple #12
0
 def contract(self, wall, shock, x, y):
     point = Point(x, y)
     wall.end = point
     shock.end = point
     newwall = Wall(point, wall.angle + shock.turningangle)
     self.remainingangle = abs(wall.angle + shock.turningangle)
     return newwall
Exemple #13
0
 def createWalls(self, width, height):
     self.Walls = []
     for y in range(int(height*0.2),height):
         x = width
         wall = Wall(x, y)
         self.Walls.append(wall)
     for x in range(0,int(width/2)):
         y = 0
         wall = Wall(x,y)
         self.Walls.append(wall)
     for x in range(0,width):
         y = height*0.2
         wall = Wall(x,y)
         self.Walls.append(wall)
     for y in range(0,height+1):
         x = 0
         wall = Wall(x,y)
         self.Walls.append(wall)
     for y in range(0, height+1):
         x = width/2
         wall = Wall(x,y)
         self.Walls.append(wall)
     for x in range(int(width/2), width):
         y = height* 0.6
         wall = Wall(x,y)
         self.Walls.append(wall)
     for x in range(0, width):
         y = height
         wall = Wall(x,y)
         self.Walls.append(wall)
Exemple #14
0
 def fillSpaceWithWalls(self):
     currentGridItems = self.grid.getGridItems()
     rows = len(currentGridItems)
     collums = len(currentGridItems[0])
     for i in range(0, rows):
         for j in range(0, collums):
             if not currentGridItems[i][j]:
                 wall = Wall()
                 self.wallManager.add(wall, (i, j))
Exemple #15
0
def setWalls():
    global listWalls, level

    # hashtag  Set list of walls depending on the current level
    listWalls = [0] * len(WallDimensions[level])

    # hashtag  Iterate through the parameters of each wall for the current level and initialize Wall class object
    for index in range(len(listWalls)):
        dimensions = WallDimensions[level][index]
        listWalls[index] = Wall(canvas, dimensions[0], dimensions[1],
                                dimensions[2], dimensions[3])
Exemple #16
0
    def __init__(self, width, height):
        self._height = height
        self._width = width
        self._backgroundColor = (0, 0, 0)
        self._origin_x = width // 2
        self._origin_y = height // 2
        self._color = (255, 255, 255)

        self._walls = [
            Wall(random.randint(0, self._height), random.randint(0, self._width), random.randint(0, self._height),
                 random.randint(0, self._width)) for i in range(5)]
        self._rays = [Ray(i) for i in range(0, 360,1)]
Exemple #17
0
    def gridForType(cls,x,y,width,gridType):

        if Void.isVoidType(gridType):
            return Void(x,y,width,gridType)

        if Dot.isDotType(gridType):
            return Dot(x,y,width,gridType)

        if Wall.isWallType(gridType):
            return Wall(x,y,width,gridType)
        
        raise ValueError("unknown grid type %s" % (gridType))
Exemple #18
0
 def pop_candy(self):
     chance = random.randint(0, 2)
     if chance == 1:
         rand = random.randint(0, 10)
         coord = (random.randint(0, self.board_size),
                  random.randint(0, self.board_size))
         if rand == 0 or rand == 1:
             DizzyCandy(random.randint(-1, 3), coord)
             pass
         elif 1 < rand < 5:
             Wall(coord)
         else:
             Candy(random.randint(-1, 3), coord)
Exemple #19
0
    def generate_objects(self, surface, layer, camera, group):

        terms = {'Oxygen': O2Term, 'Energy': EnergyTerm, 'Main': MainTerm}

        for obj in layer:
            if layer.name == 'walls':
                Wall(obj.image, obj.x, obj.y, group['walls'])

            elif layer.name == 'doors':
                Door(obj.image, obj.x, obj.y, group['doors'],
                     obj.properties['condition'])

            elif layer.name == 'player':
                pass

            elif layer.name == 'terminals' and obj.name != None:
                if obj.name == 'Energy':
                    terms[obj.name](obj.image, obj.name, obj.x, obj.y,
                                    group['terms'], obj.properties['text'],
                                    obj.properties['answer'],
                                    obj.properties['improved_text'],
                                    obj.properties['task'],
                                    obj.properties['broken'])
                else:
                    terms[obj.name](obj.image, obj.name, obj.x, obj.y,
                                    group['terms'], obj.properties['text'],
                                    obj.properties['answer'],
                                    obj.properties['improved_text'],
                                    obj.properties['broken'])

            elif layer.name == 'volvo':
                Valve(obj.image, group['valves'], obj.x, obj.y,
                      obj.properties['waste'])

            elif layer.name == 'shattle':
                Shattle(obj.image, group['shattle'], obj.x, obj.y)

            else:
                Wall(obj.image, obj.x, obj.y, group['other'])
Exemple #20
0
    def generate_board(self):
        """ generate_board generates the board to be used in the game. """
        to_return = []
        for i in range(self.row):
            curr_row = []
            for j in range(self.col):
                if i % 2 == 0 and j % 2 == 0:
                    curr_row.append([Wall(i, j)])
                else:
                    curr_row.append([])
            to_return.append(curr_row)

        to_return[1][1].append(Bomberman(1, 1))

        for i in range(self.row):
            to_return[i][0].append(Wall(i, 0))
            to_return[i][self.col - 1].append(Wall(i, self.col - 1))

        for j in range(self.col):
            to_return[0][j].append(Wall(0, j))
            to_return[self.row - 1][j].append(Wall(self.row - 1, j))

        for i in range(self.bricks_count):
            while True:
                rand_x = random.randint(0, self.row - 1)
                rand_y = random.randint(0, self.col - 1)
                if len(to_return[rand_x][rand_y]) == 0:
                    to_return[rand_x][rand_y].append(Brick(rand_x, rand_y))
                    break

        for i in range(self.enemy_count):
            while True:
                rand_x = random.randint(0, self.row - 1)
                rand_y = random.randint(0, self.col - 1)
                if len(to_return[rand_x][rand_y]) == 0:
                    to_return[rand_x][rand_y].append(Enemy(rand_x, rand_y))
                    break

        return to_return
Exemple #21
0
    def prepareMap(self, mazeArray):
        x, y = 0, 0
        spriteWall = pygame.image.load("img/wall.png")
        spriteRoad = pygame.image.load("img/ground.png")

        for row in mazeArray:
            for cell in row:
                if cell:
                    self.walls.append(Wall(y, x, spriteWall))
                self.roads.append(Road(y, x, spriteRoad))
                y += config.SIZE_OF_WALL
            x += config.SIZE_OF_WALL
            y = 0
Exemple #22
0
 def create_tile_map(self):
     for i, row in enumerate(self.map_array):
         row.remove("\n")
         for j, tile in enumerate(row):
             tile_type = tile[0]
             if tile not in self.seen_tiles:
                 image = self.img_loader.load_image(ALL_IMAGES[tile])
                 self.seen_tiles[tile] = image
             image = self.seen_tiles[tile]
             if tile_type == "F":
                 self.tile_map[j, i] = Floor(image, j, i)
             elif tile_type == "W":
                 self.tile_map[j, i] = Wall(image, j, i)
Exemple #23
0
 def wall(self):
     wall = Wall(self.scene,
                 (self.rect.centerx + self.direct * 50, self.rect[1]),
                 self.direct)
     self.scene.walls.add(wall)
     if self.is_online:
         self.scene.send_role_animation(self.attackTrigger)
         if self.direct == -1:
             self.scene.send_new_wall(self.rect.centerx + self, direct * 50,
                                      self.rect[1], 0)
         else:
             self.scene.send_new_wall(self.rect.centerx + self, direct * 50,
                                      self.rect[1], self.direct)
class TreeAndWall:

    global Img_top_tree
    global tree_y1, tree_y2
    global weapCollision
    w1 = Wall((0, tree_y1), (display_width, tree_y1), 12, 'Green', Vector((0, 1)))
    w2 = Wall((0, tree_y2), (display_width, tree_y2), 12, 'Green', Vector((0, -1)))

    weapCollision.addWall(w1)
    weapCollision.addWall(w2)


    def draw(self,canvas):
        #to sort out why the pic won't draw and the rest of the stuffs
        # canvas.draw_line((0, 75), (display_width, 75), 12, 'Green')
         # canvas.draw_line((0, 600), (display_width, 600), 12, 'Green')
        pass

    def updateTree(self,canvas):
        global tree_y_top
        global tree_y_bottom
        global tree_speed
     #  global car_speed  and values cannot be hanged unless it's inherited as a global value

        tree_y_top-=tree_speed
        tree_y_bottom-=tree_speed

        if tree_y_top < 0-tree_w:
            tree_y_top = display_width + tree_w  # reset y
            #car_speed += 1 / 15

        if tree_y_bottom < 0-tree_w:
            tree_y_bottom = display_width + tree_w  # reset y
            #car_speed += 1 / 15


        canvas.draw_image(Img_top_tree, (tree_centre_x, tree_centre_y), (tree_w, tree_h), (tree_y_top, 28), (tree_x1, tree_y1))  # 605x57
        canvas.draw_image(Img_bottom_tree, (tree_centre_x, tree_centre_y), (tree_w, tree_h), (tree_y_bottom, 641), (tree_x1, tree_y1))  # 605x57
Exemple #25
0
    def __init__(self, width, height, score_callback):
        self.width = width
        self.height = height
        self.score_callback = score_callback
        # self.pixels = np.zeros((WIDTH, HEIGHT))

        self.ball = Ball(920, 360)
        self.ball.velocity = Vec2(-0.707, -0.607)
        self.ball.velocity *= SPEED_BALL
        self.ball.abs_vel = math.sqrt(math.pow(self.ball.velocity.x, 2) + math.pow(self.ball.velocity.y, 2))
        self.track_ball = self.ball
        self.computer = ComputerPaddle(0.1 * WIDTH, HEIGHT / 2)
        self.player = PlayerPaddle(0.9 * WIDTH, HEIGHT / 2)
        self.wall_north = Wall(WIDTH / 2, 0, WIDTH, 20)
        self.wall_east = Wall(WIDTH, 360, 20, HEIGHT)
        self.wall_south = Wall(WIDTH / 2, HEIGHT, WIDTH, 20)
        self.wall_west = Wall(0, HEIGHT / 2, 20, HEIGHT)

        self.paddles = [self.computer, self.player]
        self.entities = [self.computer, self.player, self.ball, self.track_ball]
        self.walls = [self.wall_north, self.wall_east, self.wall_south, self.wall_west]

        self.track_ball = self.spawn_trackball()
Exemple #26
0
    def __init__(self,
                 file="F:\AtomEnergyProject\XMLExport\!ExportStructure.xml"):

        dom = xml.dom.minidom.parse(file)
        #dom = xml.dom.minidom.parse("F:\AtomEnergyProject\Structure.xml")
        dom.normalize()

        WallNodes = dom.getElementsByTagName('SPSWallPart')
        self.walls = []
        print(len(WallNodes))
        for wallNode in WallNodes:
            wall = Wall().getNode(wallNode)
            self.walls.extend(wall.split())
#print(len(WallNodes),len(Walls))

        SlabNodes = dom.getElementsByTagName('CSPSSlabEntity')
        self.slabs = []
        print(len(SlabNodes))
        for slabNode in SlabNodes:
            slab = Slab().getNode(slabNode)
            self.slabs.append(slab)

        self.buildings = []
Exemple #27
0
 def convertCharToObject(
     self, char, pos
 ):  #Used to generate a grid from a map, takes in characters and returns an object associated with that character
     if char == "x":
         return [Wall(pos, self.tileSize)]
     elif char == "D":
         return [Diamond(pos, self.tileSize)]
     elif char == "T":
         return [Tile(pos, self.tileSize)]
     elif char == "C":
         return [Tile(pos, self.tileSize), Crate(pos, self.tileSize)]
     elif char == "P":
         return [
             Tile(pos, self.tileSize),
             WarehouseKeeper(pos, self.tileSize)
         ]
Exemple #28
0
    def setup(self):
        self.grid.reset()
        self.player.setCoordinates((2, 4))
        self.grid.addItem(self.player.getCoordinates(), self.player)

        self.tileManager.setup(GridSquare.generate(16),
                               [(0, 2), (0, 3), (0, 4), (1, 2), (1, 5), (2, 2),
                                (2, 3), (2, 4), (2, 5), (2, 6), (3, 2), (3, 4),
                                (3, 5), (3, 6), (4, 3), (4, 4)])
        self.diamondManager.setup(GridSquareStar.generate(2), [(0, 5), (4, 2)])
        self.wallManager.setup(Wall.generate(3), [(1, 3), (1, 4), (3, 3)])
        self.crateManager.setup(Crate.generate(2), [(1, 2), (3, 5)])

        self.grid.addItemsBySpriteManager(self.tileManager)
        self.grid.addItemsBySpriteManager(self.diamondManager)
        self.grid.addItemsBySpriteManager(self.wallManager)
        self.grid.addItemsBySpriteManager(self.crateManager)
Exemple #29
0
 def setUp(self):
     carX = self.carConfig.x
     carY = self.carConfig.y
     carAngle = self.carConfig.angle
     self.car = Car((carX, carY), carAngle)
     walls = []
     for entity in self.entities:
         if entity.type_ == 'Wall':
             posX = entity.x
             posY = entity.y
             relX = entity.relX
             relY = entity.relY
             walls.append(Wall((posX, posY), (posX + relX, posY + relY)))
         if entity.type_ == 'Point':
             pointX = entity.x
             pointY = entity.y
     self.point = (pointX, pointY)
     self.walls = walls
    def __init__(self):
        ne_portal1 = Portal(None, 0, 5, np.array([50, 50]),
                            makeRotationMat(np.radians(45)), 45,
                            np.array([135, 100]), 0)
        opening_portal1 = Portal(None, 1, 5)

        # make first sector
        vec1 = np.array([50, 50])
        vec2 = np.array([25, 75])
        vec3 = np.array([100, 100])

        wall1 = Wall(vec1, vec2, 0, 6, ne_portal1, False, (150, 0, 0))
        wall2 = Wall(vec2, vec3, 0, 6, None, False, (150, 0, 150))
        wall3 = Wall(vec3, vec1, 0, 6, opening_portal1, True, (150, 0, 150))
        sector1 = Sector(1, True, 5, [wall3, wall2, wall1], (100, 0, 100),
                         (100, 100, 0))

        # make second sector
        vec1 = np.array([50, 50])
        vec2 = np.array([100, 100])
        vec3 = np.array([135, 100])
        vec4 = np.array([200, 50])
        vec5 = np.array([75, 25])

        opening_portal2 = Portal(sector1, 1, 5)
        ne_portal2 = Portal(sector1, 1, 4, np.array([135, 100]),
                            makeRotationMat(np.radians(-45)), -45,
                            np.array([50, 50]), 1)

        wall1 = Wall(vec1, vec2, 0, 5, opening_portal2, False, (150, 0, 0))
        wall2 = Wall(vec2, vec3, 0, 5, ne_portal2, True, (150, 0, 150))
        wall3 = Wall(vec3, vec4, 0, 5, None, True, (150, 150, 0))
        wall4 = Wall(vec4, vec5, 0, 5, None, True, (150, 150, 150))
        wall5 = Wall(vec5, vec1, 0, 5, None, False, (150, 150, 150))
        sector2 = Sector(0, True, 5, [wall2, wall1, wall3, wall4, wall5],
                         (100, 100, 100), (100, 0, 100))

        ne_portal1.sector = sector2
        opening_portal1.sector = sector2

        self.sectors = [sector1,
                        sector2]  # an environment is a list of sectors
Exemple #31
0
def genlevel(gameWindow, walls, solid, pips):
    """
    generates a new level
    """
    #do we want to make this a pure function - batrex

    #create the walls
    for x in range(1, gameWindow.TILEWIDTH + 1):
        for y in range(1, gameWindow.TILEHEIGHT + 1):
            if random.randint(0, 10) == 0:
                walls.append(Wall(gameWindow,x,y))

    #define and fill solids
    for wall in walls:
        solid.append((wall.x, wall.y))

    #create the Pips
    for x in range(1, gameWindow.TILEWIDTH + 1):
        for y in range(1, gameWindow.TILEHEIGHT + 1):
                if (x, y) not in solid:
                    pips.append(Pip(gameWindow,x,y))
Exemple #32
0
cookie  = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
session = cookie.get("session")

if session is not None:
    session = session.value
user = User.find_cookie(session)

form   = cgi.FieldStorage()
action = form.getfirst("action", "")

if action == "publish":
    text = form.getfirst("text", "")
    text = html.escape(text)
    if text and user is not None:
        Wall.publish(user,text)
elif action == "register":
    login    = form.getfirst("login", "")
    login    = html.escape(login)
    password = form.getfirst("password", "")
    password = html.escape(password)
    if User.find(login, password):
        cookie = User.set_cookie(login)
        print('Set-cookie: session={}'.format(cookie))
    elif  User.find(login):
        print ('¬ведите пароль')
    else:
        User.register(login,password)
        cookie = User.set_cookie(login)
        print('Set-cookie: session={}'.format(cookie))
Exemple #33
0
        pygame.draw.circle (window, Colour.BLUE, b.rect.center, b.rect.width / 2)
        
    scores_surfaces = [players [0].getScoreSurface (), players [1].getScoreSurface ()]
    scores_rects = [scores_surfaces [0].get_rect (), scores_surfaces [1].get_rect ()]
    scores_rects [0].topright = (WINDOWSIZE [0] / 2 - 50, Wall.SIZE)
    scores_rects [1].topleft = scores_rects [1].topleft = (WINDOWSIZE [0] / 2 + 50, Wall.SIZE)
    for i in range (2):
        window.blit (scores_surfaces [i], scores_rects [i])
    pygame.display.update ()




# Create game objects
clock = pygame.time.Clock ()
walls = Wall.createList ()
players = [Player (25, Player.SIZE, 2, 270), Player (775, Player.SIZE, 2, 90)]
balls = [Ball (Ball.SIZE, Ball.SPEED, [])]

if Sound.isOn:
    pygame.mixer.music.set_volume (0.6)
    pygame.mixer.music.play ()

keepGoing = True
while keepGoing:
    for event in pygame.event.get ():
        if event.type == QUIT:
            keepGoing = False

        # Set  players' directions
        elif event.type == KEYDOWN: