Пример #1
0
    def _move_up(self, amount: int) -> None:
        """Move the outline on the workspace spritesheet to the up by amount."""
        #current outline coords
        a, b = self._outline_coords()

        #adjust for the translation amount
        new_a = Point(a.x, a.y + amount)
        new_b = Point(b.x, b.y + amount)

        #change the outline's boundaries
        self._sheet_start(new_a)
        self._sheet_end(new_b)
Пример #2
0
    def _zoom_out(self, zoom: int, movement: int) -> None:
        """Shrink the outline's boundaries to match the zoom amount"""
        #get reference images' a and b, then apply scale to that to calculate the coordinate
        ref_a = self.a
        ref_b = self.b

        #apply scaling factor to each point
        new_a = Point(ref_a.x // zoom, ref_a.y // zoom)
        new_b = Point(ref_b.x // zoom, ref_b.y // zoom)

        #change the outline's boundaries
        self._sheet_start(new_a)
        self._sheet_end(new_b)
Пример #3
0
    def __init__(self):
        self.primary_ref = 0
        self.secondary_ref = 0
        self.color = (255, 0, 0)
        self.line_width = 3

        #reference image
        self.a = Point(0, 0)
        self.b = Point(0, 0)
        self.width = 0
        self.height = 0

        #workspace spritesheet
        self.sheet_a = Point(0, 0)
        self.sheet_b = Point(0, 0)
        self.sheet_w = 0
        self.sheet_h = 0
        self.batch = pyglet.graphics.Batch()

        self.top_line = pyglet.shapes.Line(self.a.x,
                                           self.a.y,
                                           self.b.x,
                                           self.b.y,
                                           width=self.line_width,
                                           color=self.color,
                                           batch=self.batch)

        self.bottom_line = pyglet.shapes.Line(self.a.x,
                                              self.a.y,
                                              self.b.x,
                                              self.b.y,
                                              width=self.line_width,
                                              color=self.color,
                                              batch=self.batch)

        self.right_line = pyglet.shapes.Line(self.a.x,
                                             self.a.y,
                                             self.b.x,
                                             self.b.y,
                                             width=self.line_width,
                                             color=self.color,
                                             batch=self.batch)

        self.left_line = pyglet.shapes.Line(self.a.x,
                                            self.a.y,
                                            self.b.x,
                                            self.b.y,
                                            width=self.line_width,
                                            color=self.color,
                                            batch=self.batch)
Пример #4
0
 def shoot_bullets(self):
     '''
     Shooting the bullet after time-interval
     '''
     x = time.time()
     if x - self.shoot_tic > self.timeinterval:
         self.shoot_tic = x
         self.left_bullets.append(
             Bullet(self.frame,
                    Point(self.paddle.point.x, self.paddle.point.y - 1),
                    self.brick_layout, self.ball))
         self.right_bullets.append(
             Bullet(
                 self.frame,
                 Point(
                     self.paddle.point.x + self.paddle.dimension.width - 1,
                     self.paddle.point.y - 1), self.brick_layout,
                 self.ball))
Пример #5
0
 def movey(self):
     '''
     Moving the bullet
     '''
     if self.used == True:
         return
     no = self.frame.current_frame[self.point.y - 1][self.point.x]
     if self.point.y <= 1:
         self.frame.clear_frame_area(self.point, self.dimension)
         self.used = True
     elif (no in BRICK_TYPE_ARRAY):
         self.break_brick_shoot(self.point.y - 1, self.point.x)
         self.frame.clear_frame_area(self.point, self.dimension)
         self.used = True
     else:
         npoint = Point(self.point.x, self.point.y - 1)
         self.frame.restore_frame(npoint, self.shape, self.dimension,
                                  self.point, self.shape, self.dimension)
         self.point = Point(self.point.x, self.point.y - 1)
Пример #6
0
 def __init__(self, frame: Frame):
     '''
     constructor of the brick layout
     '''
     self.frame = frame
     self.total_bricks = 0
     self.point = Point(LAYOUTXOFFSET, LAYOUTYOFFSET)
     self.dimension = Dimension(LAYOUTWIDTH, LAYOUTHEIGHT)
     self.location_n_type_matrix = self.generate_location_n_type_matrix()
     self.brick_matrix = self.make_brick_matrix(self.frame)
Пример #7
0
    def change_outline_start(self, ref_coord: Point) -> None:
        """Change the outline's starting point."""
        self.outline._start(ref_coord)

        #adjust outline as sprite sheet is transformed
        scale = self.sprites._scale()
        translation = self.sprites._coords()
        sheet_coord = Point(ref_coord[0] + translation[0],
                            ref_coord[1] + translation[1])
        self.outline._sheet_start(sheet_coord)
Пример #8
0
 def _pixel(self, pos: Point) -> Pixel:
     """Get pixel's coordinate and RGB data."""
     scale = self._scale()
     coord = Point(pos.x // scale, pos.y // scale)
     x = int(coord[0])
     y = int(self.image.height - coord[1])
     try:
         rgb = self.reference_image.getpixel((x, y))
     except IndexError:
         rgb = (0, 0, 0)
     return coord, rgb
Пример #9
0
 def __init__(self,frame: Frame):
     self.paddlestepx = PADDLESTEPX
     self.frame = frame
     self.shape = self.initial_shape(PADDLEWIDTH,PADDLEHEIGHT)
     self.dimension = Dimension(PADDLEWIDTH,PADDLEHEIGHT)
     self.point = Point(
         randint(50, FRAMEWIDTH-4*PADDLEWIDTH), 
         randint(FRAMEHEIGHT-5,FRAMEHEIGHT-5)
     )
     self.health = PADDLEHEALTH
     self.draw()
Пример #10
0
    def movey(self):
        '''
        dropping of the bomb
        '''
        if self.blasted:
            return

        no = self.ufo.frame.current_frame[self.point.y + 1][self.point.x]
        if self.point.y >= FRAMEHEIGHT - 2:
            self.ufo.frame.clear_frame_area(self.point, self.dimension)
            self.blasted = True
        elif no == self.ufo.paddle.shape[0][0]:
            self.ufo.frame.clear_frame_area(self.point, self.dimension)
            self.blasted = True
            self.ufo.frame.status.add_kill()
        else:
            npoint = Point(self.point.x, self.point.y + 1)
            self.ufo.frame.restore_frame(npoint, self.shape, self.dimension,
                                         self.point, self.shape,
                                         self.dimension)
            self.point = Point(self.point.x, self.point.y + 1)
Пример #11
0
 def __init__(self, frame, point, brick_layout, ball):
     self.frame = frame
     self.ball = ball
     self.brick_layout = brick_layout
     self.point = Point(point.x, point.y)
     self.dimension = Dimension(1, 1)
     self.shape = [[f"{Fore.GREEN}{Style.BRIGHT}|{Style.RESET_ALL}"]]
     self.used = False
     self.direction_x = False
     self.direction_y = True
     self.speedx = 0
     self.speedy = 1
     self.draw()
Пример #12
0
 def __init__(self, paddle, frame):
     '''
     constructor of the class
     '''
     self.paddle = paddle
     self.frame = frame
     self.point = Point(self.paddle.point.x - 4, 2)
     self.shape = self.initial_shape()
     self.dimension = self.get_dimension()
     self.health = ENEMYHEALTH
     self.draw()
     self.tic = time.time()
     self.bomb = []
Пример #13
0
 def __init__(self, ufo):
     '''
     constructor for the class
     '''
     self.ufo = ufo
     self.point = Point(
         (self.ufo.point.x + (self.ufo.dimension.width // 2)),
         self.ufo.point.y + self.ufo.dimension.height)
     self.dimension = Dimension(1, 1)
     self.shape = [[
         f"{Fore.RED}{Back.WHITE}{Style.BRIGHT}o{Style.RESET_ALL}"
     ]]
     self.blasted = False
     self.draw()
Пример #14
0
    def move_with_paddle(self):
        '''
        Logic for moving ball with paddle horizontally when stick.
        '''
        if self.health <= 0:
            return False

        new_point = Point(self.paddle.point.x - 4, self.point.y)

        if (new_point.x < 2) or (new_point.x + self.dimension.width >
                                 FRAMEWIDTH - 2):
            return
        self.re_draw(new_point, self.shape, self.dimension)
        return True
Пример #15
0
 def __init__(self, frame: Frame):
     '''
     constructor of the brick layout
     '''
     self.frame = frame
     self.total_bricks = 0
     self.point = Point(LAYOUTXOFFSET, LAYOUTYOFFSET)
     self.dimension = Dimension(LAYOUTWIDTH, LAYOUTHEIGHT)
     self.location_n_type_matrix = self.generate_location_n_type_matrix()
     self.brick_matrix = self.make_brick_matrix(self.frame)
     self.shift_down = SHIFTDOWN
     self.shift_down_after = SHIFTDOWNSTARTAFTER
     self.formed_time = time.time()
     self.lowermost = self.get_lowermost_layout_point()
Пример #16
0
 def move_left(self):
     '''
     Logic for moving paddle left
     '''
     if(self.point.x <= 1):
         return False
     
     final_posx = self.point.x - PADDLESTEPX
     if(self.point.x <= PADDLESTEPX):
         final_posx = 1
     new_point = Point(
         final_posx,
         self.point.y
     )
     self.frame.restore_frame(new_point,self.shape,self.dimension,self.point,self.shape,self.dimension)
     self.point = new_point
     return True
Пример #17
0
    def automatic_move(self):
        '''
        Moves the power up on frame
        '''
        if self.display == False:
            return False

        new_y = self.movey()
        new_x = self.movex()

        if self.check_paddle_collision(new_x, new_y) or self.check_lost(new_y):
            self.remove_power_up()
            return False

        new_point = Point(new_x, new_y)
        self.re_draw(new_point, self.shape, self.dimension)
        return True
Пример #18
0
    def move_right(self):
        '''
        Logic for moving paddle right
        '''
        if(self.point.x + self.dimension.width >= FRAMEWIDTH-1):
            return False
        
        final_pos = self.point.x + PADDLESTEPX
        if(self.point.x + self.dimension.width >= FRAMEWIDTH-PADDLESTEPX-1):
            final_pos = FRAMEWIDTH-1-self.dimension.width

        new_point = Point(
            final_pos,
            self.point.y
        )
        self.frame.restore_frame(new_point,self.shape,self.dimension,self.point,self.shape,self.dimension)
        self.point = new_point
        return True
Пример #19
0
 def update_all_brick_location(self):
     '''
     This method will account for moving all the bricks down
     by amount=self.shift_down
     '''
     if (time.time() - self.formed_time) > self.shift_down_after:
         self.point = Point(self.point.x, self.point.y + SHIFTDOWN)
         for row in range(len(self.brick_matrix)):
             orow = len(self.brick_matrix) - 1 - row
             for cell in range(len(self.brick_matrix[orow])):
                 # print("Moving down")
                 self.brick_matrix[orow][cell].move_down(self.shift_down)
         # print(self.get_lowermost_layout_point())
         # time.sleep(2)
         if self.get_lowermost_layout_point() > (FRAMEHEIGHT - 5):
             # self.frame.status.add_kill()
             show_result(self.frame.status.ret_status())
             self.frame.status.start_game()
Пример #20
0
 def generate_location_n_type_matrix(self):
     '''
     This function will generate a matrix of points i.e. (x,y)
     which will be used to place the SingleBricks.And store it
     in location_n_type_matrix matrix.
     '''
     row_height = BRICKHEIGHT + 1
     cell_width = BRICKWIDTH + 1
     location_n_type_matrix = [[] for j in range((self.dimension.height) //
                                                 (row_height))]
     for row in range(len(location_n_type_matrix)):
         y_coordinate = self.point.y + (row * (row_height))
         x_coordinate = self.point.x
         while x_coordinate <= (self.point.x + self.dimension.width -
                                cell_width):
             location_n_type_matrix[row].append(
                 LocationType(Point(x_coordinate, y_coordinate), 1))
             x_coordinate += cell_width
     return location_n_type_matrix
Пример #21
0
 def __init__(self, window, img):
     self.window = window
     self.control_panel = ControlPanel(self.window)
     self.workspace = Workspace(img)
     self.mouse_pos = Point(0, 0)
     self.sprite_outline_b = Point(0, 0)
Пример #22
0
 def ref_mouse_pos(self) -> Point:
     """Get mouse position relative to the reference image."""
     x, y = self.sheet_coords()
     scale = self.sheet_scale()
     pos = self.mouse_pos
     return Point(int((pos[0] - x) // scale), int((pos[1] - y) // scale))
Пример #23
0
 def sheet_mouse_pos(self) -> Point:
     """Get the mouse position relative to the sprite sheet."""
     x, y = self.sheet_coords()
     pos = self.mouse_pos
     return Point(int(pos[0] - x), int(pos[1] - y))
Пример #24
0
 def reset(self) -> None:
     self.a = Point(0, 0)
     self.b = Point(0, 0)
     self.sheet_a = Point(0, 0)
     self.sheet_b = Point(0, 0)