Page 1 of 1

My First Complete game

Posted: 24 Mar 2016, 21:52
by RPGMAN34
This is just a simple game I made in like half an hour (which is pong) so I thought I would show you it!
this game is a 2 player game so you have to play with someone else, or you can play by yourself

I will try to share a screenshot ASAP

download link: https://drive.google.com/open?id=0B8lwq ... GZtZGM2STQ
player1:
w = move left up
s = move left down

player2:
up = move right up
down = move right down

Re: My First Complete game

Posted: 24 Mar 2016, 22:53
by Qcode
I took a look through the code, I'd recommend changing the following (and anything similar):

Code: Select all

paddle.left.y = paddle.left.y - 5
This is an easy mistake to make, as it's not a recognizable problem until you change computers. This code moves the paddle 5 pixels per frame. If you're running the game on a computer at 30fps, this means the paddle will move at 30*5 = 150 pixels per second. However, if you then run the same code on a computer at 60 fps, the paddle will move at 60*5 = 300 pixels per second.

So, by using two different computers at two different framerates, your game will feel different on both. This is obviously not the optimal game experience, you want the game to feel the same no matter what machine you play it on.

The way to fix this is with a thing called "delta-time". This is the amount of time from 1 frame of your game to another. So if you're running at 1 frame per second, dt (delta-time) will equal 1. 2 frames per second, dt will equal 1/2 = .5. 30fps, dt will equal 1/30, or .0333, you get the idea.

You can get dt by changing your love.update declaration to

Code: Select all

function love.update(dt)
...
end
Then, whenever you move an object in the update function you should multiply the value by dt, like so:

Code: Select all

paddle.left.y = paddle.left.y - 5*dt
This changes the operation so that instead of your paddle moving 5 pixels per frame, your paddle will move 5 pixels per second, which therefore makes the value equal across all framerates. You'll then need to scale up the value (because I assume you weren't used to your game running at 1 fps), but nevertheless, that scaled value will work similarly across all framerates.

Just one extra step to making a better game. Let me know if you have any other questions.

Re: My First Complete game

Posted: 24 Mar 2016, 23:45
by RPGMAN34
Qcode wrote:I took a look through the code, I'd recommend changing the following (and anything similar):

Code: Select all

paddle.left.y = paddle.left.y - 5
This is an easy mistake to make, as it's not a recognizable problem until you change computers. This code moves the paddle 5 pixels per frame. If you're running the game on a computer at 30fps, this means the paddle will move at 30*5 = 150 pixels per second. However, if you then run the same code on a computer at 60 fps, the paddle will move at 60*5 = 300 pixels per second.

So, by using two different computers at two different framerates, your game will feel different on both. This is obviously not the optimal game experience, you want the game to feel the same no matter what machine you play it on.

The way to fix this is with a thing called "delta-time". This is the amount of time from 1 frame of your game to another. So if you're running at 1 frame per second, dt (delta-time) will equal 1. 2 frames per second, dt will equal 1/2 = .5. 30fps, dt will equal 1/30, or .0333, you get the idea.

You can get dt by changing your love.update declaration to

Code: Select all

function love.update(dt)
...
end
Then, whenever you move an object in the update function you should multiply the value by dt, like so:

Code: Select all

paddle.left.y = paddle.left.y - 5*dt
This changes the operation so that instead of your paddle moving 5 pixels per frame, your paddle will move 5 pixels per second, which therefore makes the value equal across all framerates. You'll then need to scale up the value (because I assume you weren't used to your game running at 1 fps), but nevertheless, that scaled value will work similarly across all framerates.

Just one extra step to making a better game. Let me know if you have any other questions.
thanks for the tip! but the problem when I did that is that the game became a lot slower

Re: My First Complete game

Posted: 25 Mar 2016, 00:19
by Qcode
Yeah, like I said, just multiply all the constant values (5) by the frames per second you used to get (probably 60) and then it will run exactly like it used to, except the same on all computers.

Re: My First Complete game

Posted: 25 Mar 2016, 02:36
by RPGMAN34
Qcode wrote:Yeah, like I said, just multiply all the constant values (5) by the frames per second you used to get (probably 60) and then it will run exactly like it used to, except the same on all computers.
i mean like when I do the dt thing

Re: My First Complete game

Posted: 25 Mar 2016, 14:10
by Qcode
Yes, when you add dt, multiply all constant values in your code by 60 and it will speed up again.

Re: My First Complete game

Posted: 25 Mar 2016, 20:58
by HugoBDesigner
I think an example will make him understand better:

Code: Select all

paddle.left.y = paddle.left.y - 5*60*dt
Or, if you actually do the maths, 5*60 = 300, so this works too:

Code: Select all

paddle.left.y = paddle.left.y - 300*dt

Re: My First Complete game

Posted: 21 Feb 2017, 19:22
by Wirespark
Could you slightly edit the game and highlight the borders? i cant play it very well with all the confusion