Esempio n. 1
0
    def __draw_score(self):
        total_score = self.font.render(
            'Score:' + str(self.total_score) + ',' + str(self.total_score2),
            False, Utils.get_color(Utils.WHITE))
        self.screen.blit(
            total_score,
            (10, self.screen_size + total_score.get_height() / 1.3))

        life = self.font.render('Energy:', False, Utils.get_color(Utils.WHITE))
        self.screen.blit(life,
                         (self.screen_size / 2 - life.get_width() / 2,
                          self.screen_size + total_score.get_height() / 1.3))
Esempio n. 2
0
 def __draw_life(self):
     if self.total_score < 50:
         self.life_fq = 10
     elif self.total_score < 100:
         self.life_fq = 9
     elif self.total_score < 150:
         self.life_fq = 8
     elif self.total_score < 200:
         self.life_fq = 7
     elif self.total_score < 250:
         self.life_fq = 6
     elif self.total_score < 300:
         self.life_fq = 5
     elif self.total_score < 350:
         self.life_fq = 4
     elif self.total_score < 400:
         self.life_fq = 3
     elif self.total_score < 450:
         self.life_fq = 2
     else:
         self.life_fq = 1
     if self.frames_count % self.life_fq == 0:
         self.life = self.life - 2 * GlobalConstants.LIVES_FACTOR_SPEED
     if self.life < 0:
         self.life = 0
         self.end_of_game = True
     max_width = self.screen_size / 2.6
     current_width = max_width * self.life / 100
     pygame.draw.rect(self.screen, Utils.get_color(Utils.WHITE), [
         self.screen_size / 2 + self.tile_size / 1.5, self.screen_size +
         self.tile_size / 8, current_width, self.tile_size / 4
     ])
Esempio n. 3
0
    def __draw_score(self):

        total_score = self.font.render(str(self.total_score) + " " + str(self.total_score_2) + " " +
                                       str(self.total_score_3),
                                       False, Utils.get_color(Utils.BLACK))
        self.screen.blit(total_score, (self.screen_size/2 - total_score.get_width()/2,
                                       self.screen_size - total_score.get_height()*2))
Esempio n. 4
0
 def __draw_score(self):
     total_score = self.font.render(
         str(self.total_score) + " " + str(self.total_score_2), False,
         Utils.get_color(Utils.WHITE))
     self.screen.blit(total_score,
                      (self.width / 2 - total_score.get_width() / 2,
                       self.height - total_score.get_height() * 2))
Esempio n. 5
0
    def __update_map(self):
        self.map.fill(Utils.get_color(Utils.BLACK))

        index = 0
        for robot in self.robots:
            if type(robot) is MilkRobotSprite:
                if robot.error:
                    self.map_sprites[index][1].draw(self.map)
                elif robot.picked:
                    self.map_sprites[index][0].draw(self.map)
                index += 1
Esempio n. 6
0
    def __draw_score(self):
        score_str = 'Score: '
        for i in range(self.num_of_objs):
            score_str += str(self.total_score[i])
            if i < self.num_of_objs - 1:
                score_str += ','

        total_score = self.font.render(score_str, False,
                                       Utils.get_color(Utils.WHITE))
        self.screen.blit(
            total_score,
            (10, self.screen_size + total_score.get_height() / 1.3))
Esempio n. 7
0
    def __render(self):

        # Handle user event
        if self.rd:
            self.__handle_event()

        # Draw background first
        self.screen.fill(Utils.get_color(Utils.BLACK))

        # Update sprites
        self.sprites.update()

        # Redraw all sprites
        self.sprites.draw(self.screen)

        # Redraw conveyors
        self.conveyor_sprites.draw(self.screen)

        # Redraw milks
        self.milk_sprites.draw(self.screen)

        # Redraw target
        self.target_sprites.draw(self.screen)

        # Redraw robots
        self.robot_sprites.draw(self.screen)

        # Update map
        self.__update_map()

        # Show status
        self.__show_status()

        # Draw score
        self.__draw_score()

        # Check terminal state
        self.__check_goal()

        # Show to the screen what we're have drawn so far
        if self.rd:
            pygame.display.flip()

        # Maintain 20 fps
        pygame.time.Clock().tick(self.speed)

        # Calculate fps
        self.__calculate_fps()

        # Debug
        self.__print_info()
