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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
tiresandplanes
Prole
Posts: 2
Joined: Tue Dec 17, 2013 11:32 pm

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

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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?)
Help us help you: attach a .love.
tiresandplanes
Prole
Posts: 2
Joined: Tue Dec 17, 2013 11:32 pm

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

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

Who is online

Users browsing this forum: Google [Bot] and 5 guests