コード例 #1
0
 def update (self):
     if (self.walkTimer.check_timer()):
         self.walkTimer = essentials.timer (0.125)
         if self.currentSprite < 3:
             self.currentSprite+=1
         else:
             self.currentSprite = 0
     self.guard = pygame.draw.rect(display.window, (122,122,122), pygame.Rect((self.position[0], self.position[1]), self.size))
     display.window.blit(self.image[self.currentSprite], self.position)
     self.position [0] -= 20
コード例 #2
0
 def __init__ (self):
     self.image = [
         pygame.image.load('pkg/level4/images/copLeft2.png'),
         pygame.image.load('pkg/level4/images/copLeft1.png'),
         pygame.image.load('pkg/level4/images/copLeft3.png'),
         pygame.image.load('pkg/level4/images/copLeft1.png')
     ]
     self.walkTimer = essentials.timer(0.125)
     self.currentSprite = 0
     self.position = [1280, 480]
     self.size = (100, 200)
コード例 #3
0
 def update (self):
     if (self.walkTimer.check_timer()):
         self.walkTimer = essentials.timer (0.125)
         if self.currentSprite < 3:
             self.currentSprite+=1
         else:
             self.currentSprite = 0
     if not self.end_game_active:
         self.rect = pygame.draw.rect(display.window, (122, 122, 122), pygame.Rect(self.position, self.size))
     if self.isCrawling:
         display.window.blit(self.crawlImages[self.currentSprite], self.position)
     else:
         display.window.blit(self.image[self.currentSprite], self.position)
     self.size.y = 200
     self.position.y = 480
     self.isCrawling = False
コード例 #4
0
 def __init__(self):
     self.end_game_active = False
     self.isCrawling = False
     self.rect = pygame.draw.rect(display.window, (122, 122, 122), pygame.Rect(self.position, self.size))
     self.image = [
         pygame.image.load('pkg/level4/images/1.walkRight.png'),
         pygame.image.load('pkg/level4/images/2.walkRight.png'),
         pygame.image.load('pkg/level4/images/3.walkRight.png'),
         pygame.image.load('pkg/level4/images/4.walkRight.png')
     ]
     self.crawlImages = [
         pygame.image.load('pkg/level4/images/1.crawl.png'),
         pygame.image.load('pkg/level4/images/2.crawl.png'),
         pygame.image.load('pkg/level4/images/3.crawl.png'),
         pygame.image.load('pkg/level4/images/4.crawl.png')
     ]
     self.walkTimer = essentials.timer(0.125)
     self.currentSprite = 0