Esempio n. 8
0
    def __render(self):

        # Handle user event
        if self.rd:
            self.__handle_event()

        # Draw background first
        self.screen.fill(Utils.get_color(Utils.BLACK))

        # Draw land
        self.lands.draw(self.screen)

        # Update sprites
        self.sprites.update()

        # Redraw all sprites
        self.sprites.draw(self.screen)

        # Update player
        self.players.update()

        # Draw player
        self.players.draw(self.screen)

        # Draw lives
        self.__draw_life()

        # Draw score
        self.__draw_score()

        # Check terminal state
        self.__check_goal()

        # Show to the screen what we're have drawn so far
        if self.rd:
            pygame.display.flip()

        # Maintain 20 fps
        pygame.time.Clock().tick(self.speed)

        # Calculate fps
        self.__calculate_fps()

        # Debug
        self.__print_info()
Esempio n. 9
0
    def __add_resources(self):
        image = pygame.image.load(self.current_path +
                                  ResourceManager.HARD_WALL)
        if self.render:
            image = pygame.transform.scale(
                image, (self.tile_size, self.tile_size)).convert_alpha()
        else:
            image = pygame.transform.scale(image,
                                           (self.tile_size, self.tile_size))

        self.resources[ResourceManager.HARD_WALL] = image

        image = pygame.image.load(self.current_path +
                                  ResourceManager.SOFT_WALL)
        if self.render:
            image = pygame.transform.scale(
                image, (self.tile_size, self.tile_size)).convert_alpha()
        else:
            image = pygame.transform.scale(image,
                                           (self.tile_size, self.tile_size))
        self.resources[ResourceManager.SOFT_WALL] = image

        image = pygame.image.load(self.current_path + ResourceManager.SEA_WALL)
        if self.render:
            image = pygame.transform.scale(
                image, (self.tile_size, self.tile_size)).convert_alpha()
        else:
            image = pygame.transform.scale(image,
                                           (self.tile_size, self.tile_size))
        self.resources[ResourceManager.SEA_WALL] = image

        image = pygame.image.load(self.current_path + ResourceManager.BASE)
        if self.render:
            image = pygame.transform.scale(
                image, (self.tile_size, self.tile_size)).convert_alpha()
        else:
            image = pygame.transform.scale(image,
                                           (self.tile_size, self.tile_size))
        self.resources[ResourceManager.BASE] = image

        image_up = pygame.image.load(self.current_path +
                                     ResourceManager.PLAYER1_UP)
        image_left = pygame.transform.rotate(image_up, 90)
        image_right = pygame.transform.rotate(image_up, -90)
        image_down = pygame.transform.rotate(image_up, 180)
        if self.render:
            image_up = pygame.transform.scale(
                image_up,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_left = pygame.transform.scale(
                image_left,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_right = pygame.transform.scale(
                image_right,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_down = pygame.transform.scale(
                image_down,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
        else:
            image_up = pygame.transform.scale(
                image_up, (self.tile_size - 1, self.tile_size - 1))
            image_left = pygame.transform.scale(
                image_left, (self.tile_size - 1, self.tile_size - 1))
            image_right = pygame.transform.scale(
                image_right, (self.tile_size - 1, self.tile_size - 1))
            image_down = pygame.transform.scale(
                image_down, (self.tile_size - 1, self.tile_size - 1))
        self.resources[ResourceManager.PLAYER1_UP] = image_up
        self.resources[ResourceManager.PLAYER1_LEFT] = image_left
        self.resources[ResourceManager.PLAYER1_RIGHT] = image_right
        self.resources[ResourceManager.PLAYER1_DOWN] = image_down

        image_up = pygame.image.load(self.current_path +
                                     ResourceManager.PLAYER2_UP)
        image_left = pygame.transform.rotate(image_up, 90)
        image_right = pygame.transform.rotate(image_up, -90)
        image_down = pygame.transform.rotate(image_up, 180)
        if self.render:
            image_up = pygame.transform.scale(
                image_up,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_left = pygame.transform.scale(
                image_left,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_right = pygame.transform.scale(
                image_right,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_down = pygame.transform.scale(
                image_down,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
        else:
            image_up = pygame.transform.scale(
                image_up, (self.tile_size - 1, self.tile_size - 1))
            image_left = pygame.transform.scale(
                image_left, (self.tile_size - 1, self.tile_size - 1))
            image_right = pygame.transform.scale(
                image_right, (self.tile_size - 1, self.tile_size - 1))
            image_down = pygame.transform.scale(
                image_down, (self.tile_size - 1, self.tile_size - 1))
        self.resources[ResourceManager.PLAYER2_UP] = image_up
        self.resources[ResourceManager.PLAYER2_LEFT] = image_left
        self.resources[ResourceManager.PLAYER2_RIGHT] = image_right
        self.resources[ResourceManager.PLAYER2_DOWN] = image_down

        image_up = pygame.image.load(self.current_path +
                                     ResourceManager.ENEMY_UP)
        image_left = pygame.transform.rotate(image_up, 90)
        image_right = pygame.transform.rotate(image_up, -90)
        image_down = pygame.transform.rotate(image_up, 180)
        if self.render:
            image_up = pygame.transform.scale(
                image_up,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_left = pygame.transform.scale(
                image_left,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_right = pygame.transform.scale(
                image_right,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
            image_down = pygame.transform.scale(
                image_down,
                (self.tile_size - 1, self.tile_size - 1)).convert_alpha()
        else:
            image_up = pygame.transform.scale(
                image_up, (self.tile_size - 1, self.tile_size - 1))
            image_left = pygame.transform.scale(
                image_left, (self.tile_size - 1, self.tile_size - 1))
            image_right = pygame.transform.scale(
                image_right, (self.tile_size - 1, self.tile_size - 1))
            image_down = pygame.transform.scale(
                image_down, (self.tile_size - 1, self.tile_size - 1))
        self.resources[ResourceManager.ENEMY_UP] = image_up
        self.resources[ResourceManager.ENEMY_LEFT] = image_left
        self.resources[ResourceManager.ENEMY_RIGHT] = image_right
        self.resources[ResourceManager.ENEMY_DOWN] = image_down

        image = pygame.Surface([self.bullet_size, self.bullet_size])
        image.fill(Utils.get_color(Utils.WHITE))
        self.resources[ResourceManager.BULLET] = image

        image_1 = pygame.image.load(self.current_path +
                                    ResourceManager.EXPLOSION_1)
        image_2 = pygame.image.load(self.current_path +
                                    ResourceManager.EXPLOSION_2)
        image_3 = pygame.image.load(self.current_path +
                                    ResourceManager.EXPLOSION_3)
        if self.render:
            image_1 = pygame.transform.scale(
                image_1, (self.tile_size, self.tile_size)).convert_alpha()
            image_2 = pygame.transform.scale(
                image_2, (self.tile_size, self.tile_size)).convert_alpha()
            image_3 = pygame.transform.scale(
                image_3, (self.tile_size, self.tile_size)).convert_alpha()
        else:
            image_1 = pygame.transform.scale(image_1,
                                             (self.tile_size, self.tile_size))
            image_2 = pygame.transform.scale(image_2,
                                             (self.tile_size, self.tile_size))
            image_3 = pygame.transform.scale(image_3,
                                             (self.tile_size, self.tile_size))

        self.resources[ResourceManager.EXPLOSION_1] = image_1
        self.resources[ResourceManager.EXPLOSION_2] = image_2
        self.resources[ResourceManager.EXPLOSION_3] = image_3
Esempio n. 10
0
    def get_state(self):
        self.map.fill(Utils.get_color(Utils.BLACK))
        if self.multi_target:
            if self.strategy == 0:
                for enemy in self.enemies:
                    if enemy.pos_y > 5 or enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                    else:
                        enemy.is_in_map = False
            elif self.strategy == 1:
                for enemy in self.enemies:
                    if (enemy.pos_y >= 6
                            and enemy.pos_y <= 8) or enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                    else:
                        enemy.is_in_map = False
            elif self.strategy == 2:
                for enemy in self.enemies:
                    if enemy.pos_y >= 9:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                    else:
                        enemy.is_in_map = False
            elif self.strategy == 3:
                for enemy in self.enemies:
                    if enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                    else:
                        enemy.is_in_map = False
                for enemy in self.enemies:
                    if enemy.is_in_map and enemy.pos_y >= 6:
                        if enemy.pos_y <= 8 and enemy.pos_x > 6:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False
                for enemy in self.enemies:
                    if enemy.pos_y >= 6 and enemy.pos_y <= 8 and enemy.pos_x > 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
            elif self.strategy == 4:  # MSCS
                for enemy in self.enemies:
                    if enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                    else:
                        enemy.is_in_map = False
                for enemy in self.enemies:
                    if enemy.is_in_map and enemy.pos_y >= 6:
                        if enemy.pos_y <= 11:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False
                for enemy in self.enemies:
                    if enemy.pos_y >= 6 and enemy.pos_y <= 11:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
        else:
            if self.strategy == 0:  # Full defend
                for enemy in self.enemies:
                    if enemy.is_in_map:
                        if enemy.pos_y > 5 or enemy.pos_x == 6:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False
                for enemy in self.enemies:
                    if enemy.pos_y > 5 or enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
            elif self.strategy == 1:  # Defend top
                for enemy in self.enemies:
                    if enemy.is_in_map:
                        if (enemy.pos_y >= 6
                                and enemy.pos_y <= 8) or enemy.pos_x == 6:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False

                for enemy in self.enemies:
                    if (enemy.pos_y >= 6
                            and enemy.pos_y <= 8) or enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
            elif self.strategy == 2:  # Defend bottom
                for enemy in self.enemies:
                    if enemy.is_in_map:
                        if enemy.pos_y >= 9 and enemy.pos_x < 6:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False

                for enemy in self.enemies:
                    if enemy.pos_y >= 9 and enemy.pos_x < 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
            elif self.strategy == 3:  # Defend top left
                for enemy in self.enemies:
                    if enemy.is_in_map:
                        if (enemy.pos_y >= 6 and enemy.pos_y <= 8
                                and enemy.pos_x <= 6) or enemy.pos_x == 6:
                            pygame.draw.rect(self.map,
                                             Utils.get_color(Utils.WHITE),
                                             (enemy.rect.x, enemy.rect.y,
                                              self.tile_size, self.tile_size))
                            return self.map
                        else:
                            enemy.is_in_map = False

                for enemy in self.enemies:
                    if (enemy.pos_y >= 6 and enemy.pos_y <= 8
                            and enemy.pos_x <= 6) or enemy.pos_x == 6:
                        pygame.draw.rect(self.map,
                                         Utils.get_color(Utils.WHITE),
                                         (enemy.rect.x, enemy.rect.y,
                                          self.tile_size, self.tile_size))
                        enemy.is_in_map = True
                        return self.map
        return self.map
Esempio n. 11
0
 def __draw_score(self):
     total_score = self.font.render('Score:' + str(self.total_score), False,
                                    Utils.get_color(Utils.WHITE))
     self.screen.blit(
         total_score,
         (10, self.screen_height + total_score.get_height() / 1.3))