Ejemplo n.º 1
0
    def test_energy_graph_show(self, mock):
        """Test used to check that plt.show is called within the energy_graph method
        Uses mocking

        """
        Animation.energy_graph_comparisson(100)
        mock.assert_called_once()
Ejemplo n.º 2
0
    def test_period_graph_update(self, beeman, plot, show):
        try:
            system = SolarSystem(3600, 10.175 * 10**3, Options.NORMAL_RUN,
                                 "CelestialObjects")

            Animation.periods_graph(100, system)
        except ZeroDivisionError as err:
            self.assertEqual(100, beeman.call_count)
Ejemplo n.º 3
0
def main():
    """
    Main function
    """
    system = SolarSystem(3600, 11.5517 * 10**3, Options.PROBE_RUN,
                         "CelestialObjects")
    animate = Animation(system)
    animate.plot()
Ejemplo n.º 4
0
 def test_scatterplot_show(self, mock):
     """Test used to prove that plt.show() is called once in scatter_plot method
     uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.scatter_plot(100)
     mock.assert_called_once()
Ejemplo n.º 5
0
 def test_plot_show(self, mock):
     """Test to prove that plt.show is called in plot() method.
     Uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     mock.assert_called()
Ejemplo n.º 6
0
 def test_energy_graph_update(self, mock, mock2, mock3, mock4):
     """Test used to verify thst the methods update_beeman and
     update euler are called the right number of times in the energy_graph
     method.
     Uses mocking
     """
     Animation.energy_graph_comparisson(100)
     self.assertEqual(100, mock.call_count)
     self.assertEqual(100, mock2.call_count)
     mock3.assert_called_once()
