p1.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. p1 = {
  2. -- Pushed values to this object on update (self.xxx)
  3. -- x,y (in) : top left corner of the entity
  4. -- vx,vy (in) : Velocity
  5. -- width (in), height : dimensions of the map<->entity hitbox
  6. -- points (in) : scored points
  7. -- intent (in-out) : Intended direction of the entity when it'll can.
  8. -- Editing intent will impact the AI's deplacement.
  9. -- The game structure
  10. -- The map is stored as 8*8pixel tiles.
  11. -- The map has a dimension of 224*248 pixels (borders included).
  12. -- To push the IA to move to another direction when it can, edit self.
  13. -- The game structure stores the players' and ghosts' position (in pixel) and velocity
  14. -- gamestructure.p1.x
  15. -- gamestructure.p2.y
  16. -- gamestructure.blinky == red
  17. -- gamestructure.inky == cyan
  18. -- gamestructure.pinky == huh
  19. -- gamestructure.clyde == orange
  20. -- gamestate functions
  21. -- Note : All of those functions needs gamestate.data as first argument
  22. -- collide(gamestate.data, x,y,w,h) checks if a rectangle defined by its left corner and its dimensions collides with the walls.
  23. -- get_tile(gamestate.data, x, y) returns the tile on the map with tile coordinates. Returns a tbale with a has_gum integer and is_solid boolean
  24. init = function(self)
  25. end,
  26. update = function(self)
  27. self.intent = math.random(0, 4)
  28. local pos = self:get_tile_coords_at_center()
  29. end,
  30. -- This one wil just be called from update or init as such:
  31. -- self:get_tile_coords_at_center
  32. -- Returns a table {x = tile_pos_y, y = tile_pos_y} or nil when the Pacman is out of bounds, so to use the variables
  33. -- do something like this:
  34. -- local pos = self:get_tile_coords_at_center()
  35. -- print("x : "..pos.x.." y : "..pos["x"])
  36. get_tile_coords_at_center = function(self)
  37. if self.x < 0 or self.x > 224-16 or self.y < 0 or self.y > 248-16 then
  38. return nil
  39. else
  40. return {x=math.floor((self.x+4)/8), y=math.floor((self.y+4)/8)}
  41. end
  42. end
  43. }