It's my first post, so first I'd like to say hello to everyone!
I've got the problem with my prototype movement system. Been through all the internets, but I just can't wrap my mind around it...
First, I load useful libs
... and I define shorthand to compute rotation angle:loader = require("ATL/Loader")
local anim8 = require 'anim8/anim8'
loader.path = "MAPS/"
local gamera = require 'gamera'
function findRotation(x1,y1,x2,y2)
return (math.atan2(y2 - y1, x2 - x1))
end -- learned from this forum
Secondly, I'm initiating everything like this:
So far so good.function love.load()
love.window.setFullscreen(true, "desktop")
--THIS WILL GO TO THE CLASSES ONE DAY
image = love.graphics.newImage("img/little_running_dude.png")
local g = anim8.newGrid(64,64,image:getWidth(), image:getHeight())
animation = anim8.newAnimation(g('1-6',1), 0.2)
map = loader.load("FloorTest.tmx"); -- LOAD MAP
gCamX,gCamY = 15*592,15*592 -- SET POSITION TO THE CENTER OF THE WORLD (30 _BIG_ TILES )
cam = gamera.new(0, 0, 30*592, 30*592); --
map:setDrawRange(0,0,30*592, 30*592)
speed = 20 -- THIS WILL BE PLAYER SPEED
Next:
Finally:function love.update(dt)
HeroDirection = findRotation(love.graphics.getWidth()/2, love.graphics.getHeight()/2, love.mouse.getX(), love.mouse.getY()) -- * arbitraly chosen constant to speed up things.
if love.keyboard.isDown("w") then
-- WHAT SHOULD I DO HERE?
-- dude should move forward, towards upper center of the screen
-- beside this:
animation:update(dt)
elseif love.keyboard.isDown("s") then
-- AND HERE?
-- opposite to above
animation:update(dt)
elseif love.keyboard.isDown("d") then
-- dude should rotate around mouse cursor //strafe
animation:update(dt)
elseif love.keyboard.isDown("a") then
-- in opposite direction
animation:update(dt)
elseif love.keyboard.isDown("escape") then
love.event.quit()
else
animation:gotoFrame(1); -- dude is standing still
end
cam:setPosition(gCamX,gCamY) -- MOVE CAMERA
cam:setAngle(HeroDirection) -- AND ROTATE IT
end
Everything works kind'a fine, in e. world rotates, dude rotates as well - always facing upper center of the screen - so that's good. But when it comes to movement, I just give up. Tried everything I could think of and every solution I've found and only wierd stuff is happening.function love.draw()
cam:draw(function()
map:draw()
animation:draw(image, gCamX, gCamY, HeroDirection )
end)
end
How should I move the dude to the direction he's facing?
And - that would be awesome - is there any way to lock the mouse cursor position on demand? So it would serve as stationary crosshair until one will enter, lets say, menu mode?
//Edit: Actually, it could just stay in a given radius around the center of a screen.
Thanks in advance!