コード例 #1
0
def main():
    myPlayer = PlayerInputManager.buildActionPlayer(
        pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d, pygame.K_SPACE,
        SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 100, 100, 5, 5)
    #debug routine
    #for i in range(10):
    #    BulletManager.buildBaseBullet(10,10,1,1,i)

    testBlock = StationaryBlock(0, 0, SCREEN_WIDTH / 3, SCREEN_HEIGHT / 3)
    test2XSpeed = PowerUp(SCREEN_WIDTH - 250, SCREEN_HEIGHT - 250, 50, 50,
                          DoubleSpeedMod())
    while (True):
        screen.fill(Color.black)

        PlayerInputManager.update(pygame.key.get_pressed())
        #eventually we'll need the collision manager update here as well
        myPlayer.update(screen, [200, 200],
                        [SCREEN_WIDTH - 200, SCREEN_HEIGHT - 200])
        testBlock.update(screen)
        if (test2XSpeed.isAlive == True):
            test2XSpeed.update(screen)
        #else:
        #del test2XSpeed

        BulletManager.update(screen, [0, 0], [SCREEN_WIDTH, SCREEN_HEIGHT])
        CollisionManager.update()

        msElapsed = clock.tick(30)  #SYNC RATE 30 FPS
        pygame.display.update()  #SYNC
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
コード例 #2
0
ファイル: PlayMap.py プロジェクト: yazici/python-animations
    def __init__(self):
        """
                Constructor method for PlayMap
                Transition: initialized into new game state
                input:none
                output:none
                """

        self.height = 500
        self.width = 550
        self.snake = Snake()  # starting coord of snake
        self.food = Food()
        self.powerUp = PowerUp()

        self.powerUpStatus = True
        self.gameStatsBar = pygame.Rect(0, 0, 550, 20)
        self.powerUpIndicator = pygame.Rect(10, 0, 10, 10)
        self.score = len(self.snake.points)
        self.diff = 0
コード例 #3
0
    def __init__(self):
        super().__init__()

        self.wallTexture = QPixmap('textures/wall.png')
        self.floorTexture = QPixmap('textures/floor.png')
        self.createBoard()

        #init Star
        self.Star1 = PowerUp.Star(QVector2D(250, 300))

        #init Robots
        Robot1 = Robots.Robot(1, QVector2D(500, 500), 290, 2, 2, 15, 90,
                              colors["pink"])
        Robot2 = Robots.Robot(2, QVector2D(100, 900), 90, 2, 2, 15, 90,
                              colors["darkblue"])
        Robot3 = Robots.Robot(3, QVector2D(250, 650), 270, 2, 2, 15, 90,
                              colors["lightblue"])
        Robot4 = Robots.Robot(4, QVector2D(950, 100), 180, 2, 2, 15, 90,
                              colors["orange"])

        Robot1.setProgram(Robots.RunAwayKeyBoard(Robot1))
        Robot2.setProgram(Robots.TargetHunt(Robot2))
        Robot3.setProgram(Robots.TargetHunt(Robot3))
        Robot4.setProgram(Robots.TargetHunt(Robot4))

        self.robots = [Robot1, Robot2, Robot3, Robot4]

        Robot1.executeProgram()
        Robot2.executeProgram()
        Robot3.executeProgram()
        Robot4.executeProgram()

        self.timer = QBasicTimer()
        self.timer.start(FPS, self)
        self.tickCount = 0

        self.initUI()
コード例 #4
0
        file.write(str(score)+"\n")
        file.close()
        pygame.quit()
        sys.exit()

    if len(enemies) == 0:
        wave+= 1
        spawn()
        Pbullets = []
        Ebullets = []
        player.health+=1
        
    num = random.randint(1, 2000)
    if num  == 1:
       randX = random.randint(0, width - 32)
       pUp = PowerUp(randX, "dios")
       pUps.append(pUp)
       
    ### Move/ user input Phase
    remove = False
    for pUp in pUps:
        pUp.update()
        if pUp.collision(player):
            if pUp.pType == "dios":
                endtime = pygame.time.get_ticks() + 3000
                limit = 100
                player.speed = 10
                timer = True
                remove = True
        if pUp.delete (height) or remove:
            remove = False
