Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "player"
- bullet = {}
- function bullet.load()
- bullet.x = player.x / 2
- bullet.y = player.y / 2
- bullet.speed = 2
- bullet.width = 2
- bullet.height = 2
- end
- function bullet.draw()
- love.graphics.setColor(128, 128, 128)
- for i,v in ipairs(bullet) do
- love.graphics.rectangle("fill", v.x, v.y, bullet.width, bullet.height)
- end
- end
- function bullet.update(dt)
- for i,v in ipairs(bullet) do
- v.x = v.x + (v.dx * dt)
- v.y = v.y + (v.dy * dt)
- end
- end
- function love.mousepressed(x, y, button)
- if button == "l" then
- local startX = player.x + player.width / 2
- local startY = player.y + player.height / 2
- local mouseX = x
- local mouseY = y
- local angle = math.atan2((mouseY - startY), (mouseX - startX))
- local bulletDx = bullet.speed * math.cos(angle)
- local bulletDy = bullet.speed * math.sin(angle)
- table.insert(bullet, {x = startX, y = startY, dx = bulletDx, dy = bulletDy})
- end
- end
- function UPDATE_BULLET(dt)
- bullet.update()
- love.mousepressed()
- end
- function DRAW_BULLET()
- bullet.draw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement