Exemple #1
0
    def use(self, w, h, board, menu):
        if start_field[w][h] == 0 and menu[board.id][1] > 0:
            start_field[w][h] = 4
            group = pygame.sprite.Group()
            FieldImage(h * board.cell_size, w * board.cell_size,
                       start_field[w][h], group)
            group.draw(screen)
            menu[board.id][1] -= 1

            x = board.id % menu_size_x
            y = int(board.id / menu_size_y)

            group_menu = pygame.sprite.Group()
            CellMenu(board.cell_size * (board_size_x + x), y * board.cell_size,
                     group_menu)
            group_menu.draw(screen)

            group = pygame.sprite.Group()
            MenuImage(board.cell_size * (board_size_x + x),
                      y * board.cell_size, self.image, group)
            group.draw(screen)
            font = pygame.font.SysFont('arial', 11)
            text = font.render(str(menu[board.id][1]), 1, (0, 0, 0))
            screen.blit(
                text,
                (board.cell_size * (board_size_x + x) + 28 -
                 3 * len(str(menu[board.id][1])), y * board.cell_size + 23))
            return menu
Exemple #2
0
 def show(self, w, h, cnt=0):
     group = pygame.sprite.Group()
     MenuImage(w, h, self.image, group)
     group.draw(screen)
     font = pygame.font.SysFont('arial', 11)
     text = font.render(str(cnt), 1, (0, 0, 0))
     screen.blit(text, (w + 28 - 3 * len(str(cnt)), h + 23))
Exemple #3
0
 def end_game(self, position_hero):
     if position_hero == self.position_arrival:
         if len(self.seringue) == 3:
             print("C'est gagné")
             screen.blit(win, self.position_start)
         else:
             print('Cest perdu')
             screen.blit(lost, self.position_start)
Exemple #4
0
 def show(self, w, h, cnt=-1):
     if cnt == -1:
         cnt = objects_array[self.id]
     group = pygame.sprite.Group()
     MenuImage(w, h, self.image, group)
     group.draw(screen)
     font = pygame.font.SysFont('arial', 11)
     text = font.render(str(cnt), 1, (120, 120, 120))
     screen.blit(text, (w + 28 - 3 * len(str(cnt)), h + 23))
Exemple #5
0
    def run(self):
        running = True
        tower_menu = Menus()
        frame = 1000
        tick = 16
        spawn_tick = 250
        
        #proof = Towers((5, 5))

        tower_menu.draw(screen)
        ground = self.load_level(2)

        sprite_terrain.draw(background) # Draws background terrain
        window.blit(background, (0, 0))

        pygame.display.update()

        grid = pathfinder.AStar()
        grid.init_path(grid_row, grid_col, self.road, self.start, self.end)
        route = grid.process()
        render_sprites = pygame.sprite.LayeredUpdates(sprite_terrain, sprite_path, layer=1)

        while running:

            for event in pygame.event.get():
                mouse_pos = pygame.mouse.get_pos()
                ratio_x = (window.get_width() / screen.get_width())
                ratio_y = (window.get_height() / screen.get_height())
                mouse_scaled = (mouse_pos[0] / ratio_x, mouse_pos[1] / ratio_y)
                if event.type == pygame.QUIT:
                    running = False
                    sys.exit(0)
                if event.type == pygame.MOUSEBUTTONDOWN:
                    # check for left button
                    if event.button == 1:
                    #    if tower_menu.basic_tower_button.collidepoint(mouse_scaled):
                    #         tower_menu.click(screen, tower_menu.basic_tower_button, True)
                    #     elif tower_menu.ice_tower_button.collidepoint(mouse_scaled):
                    #         tower_menu.click(screen, tower_menu.ice_tower_button, True)
                        for x in range(grid_col):
                            for y in range(grid_row):
                                if pygame.Rect(ground[x][y].location).collidepoint(mouse_scaled):
                                    if ground[x][y].can_place:
                                        self.towers.append(Towers(ground[x][y].location))
                                        ground[x][y].can_place = False
                                        render_sprites.add(sprite_towers, layer=2)
                        for num in range(len(self.minion)):
                            if self.minion[num].sprite.rect.collidepoint(mouse_scaled):
                                self.minion[num].health = 0
                # if event.type == pygame.MOUSEBUTTONUP:
                #     if event.button == 1:
                #         # if tower_menu.state:
                #         #     tower_menu.click(screen, tower_menu.basic_tower_button, False)
                # # if tower_menu.basic_tower_button.collidepoint(mouse_scaled) and not tower_menu.over:
                # #     tower_menu.hover(screen, tower_menu.basic_tower_button)
                # # elif tower_menu.over and not tower_menu.basic_tower_button.collidepoint(mouse_scaled):
                # #     tower_menu.hover_off(screen, tower_menu.basic_tower_button)

            if time() > tick:
                tick = time() + 17
                kill = []
                minion_hitboxs = []

                for num in range(len(self.minion)):
                    if self.minion[num]:
                        if not self.minion[num].alive:
                            kill.append(num)
                        elif self.minion[num].health > 0:
                            self.minion[num].update_location(route)
                            minion_hitboxs.append(self.minion[num].sprite.rect)

                if len(kill) > 0: # If there are minions to kill in the list this del them
                    for d in range(len(kill)):
                        del self.minion[kill[d]]
                    kill = []

                for num in range(len(self.towers)):
                    current_tower = self.towers[num]
                    collision_index = current_tower.hit_box.rect.collidelist(minion_hitboxs)
                    if not collision_index == -1 and current_tower.target == None:
                        current_tower.target = collision_index
                    elif not current_tower.target == collision_index:
                        current_tower.target = None
                    if not current_tower.target == None:
                        self.minion[current_tower.target].health -= current_tower.damage
                #Clears then render sprites to display
                render_sprites.remove_sprites_of_layer(3)
                render_sprites.add(sprite_creeps, layer=3)

            if time() > frame: # Update minion animation frames
                frame = 80 + time()
                for num in range(len(self.minion)):
                    if self.minion[num].health <= 0:
                        if self.minion[num].update(12) == "dead":
                            self.minion[num].alive = False
                    else:
                        self.minion[num].update()

                for num in range(len(self.towers)):
                    self.towers[num].update()

            if time() > spawn_tick:
                if wave_Count >= len(self.minion):
                    spawn_type = random.choice([Dwarf, Deer, Satyr, Hunter, Druid, Pixie])
                    #spawn_type = [Dwarf, Deer, Satyr, Hunter, Druid, Pixie]
                    self.minion.append(spawn_type(self.spawn))
                    spawn_tick = time() + 500
                render_sprites.add(sprite_creeps, layer = 3)

                #if wave_Count >= len(self.minion):
                #    self.minion.append(Deer(self.spawn))
                #    spawn_tick = time() + 500
                #render_sprites.add(sprite_creeps)

            clock.tick()
            render_sprites.draw(screen)
            #for num in range(len(self.towers)):
            #    screen.blit(self.towers[num].hit_box.image, (self.towers[num].sprite.rect.center))
            fps = myfont.render(str(int(clock.get_fps())), 1, (255, 255, 255), (15, 210, 50))
            screen.blit(fps, (20, screen_height - 30))
            window.blit((render_to_window(screen)), (0, 0))
            pygame.display.update()
