Page 1 of 1

Can someone help me with dt (for a frogger game)

Posted: Mon Jan 20, 2014 6:18 pm
by tiresandplanes
I'm having trouble using dt with a frogger clone I'm making. dt works but it doesn't loop the cars back around like I want it to. Here are the parts of the code that matter. I'm pretty sure I understand the problem, I just don't know how to fix it exactly. I think the variables in volks:new() have changed so when I put a volks:new() it is taking the current variables so it just keeps moving forward. How would I make it so it loops?

Code: Select all

volks = {}
 function volks:new()
 		vw = {

			act_x_vw =0,
			act_y_vw =315,
			 
			grid_x_vw = 0,
			grid_y_vw =315,

			speed = 30,

			w =60,
			h = 20,
			imgbuggy = love.graphics.newImage("img/buggy.png"),

			act_x_vwt = 0,
			act_y_vwt =160,
			 
			grid_x_vwt = 0,
			grid_y_vwt =160,

 			}
 			setmetatable(vw,{__index = volks})
 			return vw
 end

 function volks:update(dt)
 		if vw.act_x_vw  ~= (580) then
			vw.act_x_vw= vw.act_x_vw + vw.speed * dt
		end
		if vw.grid_x_vw ~= (580) then
			vw.grid_x_vw = vw.grid_x_vw + vw.speed * dt
		end
		if vw.act_x_vw  == (580) then
			volks:new() 
		end
		if vw.grid_x_vw == (580) then
			volks:new() 
		end

end

Re: Can someone help me with dt (for a frogger game)

Posted: Mon Jan 20, 2014 6:36 pm
by Robin
You check if it is equal to 580, so if it overshoots, it'll never reset.

Solution: replace ~= by < and == by >=.

(Also, why do you have both act_x_vw and grid_x_vw?)

Re: Can someone help me with dt (for a frogger game)

Posted: Mon Jan 20, 2014 7:02 pm
by tiresandplanes
ahh thank you so much, I am not sure why I had both act_x_vw and grid_x_vw, got rid of one of them. I think I originally wanted it to be okay with collision with the frog, but it seems fine.