Example #1
0
    def reset(self):
        self.level = 1
        CJFight.CEntityBase.instances.clear()
        CJFight.player = CJFight.CHero(
            CJFight.CHero.TYPE_NINJA,
            position=vector_t(
                (self.sprites['background'].get_size()[0] / 2, 0)))

        CJFight.CMonsterCyclopes()
        CJFight.CMonsterCyclopes(position=vector_t((500, 1)))
Example #2
0
    def __init__(self, resolution):
        self.is_run = False
        self.resolution = vector_t(resolution)
        self.level = 1

        CJFight.screen = pygame.display.set_mode(resolution)
        pygame.display.set_caption('JGames - JFight')
        background_size = vector_t(self.sprites['background'].get_size())
        self.sprites['background'] = pygame.transform.scale(
            self.sprites['background'],
            (background_size * resolution[1] / background_size.y).__tuple__())
Example #3
0
        def render(self, screen):
            screen_size = vector_t(screen.get_size())
            self.position += self.velocity

            if self.jump_time_counter < self.max_jump_time:
                h_t = self.max_height / self.max_jump_time
                self.velocity.y = 4 * h_t * (
                    2 * self.jump_time_counter / self.max_jump_time - 1)
                self.jump_time_counter += 1
            else:
                self.velocity.y = self.gravity

            if self.velocity.x * self.old_direction_x < 0:
                self.is_flip = not self.is_flip
                self.old_direction_x = self.velocity.x
                self.sprite = pygame.transform.flip(self.sprite, True, False)

            # check bound left
            if self.position.x - self.sprite_size.x / 2 < 0:
                self.position.x = self.sprite_size.x / 2

            # check bound right
            if self.position.x + self.sprite_size.x / 2 > screen_size.y * (
                    2048 / 819):
                self.position.x = screen_size.y * (
                    2048 / 819) - self.sprite_size.x / 2

            # check on ground
            if self.position.y + self.sprite_size.y / 2 > screen_size.y:
                self.position.y = screen_size.y - self.sprite_size.y / 2
                self.jump_time = 2

            # earn damage
            for entity in CJFight.CEntityBase.instances:
                if self != entity and self.is_impact(entity):
                    if isinstance(entity, CJFight.CBullet):
                        if entity.bullet_type == CJFight.CBullet.TYPE_VIRUS:
                            self.health -= 10
                            entity.release()
                            CJFight.sounds['hit'].stop()
                            CJFight.sounds['hit'].play()

            # check health
            real_pos = self.position + CJFight.get_origin(
            ) - self.sprite_size / 2
            pygame.draw.rect(
                screen, (255, 0, 0),
                (real_pos.x, real_pos.y - 25, self.sprite_size.x, 20))
            pygame.draw.rect(screen, (0, 255, 0),
                             (real_pos.x, real_pos.y - 25, self.health /
                              self.max_health * self.sprite_size.x, 20))
            if self.health <= 0:
                self.release()
                CJFight.state = CJFight.GameState.GAMEOVER
                CJFight.sounds['background'].stop()
                CJFight.sounds['game-over'].play()

            screen.blit(self.sprite,
                        ((screen_size.x - self.sprite_size.x) / 2,
                         self.position.y - self.sprite_size.y / 2))
Example #4
0
        def __init__(self, hero_type, position=vector_t(),
                     velocity=vector_t()):
            super().__init__(position,
                             velocity,
                             sprite=CJFight.sprites['heroes']
                             ['turtle' if hero_type ==
                              CJFight.CHero.TYPE_TURTLE else 'ninja'])
            self.is_flip = False
            self.old_direction_x = -1
            self.max_height = 200
            self.max_jump_time = 200
            self.jump_time_counter = self.max_jump_time
            # triple-jump
            self.jump_time = 2

            self.screen = None
Example #5
0
        def __init__(self,
                     health,
                     attack_cooldown,
                     sprite,
                     position=vector_t()):
            super().__init__(position=position, sprite=sprite)
            self.health = health
            self.max_health = self.health
            self.attack_cooldown = attack_cooldown
            self.attack_tcounter = self.attack_cooldown

            self.is_flip = False
            self.old_direction_x = -1
Example #6
0
    def play(self):
        # real - local = origin
        self.screen.blit(self.sprites['background'],
                         (self.resolution.x // 2 - self.player.position.x, 0))
        self.screen.blit(
            font.render('LEVEL: {level}'.format(level=self.level), False,
                        (255, 0, 0)), (20, 20))

        counter = 0
        for entity in CJFight.CEntityBase.instances:
            entity.render(self.screen)
            if not isinstance(entity, (CJFight.CBullet, CJFight.CHero)):
                counter += 1
        if counter == 0:
            self.level += 1
            for _ in range(self.level):
                CJFight.CMonsterCyclopes(vector_t((0, 0)))
Example #7
0
        def __init__(self,
                     position=vector_t(),
                     velocity=vector_t(),
                     collider=vector_t(),
                     sprite=None):
            self.position = position
            self.velocity = velocity
            self.collider = collider
            self.sprite = sprite
            self.sprite_size = vector_t(sprite.get_size())
            CJFight.CEntityBase.instances.append(self)

            if collider == vector_t():
                self.collider = vector_t(sprite.get_size()) / 2
Example #8
0
 def get_origin():
     return vector_t(
         (CJFight.screen.get_size()[0] // 2 - CJFight.player.position.x, 0))
Example #9
0
 def __init__(self, position=vector_t((0, 0))):
     super().__init__(position=position,
                      sprite=CJFight.sprites['monsters']['retarded'],
                      health=200,
                      attack_cooldown=70)
     self.speed = 2
Example #10
0
 def __init__(self, position=vector_t((0, 0))):
     super().__init__(position=position,
                      sprite=CJFight.sprites['monsters']['cyclopes'],
                      health=100,
                      attack_cooldown=100)
     self.speed = 1
Example #11
0
 def attack(self):
     CJFight.CBullet(bullet_type=CJFight.CBullet.TYPE_SHURIKEN,
                     position=self.position,
                     direction=vector_t((1,
                                         0) if self.is_flip else (-1,
                                                                  0)))