• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cold_heats_.--.

General newbie question

9 posts in this topic

Hello there.I'm reading a book about physics and how to make your game look more realistic.It's a fascinating book, but even so, there are some things I dont understand yet.

Suppose I have a dot in a 2D cartesian plane, placed randomly. [Dot.x=2, Dot.y=3].It moves in a straight line with a constant speed/velocity.[const int speed = 5 ;// meters /seconds]
I'm imagining the game loop would look like this :
while(!game_over)
{
seconds++;
delete the dot;
dot.x+=speed;
redraw the dot;
}
I dont understand how exactly is the dot's animation done.At the second 0 the dot is in (2,3) and the second 2 it immediatly jumps at (7,3).Isnt that motion kind of unnatural?Its like, one moment he's here and the next moment he's suddenly far away, without me seeing how he actually "goes".
To help you understand better what I'm trying to say, l sketched the first and second iteration [or, how I think they should be ] :
Iter1:
[img]http://i.imgur.com/YQ0gw.png[/img]
Iter2:
[img]http://i.imgur.com/9940L.png[/img]

I hope you understand.
So how can the game loop be altered to achieve that animation ?
Does it have something to do with the frame-rate ? I dont know much about this concept except that in one second, the user seex 40-60 frames.
The only background I have in game programming is simple console games and replicates after popular games [like snake, breakout, collapse, ].So this is a new territory for me . Edited by cold_heats_.--.
0

Share this post


Link to post
Share on other sites
Hope what I write actually makes some sense:

The simplest of the simplest way to move the ball would probably be:

while(!game_over)
{
dot.x++;
drawball(dot.x, dot.y);
}
This way the x position will constantly increase while the game is running.
You don't delete the ball and then create it again. Only the position is changed.

Generally when things are drawn. They are actually done on a backbuffer(a 2D image) and then this image if flipped to the screen (what we see). This flipping thing happens 30/60 (or more) times depending on program/machine. And thus making it look like things are moving smoothly.

Next try to move the ball constantly while taking account time:
dot.x = dt * dot.x;
dt - the delta time change between frames.
The movement should be much nicer.....(at least it was when i wrote something like that)

To move to a position such as from 2,2, to 7,2. Psuedo code :

gameloop
{
if(ball has target)
{
move() * dt
}
}

where move would calculate 5,0

Just try to build something small and play around with the code. Hope this is somewhat useful hehe Edited by ZeroBeat
0

Share this post


Link to post
Share on other sites
You want to modify your movement to take into effect how fast your game is running, so yes, the frame rate is a factor.

Lets say you want your dot to move .x at a rate of 100 pixels PER second.

Then you need to update your .x value by a fraction of 100 represented by your current frame rate..

So in your game loop, you need to keep track of how much time occured since the last time it was called. Call this delta.

Delta will represent the amount of time that has elapsed between your current frame and previous frame in (hopefully ) milliseconds. Now you need to figure out how much you want to move .x if you want a speed of 100 pixels per second, you first figure out your frame rate:

frameRate = 1000/delta;

This means that if you currently are taking 100 ms between game loop calls, you are running at 1000/100 or 10fps.

Now that you know you are running at 10 frames per second, if you want your pixels to move by 100 pixels per second, that means this frame, you want to move a total of 10% ( as at your current speed, you are going to update 10 times in a second) of 100, or in other words, by 10 pixels.
2

Share this post


Link to post
Share on other sites
For the time being, I strongly suggest going simple. Something like this:

[CODE]
erasedot();
dot.x++;
drawdot();
Sleep(1000); // Makes the computer wait for 1 second
[/CODE]

Now, this is the amateur, introductory way of doing things but you're more likely to understand this than anything else. After this, you can move on to timing. Edited by GameCreator
-2

Share this post


Link to post
Share on other sites
[quote name='GameCreator' timestamp='1340231120' post='4951138']
For the time being, I strongly suggest going simple. Something like this:

[CODE]
erasedot();
dot.x++;
drawdot();
Sleep(1000); // Makes the computer wait for 1 second
[/CODE]

Now, this is the amateur, introductory way of doing things but you're more likely to understand this than anything else. After this, you can move on to timing.
[/quote]
I do understand this though, I've done similar things like this in my console games, especially making the computer "lag" a bit .
0

Share this post


Link to post
Share on other sites
If you're on windows, I recommend using a function called timeGetTime() (it's good and easy), which will return the current time. If you check this every cycle of your game, and store it in a variable, you can check the difference between the time stored in your last cycle and the time of the current cycle to see how many milliseconds have passed, and then update the entire game based on that value.

Remember that pretty much everything is dependent on time, so use the time value for anything that happens in the game. One example where time gets interesting and important is when the main character has a machine gun, which fires faster than the framerate. If the gun needs to fire 4 bullet in one cycle, time will stil need to pass between each bullet, even though you're only calculating the time between each frame. If you don't calculate this correctly, the machinegun will fire 4 bullets at the same time, then wait until the next frame, and fire another 4 bullets, instead of seemingly firing them evenly.
The same thing goes for particle emitters, for example. And to get even more advanced, the dreaded collision detection and response.

Just do not settle with Sleep(x), unless you want to simulate some kind of old-school effect. Making the computer sleep during game play is as bad as it sounds.

One tip, if you want to play around, is to assume you will be running at 60fps (vsync'd), and therefore set the time per frame to 16ms, or 0.016 seconds. You can add a real timer later on. I tend to do this when I'm testing stuff, to avoid having to add and link a library when I know my compute rwill be running it at 60fps.

/Justice
0

Share this post


Link to post
Share on other sites
[quote name='GameCreator' timestamp='1340429539' post='4951927']
Great. Then we can get a bit more specific. Which engine or library are you using?
[/quote]
Sorry for replying a bit late.Well , currently, I'm not using any engine or library .
I'm trying to learn SDL .
0

Share this post


Link to post
Share on other sites
No prob. Check this out:
[url="http://gameprogrammingtutorials.blogspot.com/2010/01/sdl-tutorial-series-part-5-dealing-with.html"]http://gameprogrammingtutorials.blogspot.com/2010/01/sdl-tutorial-series-part-5-dealing-with.html[/url]

Does that help or do you need a simpler explanation?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0