Esempio n. 1
0
    def __init__(self, name='Taxi Agent Editor', use_ai=False, map_name=None):
        self.name = name
        self.map_name = map_name
        self.use_ai = use_ai

        pygame.init()

        self.evManager = Event.EventManager()

        if self.name == 'Taxi Agent':
            self.player = Player.Player(self.evManager)

            self.character = Car.Car(Settings.CAR_IMAGE, self.evManager)
            self.map = Map.Map(self.evManager)

            if self.map_name is not None:
                self.map.load_map(self.map_name)
                self.mode = Game.Mode(Game.Mode.PLAY_MODE)
            else:
                self.mode = Game.Mode(Game.Mode.POINT_EDITING)

            self.game = Game.Game(self.player, self.character, self.map,
                                  self.mode, self.evManager)
            self.gameController = Game.GameController(self.game,
                                                      self.evManager)

            self.gameView = None

            self.evManager.post(Event.ChangeModeEvent(self.mode))
Esempio n. 2
0
	def notify(self, event):
		if isinstance(event, Event.TickEvent):
			for event in pygame.event.get():

				ev = None

				# Quit event from pygame
				if event.type == pygame.QUIT:
					ev = Event.QuitEvent()

				# If keyboard key is pressed
				elif event.type == pygame.KEYDOWN:

					if event.key == Settings.KEY_QUIT:
						ev = Event.QuitEvent()

					elif event.key == Settings.KEY_POINT_EDITING:
						ev = Event.ChangeModeEvent(Game.Mode(Game.Mode.POINT_EDITING))

					elif event.key == Settings.KEY_LINE_EDITING:
						ev = Event.ChangeModeEvent(Game.Mode(Game.Mode.LINE_EDITING))

					elif event.key == Settings.KEY_PLAY_MODE:
						ev = Event.ChangeModeEvent(Game.Mode(Game.Mode.PLAY_MODE))

					elif event.key == Settings.KEY_TOGGLE_DEBUG:
						ev = Event.ToggleDebugEvent()

					elif event.key == Settings.KEY_SAVE_MAP:
						ev = Event.SaveMapEvent(input('Map name : '))

					elif event.key == Settings.KEY_LOAD_MAP:
						ev = Event.LoadMapEvent(input('Map name : '))

				# If mouse is pressed
				elif event.type == pygame.MOUSEBUTTONDOWN:

					if event.button == Settings.MOUSE_CREATE:
						ev = Event.CreationEvent()

					elif event.button == Settings.MOUSE_REMOVE:
						ev = Event.RemovingEvent()

				if ev is not None:
					self.evManager.post(ev)

			# Keyboard inputs that has to be maintained
			key_pressed = pygame.key.get_pressed()
			direction = Vector2(0, 0)

			if key_pressed[Settings.KEY_MOVE_FRONT]:
				direction += Vector2(1, 0)

			if key_pressed[Settings.KEY_MOVE_BACK]:
				direction += Vector2(-1, 0)

			if key_pressed[Settings.KEY_MOVE_LEFT]:
				direction += Vector2(0, 1)

			if key_pressed[Settings.KEY_MOVE_RIGHT]:
				direction += Vector2(0, -1)

			if direction.x != 0 or direction.y != 0:
				self.evManager.post(Event.MovePlayerEvent(direction))