Streaming game development: https://www.twitch.tv/stabyourself Image

My First Complete game

Feel free to showcase your own projects!
RPGMAN34
User avatar
Posts: 34
Joined: 21 Mar 2014, 03:46
Reputation: 3

Post » 24 Mar 2016, 21:52

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

Qcode
User avatar
Posts: 1466
Joined: 05 Feb 2012, 18:00
Reputation: 72
Contact:

Post » 24 Mar 2016, 22:53

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.

RPGMAN34
User avatar
Posts: 34
Joined: 21 Mar 2014, 03:46
Reputation: 3

Post » 24 Mar 2016, 23:45

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

Qcode
User avatar
Posts: 1466
Joined: 05 Feb 2012, 18:00
Reputation: 72
Contact:

Post » 25 Mar 2016, 00:19

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.

RPGMAN34
User avatar
Posts: 34
Joined: 21 Mar 2014, 03:46
Reputation: 3

Post » 25 Mar 2016, 02:36

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

Qcode
User avatar
Posts: 1466
Joined: 05 Feb 2012, 18:00
Reputation: 72
Contact:

Post » 25 Mar 2016, 14:10

Yes, when you add dt, multiply all constant values in your code by 60 and it will speed up again.

HugoBDesigner
User avatar
Posts: 2121
Joined: 19 Sep 2012, 02:23
Reputation: 674
Contact:

Post » 25 Mar 2016, 20:58

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

Wirespark
User avatar
Posts: 20
Joined: 23 Nov 2013, 08:01
Reputation: 2

Post » 21 Feb 2017, 19:22

Could you slightly edit the game and highlight the borders? i cant play it very well with all the confusion


Return to “Game development”

Who is online

Users browsing this forum: No registered users and 1 guest

cron