def intro(clock,screen):

    game_icon=pygame.image.load(os.path.join('assets','icon.png'))
    pygame.display.set_icon(game_icon)
    pygame.display.set_caption('QUARENTINE: THE PANDEMIC GAME')


    mixer.music.load(os.path.join('assets','alexander-nakarada-chase.ogg'))
    mixer.music.play(-1)

    for i in range(1,20):
        clock.tick(20)
        if i<10:
            image='ezgif-frame-00{}.png'.format(str(i))
        else:
            image='ezgif-frame-0{}.png'.format(str(i))
        image=pygame.image.load(os.path.join('assets','Intro I', image))
        image=pygame.transform.scale(image, (SCREEN_WIDTH, SCREEN_HEIGHT))
        screen.blit(image, (0, 0))
        pygame.display.update()

    for i in range(1,51):
        clock.tick(100)
        if i<10:
            image='ezgif-frame-00{}.png'.format(str(i))
        else:
            image='ezgif-frame-0{}.png'.format(str(i))
        image=pygame.image.load(os.path.join('assets','Intro II', image))
        image=pygame.transform.scale(image, (SCREEN_WIDTH, SCREEN_HEIGHT))
        screen.blit(image, (0, 0))
        pygame.display.update()

    background = pygame.Surface(screen.get_size())
    background = background.convert()

    for i in range(0,15):
        clock.tick(20)
        possibleColors=[(250, 250, 250),(250, 0, 0),(0, 0, 0)]
        background.fill(possibleColors[i%3])
        screen.blit(background, (0, 0))
        pygame.display.update()

    start=False
    while(not start):
        clock.tick(10)
        image=pygame.image.load(os.path.join('assets','Quarantine The Pandemic Game.png'))
        image=pygame.transform.scale(image, (SCREEN_WIDTH, SCREEN_HEIGHT))
        screen.blit(image, (0, 0))
        pygame.display.update()
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONUP:
                x,y=pygame.mouse.get_pos()
                if x>=600*SCREEN_WIDTH/1600 and x<=880*SCREEN_WIDTH/1600:
                    if y>=710*SCREEN_HEIGHT/900 and y<=830*SCREEN_HEIGHT/900:
                        start=True
            if event.type == pygame.QUIT:
                pygame.quit()
    for i in range(1,126):
        if i==22:
            clock.tick(0.5)
        elif i==47:
            clock.tick(0.5)
        elif i==73:
            clock.tick(0.5)
        elif i==96:
            clock.tick(0.2)
        else:
            clock.tick(15)
        if i<10:
            image='ezgif-frame-00{}.png'.format(str(i))
        elif i<100:
            image='ezgif-frame-0{}.png'.format(str(i))
        else:
            image='ezgif-frame-{}.png'.format(str(i))
        image=pygame.image.load(os.path.join('assets','Inicio do Jogo', image))
        image=pygame.transform.scale(image, (SCREEN_WIDTH, SCREEN_HEIGHT))
        screen.blit(image, (0, 0))
        pygame.display.update()
Exemple #7
0
 def counter_items(self, black):
     score = f"{len(self.seringue)}  items ramassés sur 3"
     myfont = pygame.font.SysFont("monospace", 16)
     counter_items = myfont.render(score, 1, (255, 255, 0))
     screen.blit(black, (self.position_information))
     screen.blit(counter_items, (self.position_information))