Advertisement
Guest User

Untitled

a guest
May 29th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. local Astar = require "engine.Astar"
  2.  
  3. newAI("creep_move_simple", function(self)
  4. if self.ai_target.grid then
  5. local tx, ty = self:aiSeeTargetPos(self.ai_target.grid)
  6. return self:moveDirection(tx, ty)
  7. end
  8. end)
  9.  
  10. newAI("creep_move_astar", function(self)
  11. if self.ai_target.grid then
  12. local tx, ty = self:aiSeeTargetPos(self.ai_target.grid)
  13. if tx==self.x and ty==self.y then
  14. self:spawnSinkReached()
  15. end
  16. local a = Astar.new(game.level.map, self)
  17. local path = a:calc(self.x, self.y, tx, ty)
  18. if not path then
  19. return self:runAI("creep_move_simple")
  20. else
  21. return self:move(path[1].x, path[1].y)
  22. end
  23. end
  24. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement