Code: Select all
width = love.graphics.getWidth()
height = love.graphics.getHeight()
xpos, ypos = width/2, height/2
xvel, yvel = 0, 0
rotation = 0
bounce = 0.01
friction = 1.0085
boost = 3000
lRTime = 60
laserReload = 0
laserInitVel = 15
laserNum = 0
lasers = {}
function love.update()
width = love.graphics.getWidth()
height = love.graphics.getHeight()
if love.keyboard.isDown("up") then
xvel = math.cos(math.rad(rotation))*5
yvel = math.sin(math.rad(rotation))*5
end
if love.keyboard.isDown("down") then
if boost > 0 then
xvel = math.cos(math.rad(rotation))*10
yvel = math.sin(math.rad(rotation))*10
boost = boost - 1
else
xvel = math.cos(math.rad(rotation))*5
yvel = math.sin(math.rad(rotation))*5
end
end
if love.keyboard.isDown("left") then
rotation = rotation - 1
end
if love.keyboard.isDown("right") then
rotation = rotation + 1
end
if love.keyboard.isDown(" ") then --Making a laser. Once a laser is made, it's given a position and a velocity
if laserReload <= 0 then
table.insert(lasers, (--[[["laser.."laserNum] = ]]{xpos+(math.cos(math.rad(rotation))*10),ypos+(math.sin(math.rad(rotation))*10), math.cos(math.rad(rotation))*laserInitVel, math.sin(math.rad(rotation))*laserInitVel}))
laserReload = laserReload + lRTime
end
end
--next part is simple collision st00f, temporary
if xpos-10 <= 0 then
xvel = xvel * -1 * bounce
xpos = 10
end
if xpos+10 >= width then
xvel = xvel * -1 * bounce
xpos = width-10
end
if ypos-10 <= 0 then
yvel = yvel * -1 * bounce
ypos = 10
end
if ypos+10 >= height then
yvel = yvel * -1 * bounce
ypos = height-10
end
if laserReload > 0 then
laserReload = laserReload - 1
end
for a, b in pairs(lasers) do--Keepin' those lasers moving. If they leave the
b[1] = b[1] + b[3]/10
b[2] = b[2] + b[4]/10
if b[1] >= width+10 or b[1] <= 0-10 or b[2] >= height+10 or b[2] <= 0-10 then
table.remove(lasers, a)
end
end
xpos = xpos + xvel/10
ypos = ypos + yvel/10
xvel = xvel/friction
yvel = yvel/friction
end
function love.draw()
love.graphics.setColor(255,63,0)
love.graphics.print("Boost Fuel: "..boost, 10, 100)
love.graphics.setColor(0,127,255)--From here...
love.graphics.translate(xpos, ypos)
love.graphics.rotate(math.rad(rotation+90))
love.graphics.polygon("fill", 0, -10, 10, 10, 0, 5, -10, 10)
love.graphics.setColor(255,255,255)
love.graphics.line(0, 5, 0, -10)--To here, components of the ship are rendered.
love.graphics.translate(0, 0)
love.graphics.rotate(math.rad(0))
for c, d in pairs(lasers) do--Rendering them lasers. Length affected by speed.
love.graphics.line(d[1]-d[3]/5, d[2]-d[4]/5, d[1]+d[3]/5, d[2]+d[4]/5)
end
end