예제 #1
0
파일: ants.py 프로젝트: nfredrik/mcandre
def play(screen, settings):
	clock=pygame.time.Clock()

	lengths=screenlengths.get_lengths(screen)

	ants=[
		Ant.Ant(
			[
				lengths["midX"]+random.choice(range(-5, 5)),
				lengths["midY"]+random.choice(range(-5, 5))
			],
			random.choice(
				[[0, 1], [1, 0], [0, -1], [-1, 0]]
			)
		)

		for i in range(settings["antcount"])
	]

	env=Environment.Environment(screen, ants, settings["foodcount"], settings["foodsize"])

	while True:
		for event in pygame.event.get():
			if event.type==pygame.QUIT:
				sys.exit()
			elif event.type==pygame.KEYDOWN:
				if event.key==settings["keyescape"]:
					sys.exit()
				elif event.key==pygame.K_q and event.mod==pygame.KMOD_LMETA or event.mod==pygame.KMOD_RMETA: # Command+Q
					sys.exit()
				elif event.key==settings["keyscreenshot"]:
					screenshot.save(screen, settings["screenshotdir"])

		env.update()

		screen.fill(env.DIRT_COLOR)

		screen.fill(env.HOME_COLOR, env.home)

		for rect in env.food_areas:
			screen.fill(env.FOOD_COLOR, rect)

		#for ant in ants:
		#	for pos in ant.visited_trail:
		#		screen.fill(ant.VISITED_TRAIL_COLOR, pygame.Rect(pos[0], pos[1], 1, 1))

		for ant in ants:
			for pos in ant.food_trail:
				screen.fill(ant.FOOD_TRAIL_COLOR, pygame.Rect(pos[0], pos[1], 1, 1))

		for ant in ants:
			if ant.is_alive:
				screen.fill(ant.COLOR, ant.get_rect())

		if settings["screensync"]:
			clock.tick(settings["fps"])

		pygame.display.flip()
예제 #2
0
def play(screen, settings):
    clock = pygame.time.Clock()

    lengths = screenlengths.get_lengths(screen)

    ants = [
        Ant.Ant([
            lengths["midX"] + random.choice(range(-5, 5)),
            lengths["midY"] + random.choice(range(-5, 5))
        ], random.choice([[0, 1], [1, 0], [0, -1], [-1, 0]]))
        for i in range(settings["antcount"])
    ]

    env = Environment.Environment(screen, ants, settings["foodcount"],
                                  settings["foodsize"])

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == settings["keyescape"]:
                    sys.exit()
                elif event.key == pygame.K_q and event.mod == pygame.KMOD_LMETA or event.mod == pygame.KMOD_RMETA:  # Command+Q
                    sys.exit()
                elif event.key == settings["keyscreenshot"]:
                    screenshot.save(screen, settings["screenshotdir"])

        env.update()

        screen.fill(env.DIRT_COLOR)

        screen.fill(env.HOME_COLOR, env.home)

        for rect in env.food_areas:
            screen.fill(env.FOOD_COLOR, rect)

        #for ant in ants:
        #	for pos in ant.visited_trail:
        #		screen.fill(ant.VISITED_TRAIL_COLOR, pygame.Rect(pos[0], pos[1], 1, 1))

        for ant in ants:
            for pos in ant.food_trail:
                screen.fill(ant.FOOD_TRAIL_COLOR,
                            pygame.Rect(pos[0], pos[1], 1, 1))

        for ant in ants:
            if ant.is_alive:
                screen.fill(ant.COLOR, ant.get_rect())

        if settings["screensync"]:
            clock.tick(settings["fps"])

        pygame.display.flip()
예제 #3
0
    def __init__(self, screen, ants, foodcount=2, foodsize=30):
        self.screen = screen
        self.lengths = screenlengths.get_lengths(screen)

        self.home = self.generate_home()

        self.ants = ants

        self.food_areas = self.generate_food(foodcount, foodsize)

        self.food = []
예제 #4
0
    def __init__(self, screen, ants, foodcount=2, foodsize=30):
        self.screen = screen
        self.lengths = screenlengths.get_lengths(screen)

        self.home = self.generate_home()

        self.ants = ants

        self.food_areas = self.generate_food(foodcount, foodsize)

        self.food = []