Page 1 of 1

First time coding a game, hit a wall

Posted: Mon Feb 01, 2016 8:52 pm
by Teshi
Hi, I've been coding a basic top down shooter for my computing project at my sixth form. Currently the current state is on github. https://github.com/TeshiV/Game

Ok the trouble im having is, ive just tried to implement a camera system, which works! But its resulted in the bullet firing being... messed up i guess. I think i understand whats going on but i dont know how to go about fixing it, if someone could point me in the right direction I would be very greatful. I think that whats happening is the mouse x and y positions dont change when i move but obviously the player's position changes so i think this is causing the problem with shooting. Sorry if what ive said is confusing :s

Re: First time coding a game, hit a wall

Posted: Mon Feb 01, 2016 9:17 pm
by bobbyjones
You are right. You need to convert the mouse coords to world coords. Maybe adding the the x and y of the top left of your camera to the mouse coords. So maybe

Code: Select all

function toWorldCoords(x,y)
    x = x + (cameraX-love.graphics.getWidth()/2)
    y = y + (cameraY-love.graphics.getHeight()/2)
    return x,y
end

Re: First time coding a game, hit a wall

Posted: Mon Feb 01, 2016 9:34 pm
by Teshi
Thanks! I managed to fix it using your suggestion with a tweak, instead of (cameraX - love.graphics.getWidth()/2) etc i just did
x = x + cameraX etc