コード例 #5
0
def run():
    global running
    global pygame

    #while running play the music
    pygame.mixer.init(44100, -16, 2, 2048)
    pygame.mixer.Channel(1).play(
        pygame.mixer.Sound('pkg/level2/sounds/elevator.wav'))

    timer = essentials.timer(3)

    #groups
    playergroup = pygame.sprite.Group()
    all_sprites = pygame.sprite.Group()
    background = pygame.sprite.Group()
    walls = pygame.sprite.Group()
    levelwalls = pygame.sprite.Group()
    enemygroup = pygame.sprite.Group()
    tafelgroup = pygame.sprite.Group()

    #Enemy waypoints
    waypoints = [[620, 100], [735, -455], [1890, -550], [1890, -450],
                 [615, -545]]
    #Enemy2 waypoints
    waypoints2 = [[1130, 165], [1115, 315], [1135, -210], [1680, -210],
                  [1680, 165]]
    #Enemy3 waypoints
    waypoints3 = [[2175, 290], [1300, 350], [1300, 290], [2175, 350]]
    #Enemy4 waypoints
    waypoints4 = [[1800, 0], [1975, -125], [2300, -130], [2300, 120],
                  [1970, 120]]
    #player position
    player = Player(((width / 2), (height / 2)))

    #side, top and bottom walls
    walltop = TopAndBottomWall(540, -620, all_sprites, walls)
    wallbottom = TopAndBottomWall(540, 410, all_sprites, walls)
    wallleft = SideWall((width / 2) - 100, (height / 2) - 930, all_sprites,
                        walls)
    wallright = SideWall((wallleft.rect.x + (1920 - 50)), (height / 2) - 930,
                         all_sprites, walls)

    ##horizontal and vertical walls
    #three in the beginning of the level
    wallvertical1 = VerticalWall(740, 230, levelwalls, walls)
    wallhorizontal1 = HorizontalWall(740, 180, levelwalls, walls)
    wallvertical2 = VerticalWall(940, 30, levelwalls, walls)

    #top part of the level
    wallvertical3 = VerticalWall(790, -370, levelwalls, walls)
    wallhorizontal2 = HorizontalWall(840, -370, levelwalls, walls)
    wallhorizontal3 = HorizontalWall(1040, -370, levelwalls, walls)
    wallhorizontal4 = HorizontalWall(1240, -370, levelwalls, walls)
    wallhorizontal5 = HorizontalWall(1440, -370, levelwalls, walls)
    wallhorizontal6 = HorizontalWall(1640, -370, levelwalls, walls)
    wallvertical3 = VerticalWall(1840, -370, levelwalls, walls)
    wallvertical4 = VerticalWall(2140, -370, levelwalls, walls)

    #bottom part of the level
    wallvertical5 = VerticalWall(1190, 230, levelwalls, walls)
    wallhorizontal7 = HorizontalWall(1690, 230, levelwalls, walls)
    wallhorizontal8 = HorizontalWall(2240, 230, levelwalls, walls)

    #big block in the middle
    wallhorizontal9 = HorizontalWall(1340, -70, levelwalls, walls)
    wallhorizontal10 = HorizontalWall(1340, -20, levelwalls, walls)
    wallhorizontal11 = HorizontalWall(1340, 30, levelwalls, walls)
    wallhorizontal12 = HorizontalWall(1340, 80, levelwalls, walls)

    #small block in the middle
    wallhorizontal13 = HorizontalWall(2040, -20, levelwalls, walls)
    wallhorizontal14 = HorizontalWall(2040, 30, levelwalls, walls)

    #enemy's
    enemy = Enemy((620, 50), waypoints, enemygroup)
    enemy2 = Enemy2((1115, 315), waypoints2, enemygroup)
    enemy3 = Enemy3((1900, -100), waypoints3, enemygroup)
    enemy4 = Enemy4((1900, -100), waypoints4, enemygroup)

    #the floor
    floor = Floor(540, -620, background)

    #tafel
    tafel = Tafel(2300, 300, tafelgroup)

    #camera
    camera = Vector2(0, 0)

    display.set_title('Level 2')

    #animated sprite
    clock = pygame.time.Clock()
    dt = clock.tick(60)

    while running:
        # Input
        for event in pygame.event.get():
            running = essentials.run_essentials(event)
            if not running:
                return True
            #player movement
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    player.vel.x = 5
                    player.vel.y = 0
                elif event.key == pygame.K_LEFT:
                    player.vel.x = -5
                    player.vel.y = 0
                elif event.key == pygame.K_UP:
                    player.vel.y = -5
                    player.vel.x = 0
                elif event.key == pygame.K_DOWN:
                    player.vel.y = 5
                    player.vel.x = 0
                if event.key == pygame.K_b:
                    pygame.mixer.Channel(0).stop()
                    pygame.mixer.Channel(1).stop()
                    return True

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT and player.vel.x > 0:
                    player.vel.x = 0
                elif event.key == pygame.K_LEFT and player.vel.x < 0:
                    player.vel.x = 0
                elif event.key == pygame.K_UP:
                    player.vel.y = 0
                elif event.key == pygame.K_DOWN:
                    player.vel.y = 0

        #update all the groups
        enemygroup.update()
        all_sprites.update()
        playergroup.update()
        background.update()
        walls.update()
        tafelgroup.update()

        ##player collision with walls
        # move player horizontal
        player.rect.x += player.vel.x
        # check collision horizontal
        if pygame.sprite.spritecollide(player, walls, False):
            # move it back
            player.rect.x -= player.vel.x
            # reset speed
            player.vel.x = 0

        # move player vertical
        player.rect.y += player.vel.y
        # check collision vertical
        if pygame.sprite.spritecollide(player, walls, False):
            # move it back
            player.rect.y -= player.vel.y
            # reset speed
            player.vel.y = 0

        camera -= player.vel

        display.window.fill((0, 0, 0))

        #draw background
        for sprite in background:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw walls in level
        for sprite in levelwalls:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        # draw player and walls
        for sprite in all_sprites:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw enemy's
        for sprite in enemygroup:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)

        #draw tafel
        for sprite in tafelgroup:
            display.window.blit(sprite.image, sprite.rect.topleft + camera)
        #draw player
        display.window.blit(player.image, player.rect.topleft + camera)

        #update all the groups
        all_sprites.update()
        playergroup.update()
        background.update()
        walls.update()
        tafelgroup.update()

        # collision with enemy
        if pygame.sprite.spritecollide(player, enemygroup, False):
            #show busted
            display.window.blit(busted, [400, 150])
            #load hasta la vista
            hastalavista = pygame.mixer.music.load(
                "pkg/level2/sounds/hastalavista.wav")
            #play arnold sound
            pygame.mixer.music.play(0)
            display.update()
            time.sleep(3)
            return False

        #collision with table
        if pygame.sprite.spritecollide(player, tafelgroup, False):
            #show arnold face
            display.window.blit(gettothechopper, [0, 0])
            #load arnold chopper sound
            pygame.mixer.music.load("pkg/level2/sounds/gettothechopper.wav")
            #play arnold chopper sound
            pygame.mixer.music.play(0)
            display.update()
            time.sleep(6)
            return True

            # Load in the fundemental functions in the game

        # Output

        ## Update the display to show the changes you made
        # counter for player animation
        player.counter(dt)
        player.counter2(dt)
        player.counter3(dt)
        player.counter4(dt)

        ##counter for enemy animation
        enemy.counter(dt)
        enemy2.counter(dt)
        enemy3.counter(dt)
        enemy4.counter(dt)
        enemygroup.update()

        display.update()
コード例 #6
0
ファイル: main.py プロジェクト: florisdegraaff/project-2-game
def run():
    global running
    global pygame

    jumping = False
    crawling = False

    player = Player()
    enemies = []

    display.set_title('Level 3')
    timer = essentials.timer(30)
    enemy_spawn_timer = essentials.timer(0)

    pygame.mixer.Channel(1).set_volume(0.4)
    pygame.mixer.Channel(1).play(pygame.mixer.Sound('files/sounds/run.wav'))
    while running == True:

        display.prepare_update()

        # Input
        for event in pygame.event.get():
            # Load in the fundemental functions in the game
            running = essentials.run_essentials(event)
            if not running:
                return True

            if event.type == pygame.KEYDOWN:
                if not jumping:
                    if event.key == pygame.K_SPACE:
                        jumping = True
                    elif event.key == pygame.K_LCTRL:
                        crawling = True
                if event.key == pygame.K_b:
                    pygame.mixer.Channel(1).stop()
                    return True

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LCTRL:
                    crawling = False
        if running:
            if timer.check_timer():
                helicopter = Helicopter()
                helicopter.update()
                player.end_game()
                if player.position.x > helicopter.position.x:
                    pygame.mixer.Channel(1).stop()
                    return True
            else:
                if enemy_spawn_timer.check_timer():
                    enemy_spawn_timer = essentials.timer(randint(1, 3))
                    if randint(0, 1) == 0:
                        enemies.append(Guard())
                    else:
                        enemies.append(Bullets())

        # Output
        pygame.font.init()
        myFont = pygame.font.SysFont('Sans Serif', 48)
        textsurface = myFont.render(str(timer.get_time() / 1000), False,
                                    (0, 0, 0))

        pygame.draw.rect(display.window, (0, 0, 0),
                         pygame.Rect((0, 680), (1280, 40)))

        if crawling:
            player.crawl()
        elif jumping:
            jumping = player.jump()

        for enemy in enemies:
            enemy.update()
            if isinstance(enemy, Guard):
                if player.rect.colliderect(enemy.guard):
                    return False
            else:
                if player.rect.colliderect(
                        enemy.bullet1) or player.rect.colliderect(
                            enemy.bullet2) or player.rect.colliderect(
                                enemy.bullet3):
                    return False

        if not running:
            return True

        display.window.blit(textsurface, (0, 0))
        player.update()

        # Update the display to show the changes you made
        display.update()