shape.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. local shape = {}
  2. shape.__index = shape
  3. local vec3 = require('lib/cpml').vec3
  4. local quat = require('lib/cpml').quat
  5. local squareModel = lovr.graphics.newModel('art/duck.dae')
  6. squareModel:setTexture(lovr.graphics.newTexture('art/duck.tga'))
  7. local circleModel = lovr.graphics.newModel('art/mobile_plane.obj')
  8. circleModel:setTexture(lovr.graphics.newTexture('art/mobile_DIFF.png'))
  9. function shape.grow(position, type)
  10. local self = {}
  11. self.type = type
  12. self.position = position
  13. if self.type == 'square' then
  14. self.model = squareModel
  15. else
  16. self.model = circleModel
  17. end
  18. self.direction = vec3(0, 0, 0) - position -- player position - my postiion
  19. self.speed = _.random(.15, .2)
  20. local quat = quat.from_direction(self.direction, vec3(0, 1, 0))
  21. self.angle, self.axis = quat.to_angle_axis(quat)
  22. return setmetatable(self, shape)
  23. end
  24. function shape:update(dt)
  25. self.position = self.position + self.direction * dt * self.speed
  26. end
  27. function shape:draw()
  28. local x, y, z = vec3.unpack(self.position)
  29. local ax, ay, az = vec3.unpack(self.axis)
  30. self.model:draw(x, y, z, .1, self.angle, ax, ay, az)
  31. end
  32. return shape