示例#1
0
	def update(self):
		if self.direction is not None:
			game_map.removeEntity(self)

			pos = Vector(self.x, self.y)
			if self.direction is NORTH:
				pos.y += 1
				pass
			elif self.direction is SOUTH:
				pos.y -= 1
				pass
			elif self.direction is EAST:
				pos.x += 1
				pass
			elif self.direction is WEST:
				pos.x -= 1
				pass

			if game_map.blocked(pos) is False:
				self.x = pos.x
				self.y = pos.y

			game_map.addEntity(self)
			self.direction = None
		pass
    def move(self):
        if self.target == Vector(self.x, self.y):
            print("Rat is resting.")
            return

        self.removeFromMap()

        if self.hunger > 0:
            self.lookForFood()

        directions = [Vector(0, 1), Vector(0, -1), Vector(1, 0), Vector(-1, 0)]

        pos = Vector(self.x, self.y)

        blocked = True

        distance = pos.distance(self.target)
        for direction in directions:
            test_pos = direction + pos
            if game_map.blocked(test_pos) is not True:
                if test_pos.distance(self.target) < distance:
                    pos = test_pos
                    distance = pos.distance(self.target)

        self.x = pos.x
        self.y = pos.y
        self.SP -= 8

        self.addToMap()
	def move(self): 
		if self.target == Vector(self.x, self.y):
			print("Rat is resting.")
			return

		self.removeFromMap()

		if self.hunger > 0:
			self.lookForFood()

		directions = [
			Vector(0, 1),
			Vector(0, -1),
			Vector(1, 0),
			Vector(-1, 0)
		]

		pos = Vector(self.x, self.y)

		blocked = True

		distance = pos.distance(self.target)
		for direction in directions:
			test_pos = direction + pos
			if game_map.blocked(test_pos) is not True:
				if test_pos.distance(self.target) < distance:
					pos = test_pos
					distance = pos.distance(self.target)

		self.x = pos.x
		self.y = pos.y
		self.SP -= 8

		self.addToMap()