Ejemplo n.º 7
0
 def test_scatterplot_update(self, mock, mock2):
     """Test used to prove that update_beeman() is called 100 times in scatter_plot method
     if the parameter passed to scatter_plot is 100.
     uses mocking
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.scatter_plot(100)
     mock.assert_called()
     self.assertEqual(mock.call_count, 100)
Ejemplo n.º 8
0
class Weapon(pygame.sprite.Sprite):
    def __init__(self, damage, w_type, sprite_sheets):

        super().__init__()

        self.idle = Animation(sprite_sheets[0], 128, 8, 1)
        self.attack = Animation(sprite_sheets[1], 128, 8, 4)
        self.block = Animation(sprite_sheets[2], 128, 8, 1)
        self.state = "idle"
        self.count = 0

        self.image = self.idle.images[0]
        self.mask = pygame.mask.from_surface(self.image)
        self.image_original = self.idle.images[0]
        self.rect = self.image.get_rect()

        self.damage = damage
        self.type = w_type

    def rot_center(self):
        """rotate an image while keeping its center and size"""
        x, y = pygame.mouse.get_pos()
        relx, rely = x - self.rect.x, y - self.rect.y
        angle = math.atan2(relx, rely)
        angle = math.degrees(angle)
        orig_rect = self.image_original.get_rect()
        rot_image = pygame.transform.rotate(self.image_original, angle)
        rot_rect = orig_rect.copy()
        rot_rect.center = rot_image.get_rect().center
        rot_image = rot_image.subsurface(rot_rect).copy()
        return rot_image

    def special_ability(self):
        pass

    def update(self, player):
        self.count += 1

        if self.state == "idle":
            self.image_original = self.idle.images[0]
            self.count = 0
        if self.state == "attack":
            self.image_original = self.attack.update()
            if self.count >= self.attack.frame_loop:
                self.state = "idle"
        if self.state == "block":
            self.image_original = self.block.update()
            if self.count >= self.block.frame_loop:
                self.state = "idle"

        self.image = self.rot_center()
        self.rect.centerx = player.rect.centerx
        self.rect.centery = player.rect.centery
        self.mask = pygame.mask.from_surface(self.image)
Ejemplo n.º 9
0
    def test_plot_animate(self, mock, mock2):
        """Test used to check that a FunCAnimator is used in plot()
        Uses mocking

        """
        mock.return_value = None
        self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                        "CelestialObjects")
        animate = Animation(self.system_probe)
        animate.plot()
        mock.assert_called()
Ejemplo n.º 10
0
    def __init__(self):
        Animation.__init__(self)
        self.DS = 0.5  # second, time separating the activation of two streams

        # set up our fade surface
        self.fade = pg.Surface((self.width, self.height))
        self.fade.fill((0, 0, 0))  # black


        # initialize a list of N_COLS inactive streams
        self.streams = []  # empty list of streams
        for i in range(self.N_COLS):
            self.streams.append(Stream(i, length=Stream.pick_length(), velocity=Stream.pick_velocity()))
        # update the N_ROWS value for each stream
        for stream in self.streams:
            stream.N_ROWS = self.N_ROWS
Ejemplo n.º 11
0
    def __init__(self, damage, w_type, sprite_sheets):

        super().__init__()

        self.idle = Animation(sprite_sheets[0], 128, 8, 1)
        self.attack = Animation(sprite_sheets[1], 128, 8, 4)
        self.block = Animation(sprite_sheets[2], 128, 8, 1)
        self.state = "idle"
        self.count = 0

        self.image = self.idle.images[0]
        self.mask = pygame.mask.from_surface(self.image)
        self.image_original = self.idle.images[0]
        self.rect = self.image.get_rect()

        self.damage = damage
        self.type = w_type
Ejemplo n.º 12
0
    def __init__(self, speed, sprite_sheets, screensize=(1080, 720)):

        super().__init__()

        self.idle = Animation(sprite_sheets[0], 64, 6, 3)
        self.image = self.idle.images[0]
        self.mask = pygame.mask.from_surface(self.image)
        self.image_original = self.idle.images[0]
        self.rect = self.image.get_rect()

        self.speed = speed
        self.time = 0
        self.move = "L"
        self.screensize = screensize
        self.health = 20
        self.dead = False
        self.vulnerability = False
        self.vul_count = 0
Ejemplo n.º 13
0
 def test_animate_update(self, mock, mock2):
     """Test used to prove that update beeman is calld in the animate method
     Uses mocking.
     """
     self.system_probe = SolarSystem(3600, 10000, Options.PROBE_RUN,
                                     "CelestialObjects")
     animate = Animation(self.system_probe)
     animate.plot()
     animate.init()
     animate.animate(0)
     mock.assert_called()
Ejemplo n.º 14
0
    def __init__(self):
        """initialisation of class"""

        super().__init__()

        sprite_sheet = SpriteSheet('character.png')

        self.image = sprite_sheet.get_image(0, 0, 128, 128)
        self.image_original = self.image
        self.mask = pygame.mask.from_surface(self.image)
        self.rect = self.image.get_rect()
        self.rect.x = 540 - self.rect.centerx
        self.rect.y = 360 - self.rect.centery

        self.speed = 5
        self.health = 100
        self.max_health = 100
        self.dead = False
        self.ghost = Animation("ghost.png", 64, 8, 3)
Ejemplo n.º 15
0
class Player(pygame.sprite.Sprite):
    """Player class that is used to create player sprite as well as control player attributes"""
    def __init__(self):
        """initialisation of class"""

        super().__init__()

        sprite_sheet = SpriteSheet('character.png')

        self.image = sprite_sheet.get_image(0, 0, 128, 128)
        self.image_original = self.image
        self.mask = pygame.mask.from_surface(self.image)
        self.rect = self.image.get_rect()
        self.rect.x = 540 - self.rect.centerx
        self.rect.y = 360 - self.rect.centery

        self.speed = 5
        self.health = 100
        self.max_health = 100
        self.dead = False
        self.ghost = Animation("ghost.png", 64, 8, 3)

    def rot_center(self):
        """rotate an image while keeping its center and size"""
        x, y = pygame.mouse.get_pos()
        relx, rely = x - self.rect.x, y - self.rect.y
        angle = math.atan2(relx, rely)
        angle = math.degrees(angle)
        orig_rect = self.image_original.get_rect()
        rot_image = pygame.transform.rotate(self.image_original, angle)
        rot_rect = orig_rect.copy()
        rot_rect.center = rot_image.get_rect().center
        rot_image = rot_image.subsurface(rot_rect).copy()
        return rot_image

    def update(self):
        """Rotates the player so that it follows the mouse"""
        if not self.dead:
            self.image = self.rot_center()
            self.mask = pygame.mask.from_surface(self.image)

        if self.health <= 0:
            self.dead = True
            self.image = self.ghost.update()
            self.mask = pygame.mask.from_surface(self.image)
Ejemplo n.º 16
0
class NPC(pygame.sprite.Sprite):
    def __init__(self, speed, sprite_sheets, screensize=(1080, 720)):

        super().__init__()

        self.idle = Animation(sprite_sheets[0], 64, 6, 3)
        self.image = self.idle.images[0]
        self.mask = pygame.mask.from_surface(self.image)
        self.image_original = self.idle.images[0]
        self.rect = self.image.get_rect()

        self.speed = speed
        self.time = 0
        self.move = "L"
        self.screensize = screensize
        self.health = 20
        self.dead = False
        self.vulnerability = False
        self.vul_count = 0

    def update(self, player):
        """General updates for NPC"""
        self.image = self.idle.update()
        self.mask = pygame.mask.from_surface(self.image)

        if self.vulnerability:
            self.vul_count += 1
            if self.vul_count >= 15:
                self.vul_count = 0
                self.vulnerability = False
        if self.health <= 0:
            self.dead = True

    def damaged(self, amount):
        self.health -= amount
        self.vulnerability = True

    def movex(self, speed):
        self.rect.x += speed

    def movey(self, speed):
        self.rect.y += speed
Ejemplo n.º 17
0
 def setUp(self):
     self.animation = Animation()
     self.animation.n = 2
     self.animation.vmax = 3
     particles = Particles('symulacja', self.animation.n)
     self.animation.simulation = simulation(particles)
     self.animation.simulation.set_velocities(self.animation.n,
                                              self.animation.vmax)
     self.animation.xmax = 30
     self.animation.xmin = 0
     self.animation.ymax = 20
     self.animation.ymin = 0
     self.animation.simulation.set_coordinations(self.animation.n, 1,
                                                 self.animation.xmin,
                                                 self.animation.ymax,
                                                 self.animation.ymin)
     self.animation.simulation.set_boundaries(self.animation.xmax,
                                              self.animation.xmin,
                                              self.animation.ymax,
                                              self.animation.ymin)
Ejemplo n.º 18
0
        pow = [sprites for sprites in powerup_group if sprites.type == 'kunai']

        if len(pow) < 1:
            powerup_group.add(Kunai_Powerup(random.randint(2000, 4000)))


width = 800

# loading all game animations once to prevent fps drops when creating new instances of any animated class

robot_go = Animation([
    '../assets/enemies/robot/go/go_1.png',
    '../assets/enemies/robot/go/go_2.png',
    '../assets/enemies/robot/go/go_3.png',
    '../assets/enemies/robot/go/go_4.png',
    '../assets/enemies/robot/go/go_5.png',
],
                     0.4,
                     frame_duration=0.4)

robot_die = Animation([
    '../assets/enemies/robot/die/die_1.png',
    '../assets/enemies/robot/die/die_2.png',
    '../assets/enemies/robot/die/die_3.png',
    '../assets/enemies/robot/die/die_4.png',
    '../assets/enemies/robot/die/die_5.png',
    '../assets/enemies/robot/die/die_6.png',
    '../assets/enemies/robot/die/die_7.png',
    '../assets/enemies/robot/die/die_8.png',
    '../assets/enemies/robot/die/die_9.png',
Ejemplo n.º 19
0
screen = pygame.display.set_mode((800, 500))
pygame.display.set_caption('Katanga Run')
pygame.display.set_icon(pygame.image.load('../assets/tile.png'))
fps = 60

# creating a database instance
db = database.Database()

# Loading player animations for the main menu
player_idle = Animation([
    '../assets/player/idle/Idle__000.png',
    '../assets/player/idle/Idle__001.png',
    '../assets/player/idle/Idle__002.png',
    '../assets/player/idle/Idle__003.png',
    '../assets/player/idle/Idle__004.png',
    '../assets/player/idle/Idle__005.png',
    '../assets/player/idle/Idle__006.png',
    '../assets/player/idle/Idle__007.png',
    '../assets/player/idle/Idle__008.png',
    '../assets/player/idle/Idle__009.png',
],
                        0.4,
                        frame_duration=0.5)

# loading platform image
platform = pygame.image.load('../assets/tile.png')
platform_image = pygame.transform.scale(platform, (100, 80))

# Font packages
main_font = pygame.font.Font('../assets/iomanoid back.ttf', 100)
smaller_font = pygame.font.Font('../assets/iomanoid front.ttf', 50)
smallest_font = pygame.font.Font('../assets/iomanoid front.ttf', 30)
Ejemplo n.º 20
0
 def test_period_graph_plot(self, plot, show):
     system = SolarSystem(1000000, 10.175 * 10**3, Options.NORMAL_RUN,
                          "CelestialObjects")
     system.celestial_bodies = system.celestial_bodies[0:2]
     Animation.periods_graph(10, system)
     show.assert_called_once()