main:
Code: Select all
require "core/font"
require "core/player_equip"
require "core/physics"
require "core/player"
require "core/player_turn"
require "core/bullet"
require "core/mobs"
function love.load()
player_create()
bullet_spawn()
love.graphics.setBackgroundColor(104, 136, 248)
end
function love.update(dt)
bullet_keyPressed()
bullet_shoot(dt)
player_turn(dt)
end
function love.draw()
player_draw()
bullet_draw()
end
function love.mousepressed(x, y, button)
end
Code: Select all
shots = {} -- This is where all of the shots are stored
objects.bullet = {}
function bullet_spawn()
objects.bullet.body = love.physics.newBody(world, objects.player.body:getX(), objects.player.body:getY(), 1)
objects.bullet.shape = love.physics.newRectangleShape(2, 5)
objects.bullet.fixture = love.physics.newFixture(objects.bullet.body, objects.bullet.shape, 1)
objects.bullet.body:setBullet(true)
end
function bullet_keyPressed()
if love.mouse.isDown("l") then
bullet_shoot()
table.insert(shots, objects.bullet)
end
end
function bullet_shoot(dt)
for i, v in ipairs(shots) do
if curDirection == playerUp then
v.y = v.y-dt * 100
elseif curDirection == playerDown then
v.y = v.y+dt * 100
elseif curDirection == playerLeft then
v.x = v.x+dt * 100
elseif curDirection == playerRight then
v.x = v.x+dt * 100
end
end
end
function bullet_draw()
love.graphics.setColor(0, 0, 0)
for i,v in ipairs(shots) do
love.graphics.rectangle("fill", v.x, v.y, 2, 5)
end
end