예제 #1
0
# }}}

# initialize walls {{{
for i in range(maze.num_rows):
    for j in range(maze.num_columns):

        # top left corner coordinate
        x1 = j * CELL_WIDTH
        y1 = i * CELL_WIDTH

        # bottom right corner coordinate
        x2 = (j + 1) * CELL_WIDTH
        y2 = (i + 1) * CELL_WIDTH

        if maze.grid[i][j].neighbors["N"] == INF:
            STATE["walls"].append(Wall(screen, (x1, y1), (x2, y1)))
        if maze.grid[i][j].neighbors["S"] == INF:
            STATE["walls"].append(Wall(screen, (x1, y2), (x2, y2)))
        if maze.grid[i][j].neighbors["W"] == INF:
            STATE["walls"].append(Wall(screen, (x1, y1), (x1, y2)))
        if maze.grid[i][j].neighbors["E"] == INF:
            STATE["walls"].append(Wall(screen, (x2, y1), (x2, y2)))
# }}}

# initialize player {{{
player_position = coordinates((0, 0), CELL_WIDTH)
player_width = CELL_WIDTH // 1.25
player_color = COLORS["red"]
player_speed = 0.1

STATE["player"] = Agent(screen,
예제 #2
0
def main():
    global run
    global result
    fps = 60
    clock = pygame.time.Clock()
    num_walls = 9
    num_enemies = 6
    num_points = 0

    # make player
    player = Player(300, 300, 64, 64)

    #make list of walls, enemies, bullets
    walls = []
    bullets = []
    enemies = []

    #set locations for walls
    wall_placement = [[150, 100], [150, 300], [150, 500],
                      [440, 100], [440, 300], [440, 500],
                      [700, 100], [700, 300], [700, 500]]

    #set locations for enemies
    enemy_placement = [[90, 100], [500, 100], [800, 100],
                       [100, 500], [400, 500], [700, 500]]

    #create walls
    for i in range(num_walls):
        wall = Wall(wall_placement[i][0], wall_placement[i][1], 64, 64)
        walls.append(wall)

    #create enemies
    for i in range(num_enemies):
        enemy = Enemy(enemy_placement[i][0], enemy_placement[i][1])
        enemies.append(enemy)

    #utilized for enemy movement throughout the game
    choices = ["up", "down", "left", "right"]
    length = 80    # time before enemy changes direction
    choice_timer = length  # timer to keep track of lenght passed
    while run:
        clock.tick(fps)

        # draw everything on screen
        renderGame(player, walls, bullets, enemies, num_points)

        if len(enemies) == 0:
            result = "You killed all the virus!"
            break

        #implements enemy artificial movement
        if choice_timer <= 0:
            choice_timer = length
        threshold = length - len(enemies)
        for enemy in enemies:
            #begins countdown till the enemy changes movement direction
            if choice_timer < threshold:
                choice_timer -= 1
            else:
                #decides a random direction for the enemy to move
                enemy.direction = random.choice(choices)
                choice_timer -= 1
            enemy.AI()

            #check wall collision
            enemy.objCollision(walls)

            #check enemy collision with another enemy
            enemy.objCollision(enemies, enemies.index(enemy))

            if enemy.playerCollision(player):
                #player collied with an enemy and lost
                run = False
                result = "You lost. Total points: " + str(num_points)

        # handel bullet movement through screen
        if player.shoot_counter < 5:
            for bullet in bullets:
                if not bullet.offScreen(WIDTH):
                    bullet.move()
                    # check for collision with wall
                    if bullet.Collision(walls) > 0:
                        bullets.pop(bullets.index(bullet))
                    # check collision with enemy
                    ret_val = bullet.Collision(enemies)
                    if ret_val == 1:
                        bullets.pop(bullets.index(bullet))
                        num_points += 1
                    elif ret_val == 2:
                        bullets.pop(bullets.index(bullet))
                else:
                    bullets.pop(bullets.index(bullet))
            player.shoot_counter += 1
        else:
            player.shoot_counter = 0

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit(0)

        keys = pygame.key.get_pressed()
        # handle player movement and check for collisions with walls
        if keys[pygame.K_a] and player.x - player.vel > 0:  # move left
            player.direction = -1
            player.x -= player.vel
            player.checkCollision(walls, "left")
        if keys[pygame.K_d] and (player.x + player.vel + 64) < WIDTH:  # move right
            player.direction = 1
            player.x += player.vel
            player.checkCollision(walls, "right")
        if keys[pygame.K_w] and player.y - player.vel > 50:  # move up (50 to account for the point counter rect
            player.y -= player.vel
            player.checkCollision(walls, "up")
        if keys[pygame.K_s] and ((player.y + player.vel + 64) < HEIGHT):  # move down
            player.y += player.vel
            player.checkCollision(walls, "down")

        # handle player shooting
        if keys[pygame.K_SPACE] and player.shoot_counter == 0:
            if player.direction == -1:
                bullets.append(Projectile(player.x - 32, player.y, player.direction))
            else:
                bullets.append(Projectile(player.x + 64, player.y, player.direction))
예제 #3
0
import pygame, sys, random
from Ball import Ball
from Player import Player
from Bullet import Bullet
from Wall import Wall
from Zombie import Zombie
from Button import Button
#from HUD import Text
#from HUD import Score


pygame.init()

clock = pygame.time.Clock()
walls = [Wall([0,200],[100,300]),
        Wall([100,200],[200,300]),
        Wall([200,200],[300,300]),
        Wall([300,200],[400,300]),
        Wall([400,200],[500,300]),
        Wall([500,200],[600,300]),
        Wall([600,200],[700,300]),
        Wall([700,200],[800,300])]

width = 800 
height = 600
size = width, height
bg = pygame.image.load("Resources/Object/Background/Sure.png")

startScreen = pygame.image.load("Resources/Object/Start Menu/Day Zeyro.png")
startScreenRect = startScreen.get_rect()
예제 #4
0
#Cria um grupo só dos meteoros
mobs = pygame.sprite.Group()

# Posição das paredes no mapa
bombPlayer1 = pygame.sprite.Group()
bombPlayer2 = pygame.sprite.Group()
bombs = pygame.sprite.Group()
walls = pygame.sprite.Group()

x = (WIDTH - (4 * WALL_WIDTH)) / 5
y = (HEIGHT - (4 * WALL_HEIGHT)) / 5

for i in range(1, 5):
    for j in range(1, 5):
        m = Wall(x * j + WALL_WIDTH * (j - 1), y * i + WALL_HEIGHT * (i - 1))
        all_sprites.add(m)
        walls.add(m)

# Cria 8 meteoros e adiciona no grupo meteoros
for i in range(1):
    m = Mob('fire', fire_anim)
    all_sprites.add(m)
    mobs.add(m)

# Comando para evitar travamentos.
try:

    # Loop principal.
    #pygame.mixer.music.play(loops=-1)
    running = True
예제 #5
0
pygame.init()

clock = pygame.time.Clock()

width = 978
height = 645
size = width, height

bgColor = r, g, b = 0, 0, 0

screen = pygame.display.set_mode(size)
bgImage = pygame.image.load("dungeon are lvl 1.PNG")
bgRect = bgImage.get_rect()

walls = [
    Wall([0, 0], [338, 68]),
    Wall([48, 133], [145, 164]),
    Wall([0, 68], [48, 230]),
    Wall([0, 230], [15, 260]),
    Wall([0, 260], [48, 611]),
    Wall([242, 326], [302, 386]),
    Wall([45, 355], [205, 386]),
    Wall([0, 613], [979, 645]),
    Wall([947, 0], [957, 543]),
    Wall([273, 132], [366, 163]),
    Wall([337, 163], [364, 290]),
    Wall([782, 228], [910, 257]),
    Wall([434, 36], [465, 98]),
    Wall([337, 0], [972, 32]),
    Wall([462, 70], [497, 230]),
    Wall([177, 388], [206, 514]),
예제 #6
0
 def segment(self):
     self._segments = LS2D.LS2D(self._wall_measurements)
     self._relative_walls = []
     for s in self._segments:
         self._relative_walls.append(Wall(*odr_line(s)))
     self.pred_rotation()
예제 #7
0
 def add_wall(self, x0, y0, x1, y1):
     """Adds a wall to the Simulation."""
     wall = Wall(x0, y0, x1, y1)
     wall.id = self.amount_walls
     self.walls.append(wall)
     self.amount_walls += 1
예제 #8
0
def create_wall(x, y, n):
    wall_list = []
    for i in range(1, n):
        wall = Wall("img/wall/walls.gif", x , y+60*i, 1)
        wall_list.append(wall)
    return wall_list
예제 #9
0
papayaImg = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Papaya_image.jpg')
explosionSheet = simplegui.load_image('http://www.cs.rhul.ac.uk/courses/CS1830/sprites/explosion-spritesheet.png')

# x values should be updated and not y values by any +ve values
treeImg = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/Test_image.jpg')
car_crash = simplegui.load_image('http://personal.rhul.ac.uk/zeac/084/carcrash.png')



explosionSprite = Sprite(explosionSheet, 9, 9)

userCar = UserCar(userCarImg, Vector((0, DISPLAYH/2)), 5, 5)
tree1 = Tree(treeImg, 0+treeImg.get_height()/2, DISPLAYW)
tree2 = Tree(treeImg, DISPLAYH-treeImg.get_height()/2, DISPLAYW)
w1 = Wall((0, 75), (DISPLAYW, 75), 12, 'Green', Vector((0, 1)))
w2 = Wall((0, 600), (DISPLAYW, 600), 12, 'Green', Vector((0, -1)))

kbd = Keyboard()

#interaction = Interaction(userCar, kbd)



def click(pos):
    for x in range(0, len(arrayButton)):
        if arrayButton[x].contains(pos):
            print("button")
            arrayButton[x].clickBtn()

def draw(canvas):
예제 #10
0
파일: Main.py 프로젝트: zeac121/PapayaRHUL
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
from Vector import Vector
from Weapon import Weapon
from WeaponCollision import WeaponCollision
from Wall import Wall
import random

CANVAS_WIDTH = 1600
CANVAS_HEIGHT = 900

rockets = []

C = WeaponCollision()
w2 = Wall(500, 5, 'red')
w4 = Wall(1200, 5, 'red')

C.addWall(w2)
C.addWall(w4)


def spawn(key):
    global CANVAS_WIDTH, CANVAS_HEIGHT
    if key == simplegui.KEY_MAP['space']:
        missile = Weapon(
            Vector((CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2)),
            Vector((random.randint(-5, 5), random.randint(-5, 5))),
            'https://i.imgur.com/RVi7F76.png', 4, 4)
        C.addWeapon(missile)


def up(key):
예제 #11
0
파일: main.py 프로젝트: atxbilly/poggers
from Wall import Wall
import random

# set gameover to False
gameover = False

# create initial Arena
arena1 = Arena(15)

# populate the Arena's tile dictionary with Tile objects
for i in range(arena1.numtiles):
    arena1.tiles[i] = Tile(i)

# populate the Arena's wall dictionary with Wall objects
for w in range(arena1.numwalls):
    arena1.walls[w] = Wall(w)

# populate the Arena's stack dictionary with Stack objects
for k in range(arena1.numstacks):
    randsize = random.randint(10, 20)
    arena1.stacks[k] = Stack(k, randsize)

# get list of unique tile positions for stacks
alltiles = [x for x in arena1.tiles]
alltiles.remove(112)
stackpositions = random.sample(alltiles, arena1.numstacks)

# remove stack positions from alltiles
for stacktile in stackpositions:
    alltiles.remove(stacktile)
예제 #12
0
    def __init__(self):
        v1 = np.array([0, 0])
        v2 = np.array([40, 0])
        v3 = np.array([100, 0])
        v4 = np.array([20, 10])
        v5 = np.array([40, 10])
        v6 = np.array([40, 40])
        v7 = np.array([60, 40])
        v8 = np.array([80, 40])
        v9 = np.array([100, 40])
        v10 = np.array([40, 60])
        v11 = np.array([60, 60])
        v12 = np.array([80, 60])
        v13 = np.array([100, 60])
        v14 = np.array([0, 90])
        v15 = np.array([20, 90])
        v16 = np.array([40, 90])
        v17 = np.array([100, 90])
        v18 = np.array([0, 100])
        v19 = np.array([100, 100])
        v20 = np.array([140, 0])
        v21 = np.array([160, 0])
        v22 = np.array([140, 80])
        v23 = np.array([160, 80])
        v24 = np.array([150, 10])
        v25 = np.array([170, 20])
        v26 = np.array([150, 70])
        v27 = np.array([170, 60])
        v28 = np.array([0, 10])
        v29 = np.array([20, 100])
        v30 = np.array([40, 100])
        v31 = np.array([100, 10])
        v32 = np.array([145, 10])
        v33 = np.array([190, 10])
        v34 = np.array([145, 70])
        v35 = np.array([190, 70])
        v36 = np.array([50, 10])
        v37 = np.array([50, 90])
        v38 = np.array([20, 0])
        v39 = np.array([50, 0])
        v40 = np.array([50, 100])
        v41 = np.array([20, 50])
        v42 = np.array([40, 50])
        v43 = np.array([150, 20])
        v44 = np.array([150, 60])
        v45 = np.array([40, 20])

        p = Portal(None, 0, 5)

        # sector 1
        w1_1 = Wall(v39, v36, 0, 5, p, False, (120, 120, 120))
        w1_3 = Wall(v36, v37, 0, 5, None, False, (120, 120, 120))
        w1_4 = Wall(v37, v40, 0, 5, p, False, (120, 120, 120))
        w1_5 = Wall(v40, v19, 0, 5, None, True, (0, 150, 0))
        w1_6 = Wall(v19, v3, 0, 5, None, True, (120, 120, 120))
        w1_7 = Wall(v3, v39, 0, 5, None, False, (150, 0, 0))
        s1 = Sector(0, False, 5, [w1_1, w1_3, w1_4, w1_5, w1_6, w1_7],
                    (0, 0, 0), (0, 0, 0), "1")

        # sector 3
        w3_1 = Wall(v38, v4, 0, 5, None, False, (120, 120, 120))
        p3_2 = Portal(None,
                      0,
                      5,
                      center_of_rotation=v4,
                      rotation_mat=np.eye(2),
                      heading_change=0,
                      new_point=v24,
                      new_y=0)
        w3_2 = Wall(v4, v5, 0, 5, p3_2, True, (120, 120, 120))
        w3_3 = Wall(v5, v36, 0, 5, None, True, (120, 120, 120))
        w3_4 = Wall(v36, v39, 0, 5, p, True, (120, 120, 120))
        w3_5 = Wall(v39, v38, 0, 5, None, False, (150, 0, 0))
        #w3_6 = Wall(v6, v45, 0, 5, None, True, (120, 120, 120))
        s3 = Sector(0, False, 5, [w3_1, w3_2, w3_3, w3_4, w3_5], (0, 0, 0),
                    (0, 0, 0), "3")

        # sector 4
        w4_1 = Wall(v15, v29, 0, 5, None, False, (120, 120, 120))
        w4_2 = Wall(v29, v40, 0, 5, None, True, (0, 150, 0))
        w4_3 = Wall(v40, v37, 0, 5, p, True, (120, 120, 120))
        w4_4 = Wall(v37, v16, 0, 5, None, False, (120, 120, 120))
        p4_4 = Portal(None,
                      0,
                      5,
                      center_of_rotation=v15,
                      rotation_mat=np.eye(2),
                      heading_change=0,
                      new_point=v26,
                      new_y=0)
        w4_5 = Wall(v16, v15, 0, 5, p4_4, False, (120, 120, 120))
        s4 = Sector(0, False, 5, [w4_1, w4_2, w4_3, w4_4, w4_5], (0, 0, 0),
                    (0, 0, 0), "4")

        # sector 6

        w6_1 = Wall(v38, v29, 0, 5, None, False, (120, 120, 120))
        w6_2 = Wall(v15, v16, 0, 5, p, True, (120, 120, 120))
        w6_3 = Wall(v16, v5, 0, 5, p, True, (120, 120, 120))
        w6_4 = Wall(v5, v4, 0, 5, p, False, (120, 120, 120))
        s6 = Sector(0, False, 5, [w6_1, w6_2, w6_3, w6_4], (0, 0, 0),
                    (0, 0, 0), "6")

        # sector 10
        w10_1 = Wall(v24, v26, 0, 5, None, False, (120, 120, 120))
        p10_2 = Portal(None,
                       0,
                       5,
                       center_of_rotation=v44,
                       rotation_mat=np.eye(2),
                       heading_change=0,
                       new_point=v15,
                       new_y=0)
        w10_2 = Wall(v44, v27, 0, 5, p10_2, True, (120, 120, 120))
        w10_3 = Wall(v27, v25, 0, 5, None, True, (120, 120, 120))
        p10_4 = Portal(None,
                       0,
                       5,
                       center_of_rotation=v43,
                       rotation_mat=np.eye(2),
                       heading_change=0,
                       new_point=v4,
                       new_y=0)
        w10_4 = Wall(v25, v43, 0, 5, p10_4, False, (120, 120, 120))
        w10_5 = Wall(v33, v32, 0, 5, None, False, (150, 0, 0))
        w10_6 = Wall(v34, v35, 0, 5, None, True, (0, 150, 0))

        s10 = Sector(0, False, 5, [w10_5, w10_6, w10_1, w10_2, w10_3, w10_4],
                     (0, 0, 0), (0, 0, 0), "10")

        # set portal sectors
        p3_2.sector = s10
        p4_4.sector = s10
        p10_2.sector = s4
        p10_4.sector = s1

        self.sectors = [s1, s3, s4, s6, s10]
예제 #13
0
def createWall(screen, walls, x, y, width, height, color):
    wall = Wall(screen, x, y, width, height, color);
    walls.add(wall);
예제 #14
0
def game():
    '''
    Initilizing all the game sprites
        -player: pacman
        -ghosts: a list of ghost (one red, one pink)
        -walls: a list of walls that make up the maze
    '''
    player = Player(screen, 575, 563.5)
    ghosts = [
        Ghost(screen, 23, 123, red_D, red_L, red_R, red_U),
        Ghost(screen, 1124, 123, pink_D, pink_L, pink_R, pink_U)
    ]
    walls = [
        Wall(screen, 0, 100, 1200, 20),
        Wall(screen, 0, 780, 1200, 20),
        Wall(screen, -10, 100, 30, 265),
        Wall(screen, -10, 435, 30, 365),
        Wall(screen, 1180, 100, 30, 265),
        Wall(screen, 1180, 435, 30, 365),
        Wall(screen, 80, 180, 310, 540),
        Wall(screen, 810, 180, 310, 540),
        Wall(screen, 452, 180, 288, 200),
        Wall(screen, 452, 440, 288, 120),
        Wall(screen, 452, 620, 288, 100)
    ]

    dots = [Dot(screen, False, x, 150) for x in range(100, 1101, 50)]
    dots.extend([Dot(screen, False, x, 750) for x in range(100, 1101, 50)])
    dots.extend([Dot(screen, False, 50, y) for y in range(200, 701, 50)])
    dots.extend([Dot(screen, False, 1150, y) for y in range(200, 701, 50)])
    dots.extend([Dot(screen, False, 420, y) for y in range(200, 701, 50)])
    dots.extend([Dot(screen, False, 770, y) for y in range(200, 701, 50)])
    dots.extend([
        Dot(screen, True, 50, 150),
        Dot(screen, True, 1150, 150),
        Dot(screen, True, 50, 750),
        Dot(screen, True, 1150, 750),
    ])

    latest_keys = None
    while True:
        '''
        Check if the user wants to quit (press the red x button that closes the game window)
        '''
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        '''
        Getting the key stokes from the user:
            -pressed variable: a list of booleans that indiciate which keys were pressed
            -latest_keys: stores the value of pressed that last time the user actually pressed a key
            -pressing the keys will only change the player's orientation
        '''
        pressed = pygame.key.get_pressed()
        no_keys_pressed = True
        for key in pressed:
            if key:
                no_keys_pressed = False
        if not no_keys_pressed or latest_keys == None:
            latest_keys = pressed

        if latest_keys[pygame.K_UP]:
            if not check_wall_collisions('U', walls, player):
                player.orientation = 'U'
        elif latest_keys[pygame.K_DOWN]:
            if not check_wall_collisions('D', walls, player):
                player.orientation = 'D'
        elif latest_keys[pygame.K_LEFT]:
            if not check_wall_collisions('L', walls, player):
                player.orientation = 'L'
        elif latest_keys[pygame.K_RIGHT]:
            if not check_wall_collisions('R', walls, player):
                player.orientation = 'R'
        '''
        Controlling player movements:
            -The player moves based on the direction its facing (orientation) and wall collisions
            -If the player collides with a wall and faces that direction (as shown in check_wall_collisions()), 
             the player can't move.
            -Also, the player can teleport to the other side of the screen if it moves off the left or right 
             edges of the screen.
        '''
        if player.orientation == 'U' and not check_wall_collisions(
                'U', walls, player):
            player.y -= player.speed
            player.rect.y -= player.speed
        elif player.orientation == 'D' and not check_wall_collisions(
                'D', walls, player):
            player.y += player.speed
            player.rect.y += player.speed
        elif player.orientation == 'L' and not check_wall_collisions(
                'L', walls, player):
            player.x -= player.speed
            player.rect.x -= player.speed
            if player.x + player.width <= 0:
                player.x = screen_w
                player.rect.x = screen_w - 3
        elif player.orientation == 'R' and not check_wall_collisions(
                'R', walls, player):
            player.x += player.speed
            player.rect.x += player.speed
            if player.x >= screen_w:
                player.x = 0 - player.width
                player.rect.x = 0 - player.width - 3
        '''
        Controlling ghost movements:
            -For each ghost in ghosts, there are two options for moving:
                *The ghost actively decides to change direction whenever it approaches the end of a wall
                *The ghost only changes direction when it hits a wall
                (A chance variable and an if-statement determines which way a ghost move at a particular moment)
            -In the for loop, only one method of changing direction is needed. However, the mixture of two methods makes
             the ghost movements more interest and fun.
        '''
        for ghost in ghosts:
            chance = random.randint(0, 1)
            if chance == 0:
                '''
                First method of changing direction
                    -The ghost actively tries to change direction whenever possible
                '''
                orientation = change_ghost_direction(walls, ghost)
                if orientation != None and at_ends(ghost.orientation, walls,
                                                   ghost):
                    ghost.orientation = orientation
                if ghost.orientation == 'R':
                    ghost.x += ghost.speed
                    ghost.rect.x += ghost.speed
                    if ghost.x >= screen_w:
                        ghost.x = 0 - ghost.width
                        ghost.rect.x = 0 - ghost.width - 3
                elif ghost.orientation == 'L':
                    ghost.x -= ghost.speed
                    ghost.rect.x -= ghost.speed
                    if ghost.x + ghost.width <= 0:
                        ghost.x = screen_w
                        ghost.rect.x = screen_w - 3
                elif ghost.orientation == 'U':
                    ghost.y -= ghost.speed
                    ghost.rect.y -= ghost.speed
                elif ghost.orientation == 'D':
                    ghost.y += ghost.speed
                    ghost.rect.y += ghost.speed
            else:
                '''
                First method of changing direction
                    -The ghost only changes direction when it collides against a wall
                '''
                if check_wall_collisions(ghost.orientation, walls, ghost):
                    ghost.orientation = change_ghost_direction(walls, ghost)
                else:
                    if ghost.orientation == 'R':
                        ghost.x += ghost.speed
                        ghost.rect.x += ghost.speed
                        if ghost.x >= screen_w:
                            ghost.x = 0 - ghost.width
                            ghost.rect.x = 0 - ghost.width - 3
                    elif ghost.orientation == 'L':
                        ghost.x -= ghost.speed
                        ghost.rect.x -= ghost.speed
                        if ghost.x + ghost.width <= 0:
                            ghost.x = screen_w
                            ghost.rect.x = screen_w - 3
                    elif ghost.orientation == 'U':
                        ghost.y -= ghost.speed
                        ghost.rect.y -= ghost.speed
                    elif ghost.orientation == 'D':
                        ghost.y += ghost.speed
                        ghost.rect.y += ghost.speed
        '''
        Pacman interaction with dots and ghosts (including switching to game over and game completion screens)
        '''

        for dot in dots.copy():
            if pygame.sprite.collide_rect(player, dot):
                if dot.is_ghost_killer:
                    for ghost in ghosts:
                        ghost.make_edible()
                dots.remove(dot)

        for ghost in ghosts:
            if pygame.sprite.collide_rect(player, ghost):
                if ghost.edible:
                    ghost.reset()
                else:
                    game_over_screen()

        if len(dots) == 0:
            game_complete_screen()
        '''
        Drawing and updating everything
        '''
        screen.fill((0, 0, 0))
        for wall in walls:
            wall.draw()
        for dot in dots:
            dot.draw()
        player.draw()
        for ghost in ghosts:
            ghost.draw()
        pygame.display.update()
        clock.tick(100)
예제 #15
0
    def __init__(self, maze_type, poi_prox_manager, unit_prox_manager,
                 convex_corner_prox_manager, concave_corner_prox_manager,
                 crit_corner_prox_manager):

        # if maze_type == 'training':
        #
        #     self.maze_units = []
        #     self.maze_walls = []
        #     self.maze_convex_corners = []
        #     self.maze_concave_corners = []
        #     self.maze_crit_corners = []
        #     self.crit_positions = []

        if maze_type == 'I' or maze_type == 'training':

            # small version
            # # introduce maze units (for unit events) and maze walls (for collisions)
            # self.maze_units = [[0, 0, -2], [0, 0, -1], [0, 0, 0], [0, 0, 1], [0, 0, 2]]
            # self.maze_walls = [[3, 4, 1, 'z', [0, 2, 3]],
            #                    [3, 4, 1, 'z', [0, 2, -3]],
            #                    [7, 4, 1, 'x', [1, 2, 0]],
            #                    [7, 4, 1, 'x', [-1, 2, 0]]]
            #
            # # position of 1x1 m prox sensors
            # self.maze_convex_corners = [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [1, 0, -3]]

            # introduce maze units (for unit events) and maze walls (for collisions)
            # start_pos = [0, 1.5, -2]

            # self.maze_units = [[0, 0, -2], [0, 0, -1], [0, 0, 0], [0, 0, 1], [0, 0, 2]]

            self.maze_units = [[0, 0, -4.5], [0, 0, -3.5], [0, 0, -2.5],
                               [0, 0, -1.5], [0, 0, -0.5], [0, 0, 4.5],
                               [0, 0, 3.5], [0, 0, 2.5], [0, 0, 1.5],
                               [0, 0, 0.5]]

            # original larger layout
            #            self.maze_walls = [[3, 4, 1, 'z', '+', [0, 2, 5.5]],
            #                               [3, 4, 1, 'z', '-', [0, 2, -5.5]],
            #                               [12, 4, 1, 'x', '+', [1, 2, 0]],
            #                               [12, 4, 1, 'x', '-', [-1, 2, 0]]]
            #
            #            self.head_walls = [[3, 4, 1, 'z', '+', [0, 2, 5.8]],
            #                               [3, 4, 1, 'z', '-', [0, 2, -5.8]],
            #                               [12, 4, 1, 'x', '+', [1.3, 2, 0]],
            #                               [12, 4, 1, 'x', '-', [-1.3, 2, 0]]]

            # fat walls
            self.maze_walls = [[5, 4, 3, 'z', '+', [0, 2, 6.5]],
                               [5, 4, 3, 'z', '-', [0, 2, -6.5]],
                               [15, 4, 3, 'x', '+', [2, 2, 0]],
                               [15, 4, 3, 'x', '-', [-2, 2, 0]]]

            self.head_walls = [[5, 4, 3, 'z', '+', [0, 2, 6.8]],
                               [5, 4, 3, 'z', '-', [0, 2, -6.8]],
                               [15, 4, 3, 'x', '+', [2.3, 2, 0]],
                               [15, 4, 3, 'x', '-', [-2.3, 2, 0]]]

            # position of 1x1 m prox sensors
            self.maze_convex_corners = [[-1, 0, -5.5], [-1, 0, 5.5],
                                        [1, 0, 5.5], [1, 0, -5.5]]
            self.maze_concave_corners = []
            self.concave_corner_size = 0

            self.maze_crit_corners = []
            start_pos = [0, 1.5, -4.5]

            self.start_sphere = vizshape.addSphere(0.2)
            self.start_sphere.setPosition(start_pos)
            self.start_sphere.visible(viz.OFF)
            self.maze_start_position = MazeUnit(
                'start_pos_maze:I',
                edge_length=0.9,
                position=start_pos,
                crit_pos=None,
                proximity_manager=poi_prox_manager)
            self.path_length = len(self.maze_units)

        elif maze_type == 'L':

            # small version
            # # introduce maze units (for unit events) and maze walls (for collisions)
            # self.maze_units = [[0, 0, 2], [0, 0, 1], [0, 0, 0], [0, 0, -1], [0, 0, -2], [1, 0, -2], [2, 0, -2]]
            # self.maze_walls = [[3, 4, 1, 'z', [0, 2, 3]],
            #                    [5, 4, 1, 'x', [0.98, 2, 1]],
            #                    [7, 4, 1, 'x', [-1, 2, 0]],
            #                    [3, 4, 1, 'z', [2, 2, -1.02]],
            #                    [3, 4, 1, 'x', [3, 2, -2]],
            #                    [5, 4, 1, 'z', [1, 2, -3]]]
            #
            # # position of 1,01 x 1,01 m prox sensors
            # self.maze_convex_corners = [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [3, 0, -1], [3, 0, -3]]
            # self.maze_concave_corners = [[1, 0, -1]]
            #
            # start_pos = [0, 1.5, 2]

            # introduce maze units (for unit events) and maze walls (for collisions)
            self.maze_units = [[-2, 0, -3], [-2, 0, -2], [-2, 0, -1],
                               [-2, 0, 0], [-2, 0, 1], [-2, 0, 2], [-1, 0, 2],
                               [0, 0, 2], [1, 0, 2], [2, 0, 2]]

            # original layout
            #            self.maze_walls = [[3, 4, 1, 'z', '-', [-2, 2, -4]],
            #                               [8, 4, 1, 'x', '-', [-3, 2, -0.5]],
            #                               [7, 4, 1, 'z', '+', [0, 2, 3]],
            #                               [3, 4, 1, 'x', '+', [3, 2, 2]],
            #                               [4.95, 4, 1, 'z', '-', [1, 2, 1]],
            #                               #[6, 4, 1, 'z', '-', [1.5, 2, 1]],
            #                               [5.95, 4, 1, 'x', '+', [-1, 2, -1.5]]]
            #                               #[5, 4, 1, 'x', '+', [-1, 2, -2]]]
            #                               #[7, 4, 1, 'x', '+', [-1, 2, -2]]]
            #
            #            self.head_walls = [[3, 4, 1, 'z', '-', [-2, 2, -4.3]],
            #                               [8, 4, 1, 'x', '-', [-3.3, 2, -0.5]],
            #                               [7, 4, 1, 'z', '+', [0, 2, 3.3]],
            #                               [3, 4, 1, 'x', '+', [3.3, 2, 2]],
            #                               [4.3, 4, 1, 'z', '-', [1, 2, 0.7]],
            #                               #[6, 4, 1, 'z', '-', [1.5, 2, 1]],
            #                               [5.3, 4, 1, 'x', '+', [-0.7, 2, -1.5]]]
            #                               #[5, 4, 1, 'x', '+', [-1, 2, -2]]]
            #                               #[7, 4, 1, 'x', '+', [-1, 2, -2]]]

            # fat walls
            self.maze_walls = [
                [3, 4, 3, 'z', '-', [-2, 2, -5]],
                [8, 4, 3, 'x', '-', [-4, 2, -0.5]],
                [7, 4, 3, 'z', '+', [0, 2, 4]],
                [3, 4, 3, 'x', '+', [4, 2, 2]],
                #[4.97, 4, 3, 'z', '-', [1, 2, 0]],
                [5, 4, 3, 'z', '-', [1, 2, 0]],
                #[6, 4, 1, 'z', '-', [1.5, 2, 1]],
                #[5.97, 4, 3, 'x', '+', [0, 2, -1.5]]]
                [6, 4, 3, 'x', '+', [0, 2, -1.5]]
            ]
            #[5, 4, 1, 'x', '+', [-1, 2, -2]]]
            #[7, 4, 1, 'x', '+', [-1, 2, -2]]]

            self.head_walls = [
                [3, 4, 3, 'z', '-', [-2, 2, -5.3]],
                [8, 4, 3, 'x', '-', [-4.3, 2, -0.5]],
                [7, 4, 3, 'z', '+', [0, 2, 4.3]],
                [3, 4, 3, 'x', '+', [4.3, 2, 2]],
                [4.3, 4, 3, 'z', '-', [1, 2, -0.3]],
                #[6, 4, 1, 'z', '-', [1.5, 2, 1]],
                [5.3, 4, 3, 'x', '+', [0.3, 2, -1.5]]
            ]
            #[5, 4, 1, 'x', '+', [-1, 2, -2]]]
            #[7, 4, 1, 'x', '+', [-1, 2, -2]]]

            # position of 1,01 x 1,01 m prox sensors
            self.maze_convex_corners = [[-3, 0, -4], [-1, 0, -4], [-3, 0, 3],
                                        [3, 0, 3], [3, 0, 1]]

            # original layout
            # self.maze_concave_corners = [[-1, 0, 1]]
            #self.maze_concave_corners = [[0, 0, 0]]
            #self.concave_corner_size = 3.1

            # new concave corners with path shapes (29.05.2017)
            #self.maze_concave_corners = [[[-1.6, 1.6], [1.6, -1.6], [-1.6, -1.6]],
            #                             [[-1.6, 1.6], [1.6, -1.6], [1.6, 1.6]]]

            # updates 30.05.2017
            self.maze_concave_corners = [[[-1.6, 1.6], [-1.5, 1.5],
                                          [-1.15, 1.5], [-1.15, 1.15],
                                          [1.6, -1.6], [-1.6, -1.6]],
                                         [[-1.6, 1.6], [-1.5, 1.5],
                                          [-1.5, 1.15], [-1.15, 1.15],
                                          [1.6, -1.6], [1.6, 1.6]]]

            self.walls_to_ignore_idx = [[4], [5]]

            self.maze_crit_corners = [[-1.36, 0, 1.36]]
            self.crit_positions = [[-1.2, 0, 1.2]]

            start_pos = [-2, 1.5, -3]

            self.start_sphere = vizshape.addSphere(0.2)
            self.start_sphere.setPosition(start_pos)
            self.start_sphere.visible(viz.OFF)
            self.maze_start_position = MazeUnit(
                'start_pos_maze:L',
                edge_length=0.9,
                position=start_pos,
                crit_pos=None,
                proximity_manager=poi_prox_manager)
            self.path_length = len(self.maze_units)

        elif maze_type == 'Z':

            # small version
            # # introduce maze units (for unit events) and maze walls (for collisions)
            # self.maze_units = [[2, 0, -2], [1, 0, -2], [0, 0, -2], [0, 0, -1], [0, 0, 0], [0, 0, 1], [0, 0, 2],
            #                    [-1, 0, 2], [-2, 0, 2]]
            #
            # self.maze_walls = [[5, 4, 1, 'z', [-1, 2, 3]],
            #                    [5, 4, 1, 'x', [0.98, 2, 1]],
            #                    [3, 4, 1, 'z', [2, 2, -1.02]],
            #                    [3, 4, 1, 'x', [3, 2, -2]],
            #                    [5, 4, 1, 'z', [1, 2, -3]],
            #                    [5, 4, 1, 'x', [-0.98, 2, -1]],
            #                    [3, 4, 1, 'z', [-2, 2, 1.02]],
            #                    [3, 4, 1, 'x', [-3, 2, 2]]
            #                    ]
            #
            # # position of 1,01 x 1,01 m prox sensors
            # self.maze_convex_corners = [[-3, 0, 1], [-3, 0, 3], [1, 0, 3], [-1, 0, -3], [3, 0, -1], [3, 0, -3]]
            # self.maze_concave_corners = [[1, 0, -1], [-1, 0, 1]]
            #
            # start_pos = [2, 1.5, -2]

            self.maze_units = [[1.5, 0, -3], [1.5, 0, -2], [1.5, 0, -1],
                               [1.5, 0, 0], [0.5, 0, 0], [-0.5, 0, 0],
                               [-1.5, 0, 0], [-1.5, 0, 1], [-1.5, 0, 2],
                               [-1.5, 0, 3]]

            # original layout
            #            self.maze_walls = [[3, 4, 1, 'z', '-', [1.5, 2, -4]],
            #                               [3.95, 4, 1, 'x', '-', [0.5, 2, -2.5]],
            #                               #[4, 4, 1, 'x', '-', [0.5, 2, -2.8]],
            #                               [3.95, 4, 1, 'z', '-', [-1, 2, -1]],
            #                               #[4, 4, 1, 'z', '-', [-1.3, 2, -1]],
            #                               [6, 4, 1, 'x', '-', [-2.5, 2, 1.5]],
            #                               [3, 4, 1, 'z', '+', [-1.5, 2, 4]],
            #                               [3.95, 4, 1, 'x', '+', [-0.5, 2, 2.5]],
            #                               #[4, 4, 1, 'x', '+', [-0.5, 2, 2.8]],
            #                               [3.95, 4, 1, 'z', '+', [1, 2, 1]],
            #                               #[4, 4, 1, 'z', '+', [1.3, 2, 1]],
            #                               [6, 4, 1, 'x', '+', [2.5, 2, -1.5]]
            #                               ]
            #
            #            self.head_walls = [[3, 4, 1, 'z', '-', [1.5, 2, -4.3]],
            #                               [3.3, 4, 1, 'x', '-', [0.2, 2, -2.5]],
            #                               #[4, 4, 1, 'x', '-', [0.5, 2, -2.8]],
            #                               [3.3, 4, 1, 'z', '-', [-1, 2, -1.3]],
            #                               #[4, 4, 1, 'z', '-', [-1.3, 2, -1]],
            #                               [6, 4, 1, 'x', '-', [-2.8, 2, 1.5]],
            #                               [3, 4, 1, 'z', '+', [-1.5, 2, 4.3]],
            #                               [3.3, 4, 1, 'x', '+', [-0.2, 2, 2.5]],
            #                               #[4, 4, 1, 'x', '+', [-0.5, 2, 2.8]],
            #                               [3.3, 4, 1, 'z', '+', [1, 2, 1.3]],
            #                               #[4, 4, 1, 'z', '+', [1.3, 2, 1]],
            #                               [6, 4, 1, 'x', '+', [2.8, 2, -1.5]]
            #                               ]

            self.maze_walls = [
                [3, 4, 3, 'z', '-', [1.5, 2, -5]],
                #[3.97, 4, 2, 'x', '-', [0, 2, -2.5]],
                [4, 4, 2, 'x', '-', [0, 2, -2.5]],
                #[4, 4, 1, 'x', '-', [0.5, 2, -2.8]],
                #[3.97, 4, 2, 'z', '-', [-1, 2, -1.5]],
                [4, 4, 2, 'z', '-', [-1, 2, -1.5]],
                #[4, 4, 1, 'z', '-', [-1.3, 2, -1]],
                [6, 4, 3, 'x', '-', [-3.5, 2, 1.5]],
                [3, 4, 3, 'z', '+', [-1.5, 2, 5]],
                #[3.97, 4, 2, 'x', '+', [0, 2, 2.5]],
                [4, 4, 2, 'x', '+', [0, 2, 2.5]],
                #[4, 4, 1, 'x', '+', [-0.5, 2, 2.8]],
                #[3.97, 4, 2, 'z', '+', [1, 2, 1.5]],
                [4, 4, 2, 'z', '+', [1, 2, 1.5]],
                #[4, 4, 1, 'z', '+', [1.3, 2, 1]],
                [6, 4, 3, 'x', '+', [3.5, 2, -1.5]]
            ]

            self.head_walls = [
                [3, 4, 3, 'z', '-', [1.5, 2, -5.3]],
                [3.3, 4, 3, 'x', '-', [-0.8, 2, -2.5]],
                #[4, 4, 1, 'x', '-', [0.5, 2, -2.8]],
                [3.3, 4, 3, 'z', '-', [-1, 2, -2.3]],
                #[4, 4, 1, 'z', '-', [-1.3, 2, -1]],
                [6, 4, 3, 'x', '-', [-3.8, 2, 1.5]],
                [3, 4, 3, 'z', '+', [-1.5, 2, 5.3]],
                [3.3, 4, 3, 'x', '+', [0.8, 2, 2.5]],
                #[4, 4, 1, 'x', '+', [-0.5, 2, 2.8]],
                [3.3, 4, 3, 'z', '+', [1, 2, 2.3]],
                #[4, 4, 3, 'z', '+', [1.3, 2, 1]],
                [6, 4, 3, 'x', '+', [3.8, 2, -1.5]]
            ]

            # position of 1,01 x 1,01 m prox sensors
            self.maze_convex_corners = [[0.5, 0, -4], [2.5, 0, -4],
                                        [-2.5, 0, -1], [-2.5, 0, 4],
                                        [-0.5, 0, 4], [2.5, 0, 1]]
            #self.maze_concave_corners = [[-0.5, 0, 1], [0.5, 0, -1]]
            #self.maze_concave_corners = [[0, 0, 1.5], [0, 0, -1.5]]
            #self.concave_corner_size = 2.1

            # new implementation 29.05.2017
            # updated 30.05.2017
            # self.maze_concave_corners = [[[-1.1, 0.4], [-1.1, 2.6], [1.1, 2.6]],
            #                              [[1.1, 2.6], [-1.1, 0.4], [1.1, 0.4]],
            #                              [[1.1, -0.4], [1.1, -2.6], [-1.1, -2.6]],
            #                              [[1.1, -0.4], [-1.1, -0.4], [-1.1, -2.6]]]

            self.maze_concave_corners = [[[1.1, 2.6], [-0.65, 0.85],
                                          [-0.65, 0.5], [-1, 0.5], [-1.1, 0.4],
                                          [-1.1, 2.6]],
                                         [[1.1, 2.6], [-0.65, 0.85],
                                          [-1, 0.85], [-1, 0.5], [-1.1, 0.4],
                                          [1.1, 0.4]],
                                         [[1.1, -0.4], [1, -0.5], [0.65, -0.5],
                                          [0.65, -0.85], [-1.1, -2.6],
                                          [1.1, -2.6]],
                                         [[1.1, -0.4], [1, -0.5], [1, -0.85],
                                          [0.65, -0.85], [-1.1, -2.6],
                                          [-1.1, -0.4]]]

            self.walls_to_ignore_idx = [[6], [5], [2], [1]]

            self.maze_crit_corners = [[-0.85, 0, 0.65], [0.85, 0, -0.65]]
            self.crit_positions = [[-0.7, 0, 0.8], [0.7, 0, -0.8]]

            start_pos = [1.5, 1.5, -3]
            self.start_sphere = vizshape.addSphere(0.2)
            self.start_sphere.setPosition(start_pos)
            self.start_sphere.visible(viz.OFF)
            self.maze_start_position = MazeUnit(
                'start_pos_maze:Z',
                edge_length=0.9,
                position=start_pos,
                crit_pos=None,
                proximity_manager=poi_prox_manager)
            self.path_length = len(self.maze_units)

        elif maze_type == 'U':

            # small version
            # # introduce maze units (for unit events) and maze walls (for collisions)
            # self.maze_units = [[-2, 0, 2], [-2, 0, 1], [-2, 0, 0], [-2, 0, -1], [-1, 0, -1], [0, 0, -1], [1, 0, -1],
            #                    [2, 0, -1], [2, 0, 0], [2, 0, 1], [2, 0, 2]]
            # self.maze_walls = [[6, 4, 1, 'x', [-3, 2, 0.5]],
            #                    [3, 4, 1, 'z', [-2, 2, 3]],
            #                    [4, 4, 1, 'x', [-1.02, 2, 1.5]],
            #                    [3, 4, 1, 'z', [0, 2, -0.02]],
            #                    [4, 4, 1, 'x', [1.02, 2, 1.5]],
            #                    [3, 4, 1, 'z', [2, 2, 3]],
            #                    [6, 4, 1, 'x', [3, 2, 0.5]],
            #                    [7, 4, 1, 'z', [0, 2, -2]]
            #                    ]
            #
            # # position of 1,01 x 1,01 m prox sensors
            # self.maze_convex_corners = [[-3, 0, 3], [-1, 0, 3], [-3, 0, -2], [3, 0, 3], [1, 0, 3], [3, 0, -2]]
            # self.maze_concave_corners = [[-1, 0, 0], [1, 0, 0]]
            #
            # start_pos = [-2, 1.5, 2]

            # introduce maze units (for unit events) and maze walls (for collisions)
            self.maze_units = [[-1.5, 0, -1.5], [-1.5, 0, -0.5],
                               [-1.5, 0, 0.5], [-1.5, 0, 1.5], [-0.5, 0, 1.5],
                               [0.5, 0, 1.5], [1.5, 0, 1.5], [1.5, 0, 0.5],
                               [1.5, 0, -0.5], [1.5, 0, -1.5]]

            # original layout
            #            self.maze_walls = [[3, 4, 1, 'z', '-', [1.5, 2, -2.5]],
            #                               [3.95, 4, 1, 'x', '-', [0.5, 2, -1]],
            #                               [1.95, 4, 1, 'z', '-', [0, 2, 0.5]],
            #                               [3.95, 4, 1, 'x', '+', [-0.5, 2, -1]],
            #                               #[4, 4, 1, 'x', '-', [0.5, 2, -1.3]],
            #                               #[1.4, 4, 1, 'z', '-', [0, 2, 0.5]],
            #                               #[4, 4, 1, 'x', '+', [-0.5, 2, -1.3]],
            #                               [3, 4, 1, 'z', '-', [-1.5, 2, -2.5]],
            #                               [6, 4, 1, 'x', '-', [-2.5, 2, 0]],
            #                               [6, 4, 1, 'z', '+', [0, 2, 2.5]],
            #                               [6, 4, 1, 'x', '+', [2.5, 2, 0]]
            #                               ]
            #
            #            self.head_walls = [[3, 4, 1, 'z', '-', [1.5, 2, -2.8]],
            #                               [3.95, 4, 1, 'x', '-', [0.2, 2, -1]],
            #                               [1, 4, 1, 'z', '-', [0, 2, 0.2]],
            #                               [3.95, 4, 1, 'x', '+', [-0.2, 2, -1]],
            #                               #[4, 4, 1, 'x', '-', [0.5, 2, -1.3]],
            #                               #[1.4, 4, 1, 'z', '-', [0, 2, 0.5]],
            #                               #[4, 4, 1, 'x', '+', [-0.5, 2, -1.3]],
            #                               [3, 4, 1, 'z', '-', [-1.5, 2, -2.8]],
            #                               [6, 4, 1, 'x', '-', [-2.8, 2, 0]],
            #                               [6, 4, 1, 'z', '+', [0, 2, 2.8]],
            #                               [6, 4, 1, 'x', '+', [2.8, 2, 0]]
            #                               ]

            self.maze_walls = [
                [3, 4, 3, 'z', '-', [1.5, 2, -3.5]],
                [3.97, 4, 1, 'x', '-', [0.5, 2, -1]],
                [1.97, 4, 1, 'z', '-', [0, 2, 0.5]],
                [3.97, 4, 1, 'x', '+', [-0.5, 2, -1]],
                #[4, 4, 1, 'x', '-', [0.5, 2, -1.3]],
                #[1.4, 4, 1, 'z', '-', [0, 2, 0.5]],
                #[4, 4, 1, 'x', '+', [-0.5, 2, -1.3]],
                [3, 4, 3, 'z', '-', [-1.5, 2, -3.5]],
                [6, 4, 3, 'x', '-', [-3.5, 2, 0]],
                [6, 4, 3, 'z', '+', [0, 2, 3.5]],
                [6, 4, 3, 'x', '+', [3.5, 2, 0]]
            ]

            self.head_walls = [
                [3, 4, 3, 'z', '-', [1.5, 2, -3.8]],
                [3.97, 4, 1, 'x', '-', [0.2, 2, -1]],
                [1, 4, 1, 'z', '-', [0, 2, 0.2]],
                [3.97, 4, 1, 'x', '+', [-0.2, 2, -1]],
                #[4, 4, 1, 'x', '-', [0.5, 2, -1.3]],
                #[1.4, 4, 1, 'z', '-', [0, 2, 0.5]],
                #[4, 4, 1, 'x', '+', [-0.5, 2, -1.3]],
                [3, 4, 3, 'z', '-', [-1.5, 2, -3.8]],
                [6, 4, 3, 'x', '-', [-3.8, 2, 0]],
                [6, 4, 3, 'z', '+', [0, 2, 3.8]],
                [6, 4, 3, 'x', '+', [3.8, 2, 0]]
            ]

            # position of 1,01 x 1,01 m prox sensors
            self.maze_convex_corners = [[-2.5, 0, 2.5], [2.5, 0, 2.5],
                                        [-2.5, 0, -2.5], [2.5, 0, -2.5],
                                        [0.5, 0, -2.5], [-0.5, 0, -2.5]]

            #self.maze_concave_corners = [[-0.5, 0, 0.5], [0.5, 0, 0.5]]
            #self.concave_corner_size = 1.1

            # new implementation 29.05.2017
            self.maze_concave_corners = [[[1.1, -0.1], [1.1, 1.1], [1, 1],
                                          [0.65, 1], [0.65, 0.65],
                                          [-0.1, -0.1]],
                                         [[-1.1, -0.1], [-1.1, 1.1], [-1, 1],
                                          [-0.65, 1], [-0.65, 0.65],
                                          [0.1, -0.1]],
                                         [[0, 0], [0.65, 0.65], [1, 0.65],
                                          [1, 1], [1.1, 1.1], [-1.1, 1.1],
                                          [-1, 1], [-1, 0.65], [-0.65, 0.65]]]

            # achtung mehrere walls to ignore in U shape
            self.walls_to_ignore_idx = [[2], [2], [1, 3]]

            self.maze_crit_corners = [[0.85, 0, 0.85], [-0.85, 0, 0.85]]
            self.crit_positions = [[0.7, 0, 0.7], [-0.7, 0, 0.7]]

            start_pos = [-1.5, 1.5, -1.5]

            self.start_sphere = vizshape.addSphere(0.2)
            self.start_sphere.setPosition(start_pos)
            self.start_sphere.visible(viz.OFF)
            self.maze_start_position = MazeUnit(
                'start_pos_maze:U',
                edge_length=0.9,
                position=start_pos,
                crit_pos=None,
                proximity_manager=poi_prox_manager)
            self.path_length = len(self.maze_units)

        # currently unused, keep for later changes in maze configurations
        # elif maze_type == 'T':
        #
        #     # introduce maze units (for unit events) and maze walls (for collisions)
        #     self.maze_units = [[0, 0, 2], [0, 0, 1], [0, 0, 0], [0, 0, -1], [0, 0, -2], [1, 0, -2], [2, 0, -2],
        #                        [-1, 0, -2], [-2, 0, -2]]
        #
        #     self.maze_walls = [[5, 4, 1, 'x', [-0.99, 2, 1]],
        #                        [3, 4, 1, 'z', [0, 2, 3]],
        #                        [5, 4, 1, 'x', [0.99, 2, 1]],
        #                        [3, 4, 1, 'z', [2, 2, -1.02]],
        #                        [3, 4, 1, 'x', [3, 2, -2]],
        #                        [7, 4, 1, 'z', [0, 2, -3]],
        #                        [3, 4, 1, 'x', [-3, 2, -2]],
        #                        [3, 4, 1, 'z', [-2, 2, -1.02]]
        #                        ]
        #
        #     # position of 1,01 x 1,01 m prox sensors
        #     self.maze_convex_corners = [[-1, 0, 3], [1, 0, 3], [3, 0, -1], [3, 0, -3], [-3, 0, -1], [-3, 0, -3]]
        #     self.maze_concave_corners = [[-1, 0, -1], [1, 0, -1]]
        #
        #     start_pos = [0, 1.5, 2]
        #
        #     self.start_sphere = vizshape.addSphere(0.2)
        #     self.start_sphere.setPosition(start_pos)
        #     self.start_sphere.visible(viz.OFF)
        #     self.maze_start_position = MazeUnit('start_pos_maze:T', edge_length=0.5, position=start_pos,
        #                                         proximity_manager=poi_prox_manager)
        #     self.path_length = len(self.maze_units)
        #
        # elif maze_type == '+':
        #
        #     self.maze_units = [[0, 0, -2], [0, 0, -1], [0, 0, 0], [0, 0, 1], [0, 0, 2], [-2, 0, 0], [-1, 0, 0],
        #                        [1, 0, 0], [2, 0, 0]]
        #
        #     self.maze_walls = [[3, 4, 1, 'z', [0, 2, 3]],
        #                        [3, 4, 1, 'x', [-1, 2, 2]],
        #                        [3, 4, 1, 'x', [1, 2, 2]],
        #                        [3, 4, 1, 'x', [3, 2, 0]],
        #                        [3, 4, 1, 'z', [2, 2, 1]],
        #                        [3, 4, 1, 'z', [2, 2, -1]],
        #                        [3, 4, 1, 'z', [0, 2, -3]],
        #                        [3, 4, 1, 'x', [-1, 2, -2]],
        #                        [3, 4, 1, 'x', [1, 2, -2]],
        #                        [3, 4, 1, 'x', [-3, 2, 0]],
        #                        [3, 4, 1, 'z', [-2, 2, 1]],
        #                        [3, 4, 1, 'z', [-2, 2, -1]],
        #                        ]
        #
        #     # position of 1,01 x 1,01 m prox sensors
        #     self.maze_convex_corners = [[-1, 0, -3], [-1, 0, 3], [1, 0, 3], [1, 0, -3], [-3, 0, 1], [-3, 0, -1],
        #                                 [3, 0, 1], [3, 0, -1]]
        #     self.maze_concave_corners = [[1, 0, 1], [-1, 0, 1], [-1, 0, -1], [1, 0, -1]]
        #
        #     start_pos = [0, 1.5, 2]
        #     self.start_sphere = vizshape.addSphere(0.2)
        #     self.start_sphere.setPosition(start_pos)
        #     self.start_sphere.visible(viz.OFF)
        #     self.maze_start_position = MazeUnit('start_pos_maze:U', edge_length=0.5, position=start_pos,
        #                                         proximity_manager=poi_prox_manager)
        #     self.path_length = len(self.maze_units)

        # create list for maze walls
        self.maze_walls_list = []
        # create maze walls and add to list
        for wall in self.maze_walls:
            new_wall = Wall('wall_id:' + str(wall),
                            wall_length=wall[0],
                            wall_height=wall[1],
                            wall_depth=wall[2],
                            orientation=wall[3],
                            feedback_dir=wall[4],
                            position=wall[5],
                            visible=False)
            self.maze_walls_list.append(new_wall)

        # create head walls and add to list
        self.maze_head_wall_list = []
        for wall in self.head_walls:
            new_wall = Wall('head_wall',
                            wall_length=wall[0],
                            wall_height=wall[1],
                            wall_depth=wall[2],
                            orientation=wall[3],
                            feedback_dir=wall[4],
                            position=wall[5],
                            visible=False)
            self.maze_head_wall_list.append(new_wall)

        self.maze_units_list = []
        for maze_unit in self.maze_units:
            new_maze_unit = MazeUnit('maze_unit_id:' + str(maze_unit),
                                     edge_length=1,
                                     position=maze_unit,
                                     crit_pos=None,
                                     proximity_manager=unit_prox_manager)
            self.maze_units_list.append(new_maze_unit)

        self.maze_convex_corners_list = []
        for convex_corner in self.maze_convex_corners:
            new_convex_corner = MazeUnit(
                'convex_corner_id:' + str(convex_corner),
                edge_length=1.1,
                position=convex_corner,
                crit_pos=None,
                proximity_manager=convex_corner_prox_manager)
            self.maze_convex_corners_list.append(new_convex_corner)

        self.maze_concave_corners_list = []
        for concave_corner in self.maze_concave_corners:
            # original layout
            #            new_concave_corner = MazeUnit('concave_corner_id:' + str(concave_corner), edge_length=1.1,
            #                                         position=concave_corner, crit_pos=None, proximity_manager=concave_corner_prox_manager)

            #             new_concave_corner = MazeUnit('concave_corner_id:' + str(concave_corner), edge_length=self.concave_corner_size,
            #                                          position=concave_corner, crit_pos=None, proximity_manager=concave_corner_prox_manager)
            #             self.maze_concave_corners_list.append(new_concave_corner)

            # todo sensor erstellung polygon area

            new_concave_corner = MazeUnitShape(
                'concave_corner_id:' + str(concave_corner), concave_corner,
                concave_corner_prox_manager)
            # #verts = [[0, 0], [1, 1], [0, 1.5], [-2, 2], [-1, 1], [-2, 0.5]]
            # sensor = vizproximity.Sensor(vizproximity.PolygonArea(concave_corner), None)
            # # and add to vizard proximity manager
            # concave_corner_prox_manager.addSensor(sensor)
            self.maze_concave_corners_list.append(new_concave_corner)

        self.maze_crit_corners_list = []
        i = 0
        for crit_corner in self.maze_crit_corners:
            print self.crit_positions[i]
            new_crit_corner = MazeUnit(
                'crit_corner_id:' + str(crit_corner),
                edge_length=0.33,
                position=crit_corner,
                crit_pos=self.crit_positions[i],
                proximity_manager=crit_corner_prox_manager)
            self.maze_crit_corners_list.append(new_crit_corner)
            i = i + 1
예제 #16
0
    def __init__(self, userInput1, userInput2, gameoutput):
        # Ustawiamy nasze kolejki od obu graczy
        # Zawieraja one sterowanie jakie wykonal gracz
        # w postaci slownika self.tmpcontrol = {"w": 0, "a": 0, "s": 0, "d": 0, "r": 0, "l": 0, "f": 0} }
        # gdzie 1 to wcisniety guzik a 0 brak wcisniecia
        self.gameOver = False
        self.idnum = 1
        self.userInput1 = userInput1
        self.userInput2 = userInput2
        self.gameoutput = gameoutput
        # maksymalna liczka klatek
        self.tps_max = 60.0

        # odpalamy srodowisko i tworzymy okno
        pygame.init()
        pygame.display.set_caption('HOST')
        print("Game Runs!")
        self.DISPLAY_SURFACE = pygame.display.set_mode((500, 500))

        # przydatne do okreslenia maksymalnej liczby klatek
        self.tps_clock = pygame.time.Clock()
        self.tps_delta = 0.0

        # tablice na wszystkie elementy gry
        self.gameEntitiesArray = []
        self.gamePlayersArray = []
        self.gameEntitiesNomovable = []

        self.tmpobj = Bullet.Bullet(PlayerColors.RED, 250, 250, 3)
        self.tmpobj.set_start(1, 0, (60, 60))
        self.gameEntitiesArray.append(self.tmpobj)
        # self.gameEntitiesNomovable.append(self.tmpobj)

        # dodajemy 1 gracza
        self.player1 = GamePlayer(PlayerColors.RED, 300, 60, 1, self.tmpobj)
        self.gameEntitiesArray.append(self.player1)
        self.gamePlayersArray.append(self.player1)
        self.idnum += 1

        self.tmpobj = Bullet.Bullet(PlayerColors.BLUE, 250, 250, 4)
        self.tmpobj.set_start(1, 0, (50, 50))
        self.gameEntitiesArray.append(self.tmpobj)
        # self.gameEntitiesNomovable.append(self.tmpobj)

        # dodajemy 2 gracza
        self.player2 = GamePlayer(PlayerColors.BLUE, 300, 440, 2, self.tmpobj)
        self.gameEntitiesArray.append(self.player2)
        self.gamePlayersArray.append(self.player2)

        # dodajemy sciany
        self.tmpobj = Wall(100, 100, 300, 20)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.tmpobj = Wall(100, 350, 300, 20)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.tmpobj = Wall(0, 0, 20, 500)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.tmpobj = Wall(480, 0, 20, 500)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.tmpobj = Wall(0, 0, 500, 20)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.tmpobj = Wall(0, 480, 500, 20)
        self.gameEntitiesArray.append(self.tmpobj)
        self.gameEntitiesNomovable.append(self.tmpobj)

        self.flag = -1

        self.timer = 0
        # Glowna petla gry tu dzieje sia cala gra
        while True:
            # sprawdzacz zdarzen i ich obslugi w tym wypatku tylko zamkniecie okna by dalo sie apke normalnie zamkac
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()

            # W tej petli rzeczy sie dzieja w ograniczonej przez nas ilosci klatek na sekunde
            self.tps_delta += self.tps_clock.tick() / 1000.0
            while self.tps_delta > 1 / self.tps_max:
                self.tick()
                self.timer += 1
                if self.timer == 3:
                    self.send()
                    self.timer = 0

                self.tps_delta -= 1 / self.tps_max

            # Aktualizujemy graczy
            self.playerUpdate()
            # Czyscimy ekran i go wyswietlamy
            self.DISPLAY_SURFACE.fill((0, 0, 0))
            self.draw()
            pygame.display.flip()
예제 #17
0
    def __init__(self):
        v1 = np.array([0, 0])
        v2 = np.array([40, 0])
        v3 = np.array([100, 0])
        v4 = np.array([20, 10])
        v5 = np.array([40, 10])
        v6 = np.array([40, 40])
        v7 = np.array([60, 40])
        v8 = np.array([80, 40])
        v9 = np.array([100, 40])
        v10 = np.array([40, 60])
        v11 = np.array([60, 60])
        v12 = np.array([80, 60])
        v13 = np.array([100, 60])
        v14 = np.array([0, 90])
        v15 = np.array([20, 90])
        v16 = np.array([40, 90])
        v17 = np.array([100, 90])
        v18 = np.array([0, 100])
        v19 = np.array([100, 100])
        v20 = np.array([140, 0])
        v21 = np.array([160, 0])
        v22 = np.array([140, 80])
        v23 = np.array([160, 80])
        v24 = np.array([110, 0])
        v25 = np.array([130, 0])
        v26 = np.array([110, 20])
        v27 = np.array([130, 20])
        v28 = np.array([0, 10])
        v29 = np.array([20, 100])
        v30 = np.array([40, 100])

        w1 = Wall(v1, v18, 0, 5, None, False, (120, 120, 120))
        w2 = Wall(v18, v19, 0, 5, None, True, (120, 120, 120))
        w3 = Wall(v19, v3, 0, 5, None, True, (120, 120, 120))
        w4 = Wall(v3, v1, 0, 5, None, False, (120, 120, 120))
        s = Sector(0, False, 5, [w1, w2, w3, w4], (0, 0, 0), (0, 0, 0))

        # sector 1
        w1_1 = Wall(v1, v28, 0, 5, None, False, (120, 120, 120))
        p1_2 = Portal(None, 0, 5)
        w1_2 = Wall(v28, v4, 0, 5, p1_2, True, (120, 120, 120))
        p1_3 = Portal(None,
                      0,
                      5,
                      center_of_rotation=v4,
                      rotation_mat=np.eye(2),
                      heading_change=0,
                      new_point=v24,
                      new_y=0)
        w1_3 = Wall(v4, v5, 0, 5, p1_3, True, (120, 120, 120))
        p1_4 = Portal(None, 0, 5)
        w1_4 = Wall(v5, v2, 0, 5, p1_4, True, (120, 120, 120))
        w1_5 = Wall(v2, v1, 0, 5, None, False, (120, 120, 120))
        s1 = Sector(0, False, 5, [w1_1, w1_2, w1_3, w1_4, w1_5], (0, 0, 0),
                    (0, 0, 0))

        # sector 2
        p2_1 = Portal(None, 0, 5)
        w2_1 = Wall(v2, v5, 0, 5, p2_1, False, (120, 120, 120))
        w2_2 = Wall(v5, v6, 0, 5, None, False, (120, 120, 120))
        p2_3 = Portal(None, 0, 5)
        w2_3 = Wall(v6, v7, 0, 5, p2_3, True, (120, 120, 120))
        p2_4 = Portal(None, 0, 5)
        w2_4 = Wall(v7, v8, 0, 5, p2_4, True, (120, 120, 120))
        p2_5 = Portal(None, 0, 5)
        w2_5 = Wall(v8, v9, 0, 5, p2_5, True, (120, 120, 120))
        w2_6 = Wall(v9, v3, 0, 5, None, True, (120, 120, 120))
        w2_7 = Wall(v3, v2, 0, 5, None, False, (120, 120, 120))
        s2 = Sector(0, False, 5, [w2_1, w2_2, w2_3, w2_4, w2_5, w2_6, w2_7],
                    (0, 0, 0), (0, 0, 0))

        # sector 3
        w3_1 = Wall(v28, v14, 0, 5, None, False, (120, 120, 120))
        p3_2 = Portal(None, 0, 5)
        w3_2 = Wall(v14, v15, 0, 5, p3_2, True, (120, 120, 120))
        w3_3 = Wall(v15, v4, 0, 5, None, True, (120, 120, 120))
        p3_4 = Portal(None, 0, 5)
        w3_4 = Wall(v4, v28, 0, 5, p3_4, False, (120, 120, 120))
        s3 = Sector(0, False, 5, [w3_1, w3_2, w3_3, w3_4], (0, 0, 0),
                    (0, 0, 0))

        # sector 4
        '''
        w4_1 = Wall(v4, v15, 0, 5, None, False, (120, 120, 120))
        p4_2 = Portal(None, 0, 5, center_of_rotation=v15, rotation_mat=np.eye(2), heading_change=0, new_point=v26, new_y=0)
        w4_2 = Wall(v15, v16, 0, 5, p4_2, True, (120, 120, 120))
        w4_3 = Wall(v16, v5, 0, 5, None, True, (120, 120, 120))
        p4_4 = Portal(None, 0, 5, center_of_rotation=v4, rotation_mat=np.eye(2), heading_change=0, new_point=v24, new_y=0)
        w4_4 = Wall(v5, v4, 0, 5, p4_4, False, (120, 120, 120))
        s4 = Sector(0, False, 5, [w4_1, w4_2, w4_3, w4_4], (0, 0, 0), (0, 0, 0))
        '''

        # sector 5
        w5_1 = Wall(v6, v10, 0, 5, None, False, (120, 120, 120))
        p5_2 = Portal(None, 0, 5)
        w5_2 = Wall(v10, v11, 0, 5, p5_2, True, (120, 120, 120))
        w5_3 = Wall(v11, v7, 0, 5, None, True, (120, 120, 120))
        p5_4 = Portal(None, 0, 5)
        w5_4 = Wall(v7, v6, 0, 5, p5_4, False, (120, 120, 120))
        s5 = Sector(0, False, 5, [w5_1, w5_2, w5_3, w5_4], (0, 0, 0),
                    (0, 0, 0))

        # sector 6
        w6_1 = Wall(v7, v11, 0, 5, None, False, (120, 120, 120))
        p6_2 = Portal(None, 0, 5)
        w6_2 = Wall(v11, v12, 0, 5, p6_2, True, (120, 120, 120))
        w6_3 = Wall(v12, v8, 0, 5, None, True, (120, 120, 120))
        p6_4 = Portal(None, 0, 5)
        w6_4 = Wall(v8, v7, 0, 5, p6_4, False, (120, 120, 120))
        s6 = Sector(0, False, 5, [w6_1, w6_2, w6_3, w6_4], (0, 0, 0),
                    (0, 0, 0))

        # sector 7
        w7_1 = Wall(v8, v12, 0, 5, None, False, (120, 120, 120))
        p7_2 = Portal(None, 0, 5)
        w7_2 = Wall(v12, v13, 0, 5, p7_2, True, (120, 120, 120))
        w7_3 = Wall(v13, v9, 0, 5, None, True, (120, 120, 120))
        p7_4 = Portal(None, 0, 5)
        w7_4 = Wall(v9, v8, 0, 5, p7_4, False, (120, 120, 120))
        s7 = Sector(0, False, 5, [w7_1, w7_2, w7_3, w7_4], (0, 0, 0),
                    (0, 0, 0))

        # sector 8
        w8_1 = Wall(v10, v16, 0, 5, None, False, (120, 120, 120))
        p8_2 = Portal(None, 0, 5)
        w8_2 = Wall(v16, v17, 0, 5, p8_2, True, (120, 120, 120))
        w8_3 = Wall(v17, v13, 0, 5, None, True, (120, 120, 120))
        p8_4 = Portal(None, 0, 5)
        w8_4 = Wall(v13, v12, 0, 5, p8_4, False, (120, 120, 120))
        p8_5 = Portal(None, 0, 5)
        w8_5 = Wall(v12, v11, 0, 5, p8_5, False, (120, 120, 120))
        p8_6 = Portal(None, 0, 5)
        w8_6 = Wall(v11, v10, 0, 5, p8_6, False, (120, 120, 120))
        s8 = Sector(0, False, 5, [w8_1, w8_2, w8_3, w8_4, w8_5, w8_6],
                    (0, 0, 0), (0, 0, 0))

        # sector 9
        w9_1 = Wall(v14, v18, 0, 5, None, False, (120, 120, 120))
        w9_2 = Wall(v30, v19, 0, 5, None, True, (120, 120, 120))
        w9_3 = Wall(v19, v17, 0, 5, None, True, (120, 120, 120))
        p9_4 = Portal(None, 0, 5)
        w9_4 = Wall(v17, v16, 0, 5, p9_4, False, (120, 120, 120))
        s9 = Sector(0, False, 5, [w9_1, w9_2, w9_3, w9_4], (0, 0, 0),
                    (0, 0, 0))
        p9_5 = Portal(None,
                      0,
                      5,
                      center_of_rotation=v15,
                      rotation_mat=np.eye(2),
                      heading_change=0,
                      new_point=v26,
                      new_y=0)
        w9_5 = Wall(v16, v15, 0, 5, p9_5, False, (120, 120, 120))
        p9_6 = Portal(None, 0, 5)
        w9_6 = Wall(v15, v14, 0, 5, p9_6, False, (120, 120, 120))

        # sector 10
        w10_1 = Wall(v24, v26, 0, 5, None, False, (150, 0, 0))
        p10_2 = Portal(None,
                       0,
                       5,
                       center_of_rotation=v26,
                       rotation_mat=np.eye(2),
                       heading_change=0,
                       new_point=v15,
                       new_y=0)
        w10_2 = Wall(v26, v27, 0, 5, p10_2, True, (120, 120, 120))
        w10_3 = Wall(v27, v25, 0, 5, None, True, (0, 150, 0))
        p10_4 = Portal(None,
                       0,
                       5,
                       center_of_rotation=v24,
                       rotation_mat=np.eye(2),
                       heading_change=0,
                       new_point=v4,
                       new_y=0)
        w10_4 = Wall(v25, v24, 0, 5, p10_4, True, (120, 120, 120))
        s10 = Sector(0, False, 5, [w10_1, w10_2, w10_3, w10_4], (0, 0, 0),
                     (0, 0, 0))

        # assign sectors to portals
        p1_2.sector = s3
        p1_3.sector = s10
        p1_4.sector = s5

        p2_1.sector = s1
        p2_3.sector = s5
        p2_4.sector = s6
        p2_5.sector = s7

        p3_2.sector = s9
        p3_4.sector = s1

        #p4_2.sector = s9
        #p4_4.sector = s1

        p5_2.sector = s8
        p5_4.sector = s2

        p6_2.sector = s8
        p6_4.sector = s2

        p7_2.sector = s8
        p7_4.sector = s2

        p8_2.sector = s9
        p8_4.sector = s7
        p8_5.sector = s6
        p8_6.sector = s5

        p9_4.sector = s8
        p9_5.sector = s10
        p9_6.sector = s3

        p10_2.sector = s9
        p10_4.sector = s1

        self.sectors = [s1, s2, s3, s5, s6, s7, s8, s9, s10]
예제 #18
0
xpose3 = random.choice(x)
xpose4 = random.choice(x)
xpose5 = random.choice(x)
xpose6 = random.choice(x)
xpose7 = random.choice(x)
xpose8 = random.choice(x)
xpose9 = random.choice(x)

root = Tk()
root.title("Step move")
#add widgets
myApp = Step_move(root)
#===================================================================

#Wall
aWall = Wall(3, 800, 3, 600)
myApp.createtable(aWall)

bWallpad = Wallpad(3, 550, 800, 600)
myApp.createWallpad(bWallpad, "light green")

cWallpad = Wallpad(3, 3, 100, 25)
myApp.createWallpad(cWallpad, "black")

cWallpad = Wallpad(100, 25, 200, 50)
myApp.createWallpad(cWallpad, "black")

cWallpad = Wallpad(200, 3, 300, 25)
myApp.createWallpad(cWallpad, "black")

cWallpad = Wallpad(300, 25, 400, 50)
예제 #19
0
파일: Main.py 프로젝트: BenBoomy/Games
def main():
    pygame.init()
    pygame.display.init()
    screen = pygame.display.set_mode((600, 950))
    gameLoop = True
    t1 = 0
    
    global idx
    idx = 0

    right_wall = Wall(550)
    left_wall = Wall(0)
    all_objects.add(right_wall)
    all_objects.add(left_wall)
    bottom = Bottom(WHITE)
    all_objects.add(bottom)
    
    while gameLoop:
        if len(player_blocks) == 0:
            newPiece()
            matrix = list2matrix()
            
        for block in player_objects:
            if bottom.rect.contains(block) or\
               pygame.sprite.spritecollideany(block, bottom_objects):
                player_objects.empty()
                bottom_objects.add(block)
                player_blocks[:] = []
                
        #moving piece down automatically
        t = time.time()
        if t - t1 > 1:
            down()
            t1 = t
            
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                #movement management
                
                if event.key == pygame.K_LEFT:
                    for block in player_blocks:
                        block.left()
                        for block in player_blocks:
                            if block.rect.x < 50:
                                for block in player_blocks:
                                    block.right()
                                    
                elif event.key == pygame.K_RIGHT:
                    for block in player_blocks:
                        block.right()
                        for block in player_blocks:
                            if block.rect.x >= 550:
                                for block in player_blocks:
                                    block.left()
                elif event.key == pygame.K_UP:
                    turnPiece(matrix, True)

                elif event.key == pygame.K_DOWN:
                    turnPiece(matrix, False)
                    
                if event.key == pygame.K_SPACE:
                    down()
        
        all_objects.update()
        screen.fill(BLACK)
        all_objects.draw(screen)
        pygame.display.flip()
gameDisplay = py.display.set_mode((800, 700))

#adds title to window top of game
py.display.set_caption("Breakout")

#updates the display
py.display.flip()

#creates ball image and gives it a rectangle to manipulate later
ball = py.image.load("ballNoBackground.png")
ballRect = ball.get_rect()

#sets initial ball direction and location
resetBall()

wall = Wall()

#creates and places paddle with a rectangle
paddle = Paddle()
paddleRect = paddle.image.get_rect()
paddleRect.x = 300
paddleRect.y = 620

#allows for held down keys to continue movement
py.key.set_repeat(10, 10)

#holds initial life value
lifeCount = 3

#initialized ballDirection variable
ballDirection = [0, 0]
예제 #21
0
def create_wall_s(x, y, n=2, image="img/wall/walls.gif", type=1):
    wall_list = []
    for i in range(n):
        wall = Wall(image, x, y + 60 * i, type)
        wall_list.append(wall)
    return wall_list