Example #1
0
    def __init__(self):
        self.width = 30 #int(settings.game_data['map_width'])
        self.height = 20 #int(settings.game_data['map_height'])
        self.seed = 42352336
        self.water = 5 # int(settings.game_data['water_level'])
        self.max_diff = 1

        self.canvas = Canvas()

        self.tile = generator.generate_map(
            width=self.width,
            height=self.height,
            seed=self.seed,
            water=self.water,
            max_diff=self.max_diff
        )

        for x in range(self.width):
            for y in range(self.height):
                self.tile[x][y].map = self
                self.canvas.add(self.tile[x][y])

        # real pixel dimensions
        self.real_x = 0
        self.real_y = 0
        self.real_w = 0
        self.real_h = 0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     if self.canvas is None:
         self.canvas = Canvas(opacity=self.opacity)
     self.add_background(self.user_pos,
                         opacity=self.opacity,
                         last_canvas=self.canvas)
Example #3
0
 def draw(self):
     app = App.get_running_app()
     if not self.canvas:
         self.canvas = Canvas()
     self.canvas.clear()
     with self.canvas:
         Color(rgb=app.COLOR_PALETTE[self.bg_color])
         Rectangle(pos=self.pos, size=(self.width, self.height))
         Color(rgb=app.COLOR_PALETTE[self.fg_color])
         Rectangle(texture=self.texture,
                   pos=self.pos,
                   size=(self.width, self.height))
    def __init__(self, canvas=None):

        self.drawBones = True
        self.drawRegionAttachments = True
        self.drawBoundingBoxes = True
        self.drawMeshHull = True
        self.drawMeshTriangles = True
        self.bounds = SkeletonBounds()
        self.shapes = None
        self.scale = 1
        self.boneWidth = 2
        self.preMultipliedAlpha = False

        if canvas is None:
            self.shapes = Canvas()
        else:
            self.shapes = canvas
Example #5
0
    def initialize(self):
        self.initialized = True

        try:
            self.window_width
            self.window_height
        except AttributeError:
            win = self.get_parent_window()

            # `window_width` & `window_height`: dimensions of the window, in pixels
            self.window_width = win.width
            self.window_height = win.height

        # `matrix`: the matrix holding the maze. Values in this matrix are:
        # - nonnegative numbers: corridors; the value represents the shortest
        #   distance to the exit (these will be set using set_walls later)
        # -1: regular (breakable) wall
        # -2: perimeter (unbreakable) wall
        # -3: exit
        # -4: entrance
        self.matrix = -numpy.transpose(
            numpy.array(create_maze(
                self.window_width // MAZE_CELL_SIZE,
                self.window_height // MAZE_CELL_SIZE,
            ),
                        dtype=numpy.int8))
        # `width`/`height`: size of the maze, in tiles
        self.width, self.height = self.matrix.shape
        # `cell_width`/`cell_height`: size of a tile, in pixels
        self.cell_width = self.window_width / self.width
        self.cell_height = self.window_height / self.height
        # `cell_size`: average size of a tile, as a scalar
        self.cell_size = (self.cell_width + self.cell_height) / 2

        # Initialize perimeter walls and entrance/exit
        for x in range(self.width):
            self.matrix[x, 0] = self.matrix[x, self.height - 1] = -2
        for y in range(self.height):
            self.matrix[0, y] = self.matrix[self.width - 1, y] = -2
        self.matrix[0, 1] = -3
        self.matrix[self.width - 1, self.height - 2] = -4

        # `balls`: list of Ball widgets on this board
        self.balls = []

        # `start_point`, `start_cranny`: Coordinates of the entrance and the
        # tile next to it. (The corresponding coordinates for the exit are
        # simply (0, 1) and (1, 1))
        self.start_point = self.width - 2, self.height - 2
        self.start_cranny = self.width - 1, self.height - 2

        # `bdist`: same as `matrix` except positive numbers indicate shortest
        #  distance to the entrance or nearest ball
        # `dist`: ditto with shortest distance to just the entrance
        self.bdist = self.dist = self.matrix
        self.set_walls(self.matrix)

        # Initialize the graphic representation
        self.background_canvas = Canvas()
        self.canvas.add(self.background_canvas)
        self.draw()

        # Add the ball source (zero-sized initially)
        self.ball_source = BallSource(size=(0, 0),
                                      pos=(self.window_width,
                                           self.window_height))
        self.add_widget(self.ball_source)

        # Initialize the countdown for the solver
        Clock.schedule_once(lambda dt: self.countdown(COUNTDOWN_START), 1)

        # Redraw every 30th of a second
        Clock.schedule_interval(self.redraw, 0.03)