コード例 #5
0
def main():
    menu = True
    pygame.init()
    deathcounter = 0
    textcounter = 0
    fpsClock = pygame.time.Clock()
    message = ""
    windowSurfaceObj = pygame.display.set_mode((1280, 720), DOUBLEBUF)
    pygame.display.set_caption("William Wallace Castle Defender X-Treme 2140")
    soundObjectExplosion = pygame.mixer.Sound('explosion.wav')
    soundDecoy = pygame.mixer.Sound('decoy.wav')
    soundPwp = pygame.mixer.Sound('powerup.wav')
    soundShld = pygame.mixer.Sound('zap2.wav')
    desertBackground = pygame.image.load(
        os.path.join(os.curdir, 'desert-background.jpg')).convert_alpha()
    SurfaceObjLife = pygame.image.load("life.png")
    level = pygame.image.load(os.path.join(os.curdir,
                                           'LEVEL.png')).convert_alpha()
    player = Player()
    ArrowList = []
    missileList = []
    ShieldList = []
    BombList = []
    PowerUpList = []
    #EXPLOSION
    exploList = []

    #Enemy variables
    maxEnemies = 50
    enemyList = []

    #Castle HP
    HP = 100
    points = 0
    if menu == True:
        Menu(menu, windowSurfaceObj, fpsClock, desertBackground)
    pygame.key.set_repeat(1, 50)
    playing = True
    gravityLimit = False

    soundObjectExplosion = pygame.mixer.Sound("explosion.wav")
    soundObjectArrow = pygame.mixer.Sound("arrow.wav")
    pygame.mixer.music.load("BackgroundMusic.mp3")
    pygame.mixer.music.play(-1)

    gravityLimit = False
    #Main Loop
    LifeUp = 1
    while playing:
        windowSurfaceObj.blit(desertBackground, (0, 0))
        windowSurfaceObj.blit(level, (0, 0))
        mousex = player.x
        mousey = player.y

        #DRAW EXLPLOSIONS
        count = len(exploList) - 1
        while (count >= 0):
            windowSurfaceObj.blit(
                exploList[count].images[exploList[count].image],
                exploList[count].rect)
            if (exploList[count].updateEnemyPos()):
                exploList.pop(count)
            count = count - 1
        if (textcounter > 0):
            #print message
            textMessage = fontObj.render(str(message), False,
                                         pygame.Color(0, 0, 0))
            windowSurfaceObj.blit(
                textMessage,
                ((1280 - textMessage.get_rect().width) / 2 * 1, 670))
            textcounter -= 1
        if (deathcounter > 0):
            if (player.Lives <= 0):
                player.fall()
                player.updatePlayerSprite(21, 1)
            else:
                player.updatePlayerSprite(20, 1)
            deathcounter -= 1
            windowSurfaceObj.blit(player.images[player.image], player.rect)
            pygame.display.flip()
            fpsClock.tick(30)

        else:
            if (player.Lives <= 0):
                retry = gameOver(points, windowSurfaceObj, fpsClock,
                                 desertBackground)
                playing = False
            #Enemy code
            enemyGenerator(enemyList, maxEnemies, points)
            count = len(enemyList) - 1
            while (count >= 0):
                windowSurfaceObj.blit(
                    enemyList[count].images[enemyList[count].image],
                    enemyList[count].rect)

                enx = enemyList[count].x
                eny = enemyList[count].y
                chance = 1
                if enemyList[count].boss:
                    chance = 5
                if random.randint(
                        0, 100) < chance:  #1% chance that an enemy shoots
                    if enemyList[count].right:
                        speed = -enemyList[count].speed
                    else:
                        speed = enemyList[count].speed
                    tmp = random.randint(0, 100)
                    if player.DecoyCounter > 0:
                        playerX = player.DecoyX
                        playerY = player.DecoyY
                    else:
                        playerX = player.x
                        playerY = player.y
                    if enemyList[count].boss:
                        for i in range(0, 30):
                            m = Missile(enx + random.randint(-180, 180),
                                        eny + random.randint(-180, 180),
                                        player.x + random.randint(-180, 180),
                                        player.y + random.randint(-180, 180),
                                        speed)
                            missileList.append(m)
                    elif tmp < 30:
                        m = Missile(enx, eny, playerX, playerY + 20, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY - 20, speed)
                        missileList.append(m)
                    elif tmp < 50:
                        m = Missile(enx, eny, playerX, playerY + 20, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY - 20, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY + 40, speed)
                        missileList.append(m)
                        m = Missile(enx, eny, playerX, playerY - 40, speed)
                        missileList.append(m)
                    else:
                        missileList.append(
                            Missile(enx, eny, playerX, playerY, speed))
                if enemyList[count].updateEnemyPos(enemyList, count):
                    HP = HP - 2
                    if HP < 0:
                        HP = 0
                    exploList.append(Explo(enx, eny, False))
                    soundObjectExplosion.play()
                    if HP == 0:
                        retry = gameOver(points, windowSurfaceObj, fpsClock,
                                         desertBackground)
                        playing = False

                    exploList.append(Explo(enx, eny, False))
                count = count - 1

            skipFall = False
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == MOUSEMOTION:
                    mousex, mousey = event.pos
                    player.updateVector(mousex, mousey)
                elif event.type == MOUSEBUTTONDOWN:
                    myx, myy = event.pos
                    if (myx < player.x):
                        player.updatePlayerSprite(18, 1)
                    else:
                        player.updatePlayerSprite(19, 1)
                elif event.type == MOUSEBUTTONUP:
                    if event.button in (1, 2, 3):
                        mousex, mousey = event.pos
                        #if player.Arrows - 1 >= 0:
                        if 1:
                            arrow = Arrow(player.x, player.y + 24, mousex,
                                          mousey, player.gunmode)
                            ArrowList.append(arrow)
                            if player.MultiShot2:
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey + 20, player.gunmode)
                                ArrowList.append(arrow)
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey - 20, player.gunmode)
                                ArrowList.append(arrow)
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey + 40, player.gunmode)
                                ArrowList.append(arrow)
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey - 40, player.gunmode)
                                ArrowList.append(arrow)
                            elif player.MultiShot:
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey + 30, player.gunmode)
                                ArrowList.append(arrow)
                                arrow = Arrow(player.x, player.y + 24, mousex,
                                              mousey - 30, player.gunmode)
                                ArrowList.append(arrow)
                            soundObjectArrow.play()
                            #player.Arrows -= 1

                        #left, middle, right button
                    elif event.button in (4, 5):
                        blah = "blah"
                        #scroll up or down
                elif event.type == KEYDOWN:
                    x = 0
                    y = 0
                    if event.key == K_SPACE:
                        if player.Repel > 0:
                            soundShld.play()
                            ShieldList.append(Shield(player.x, player.y))
                            player.Repel -= 1

                            #rep = pygame.image.load("pexpl1.png")
                            #windowSurfaceObj.blit(rep,rep.get_rect())
                            for i in range(0, len(missileList)):
                                missXp = missileList[i].x
                                missYp = missileList[i].y

                                diffX = missileList[i].x - player.x
                                diffY = missileList[i].y - player.y

                                if diffX != 0 and diffY != 0:
                                    missileList[i].vector = Vector(
                                        (diffX /
                                         sqrt(diffX * diffX + diffY * diffY)),
                                        (diffY /
                                         sqrt(diffX * diffX + diffY * diffY)))
                                else:
                                    if diffX == 0:
                                        if diffY < 0:
                                            missileList[i].vector = Vector(
                                                0, -1)
                                        elif diffY > 0:
                                            missileList[i].vector = Vector(
                                                0, 1)
                                    elif diffY == 0:
                                        if diffX < 0:
                                            missileList[i].vector = Vector(
                                                -1, 0)
                                        elif diffX > 0:
                                            missileList[i].vector = Vector(
                                                1, 0)
                                    else:
                                        missileList[i].vector = Vector(1, 0)
                                missileList[i].vel = 15
                    if event.key == K_LSHIFT:
                        if player.DecoyNum > 0:
                            soundDecoy.play()
                            player.Decoy(player.x, player.y)
                            player.DecoyNum -= 1

                    if event.key == K_LEFT or event.key == K_a:
                        x = -10
                    if event.key == K_RIGHT or event.key == K_d:
                        x = 10
                    if event.key == K_UP or event.key == K_w:
                        y = -.5
                    keystate = pygame.key.get_pressed()
                    if keystate[pygame.locals.K_UP] or keystate[
                            pygame.locals.K_w]:
                        y = -10
                    if keystate[pygame.locals.K_RIGHT] or keystate[
                            pygame.locals.K_d]:
                        x = 10
                    if keystate[pygame.locals.K_LEFT] or keystate[
                            pygame.locals.K_a]:
                        x = -10
                    #player.updatePlayerPos(x,0)
                    if y != 0:
                        if player.Gravity - 1 >= 0 and gravityLimit:
                            player.jet()
                            skipFall = True
                            player.Gravity -= 1
                        else:
                            if player.Gravity >= 20:
                                gravityLimit = True
                            else:
                                gravityLimit = False
                    if event.key == K_ESCAPE:
                        pygame.event.post(pygame.event.Event(QUIT))
                #else:
            x = 0
            y = 0
            keystate = pygame.key.get_pressed()
            if keystate[pygame.locals.K_UP] or keystate[pygame.locals.K_w]:
                y = -10
            if keystate[pygame.locals.K_RIGHT] or keystate[pygame.locals.K_d]:
                x = 10
            if keystate[pygame.locals.K_LEFT] or keystate[pygame.locals.K_a]:
                x = -10
            if (x != 0 or y != 0):
                player.updatePlayerPos(x, 0)
            if y != 0:
                if player.Gravity - 1 >= 0 and gravityLimit:
                    player.jet()
                    skipFall = True
                    player.Gravity -= 1
                else:
                    if player.Gravity >= 20:
                        gravityLimit = True
                    else:
                        gravityLimit = False

            #player.updateVector(mousex,mousey)
            #Castle health bar
            pygame.draw.rect(windowSurfaceObj, pygame.Color(255, 0, 0),
                             (540, 260, 200, 20))
            pygame.draw.rect(windowSurfaceObj, pygame.Color(0, 255, 0),
                             (540, 260, HP * 2, 20))
            #Display Points
            fontObj = pygame.font.Font('freesansbold.ttf', 32)
            pointsSurfaceObj = fontObj.render("Points: " + str(points), False,
                                              pygame.Color(255, 255, 255))
            windowSurfaceObj.blit(pointsSurfaceObj,
                                  (windowSurfaceObj.get_rect().width -
                                   pointsSurfaceObj.get_rect().width - 25, 25))
            #Display Lives
            fontObj = pygame.font.Font('freesansbold.ttf', 32)
            livesSurfaceObj = fontObj.render("Lives:", False,
                                             pygame.Color(255, 255, 255))
            windowSurfaceObj.blit(livesSurfaceObj, (300, 25))
            for i in range(0, player.Lives):
                windowSurfaceObj.blit(
                    SurfaceObjLife,
                    (300 + livesSurfaceObj.get_rect().width +
                     (i * (SurfaceObjLife.get_rect().width + 25)),
                     25 - SurfaceObjLife.get_rect().height / 4))
            #Display Arrows and gravity
            decoysSurfaceObj = fontObj.render(
                "Decoys: " + str(player.DecoyNum), False,
                pygame.Color(255, 255, 255))
            #arrowsSurfaceObj = fontObj.render("Arrows: " + str(player.Arrows)+"/"+str(player.ArrowsMax), False, pygame.Color(255,255,255))
            #gravitySurfaceObj = fontObj.render("Anti-Gravity: ", False, pygame.Color(255,255,255))
            windowSurfaceObj.blit(decoysSurfaceObj, (40, 15))
            repelSurfaceObj = fontObj.render("Repels: " + str(player.Repel),
                                             False,
                                             pygame.Color(255, 255, 255))
            windowSurfaceObj.blit(repelSurfaceObj, (40, 70))

            pygame.draw.rect(windowSurfaceObj, pygame.Color(255, 255, 0),
                             (20, 120, 200, 20))
            pygame.draw.rect(windowSurfaceObj, pygame.Color(255, 0, 0),
                             (20, 120, 40, 20))
            pygame.draw.rect(windowSurfaceObj, pygame.Color(0, 255, 0),
                             (20, 120, player.Gravity * 2, 20))
            #windowSurfaceObj.blit(arrowsSurfaceObj, (25, 25))
            #windowSurfaceObj.blit(gravitySurfaceObj, (25, arrowsSurfaceObj.get_rect().height + 50))
            #player.updatePos()
            if not skipFall:
                player.fall()
            #Arrow Code
            end = len(ArrowList)
            i = end - 1
            while i >= 0:
                chk = ArrowList[i].updateArrowPos()
                if not chk:
                    ArrowList.pop(i)
                    i = i - 1
                else:
                    end = len(enemyList) - 1
                    count = end
                    chk = True
                    while count >= 0:
                        if ArrowList[i].rect.colliderect(
                                enemyList[count].rect):
                            if (not player.gunmode):
                                ArrowList.pop(i)
                                i = i - 1
                            enx = enemyList[count].x
                            eny = enemyList[count].y
                            if (enemyList[count].Hit(enemyList, count, 5)):
                                exploList.append(Explo(enx, eny, False))
                                x = random.randint(0, 100)
                                if x <= 25:
                                    tmp = PowerUp(enx, eny)
                                    PowerUpList.append(tmp)
                                elif x > 95:
                                    b = Bomb(enx, eny)
                                    BombList.append(b)
                                soundObjectExplosion.play()
                            points = points + 5
                            if points / LifeUp >= 100:
                                LifeUp += 1
                                player.Lives += 1
                            chk = False
                        count -= 1
                        if i < 0:
                            count = -1
                    if chk:
                        ArrowObj = ArrowList[i].ArrowObj
                        windowSurfaceObj.blit(ArrowObj, ArrowList[i].rect)
                i = i - 1

            #Bomb Code
            i = len(BombList) - 1
            while i >= 0:
                if BombList[i].rect.colliderect(player.rect):
                    killAllEnemies(enemyList, exploList, soundObjectExplosion)
                    #deathcounter=45
                    points = points + 30
                    if points / LifeUp >= 100:
                        LifeUp += 1
                        player.Lives += 1
                    for i in range(0, 60):
                        x = random.randint(0, 1280)
                        y = random.randint(0, 720)
                        z = random.randint(0, 1)
                        exploList.append(Explo(x, y, z))
                    BombList = []
                    missileList = []
                    arrowList = []
                    i = -1
                else:
                    windowSurfaceObj.blit(BombList[i].image, BombList[i].rect)
                i = i - 1

            #Missile Code
            end = len(missileList)
            i = end - 1

            while i >= 0:
                chk = missileList[i].updateMissilePos()
                if not chk:
                    missileList.pop(i)
                    i = i - 1
                else:
                    if missileList[i].rect.colliderect(player.rect):
                        exploList.append(
                            Explo(missileList[i].x, missileList[i].y, True))
                        soundObjectExplosion.play()
                        missileList.pop(i)
                        player.Lives -= 1
                        #i = i - 1
                        if player.Lives <= 0 and playing == True:
                            killAllEnemies(enemyList, exploList,
                                           soundObjectExplosion)
                            deathcounter = 70
                        else:
                            i = -1
                            player.ArrowsMax = 20
                            player.ArrowsReplRate = 0.05
                            missileList = []
                            arrowList = []
                            #TODO
                            killAllEnemies(enemyList, exploList,
                                           soundObjectExplosion)
                            deathcounter = 45
                            player.RapidFire = False
                            player.MultiShot = False
                            player.MultiShot2 = False
                            player.gunmode = False
                        chk = False
                    if i < 0:
                        count = -1
                if chk:
                    missileObj = missileList[i].missileObj
                    windowSurfaceObj.blit(missileObj, missileList[i].rect)
                i = i - 1

            i = len(PowerUpList) - 1
            while i >= 0:
                PowerUpList[i].updateBoxSprite()
                if player.rect.colliderect(PowerUpList[i].rect):
                    soundPwp.play()
                    if PowerUpList[i].type == 0:
                        player.Repel += 1
                        message = "Repel!"
                        textcounter = 120
                    elif PowerUpList[i].type == 1:
                        if player.MultiShot:
                            player.MultiShot2 = True
                        player.MultiShot = True
                        message = "Multi Shot!"
                        textcounter = 120
                    elif PowerUpList[i].type == 2:
                        player.DecoyNum += 1
                        message = "Decoy!"
                        textcounter = 120
                    elif PowerUpList[i].type == 3:
                        if HP + 10 >= 100:
                            HP = 100
                        else:
                            HP += 10
                        message = "Castle HP restored!"
                        textcounter = 120
                    elif PowerUpList[i].type == 4:
                        player.gunmode = True
                        message = "Piercing bullets!"
                        textcounter = 120
                        soundObjectArrow = pygame.mixer.Sound("gun.wav")
                    PowerUpList.pop(i)
                else:
                    windowSurfaceObj.blit(
                        PowerUpList[i].images[PowerUpList[i].image],
                        PowerUpList[i].rect)
                i = i - 1
            #check enemy detection with player
            i = len(enemyList) - 1
            while i >= 0:
                if player.rect.colliderect(enemyList[i].rect):
                    player.Lives -= 1
                    exploList.append(
                        Explo(enemyList[i].x, enemyList[i].y, True))
                    soundObjectExplosion.play()
                    exploList.append(
                        Explo(enemyList[i].x, enemyList[i].y, True))
                    enemyList.pop(i)
                    if player.Lives <= 0 and playing == True:
                        killAllEnemies(enemyList, exploList,
                                       soundObjectExplosion)
                        deathcounter = 70
                    else:
                        player.ArrowsMax = 20
                        player.ArrowsReplRate = 0.05
                        killAllEnemies(enemyList, exploList,
                                       soundObjectExplosion)
                        deathcounter = 45
                        missileList = []
                        arrowsList = []
                        player.RapidFire = False
                        player.MultiShot = False
                        player.MultiShot2 = False
                        player.gunmode = False
                    i = len(enemyList)
                i = i - 1

            windowSurfaceObj.blit(player.images[player.image], player.rect)
            player.DecoyCounter -= 5
            if player.DecoyCounter > 0:
                windowSurfaceObj.blit(player.images[21],
                                      (player.DecoyX, player.DecoyY))
            #DRAW SHIELD
            count = len(ShieldList) - 1
            while (count >= 0):
                windowSurfaceObj.blit(
                    ShieldList[count].images[ShieldList[count].image],
                    ShieldList[count].rect)
                ShieldList[count].x = player.x
                ShieldList[count].y = player.y

                if (ShieldList[count].move(0, 0)):
                    ShieldList.pop(count)
                count = count - 1

            #pygame.display.update()
            pygame.display.flip()
            fpsClock.tick(30)
            #if player.Arrows + 1 <= player.ArrowsMax:
            #    player.ArrowsRepl += player.ArrowsReplRate
            #   if player.ArrowsRepl >= 1.0:
            #       player.Arrows += 1
            #      player.ArrowsRepl = 0.0
            if player.Gravity + 1 <= 100:
                player.GravityRepl += .5
                if player.GravityRepl >= 1.0:
                    player.Gravity += 1
                    player.GravityRepl = 0.0

    if retry:
        pygame.mixer.music.stop
        main()
    else:
        pygame.quit()
コード例 #6
0
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    bullet = PlayerBullet(player.rect.center)
                    pBullets.append(bullet)

        if len(enemies) == 0:
            wave += 1
            waveLabel = font.render("wave " +str(wave), False, white)
            spawn()

    ###user input/mothing things
        player.update()

        power = random.randint(1, 500)
        if power == 1:
            pUp = PowerUp(width, 1)
            pUpList.append(pUp)
            
        for pUp in pUpList:
            pUp.update()
            if pUp.collision(player):
                player.pUp = True
                pUpList.remove(pUp)

                


        for bullet in pBullets:
            bullet.update()

コード例 #7
0
ファイル: tests.py プロジェクト: vlbpdasilva/FlappyJayhawk2
class TestPowerUpDefs(unittest.TestCase):
    """
    Testcase for PowerUp Class Defintions
    """
    #Required testing variables
    testpipeimage = pygame.image.load(os.path.join('images', 'pipe.png'))
    testpipemanager = PipeManager(testpipeimage)
    testjayimage = pygame.image.load(os.path.join('images', 'jayhawk.png'))
    testjayhawk = Jayhawk(1, 1, (1, 1), testjayimage)
    testpipe = Pipe(testpipeimage, 300)
    testpowerup = PowerUp((0, 0, 0), (50, 50), 20, 0, testjayimage, 'test')

    #Sets up the test
    def setUp(self):
        """
        Sets up the test
        Prints short descriptions of the tests
        """
        currentTest = self.shortDescription()
        if (currentTest == "test_is_loadImports_working"):
            sys.stderr.write(
                "Testing if loadImports is returning a string ... ")
        elif (currentTest == "test_is_scroll_working"):
            sys.stderr.write("Testing if scroll is scrolling to left ... ")
        elif (currentTest == "test_is_circle_color_working"):
            sys.stderr.write(
                "Testing if circle color is returning a color ... ")
        elif (currentTest == "test_is_circle_pos_working"):
            sys.stderr.write(
                "Testing if circle position is returning a tuple of two arguments ... "
            )
        elif (currentTest == "test_is_circle_radius_working"):
            sys.stderr.write(
                "Testing if circle radius is returning an int ... ")
        elif (currentTest == "test_is_circle_width_working"):
            sys.stderr.write(
                "Testing if circle width is returning an int ... ")
        elif (currentTest == "test_is_image_working"):
            sys.stderr.write(
                "Testing if something is being passed into image ... ")
        elif (currentTest == "test_is_image_rect_working"):
            sys.stderr.write(
                "Testing if image rect is returning type rect ... ")
        elif (currentTest == "test_is_update_duration_working"):
            sys.stderr.write(
                "Testing if update duration is decreasing the duration time ... "
            )
        elif (currentTest == "test_is_duration_expired_working"):
            sys.stderr.write(
                "Testing if duration expired is returning proper booleans for duration time ... "
            )
        else:
            sys.stderr.write("Unnamed test ... ")

    #Tears down the tests
    def tearDown(self):
        """
        Cleans up after the test
        Nothing is required here
        """

    #Testing if loadImports definition is working
    #Checks if loadImports is loading proper strings
    #Asserts True if loadImports is passing a string
    def test_is_loadImports_working(self):
        """test_is_loadImports_working"""
        self.assertEqual(type(loadImports(".")), str,
                         "loadImports passing back a string FAILED")

    #Testing if scroll definition is working
    #Asserts if scroll is scrolling to the left
    def test_is_scroll_working(self):
        """test_is_scroll_working"""
        self.unscrolledPos = TestPowerUpDefs.testpowerup.x
        TestPowerUpDefs.testpowerup.scroll()
        self.assertTrue(TestPowerUpDefs.testpowerup.x < self.unscrolledPos,
                        "Scroll moves powerup to left FAILED")

    #Testing if circle_color definition is working
    #Asserts if circle color is returning a color
    def test_is_circle_color_working(self):
        """test_is_circle_color_working"""
        self.assertEqual(type(TestPowerUpDefs.testpowerup.circle_color), tuple,
                         "Circle color is returning type tuple FAILED")
        self.assertTrue(
            len(TestPowerUpDefs.testpowerup.circle_color) == 3,
            "Circle color is not returning 3 tuple arguments")

    #Testing if circle_pos definition is working
    #Asserts if circle pos is returning a tuple of a valid position
    def test_is_circle_pos_working(self):
        """test_is_circle_pos_working"""
        self.assertEqual(type(TestPowerUpDefs.testpowerup.circle_pos), tuple,
                         "Circle pos is returning type tuple FAILED")
        self.assertTrue(
            len(TestPowerUpDefs.testpowerup.circle_pos) == 2,
            "Circle pos is not returning 2 tuple arguments")

    #Testing if circle_radius definition is working
    #Asserts if circle radius is returning a int
    def test_is_circle_radius_working(self):
        """test_is_circle_radius_working"""
        self.assertEqual(type(TestPowerUpDefs.testpowerup.circle_radius), int,
                         "Circle radius is returning type int FAILED")

    #Testing if circle_width definition is working
    #Asserts if circle width is returning a int
    def test_is_circle_width_working(self):
        """test_is_circle_width_working"""
        self.assertEqual(type(TestPowerUpDefs.testpowerup.circle_width), int,
                         "Circle width is returning type int FAILED")

    #Testing if image definition is working
    #Asserts if image is not returning nothing
    def test_is_image_working(self):
        """test_is_image_working"""
        self.assertNotEqual(type(TestPowerUpDefs.testpowerup.image), None,
                            "image is not returnong nothing FAILED")

    #Testing if image_rect definition is working
    #Asserts if image_rect is returning a rect
    def test_is_image_rect_working(self):
        """test_is_image_rect_working"""
        self.assertEqual(type(TestPowerUpDefs.testpowerup.image_rect),
                         pygame.Rect,
                         "image rect is returning type rect FAILED")

    #Testing if update_duration definition is working
    #Asserts if update_duration is shortening the duration of the powerup
    def test_is_update_duration_working(self):
        """test_is_update_duration_working"""
        self.notUpdatedDuration = TestPowerUpDefs.testpowerup.duration_remaining
        TestPowerUpDefs.testpowerup.update_duration()
        self.assertTrue(
            TestPowerUpDefs.testpowerup.duration_remaining <
            self.notUpdatedDuration, "Duration decreases FAILED")

    #Testing if duration_expired definition is working
    #Asserts if duration_expired is returning false if duration remains and true if duration expired
    def test_is_duration_expired_working(self):
        """test_is_duration_expired_working"""
        TestPowerUpDefs.testpowerup.duration_remaining = 300
        self.assertEqual(
            TestPowerUpDefs.testpowerup.duration_expired, False,
            "Duration expired returning false on duration not expired FAILED")
        TestPowerUpDefs.testpowerup.duration_remaining = 0
        self.assertEqual(
            TestPowerUpDefs.testpowerup.duration_expired, True,
            "Duration expired returning true on duration expired FAILED")
