First time coding a game, hit a wall

Show off your games, demos and other (playable) creations.
Post Reply
Teshi
Prole
Posts: 11
Joined: Mon Feb 01, 2016 6:51 pm

First time coding a game, hit a wall

Post 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
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: First time coding a game, hit a wall

Post 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
Teshi
Prole
Posts: 11
Joined: Mon Feb 01, 2016 6:51 pm

Re: First time coding a game, hit a wall

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests