Forever Alone Pong

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Forever Alone Pong

Post by veethree »

made this due to boredom and nothing else. This is basically single player pong where you control both of the players.

The whole thing is quite messy right now, Bunch of bugs and stuff. If i continue working on this i'll polish it a bit ;)

Image

Also, The ball will likely move really slow for you..it did that for my friend, just change the ball.speed and ball.a values in the script to something higher.
User avatar
hughes
Prole
Posts: 21
Joined: Fri Oct 28, 2011 3:10 am

Re: Forever Alone Pong

Post by hughes »

The ball moves at different speeds on different machines because you've made it dependent on the frame rate:

Code: Select all

ball.x = ball.x - ball.speed
Code like this makes the ball take a step of the same size in every frame regardless of how much time there is between frames.
What you could do is simply multiply the speed by dt:

Code: Select all

ball.x = ball.x - ball.speed*dt
Now it makes physical sense and will go at the same speed on every machine.

I say it makes physical sense because consider the units:

Code: Select all

[pixels] = [pixels] - [pixels/sec] -- subtracting pixels per second from pixels makes no physical sense

Code: Select all

[pixels] = [pixels] - [pixels/sec]*[sec] -- the seconds cancel, subtracting pixels from pixels is allowed
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Forever Alone Pong

Post by veethree »

hughes wrote:The ball moves at different speeds on different machines because you've made it dependent on the frame rate:

Code: Select all

ball.x = ball.x - ball.speed
Code like this makes the ball take a step of the same size in every frame regardless of how much time there is between frames.
What you could do is simply multiply the speed by dt:

Code: Select all

ball.x = ball.x - ball.speed*dt
Now it makes physical sense and will go at the same speed on every machine.

I say it makes physical sense because consider the units:

Code: Select all

[pixels] = [pixels] - [pixels/sec] -- subtracting pixels per second from pixels makes no physical sense

Code: Select all

[pixels] = [pixels] - [pixels/sec]*[sec] -- the seconds cancel, subtracting pixels from pixels is allowed
thanks!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Forever Alone Pong

Post by Robin »

Found a bug: if the ball gets far enough, it can get stuck, because it will still be to far, it "bounces" again and again and again.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Forever Alone Pong

Post by bartbes »

The solution being the use of math.abs (or -math.abs).
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Forever Alone Pong

Post by veethree »

bartbes wrote:The solution being the use of math.abs (or -math.abs).
how exactly can i use that?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Forever Alone Pong

Post by bartbes »

Well, if you're at the left and you need to bounce you set the direction to math.abs(current_speed) and on the right you set it to -math.abs(current_speed). (That's always-right or always-left respectively.)

EDIT: Where current_speed is the speed on the X axis, I should add.
Post Reply

Who is online

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