def __init__(self, rep, position, velocity):
        """
        Constructor for background
        """
        color = util.tup_to_array(rep.shape, (config.BG_COL, config.FG_COL))

        super().__init__(rep, position, velocity, np.array([0., 0.]), 0, color)
Exemplo n.º 2
0
 def deactivate_shield(self):
     """
     Deactivates shield on the player
     """
     self.shield_active = False
     grid_col = util.tup_to_array(self.get_shape(),
                                  (config.BG_COL, config.FG_COL))
     self.set_color(grid_col)
Exemplo n.º 3
0
    def __init__(self, position, player):
        velocity = np.array([-2., 0.])
        rep = util.str_to_array(graphics.BOSS_BULLET)
        color = util.tup_to_array(rep.shape, (col.Back.RED, col.Fore.YELLOW))

        self.player = player

        super().__init__(rep, position, velocity, color)
Exemplo n.º 4
0
 def activate_shield(self):
     """
     Activates shield on the player
     """
     self.shield_active = True
     grid_col = util.tup_to_array(self.get_shape(),
                                  (col.Back.YELLOW, config.FG_COL))
     self.set_color(grid_col)
Exemplo n.º 5
0
    def clear(self):
        """
        This function clears the current frame
        """
        self.display = np.full((self.height, self.width), " ")

        self.color = util.tup_to_array((self.height, self.width),
                                       (config.BG_COL, config.FG_COL))
Exemplo n.º 6
0
    def __init__(self):
        """
        Constructor for Ground
        """
        rep = np.full((config.GROUND_HEIGHT, config.WIDTH), ".")
        color = util.tup_to_array(rep.shape, (col.Back.GREEN, col.Fore.BLACK))
        pos = np.array([0, config.MAX_HEIGHT])

        super().__init__(rep=rep, position=pos, color=color)
Exemplo n.º 7
0
    def __init__(self, game):
        """
        Constructor for the Dragon
        """
        grid = util.str_to_array(graphics.DRAGON)
        grid_col = util.tup_to_array(grid.shape,
                                     (col.Back.RED, col.Fore.BLACK))
        grid_col = util.mask(grid, grid_col)
        self.game = game

        super().__init__(grid, \
                    np.array([config.WIDTH - 50, 0], dtype="float64"), \
                    0, grid_col, config.DRAGONBOSS_LIVES, self.game)
Exemplo n.º 8
0
    def __init__(self, position, game):
        """
        Constructor for Magnet

        Args:
            position [px, py] : Initial position of the Magnet
            game (Game)       : The game object
        """

        self.game = game
        rep = util.str_to_array(graphics.MAGNET)
        color = util.tup_to_array(rep.shape, (col.Back.MAGENTA, col.Fore.RED))

        super().__init__(rep, position, np.array([-2., 0.]), color=color)
Exemplo n.º 9
0
    def __init__(self, game):
        """
        Constructor for the Mandalorian
        """
        grid = util.str_to_array(graphics.MANDALORIAN)
        grid_col = util.tup_to_array(grid.shape,
                                     (col.Back.BLUE, col.Fore.BLACK))
        self.init_pos = np.array([10, config.MAX_HEIGHT], dtype='float64')

        super().__init__(grid, \
                self.init_pos.copy(),\
                0.45, grid_col, config.MANDALORIAN_LIVES, game)

        self.__controls = ["w", "a", "d"]
        self.shield_active = False
Exemplo n.º 10
0
    def __init__(self, game):
        """
        Constructor for the dragon
        """
        self.width = 60
        self.height = 7
        self.controls = ["w"]
        self.head = 0

        rep = np.full((self.height, self.width), " ")
        color = util.tup_to_array((self.height, self.width),
                                  (col.Back.BLACK, col.Fore.GREEN))

        super().__init__(rep, np.array([0., config.MAX_HEIGHT - self.height]),
                         0.3, color, 1, game)
Exemplo n.º 11
0
    def __init__(self, position, orientation=None):
        """
        Constructor for FireBeam

        Args:
            position [px, py] : Initial position of the FireBeam
            orientation (int) : 0 -> config.FIREBEAM_MAX, type of FireBeam
        """
        if orientation is None or orientation < 0 or orientation > config.FIREBEAM_MAX:
            orientation = util.randint(0, config.FIREBEAM_MAX - 1)

        rep = util.str_to_array(graphics.FIREBEAM[orientation])
        color = util.tup_to_array(rep.shape, (col.Back.RED, col.Fore.YELLOW))

        super().__init__(rep, position, np.array([-2., 0.]),
                         util.mask(rep, color))
Exemplo n.º 12
0
    def get_rep(self, phase_offset=0):
        """
        Returns the live representation of dragon
        """
        rep = np.full((self.height, self.width), " ")
        color = util.tup_to_array(rep.shape, (col.Back.BLACK, col.Fore.GREEN))

        dragon_head = util.str_to_array(graphics.DRAGON_HEAD)
        head_h, head_w = dragon_head.shape

        # phase_offset = 4 * (phase_offset // 4)

        _h, _w = self.get_shape()

        body_width = _w - head_w

        _y = np.sin(np.linspace(-np.pi, np.pi, body_width) + phase_offset)
        _y *= (_h / 2)
        _y += (_h / 2)

        _y = _y.astype(int)

        for i in range(body_width):
            rep[_y[i]][i] = "~"

            if _y[i] > self.height - 2:
                rep[_y[i] - 2][i] = "~"
            else:
                rep[_y[i] + 1][i] = "~"

            if _y[i] == 0:
                rep[2][i] = "~"
            else:
                rep[_y[i] - 1][i] = "~"

        beg_h = int(min(_y[-1], self.height - head_h))

        rep[beg_h:beg_h + head_h, -head_w:] = dragon_head

        self.head = self.get_position() + beg_h

        color = util.mask(rep, color)

        return rep, color
Exemplo n.º 13
0
    def from_string(rep,
                    position=np.array([0., 0.]),
                    velocity=np.array([0., 0.]),
                    accel=np.array([0., 0.]),
                    gravity=0,
                    color=("", "")):
        """
        Creates a GameObject from string

        Args:
            rep (2D np.array)   : The object representation (How does it look?)
            position ([x, y])   : Initial position of the object
            velocity ([vx, vy]) : Speed with which the object moves to left
            accel ([fx, fy])    : accel in both dir
            gravity (float)     : Gravitational accel on that object
            color (str, str)    : Color of each character (bg, fg)

        Returns:
            GameObject with all the parameters
        """
        grid = util.str_to_array(rep)
        color = util.mask(grid, util.tup_to_array(grid.shape, color))

        return GameObject(grid, position, velocity, accel, gravity, color)
Exemplo n.º 14
0
    def __init__(self, position):
        rep = np.array([["$"]])

        super().__init__(rep, position, np.array([-2., 0.]), \
                   np.array([0., 0.]), 0, util.tup_to_array((1, 1), \
                   (col.Back.YELLOW, col.Fore.RED)))
Exemplo n.º 15
0
    def __init__(self, position):
        velocity = np.array([2., 0.])
        rep = util.str_to_array(graphics.MANDALORIAN_BULLET)
        color = util.tup_to_array(rep.shape, (col.Back.WHITE, col.Fore.BLACK))

        super().__init__(rep, position, velocity, color)