Ejemplo n.º 1
0
	def update(self, time_elapsed, events):
		# super
		Sprite.update(self, time_elapsed, events)

		hover = False
		# hover images
		if self.hover():
			self.mouse_over()
			hover = True
		else:
			self.mouse_out()


		for event in events:
			if (event.type == pygame.MOUSEBUTTONDOWN):# and (event.button == 1):
				if hover:
					self.phase1 = True
				else:
					self.phase1 = False

			if (event.type == pygame.MOUSEBUTTONUP):# and (event.button == 1):
				if hover:
					self.phase2 = True and self.phase1
				else:
					self.phase2 = False

		if (self.phase1) and (self.phase2):
			self.click()
			self.phase1 = False
			self.phase2 = False
Ejemplo n.º 2
0
    def __init__(self, level):
        super(Game, self).__init__()
        self.level = Level.load_level(level)
        self.background = Sprite(source='img/background.PNG')
        self.size = self.background.size
        self.player = None
        self.boxes = []

        # Initiate the game by creating tiles
        Tile.make_tiles(self.size, self.level)

        # Add bg widget first to not cover other sprites
        self.add_widget(self.background)

        # Add proper widgets for every non-empty tile in the Tile.List
        for tile in Tile.List:
            if tile.type != 'empty':
                if Tile.get_tile(tile.number - Tile.V).walkable:
                    self.add_widget(Sprite(
                        source=Tile.image_files[tile.type],
                        pos=(tile.x, tile.y)), index=2)
                else:
                    self.add_widget(Sprite(
                        source=Tile.image_files[tile.type + '_edge'],
                        pos=(tile.x, tile.y - SPRITE_EDGE_OFFSET)))

        for tile in self.level.boxspawn:
            self.boxes.append(Box(tile, self))

        self.player = Player(self.level.playerspawn, self)

        self.fps_lab = Label(
            text='FPS: ' + str(Clock.get_rfps()),
            pos=(2, self.height - 110),
            font_name=APP_FONT,
            font_size=18,
            color=(240, 240, 240, 0.8))

        self.add_widget(self.fps_lab)

        self.add_widget(Label(
            text="Level {}".format(self.level.level),
            pos=(0, self.height - 80),
            font_name=APP_FONT,
            font_size=18,
            color=(240, 240, 240, 0.8)))

        # Schedule an interval for the game update function
        Clock.schedule_interval(self.update, 1.0/60.0)
Ejemplo n.º 3
0
	def __init__( self            ,
		          loc             ,
		          size            ,
		          action          ,
	              image_up_file   = "../img/btn/button.png"      ,
	              image_down_file = "../img/btn/button_down.png" ):
		# super
		Sprite.__init__(self, loc, size, image_up_file)

		# image data
		self.image_up   = pygame.transform.scale(pygame.image.load(image_up_file)  , size)
		self.image_down = pygame.transform.scale(pygame.image.load(image_down_file), size)

		# button action
		self.action     = action

		# verification vars
		self.phase1     = False
		self.phase2     = False