コード例 #8
0
ファイル: main.py プロジェクト: RishKhanna/Brick_Game
        if (Balls[0].attached == False):
            try:
                next_block = present_board[Balls[0].y +
                                           Balls[0].v_y][Balls[0].x +
                                                         Balls[0].v_x]
                if ((next_block == "3") or (next_block == "2")
                        or (next_block == "1") or (next_block == "N")):
                    Bricks = bricks.Brick_collision(Bricks, Balls[0].x,
                                                    Balls[0].y, Balls[0].v_x,
                                                    Balls[0].v_y)
                    present_points += 10
                    Balls[0].v_x *= -1
                    Balls[0].v_y *= -1
                    if (np.random.randint(10) > 3):
                        PowerUps.append(
                            PowerUp.PowerUp(Balls[0].x - Balls[0].v_x,
                                            Balls[0].y - Balls[0].v_y))
                if (next_block == "E"):
                    Balls[0].v_x *= -1
                    Balls[0].v_y *= -1
                    Bricks = bricks.Explode(Bricks, Balls[0].x - Balls[0].v_x,
                                            Balls[0].y - Balls[0].v_y)

                present_board = Fresh_Board
                present_board = Paddle.move(1, present_board)
                present_board = Paddle.move(-1, present_board)
                for i in Bricks:
                    present_board = i.display(present_board)
            except:
                pass

        if (Balls[0].attached == False):
コード例 #9
0
ファイル: lib.py プロジェクト: JonathanB05/BulletHeck
def spawn_powerups(chance, powerups):
    if random.random() <= chance/FRAMERATE:  # This makes it so that the chance is per second
        x = PowerUp.PowerUp(random.randint(8, 8))
        powerups.append(x)