Code: Select all
-- Asteroids Clons
-- Author: Michael Wales ([email protected])
-- License: Creative Commons BSD (http://creativecommons.org/licenses/BSD)
function love.load()
love.graphics.setMode(1024, 768, false, false)
game = {}
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
player = {}
player.sprite = love.graphics.newImage("player.png")
player.x = game.width / 2
player.y = game.height / 2
player.accelerating = false
player.velocity = 0
player.max_velocity = 10.0
player.acceleration = 0.5
player.rotate = 0
player.rotation_speed = 0.25
-- Preload image resources
background = love.graphics.newImage("background.png")
end
function love.update(dt)
if love.keyboard.isDown("up") then
player.accelerating = true
else
player.accelerating = false
end
if love.keyboard.isDown("right") then
player.rotate = player.rotate + player.rotation_speed
print("RIGHT")
elseif love.keyboard.isDown("left") then
player.rotate = player.rotate - player.rotation_speed
print("LEFT")
end
if player.accelerating then
player.velocity = player.velocity + player.acceleration
if player.velocity >= player.max_velocity then
player.velocity = player.max_velocity
end
else
player.velocity = player.velocity - player.acceleration
if player.velocity <= 0 then
player.velocity = 0
end
end
end
function love.draw()
love.graphics.draw(background, 0, 0)
love.graphics.draw(player.sprite, player.x, player.y, player.rotate * (math.pi / 180), 1, 1, player.sprite:getWidth() / 2, player.sprite:getHeight() / 2)
-- Debug Info
love.graphics.print("FPS: " .. love.timer.getFPS(), 10, 10)
end
function love.keypressed(key)
end
Another thought I had was using slope grade and I did a bit of proofing in regards to that:
0-degrees = -player.velocity/0
90-degrees = 0/velocity
180-degrees = velocity/0
270-degrees = 0/-velocity
45-degrees = -(velocity/2)/(velocity/2)
Even running through those scenarios hasn't pointed me in the right direction. I'm confident that math.tan() is going to point me in the right direction but the grid coordinate system is messing with my brain (as opposed to the grid coordinate system we always learned in school, where (0, 0) was center).
Can anyone give me a helpful hint in the right direction? Not looking for completed code here, just a helpful nudge to send me into the "AHA!" moment.