Esempio n. 1
0
	def run(self):
		pygame.display.init()
		pygame.font.init()

		ui.loadImages('assets/ui')
		bullet.loadImages('assets/bullets')
		explosion.loadImages('assets/explosion')
		sound.loadSounds('assets/sounds')

		self.clock = pygame.time.Clock()
		self.event_manager = event.EventManager()
		self.interface = menu.Menu(self.screen)
		self.cursor = ui.IMAGES['cursor']
		pygame.mouse.set_visible(False)

		while self.running:
			self.event_manager.get()

			if self.game is not None:
				self.game.tick()
			self.interface = self.interface.update(self.event_manager.events)

			self.screen.blit(self.cursor, pygame.mouse.get_pos())

			pygame.display.flip()
			self.clock.tick(my.FPS)
			pygame.display.set_caption("Tanks - v" + my.VERSION + " - FPS: " + str(round(self.clock.get_fps(), 1)))
Esempio n. 2
0
def main():
    # # Initialise screen and event manager  
    event_manager = event.EventManager()
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    event_manager.register("quit", close)

    #initialise view, model
    player_view = view.View(event_manager, screen)
    game_model = model.Model(event_manager)
    fpsClock = pygame.time.Clock()
    

    ## Event loop (should be all the logic in this file apart from setup)
    while running:
        fpsClock.tick(settings.FRAME_TIME)
        event_manager.notify("update", fpsClock.get_time()/1000.0)
        event_manager.update()
Esempio n. 3
0
    def initialize(self, settings, opts=None, progressCB=None):
        """ Initialize the environment. """
        self.settings = settings
        self.mCmdOpts = opts

        # -- Event Manager -- #
        # Create an event dispatcher that will:
        #   - Connect to remote event manager objects.
        #   - Emit events to remote event manager objects.
        self.mEventManager = event.EventManager()

        # -- Plugin manager -- #
        self.mPluginManager = maestro.util.plugin.PluginManager()
        self.mPluginManager.scan(pj(maestro.core.const.PLUGIN_DIR), progressCB)
        #self.pluginManager.scan(self.settings.plugin_paths, progressCB)
        plugins = self.mPluginManager.getPlugins(returnNameDict=True)
        self.mLogger.info('Environment found plug-ins:')
        for (name, p) in plugins.iteritems():
            self.mLogger.info('  %s : %s' % (name, p))
Esempio n. 4
0
def startIa(pipe=None, ia_color="YELLOW"):
    Communication = communication.CommunicationGlobale()
    arduino_constantes = Communication.getConst()

    logging.basicConfig(
        filename=os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              "log/last_" + str(ia_color) + ".log"),
        filemode='w',
        level=logging.DEBUG,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    logger = logging.getLogger(__name__.split('.')[0])

    if pipe == None:
        logger.info("Demarrage d'une IA normal")
        time.sleep(10)  # on attend que les communications s'établissent

        if TEST_MODE == False:
            #On teste si les systèmes demandés sont bien en lignes
            ready_list = Communication.getSystemReady()
            if ENABLE_FLUSSMITTEL == True and (
                ('ADDR_FLUSSMITTEL_OTHER' not in ready_list) or
                ('ADDR_FLUSSMITTEL_ASSERV' not in ready_list)):
                logger.critical(
                    "ERREUR: Incohérence de communication avec le gros robot, le systeme suivant a été demandé mais pas trouvé: ENABLE_FLUSSMITTEL: "
                    + str(ENABLE_FLUSSMITTEL) + " ready_list: " +
                    str(ready_list))
                exit()
            if ENABLE_TIBOT == True and (
                ('ADDR_TIBOT_OTHER' not in ready_list) or
                ('ADDR_TIBOT_ASSERV' not in ready_list)):
                logger.critical(
                    "ERREUR: Incohérence de communication avec le petit robot, le systeme suivant a été demandé mais pas trouvé: ENABLE_TIBOT: "
                    + str(ENABLE_TIBOT) + " ready_list: " + str(ready_list))
                exit()
            if ENABLE_TOURELLE == True and 'ADDR_TOURELLE' not in ready_list:
                logger.critical(
                    "ERREUR: Incohérence de communication avec la tourelle, le systeme suivant a été demandé mais pas trouvé: ENABLE_TOURELLE: "
                    + str(ENABLE_TOURELLE) + " ready_list: " + str(ready_list))
                exit()
            logger.info(
                "Les systèmes attendu ont bien été détéctés. Flussmittel: %s   Tibot: %s   Tourelle: %s   ready_list: %s",
                ENABLE_FLUSSMITTEL, ENABLE_TIBOT, ENABLE_TOURELLE, ready_list)
        else:
            print("---------------------TEST_MODE activé---------------------")
            logger.warning(
                "----------------------------------------TEST_MODE activé----------------------------------------"
            )

    else:
        logger.info("Demarrage d'une IA depuis le simuateur")
        Communication = communication.CommSimulateur(pipe)

    Data = data.Data(Communication, arduino_constantes, ia_color)

    data.parametrerHokuyo()
    data.parametrerIa(Data.MetaData, ia_color)  #TODO, remove ia_color

    TimeManager = event.TimeManager(Communication, Data)
    EventManager = event.EventManager(Communication, Data)

    print("IA Ready !")
    while Data.MetaData.getInGame() == False:
        time.sleep(0.01)
    TimeManager.startMatch()

    #On attend sagement la fin
    while True:
        time.sleep(0.1)
Esempio n. 5
0
import ai
import event

e = event.EventManager()
a = ai.Agent(e)

a._reset_world()
a.visited = [(0, 0), (1, 0), (2, 0), (0, 1), (0, 2), (1, 2)]
a.pos = (2, 0)
goal = (1, 3)
path = a._shortest_path(goal)
plan = a._path2plan(path)

print "visited :", a.visited
print "cur_pos :", a.pos
print "goal :", goal
print "path :", path
print "plan :", plan