Exemple #1
0
    def setup(self):
        self.circle1 = scene.Rect(50, 50, 50, 50)
        self.circle2 = scene.Rect(150, 50, 50, 50)

        self.circle1_layer = scene.Layer(self.circle1)
        circle1 = Image.new('RGBA', (101, 101))
        draw1 = ImageDraw.Draw(circle1)
        draw1.ellipse((0, 0, 100, 100), fill=(0, 255, 0, 255))
        self.circle1_layer.image = scene.load_pil_image(circle1)
        self.circle1_layer.animate('alpha',
                                   0.0,
                                   duration=1.0,
                                   autoreverse=True,
                                   repeat=3)  # alpha animation
        self.add_layer(self.circle1_layer)  # touch handling

        self.circle2_layer = scene.Layer(self.circle2)
        circle2 = Image.new('RGBA', (101, 101))
        draw2 = ImageDraw.Draw(circle2)
        draw2.ellipse((0, 0, 100, 100), fill=(255, 0, 0, 255))
        self.circle2_layer.image = scene.load_pil_image(circle2)
        self.circle2_layer.animate('scale_x',
                                   2.0,
                                   duration=1.0,
                                   autoreverse=True,
                                   repeat=sys.maxint)  # alpha animation
        self.circle2_layer.animate('scale_y',
                                   2.0,
                                   duration=1.0,
                                   autoreverse=True,
                                   repeat=sys.maxint)  # alpha animation
Exemple #2
0
 def setup(self):
     self.rect1 = scene.Rect(50, 50, 50, 50)
     self.rect2 = scene.Rect(150, 50, 50, 50)
     self.rect1_layer = scene.Layer(self.rect1)
     self.add_layer(self.rect1_layer)
     self.rect2_layer = scene.Layer(self.rect2)
     self.add_layer(self.rect2_layer)
Exemple #3
0
 def check_collision(self, position, size):
     dino_rect = scene.Rect(*(position - self.position), *size)
     for cactus in self.children:
         cactus_rect = scene.Rect(*(cactus.left_buttom_coord), *cactus.size)
         if dino_rect.intersects(cactus_rect):
             return True
     return False
 def setup(self):
     self.rect1 = scene.Rect(50, 50, 50, 50)
     self.circle2 = scene.Rect(150, 50, 50, 50)
     self.rect1_layer = scene.Layer(self.rect1)
     self.rect1_layer.background = scene.Color(0, 1, 0)
     self.rect1_layer.animate('alpha',
                              0.0,
                              duration=1.0,
                              autoreverse=True,
                              repeat=3)  # alpha animation
     self.add_layer(self.rect1_layer)  # touch handling
     self.circle2_layer = scene.Layer(self.circle2)
     self.add_layer(self.circle2_layer)
Exemple #5
0
    def draw(self):
        #self.prevmode = self.mode
        self.mode = 'off'
        for touch in touches:
            if touch.location in scene.Rect(*self.rect):
                self.mode = 'on'
            #elif self.prevmode == 'on':
            #self.mode = 'up'

#		if self.mode == 'on':
#			try:
#				self.on()
#			except AttributeError:
#				pass
#		elif self.mode == 'up':
#			try:
#				self.up()
#			except AttributeError:
#				pass
#		else:
#			try:
#				self.off()
#			except AttributeError:
#				pass

        try:
            if self.mode == 'on':
                self.on()
            else:
                self.off()
        except AttributeError:
            pass
Exemple #6
0
    def setup(self):
        self.button_dict = collections.OrderedDict([
            ('+', self.increase_font_size), ('—', self.decrease_font_size),
            ('Font', self.next_font), ('Color', self.next_color),
            ('Save', self.save_image), ('Cancel', self.cancel)
        ])

        fgColor = scene.Color(*color('black'))
        bgColor = scene.Color(*color('grey'))
        loc = [0, 0]
        for button_text in self.button_dict:
            if button_text == '+':
                button_text = '  +  '  # double spaces around '+'
            else:  # single space around others
                button_text = ' ' + button_text + ' '
            theButton = TextButton(self, loc, button_text, fgColor, bgColor)
            self.btn_height = max(self.btn_height, theButton.frame.h)
            loc[0] += theButton.frame.w + 4  # 4 pixels between each button

        self.picratio = self.picsize.w / (self.picsize.h * 1.0)
        usable_space = self.bounds.h - self.btn_height
        x = usable_space * self.picratio
        if x <= self.bounds.w:
            y = usable_space
        else:
            x = self.bounds.w
            y = self.bounds.w / self.picratio
        self.position = scene.Size(x / 2, y / 2)  # no ...y/2+self.btn_height
        self.picscale = self.picsize[0] / (x * 1.0)
        self.layer = scene.Layer(scene.Rect(0, self.btn_height, x, y))
        self.layer.image = scene.load_pil_image(self.img)
        self.add_layer(self.layer)
 def setup(self):
     (imageName, imageSize) = self.getImageNameAndSize()
     theRect = scene.Rect(0, 0, *imageSize)
     theRect.center(self.bounds.center())
     print(theRect),
     print(self.bounds)
     self.add_layer(scene.Layer(theRect))
     self.root_layer.image = imageName
Exemple #8
0
	def __init__(self, inFontName = 'Helvetica'):
		(imageName, imageSize) = scene.render_text(inFontName,
		font_name=inFontName, font_size=64)
		theRect = scene.Rect(0, 0, imageSize.w, imageSize.h)
		super(self.__class__, self).__init__(theRect)
		self.tint = colorLightBlue
		# self.background = colorWhite  # useful for debugging
		self.image = imageName
		self.dx = 1
		self.dy = 1
Exemple #9
0
 def setup(self):
     # Setup screen with top 200 pixels reserved for text
     w = self.col_width = self.size.w / 4
     h = self.row_height = (self.size.h - 200) / 4
     for animal in animals:
         layer = scene.Layer(scene.Rect(0, 0, w, h))
         layer.image = animal
         self.add_layer(layer)
     self.shuffle_layer_locations()
     self.current_animal = self.different_layer()
Exemple #10
0
 def __init__(self, inScene, inLoc, inText, inFgColor, inBgColor):
     (theImage, theSize) = scene.render_text(inText, font_size=48)
     super(self.__class__,
           self).__init__(scene.Rect(inLoc[0], inLoc[1], *theSize))
     inScene.add_layer(self)
     self.parent = inScene
     self.text = inText.strip()
     self.image = theImage
     self.stroke = inFgColor  # border color
     self.stroke_weight = 2  # border width
     self.background = inBgColor
 def touch_began(self, touch):
     w, h = self.button_size.x, self.button_size.y
     for button in self.buttons:
         name, title, value, position, action = button
         hit_test = scene.Rect(position.x, position.y, w, h)
         if touch.location in hit_test:
             if action:  # toggles have action == None
                 action()
             else:
                 self.toggle(name)
             self.sync_data()
             break
Exemple #12
0
    def check_fall_off(self):

        # If the player is at the bottom of the jump, see if the block frame intersects the player hitbox
        if self.count % len(self.jump) == 0:
            player_hitbox = sc.Rect(self.player.position.x - 20,
                                    self.player.position.y - 5, 40, 65)

            block = self.current_block
            if block.frame.intersects(player_hitbox):
                fall = False
            else:
                fall = True
                self.run_action(sc.Action.call(self.player_dead))
Exemple #13
0
    def check_jump(self):
        # Define a player hitbox as a rectangle around the player
        player_hitbox = sc.Rect(self.player.position.x - 20,
                                self.player.position.y, 40, 65)

        # Iterate over blocks in the game
        for block in list(self.blocks):

            # check if the block position overlaps with the player, while the player is falling
            if self.vel + np.round(
                    32 + block.position.y, 0
            ) > self.player.position.y and np.round(
                    32 + block.position.y, 0
            ) - self.vel < self.player.position.y and block.frame.intersects(
                    player_hitbox) and self.jump[self.count %
                                                 len(self.jump)] < 0:

                # if the condition is satisfied, the player has performed a succesful jump. The camera view should now be shifted. This can be done by moving all in-game blocks by the distance of the jump

                for b in list(self.blocks):
                    b.run_action(
                        sc.Action.move_by(0, -block.position.y, 0.5,
                                          sc.TIMING_SINODIAL))

                    # Additionally, if blocks have moved below the current camera view, they should be removed from the game
                    if b.position.y < 0:
                        b.remove_from_parent()
                        b.run_action(sc.Action.remove())
                        self.blocks.remove(b)

                # Reset the counter to 1 and the player position to 32 (corresponds to the start of a new jump)
                self.count = -1
                self.player.position.y = 32

                # Change the moving function to True to ensure that a correct, modified jump mechanics are applied
                self.moving = True

                # Make sure that the ground is removed from the game
                self.ground.run_action(sc.Action.remove())

                # Define the block the player is currently standing on
                self.current_block = block
                self.jumped = True

                self.player.texture = landing_texture

                # Increment the score by the normalised jump distance
                self.score += int(np.round(block.position.y / 10, 0))
                self.score_label.text = str(self.score)
                self.high_score_val = max(self.score, self.high_score_val)
                self.high_score.text = str(self.high_score_val)
Exemple #14
0
 def setup(self):
     self.center = self.bounds.center()
     pad = 4  # pixels between buttons
     loc = scene.Point(pad, pad)
     keyboard = make_keyboards()[0]
     for keyrow in keyboard:
         button_height = loc.x = pad
         for key in keyrow:
             width = 740 if key == 'space' else 89
             key_button = TextButton(self, scene.Rect(loc[0], loc[1], width, 40), key)
             loc.x += key_button.frame.w + pad
             button_height = max(button_height, key_button.frame.h)
         loc.y += button_height + pad
     self.center.y += loc.y / 2  # move center up to compensate for keyboard
Exemple #15
0
    def setup(self):
        # Determine which pawn is being promoted and set up the options
        board = self.game_view.game.board
        self.turn = board.turn
        for p in board.pieces:
            if p.is_promotable:
                self.promoter = p
                self.color = p.color  # this syntax is a bit mind numbing
        if not hasattr(self, 'promoter'):
            del self  # ???
            #self.parent.switch_scene(self.game.data['screen_main'])
        self.owner = self.promoter.owner
        y = 7 if self.color == 'white' else 0
        self.spawncoord = Coord(self.promoter.coord.x, y)
        qpos, rpos, bpos, kpos = [Coord(x, 4) for x in (2, 3, 4, 5)]
        self.queen = Queen(qpos, self.color, self.promoter.owner)
        self.rook = Rook(rpos, self.color, self.promoter.owner)
        self.bishop = Bishop(bpos, self.color, self.promoter.owner)
        self.knight = Knight(kpos, self.color, self.promoter.owner)
        self.pieces = [self.queen, self.rook, self.bishop, self.knight]

        self.qrect = scene.Rect(self.queen.coord.as_screen.x,
                                self.queen.coord.as_screen.y, scale_factor,
                                scale_factor)
        self.rrect = scene.Rect(self.rook.coord.as_screen.x,
                                self.rook.coord.as_screen.y, scale_factor,
                                scale_factor)
        self.brect = scene.Rect(self.bishop.coord.as_screen.x,
                                self.bishop.coord.as_screen.y, scale_factor,
                                scale_factor)
        self.krect = scene.Rect(self.knight.coord.as_screen.x,
                                self.knight.coord.as_screen.y, scale_factor,
                                scale_factor)

        piece_types = [p.ptype for p in self.pieces]
        self.img_names = self.game_view.load_images(piece_types)
Exemple #16
0
    def check_item_collisions(self):

        # Define a player hitbox as a rectangle around the player
        player_hitbox = sc.Rect(self.player.position.x - 20,
                                self.player.position.y, 40, 65)

        # for each item in the game check if the item intersects the hitbox. Run the collection function if appropriate
        for item in list(self.items):
            if isinstance(item, Coin):
                if item.frame.intersects(player_hitbox):
                    self.collect_item(item)
                #	 When a coin has finished its animation, it is automatically removed from the scene by its Action sequence. When that's the case, also remove it from the `items` list, so it isn't checked for collisions anymore:
                elif not item.parent:
                    self.items.remove(item)
            if isinstance(item, Monster):
                if item.frame.intersects(player_hitbox):
                    self.player_dead()
Exemple #17
0
    def __init__(self, screen, w, h):
        self.size = scene.Size(w, h)
        w, h = (screen.w / w, screen.h / h)
        self.cells = {(x, y): Cell(x, y, scene.Rect(x * w, y * h, w, h))
                      for x in xrange(self.size.w)
                      for y in xrange(self.size.h)}
        grid_img = Image.new('RGBA', [int(i) for i in screen.as_tuple()])
        grid_draw = ImageDraw.Draw(grid_img)

        for x in xrange(self.size.w):
            grid_draw.line((x * w, 0, x * w, screen.h))
        x = self.size.w
        grid_draw.line((x * w - 1, 0, x * w - 1, screen.h))

        for y in xrange(self.size.h):
            grid_draw.line((0, y * h, screen.w, y * h))
        y = self.size.h
        grid_draw.line((0, y * h - 1, screen.w, y * h - 1))
        self.grid_img = scene.load_pil_image(grid_img)
        del grid_img, grid_draw
Exemple #18
0
 def __init__(self, *args, **kwargs):
     w = scene.get_screen_size().w * 0.8
     h = scene.get_screen_size().h * 0.25
     path = ui.Path.rounded_rect(0, 0, w, h, 10)
     path.line_width = 8
     scene.ShapeNode.__init__(self,
                              path=path,
                              fill_color='#CDC1B4',
                              stroke_color='#BBADA0',
                              *args,
                              **kwargs)
     board = self.parent.board
     box = scene.Rect(board.bbox.x, board.bbox.y + board.bbox.h,
                      board.bbox.w, self.parent.size.h - board.bbox.h)
     self.position = box.center()
     self.score = 0
     self.highscore = dict()
     self.load_highscore()
     self.score_label = self.create_score_label()
     self.highscore_label = self.create_highscore_label()
     self.create_title_label()
     self.player_label = self.create_player_label()
Exemple #19
0
    def draw(self):
        self.prevmode = self.mode
        self.mode = 'off'
        for touch in touches:
            if touch.location in scene.Rect(*self.rect):
                self.mode = 'on'
            elif self.prevmode == 'on':
                self.mode = 'up'

        if self.mode == 'on':
            scene.fill(*self.altcolor)
            scene.tint(*self.alttxtcolor)
            scene.stroke(*self.altbordrcolor)
        else:
            scene.fill(*self.color)
            scene.tint(*self.txtcolor)
            scene.stroke(*self.bordrcolor)

        scene.stroke_weight(self.bordrw)
        scene.rect(*self.rect)
        scene.text(self.text, self.font, self.fontsize,
                   self.rect[0] + self.rect[2] / 2,
                   self.rect[1] + self.rect[3] / 2)
Exemple #20
0
 def __init__(self, x, y, w, h):
     self.rect = scene.Rect(x, y, w, h)
     self.colors = [(0, 0, 0, 0)]
 def __init__(self, frame=None, velocity=None, color=None):
     self.frame = frame or scene.Rect(0, 0, 25, 25)
     self.velocity = velocity or scene.Point(0, 0)
     self.color = color or random_color()
 def __init__(self, x, y, w, h):
     self.rect = scene.Rect(x, y, w, h)  # Important: (x,y) is the lower-left corner
     self.color = (0, 0, 0, 0)
     self.index = 0                      # Used to find neighbors
     self.position = (x,y)               # Used when writing images
Exemple #23
0
# https://forum.omz-software.com/topic/3268/pythonista-3-rect-attributes/2

import scene, ui
print(scene.Rect() == ui.Rect())  # True
print(scene.Rect == ui.Rect)      # True
print(scene.Rect is ui.Rect)      # True

Exemple #24
0
 def __init__(self, inImageName):
     theRect = scene.Rect(0, 0, imageWidth, imageWidth)
     scene.Layer.__init__(self, theRect)
     self.dx = self.dy = 2  # Initial direction: upperRight
     self.image = scene.load_image_file(inImageName)
Exemple #25
0
 def __init__(self, x, y):
     self.bounds = scene.Rect(x, y, 80, 80)
Exemple #26
0
 def __init__(self):
     theImage = diagonalLineImage()
     theRect = scene.Rect(0, 0, *theImage.size)
     super(self.__class__, self).__init__(theRect)
     self.image = scene.load_pil_image(theImage)
 def make_player(self):
     player_size = 35
     frame = scene.Rect(0, (self.bounds.h - player_size) / 2, player_size,
                        player_size)
     color = scene.Color(1, 1, 1)
     return Particle(frame=frame, color=color)
 def setup(self):
     x, y = self.bounds.center()
     self.add_layer(Circle(scene.Rect(x - 150, y - 150, 100, 100)))
     self.add_layer(Square(scene.Rect(x + 50, y + 50, 100, 100)))
Exemple #29
0
 def setup(self):
     w, h = self.picsize
     self.textPosition = scene.Size(w/2/self.scale, h/2/self.scale)
     self.layer = scene.Layer(scene.Rect(0, 0, w/2, h/2))
     self.layer.image = scene.load_pil_image(self.img)
     self.add_layer(self.layer)
Exemple #30
0
def rectFromPt(inPoint):  # returns a scene.Rect centered on inPoint
	half = sizeInPixels / 2
	return scene.Rect(inPoint.x - half, inPoint.y - half, sizeInPixels, sizeInPixels)