I've attached a screen shot to get a better reference to whats going on. the white dot represents the mouse...
thank you guys!
Code: Select all
function love.load()
world = love.physics.newWorld(0, 0, false)
sprites = {}
sprites.player1 = love.graphics.newImage("sprites/Soldier1/soldier1_hold.png")
sprites.player2 = love.graphics.newImage("sprites/Soldier1/soldier1_gun.png")
sprites.weapon1 = love.graphics.newImage("sprites/weapon_gun.png")
require("player")
cameraFile = require('library/hump-master/camera')
cam = cameraFile()
bullets = {}
end
function love.update(dt)
for i, b in ipairs(bullets) do
b.x = b.x + math.cos(b.direction) * b.speed * dt
b.y = b.y + math.sin(b.direction) * b.speed * dt
end
cam:lookAt(player.body:getX(), player.body:getY())
world:update(dt)
playerUpdate(dt)
end
function love.draw()
cam:attach()
if player.hasWeapon == false then
love.graphics.draw(sprites.player1, player.body:getX(), player.body:getY(), playerRotation(), nil, nil, sprites.player1:getWidth()/2, sprites.player1:getHeight()/2)
elseif player.hasWeapon == true then
love.graphics.draw(sprites.player2, player.body:getX(), player.body:getY(), playerRotation(), nil, nil, sprites.player2:getWidth()/2, sprites.player2:getHeight()/2)
end
for i, b in ipairs(bullets) do
love.graphics.draw(sprites.weapon1, b.x, b.y, nil, 0.25, 0.5, sprites.weapon1:getWidth()/2, sprites.weapon1:getHeight()/2)
end
cam:detach()
end
function spawnBullet()
bullet = {}
bullet.x = player.body:getX()
bullet.y = player.body:getY()
bullet.direction = playerRotation()
bullet.speed = 500
bullet.dead = false
table.insert(bullets, bullet)
end
function playerRotation()
return math.atan2(player.body:getY() - love.mouse.getY(), player.body:getX() - love.mouse.getX()) + math.pi
end