Ejemplo n.º 1
0
    def draw(self, screen):
        """Draw the sprite translated by the camera's position.

        Does not draw if self.visible is False

        :param screen: pygame.Surface
        """
        if self.visible:
            screen.blit(self.image, camera.apply(self.rect))
Ejemplo n.º 2
0
def find_examine_text(cursor_pos):
    for obj in screen_objects:
        if obj.rect.collidepoint(cursor_pos):
            return obj.examine

    for obj in game_objects:
        # regular collision
        if camera.apply(obj.rect).collidepoint(cursor_pos):
            return obj.examine

        # pixel perfect collision
        # try:
        #     rel_point = util.sub(cursor_pos, camera.apply(object).topleft)
        #     if object.mask.get_at(rel_point):
        #         return object.examine
        # except (IndexError, AttributeError):
        #     pass
    return ""
Ejemplo n.º 3
0
 def draw(self, screen):
     screen.blit(self.image, camera.apply(self.rect))
Ejemplo n.º 4
0
 def draw(self, screen):
     screen.blit(self.image, camera.apply(self.rect))
Ejemplo n.º 5
0
                down = False
            elif e.key == pygame.K_RIGHT:
                right = False
            elif e.key == pygame.K_LEFT:
                left = False

    # clear/erase the last drawn sprites
    display.blit(background, (0, 0))
    # update all the sprites
    all.update()  #RenderUpdates

    hero.update(left, right, up, down, blocks)  # передвижение
    camera.update(hero)

    for e in all:
        # display.blit(e.image,[0,0])
        # display.blit(e.image,e.rect)
        display.blit(e.image, camera.apply(e))

    display.blit(hero.image, camera.apply(hero))

    if hero.weapon.visible:
        x0 = hero.rect.x + hero.rect.width / 2
        y0 = hero.rect.y - hero.rect.width / 2
        hero.weapon.update(x0, y0, blocks)
        display.blit(hero.weapon.image, camera.apply(hero.weapon))

    # dirty = all.draw(display)	#RenderUpdates
    # pygame.display.update(dirty)	#RenderUpdates
    pygame.display.flip()
    clock.tick(FPS)
Ejemplo n.º 6
0
def run_level(level):
	player = level.player
	triggers = level.triggers
	entities = level.entities
	background_entities = level.background_entities
	camera = level.camera
	barbers = level.barbers

	while True:
		CLOCK.tick(FPS)

		key_presses = pygame.event.get(pygame.KEYDOWN)
		key_states = pygame.key.get_pressed()

		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				return 'quit'

		if key_states[pygame.K_r]:
			return 'restart'

		if key_states[pygame.K_ESCAPE]:
			return 'quit'

		if player.life_lost == True:
			display_life_lost_screen()
			player.life_lost = False

		player.update(key_presses, key_states, level)
		player.mustache.update()
		camera.update(player)

		if player.dead == True:
			display_death_screen()
			return 'dead'

		if player.mustache_numb == 4 and player.completed == False:
			display_sequence_screens(SCREENS_COMPLETED)
			player.completed = True


		# draw the background
		for y in range(26):
			for x in range(20):
				SCREEN.blit(IMAGES['bg_wall'], (x * TILESIZE, y * TILESIZE))

		for entity in background_entities:
			entity.update()
			if entity.image.get_rect().colliderect(SCREEN.get_rect()):
				SCREEN.blit(entity.image, camera.apply(entity))

		for entity in triggers:
			SCREEN.blit(entity.image, camera.apply(entity))

		for barber in barbers:
			barber.update(level)

		for entity in entities:
			if entity.image.get_rect().colliderect(SCREEN.get_rect()):
				SCREEN.blit(entity.image, camera.apply(entity))
				SCREEN.blit(player.mustache.image, camera.apply(player))

		pygame.display.update()