コード例 #1
0
class GravityGame():
	def __init__(self):
		self.playerscolors = ColorCollection()
		self.clock=pygame.time.Clock()
		self.ThisWorld = MyWorld(self)
		self.ThisWorld.makeworld(0)
	def run(self):
		while self.ThisWorld.done == False:
			HandleEvents(self.ThisWorld)
			self.ThisWorld.update()
			for epl in self.ThisWorld.list_of_explosions:
				pygame.sprite.spritecollide(epl, self.ThisWorld.players, True, pygame.sprite.collide_circle)
			for p in self.ThisWorld.list_of_planets:
				pygame.sprite.spritecollide(p, self.ThisWorld.list_of_bullets, True, pygame.sprite.collide_circle)
				p.update()
			self.ThisWorld.players.draw(background)
			self.ThisWorld.list_of_bullets.draw(background)
			self.ThisWorld.list_of_explosions.draw(background)
			screen.blit(background, (0,0))
			self.clock.tick(20)
			pygame.display.flip()
		self.playerscolors.reset()
		if len(self.ThisWorld.players)<2:
			# assuming we have some winner now that the game is over
			wscreen = winscreen(self.ThisWorld.players.sprites()[0].id)
		else:
			messagescreen("Cancelled by User")
		screen.blit(background, (0,0))
		pygame.display.flip()
		time.sleep(5)
コード例 #2
0
def main():
    wsizex = 512
    wsizey = 512
    margin = 10
    root = Tk()
    root.title(" Simulador de Doenças ")
    world = MyWorld()
    # maps the world rectangle onto a viewport of wsizex x wsizey pixels .
    canvas = Canvas(root, width=512, height=512, background='dark grey')
    sp = SimulationPanel(world, canvas)
    sp.wvmap = mapper([0, 0, world.getWidth() - 1,
                       world.getHeight() - 1],
                      [margin, margin, wsizex - margin, wsizey - margin],
                      False, False)
    print([0, 0, world.getWidth() - 1,
           world.getHeight() - 1],
          [margin, margin, wsizex - margin, wsizey - margin])
    poll = Timer(root, sp.draw, 500)
    canvas.bind("<Configure>", sp.resize)
    root.bind("<Escape>", lambda _: root.destroy())
    root.bind("s", lambda _: poll.stop())
    root.bind("r", lambda _: poll.restart())
    root.bind("p", sp.printData)
    root.bind("<Button-1>", lambda e: sp.mousePressed(e))
    poll.run()
    root.mainloop()
コード例 #3
0
def main(args=None):
    numItr = 5
    if len(args) > 1:
        numItr = (args[1])
    print('Simulation of MyWorld')
    world = MyWorld()
    for x in range(numItr):
        world.act()
        obj = world.getObjects()
        for each in obj:
            each.act()
    print('Simulation of World')
    world = World(100, 100)
    world.addObject(Actor(), 10, 10)
    world.addObject(Actor(), 90, 90)
    for x in range(numItr):
        world.act()
        obj = world.getObjects()
        for each in obj:
            each.act()
コード例 #4
0
	def __init__(self):
		self.playerscolors = ColorCollection()
		self.clock=pygame.time.Clock()
		self.ThisWorld = MyWorld(self)
		self.ThisWorld.makeworld(0)