Beispiel #1
0
def movePac(app, direction):
    shiftX = (app.pac.speed *
              math.cos(math.radians(app.pac.angle))) * direction
    shiftY = (app.pac.speed *
              math.sin(math.radians(app.pac.angle))) * direction

    app.pac.x += shiftX
    app.pac.y -= shiftY

    #Boundry Move
    row, col = helper.getCell(app, app.pac.x, app.pac.y)
    if row == 14:
        if app.pac.x <= app.pac.radius + 1:
            app.pac.x = app.width - app.pac.radius - 1
        elif app.pac.x >= app.width - app.pac.radius - 1:
            app.pac.x = app.pac.radius + 1

    #Legal Check
    if not legalPacMove(app):
        app.pac.x -= shiftX
        app.pac.y += shiftY
        return False
    elif app.board[row][col] == app.emptyColor:
        return False
    return True
Beispiel #2
0
def updateGhostList(app):
    #25 app.timer increases is roughtly 1 second on my computer
    if app.timer < 160:
        #Game Start Ghost Appearances
        if app.timer == 50:
            app.ghostList.append(app.g2)
        if app.timer == 100:
            app.ghostList.append(app.g3)
        if app.timer == 150:
            app.ghostList.append(app.g4)
    if app.timer < 2200:
        ##Scatter Intervals####
        if app.timer == 175:
            character.ghost.scatter = False
        if app.timer == 675:
            character.ghost.scatter = True
        if app.timer == 850:
            character.ghost.scatter = False
        if app.timer == 1350:
            character.ghost.scatter = True
        if app.timer == 1475:
            character.ghost.scatter = False
        if app.timer == 1975:
            character.ghost.scatter = True
        if app.timer == 2100:
            character.ghost.scatter = False

    #If Pac Man eats a ghost
    row, col = helper.getCell(app, app.pac.x, app.pac.y)
    if character.ghost.scared:
        for ghost in app.ghostList:
            if ghost.row == row and ghost.col == col:
                app.score += 200
                ghost.tod = app.timer
                app.ghostList.remove(ghost)

    #Length of super time
    if app.timer - app.superHold == 150:
        character.ghost.scared = False
        character.ghost.speed = 14
        app.pac.speed = app.cellSize / 16

    #Length of death time
    if app.timer > 160:
        for ghost in [app.g1, app.g2, app.g3, app.g4]:
            if ghost not in app.ghostList and app.timer - ghost.tod == 100:
                ghost.row = 12
                ghost.col = 13
                ghost.rowDir = -1
                ghost.colDir = 0
                app.ghostList.append(ghost)
Beispiel #3
0
def eat(app):
    row, col = helper.getCell(app, app.pac.x, app.pac.y)

    if app.board[row][col] == app.pillColor:
        app.score += 10
        app.pellets += 1
    elif app.board[row][col] == app.superColor:
        app.score += 50
        character.ghost.scared = True
        character.ghost.speed = 20
        app.pac.speed = app.cellSize / 14
        app.superHold = app.timer

    app.board[row][col] = app.emptyColor
Beispiel #4
0
def legalPacMove(app):
    if (app.pac.x < 0 or app.pac.y < 0 or app.pac.x > app.width
            or app.pac.y >= app.height):
        return False

    for node in app.pac.collision:
        nodeX, nodeY = node
        row, col = helper.getCell(app, app.pac.x + nodeX, app.pac.y + nodeY)

        if (app.board[row][col] != app.pillColor
                and app.board[row][col] != app.emptyColor
                and app.board[row][col] != app.superColor):
            return False
    return True
Beispiel #5
0
def run(app, canvas):
    seenPill = set()
    seenGhost = set()
    entityList = {}
    distanceList = []
    ########################################
    #Big Loop
    for i in range(app.fov):
        angle = app.pac.angle + app.fov / 2 - i
        x = app.pac.x
        y = app.pac.y
        hitWall = False

        #Extend x,y out in an angle until it hits a wall
        while hitWall == False:
            row, col = helper.getCell(app, x, y)
            entDis = distance(app, x, y, i)

            #Ghost Check
            for ghost in app.ghostList:
                if ((row == ghost.row and col == ghost.col)
                        and (row, col) not in seenGhost
                        and helper.near(app, helper.getCxCy(app, row, col),
                                        (x, y))):

                    seenGhost.add((row, col))
                    entityList[entDis] = entityList.get(entDis, [])
                    entityList[entDis] += [(i, ghost.color)]
                    distanceList.append(entDis)

            #Pill Check
            if (col < 28 and col > -1
                    and (app.board[row][col] == app.pillColor
                         or app.board[row][col] == app.superColor)
                    and (row, col) not in seenPill
                    and helper.near(app, helper.getCxCy(app, row, col), (x, y))
                    and helper.ghostCell(app, row, col) == False):
                if entDis > 0:
                    seenPill.add((row, col))
                    entityList[entDis] = entityList.get(entDis, [])
                    if app.board[row][col] == app.pillColor:
                        entityList[entDis] += [(i, app.pillColor)]
                    elif app.board[row][col] == app.superColor:
                        entityList[entDis] += [(i, app.superColor)]
                    distanceList.append(entDis)

            #Wall Check
            if (col > 27 or col < 0
                    or (app.board[row][col] != app.pillColor
                        and app.board[row][col] != app.emptyColor
                        and app.board[row][col] != app.superColor)):
                hitWall = True

            x += math.cos(math.radians(angle))
            y -= math.sin(math.radians(angle))

        #Find the projection distance of that
        wallDis = distance(app, x, y, i)

        #Draw a line/rectangle with correct height
        width = app.width / (app.fov)
        cx = width * i
        drawWall(app, canvas, cx, wallDis)

        #Repeat for all angles in FOV
        #######################################
    #Drawing all the pills
    entity(app, canvas, entityList, distanceList)
Beispiel #6
0
def pacDead(app):
    if character.ghost.scared == False:
        row, col = helper.getCell(app, app.pac.x, app.pac.y)
        return helper.ghostCell(app, row, col)
    else:
        return False