Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. require "player"
  2.  
  3. bullet = {}
  4.  
  5. function bullet.load()
  6.     bullet.x = player.x / 2
  7.     bullet.y = player.y / 2
  8.     bullet.speed = 2
  9.     bullet.width = 2
  10.     bullet.height = 2
  11. end
  12.  
  13. function bullet.draw()
  14.     love.graphics.setColor(128, 128, 128)
  15.     for i,v in ipairs(bullet) do
  16.         love.graphics.rectangle("fill", v.x, v.y, bullet.width, bullet.height)
  17.     end
  18. end
  19.  
  20. function bullet.update(dt)
  21.     for i,v in ipairs(bullet) do
  22.         v.x = v.x + (v.dx * dt)
  23.         v.y = v.y + (v.dy * dt)
  24.     end
  25. end
  26.  
  27. function love.mousepressed(x, y, button)
  28.     if button == "l" then
  29.         local startX = player.x + player.width / 2
  30.         local startY = player.y + player.height / 2
  31.         local mouseX = x
  32.         local mouseY = y
  33.  
  34.         local angle = math.atan2((mouseY - startY), (mouseX - startX))
  35.  
  36.         local bulletDx = bullet.speed * math.cos(angle)
  37.         local bulletDy = bullet.speed * math.sin(angle)
  38.  
  39.         table.insert(bullet, {x = startX, y = startY, dx = bulletDx, dy = bulletDy})
  40.     end
  41. end
  42.  
  43. function UPDATE_BULLET(dt)
  44.     bullet.update()
  45.     love.mousepressed()
  46. end
  47. function DRAW_BULLET()
  48.     bullet.draw()
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement