예제 #1
0
    def run(self):
        gameover = False
        FPS = 60
        clock = py.time.Clock()

        en = Enemy(xCoor + self.row_count * self.blockSize - self.blockSize,
                   yCoor + self.blockSize, self.blockSize, self.gridarr)

        while not gameover:
            self.screen.fill((0, 0, 0))
            self.DrawGrid()
            en.Draw(self.screen, self.row_count, self.column_count)
            for event in py.event.get():
                if event.type == py.QUIT:
                    gameover = True
            #Sets the frames per second the run loop will draw things onto the screen
            clock.tick(FPS)
            py.display.update()
예제 #2
0
 def spawnEnemy(self, eI, doIt=True):
     #print('hey lol', self.useNodes)
     if not doIt:
         return False
     en = self.enemyProps[eI]
     self.enemies.add(
         Enemy(
             en['appearance'], en['animTime'], en['speed'], en['hp'],
             pygame.Rect(self.useNodes[0][0], self.useNodes[0][1], 50, 50),
             self.useNodes, en['bounty']))
예제 #3
0
    def __init__(self, segment_id, start_point, platforms, spikes, coins,
                 enemies, projectiles):
        self.position = start_point

        self.platforms = platforms
        self.spikes = spikes
        self.coins = coins
        self.enemies = enemies

        self.my_platforms = []
        self.my_spikes = []
        self.my_coins = []
        self.my_enemies = []

        segment_dict = segment_dicts[segment_id]
        self.length = segment_dict['length']

        for platform in segment_dict['platforms']:
            Platform((platform['x'] + self.position, platform['y']),
                     platform['length'], self.my_platforms)

        for spike in segment_dict['spikes']:
            miscClasses.Spike((spike['x'] + self.position, spike['y']),
                              self.my_spikes)

        for coin in segment_dict['coins']:
            miscClasses.Coin((coin['x'] + self.position, coin['y']),
                             self.my_coins, self.coins)

        for enemy in segment_dict['enemies']:
            Enemy((enemy['x'] + self.position, enemy['y']), self.my_enemies,
                  self.enemies, projectiles)

        for platform in self.my_platforms:
            self.platforms.append(platform)
        for spike in self.my_spikes:
            self.spikes.append(spike)
        for coin in self.my_coins:
            self.coins.append(coin)
        for enemy in self.my_enemies:
            self.enemies.append(enemy)
예제 #4
0
level5_buttons = [button_Previous3]

#create groups for sprites
all_sprites_list = pygame.sprite.Group()
all_enemies_list = pygame.sprite.Group()

#create player
playerMain = Player(80, 80, 20)
playerMain.rect.x = SCREENWIDTH / 2
playerMain.rect.y = SCREENHEIGHT - 100

all_sprites_list.add(playerMain)

#create zombies
for i in range(5):  # make 5 zombies for now
    zombie = Enemy(80, 80, 2)  #make enemies the same size as the player
    zombie.rect.x = random.randint(0, SCREENWIDTH - 80)
    zombie.rect.y = random.randint(-400, -200)
    all_sprites_list.add(zombie)
    all_enemies_list.add(zombie)

#---------Main Program Loop----------
screen.blit(background, (0, 0))
while carryOn:
    # --- Main event loop ---
    for event in pygame.event.get():  # Player did something
        if event.type == pygame.QUIT:  # Player clicked close button
            carryOn = False
        elif event.type == pygame.MOUSEBUTTONDOWN:  # Player clicked the mouse
            mousebuttondown(level)
#arrange button groups depending on level
level1_buttons = [button_HELLO, button_SETTINGS, button_QUIT]
level2_buttons = [
    button_Previous2,
    button_Sound,
]
level3_buttons = [button_ON, button_OFF, button_Previous2]
level4_buttons = [button_Previous3, button_CONTINUE]
level5_buttons = [button_Previous3]

#create player
playerMain = Player(80, 80, 20)
playerMain.rect.x = SCREENWIDTH / 2
playerMain.rect.y = SCREENHEIGHT - 120

enemy1 = Enemy(80, 80, 80)
enemy1.rect.x = 50
enemy1.rect.y = -200

enemy2 = Enemy(80, 80, 80)
enemy2.rect.x = 200
enemy2.rect.y = -200

enemy3 = Enemy(80, 80, 80)
enemy3.rect.x = 350
enemy3.rect.y = -200

enemy4 = Enemy(80, 80, 80)
enemy4.rect.x = 500
enemy4.rect.y = -200