SFML community forums

Help => General => Topic started by: Broken on January 20, 2010, 05:57:56 pm

Title: What now ?
Post by: Broken on January 20, 2010, 05:57:56 pm
Hi until now I learn SFML from tutorials now when I finish with them what now ?
Sorry this is first API which I learn so should I learn from documentation,SFML wiki tutorials or something else ?
Title: What now ?
Post by: Laurent on January 20, 2010, 06:07:06 pm
Do you learn it for fun, or do you have a project? What's your final goal?
Title: What now ?
Post by: Broken on January 20, 2010, 09:37:02 pm
I am going to some kind of programming school and I decide to programming simple game for my last work. And the answer is, yes it is for my project.
Title: What now ?
Post by: gsaurus on January 20, 2010, 11:35:36 pm
After doing the tutorials I suggest to play with SFML by yourself.

Starting from small things, always thinking on your project, you'll find answers about how to start implementing the game.
Like a prototype. Imagine that you want to do a character moving in a nice way, and it will be defined by some complicated class. You start by making just a sprite in the main function, moving somehow, improve it a bit, then you think "ok, this works :), the complicated character class will work like this somehow".
When you get enough comfortable with it, leave the prototyping away and start really implementing your project.
That's how I do when I try a new API.

SFML tutorials covers everything you need to know, so there isn't much more to learn, hands on it ;)

If you didn't think about what game you want to do, you should do it soon ;-)
Title: What now ?
Post by: dunce on January 21, 2010, 09:03:28 am
Try to make a simple and well known game like Tetris or Worm. They require neither a lot of assets nor a lot of coding. It won't take you much time to finish one of them, and you'll get good practical skills in using SFML api in a real project.
Title: What now ?
Post by: Broken on January 21, 2010, 10:30:37 pm
Ok, thanks on advice me,I will try bulid some clone like snake,tetris or pacman and when I stuck with coding I'll need your help  :roll:
Title: What now ?
Post by: Broken on January 31, 2010, 05:24:32 pm
Hi I decided to make Space Inviders clone. And I know put background, fonts ,sound, and image(space ship) but I don't know collision detection, how to make other ships which my ship destroys and how to make that my ship fire missles?
So if there is someone who could help i would like it.
Title: What now ?
Post by: gsaurus on January 31, 2010, 06:01:22 pm
space games are the best ones to start in my opinion, good start point  :).

You can see spaceships as circles: they have a center and a radius. That way it's easy to test collisions between them, it's intersections between circles, basic geometry formulas. If you're not familiar with it search for circle intersections or something.

Ok, I suppose you have a class for the spaceships, and you store your spaceships on some container. You need to do the same for missiles. When you want a spaceship to fire, simply create a new Missile instance in front of the spaceship, and put it on the missiles container, so that the game cycle can iterate over all missile instances on the container to update their position, test collisions and draw them.
A missile colliding with a spaceship can be simply test if it's center, a point, is contained on the circle (geometry again). If yes, missile is destroyed as well as the spaceship. You may not want to add animations yet, so simply remove the missile and spaceship from the respective containers.
Title: What now ?
Post by: Samyboy on February 01, 2010, 09:29:14 pm
Quote from: "gsaurus"
space games are the best ones to start in my opinion, good start point  :).

You can see spaceships as circles: they have a center and a radius. That way it's easy to test collisions between them, it's intersections between circles, basic geometry formulas. If you're not familiar with it search for circle intersections or something.

Ok, I suppose you have a class for the spaceships, and you store your spaceships on some container. You need to do the same for missiles. When you want a spaceship to fire, simply create a new Missile instance in front of the spaceship, and put it on the missiles container, so that the game cycle can iterate over all missile instances on the container to update their position, test collisions and draw them.
A missile colliding with a spaceship can be simply test if it's center, a point, is contained on the circle (geometry again). If yes, missile is destroyed as well as the spaceship. You may not want to add animations yet, so simply remove the missile and spaceship from the respective containers.


Hello, I am very eager to learn more about simple collision detection using a circle.

So for the actual formula I will use google, of course. I have another question:

How would you go on testing if a missile is colliding with another Sprite? I mean the forumula is all good and fine, but do you save all your sprites in a Vector and iterate through them every Frame? Am I understanding something totally wrong?

Some piece of example code would be very appreciated!

Thanks and have a nice day :D
Title: What now ?
Post by: gsaurus on February 01, 2010, 10:14:24 pm
Quote from: "Samyboy"
How would you go on testing if a missile is colliding with another Sprite? I mean the forumula is all good and fine, but do you save all your sprites in a Vector and iterate through them every Frame?


Yeah that's fine, really!  :) Unless you have thousands of objects on the screen, which I don't think is the case  :lol:
Title: What now ?
Post by: Samyboy on February 01, 2010, 10:23:19 pm
Quote from: "gsaurus"
Quote from: "Samyboy"
How would you go on testing if a missile is colliding with another Sprite? I mean the forumula is all good and fine, but do you save all your sprites in a Vector and iterate through them every Frame?


Yeah that's fine, really!  :) Unless you have thousands of objects on the screen, which I don't think is the case  :lol:


Well, what about all my projectiles flying around? :p

Is there really no better way?
Title: What now ?
Post by: gsaurus on February 01, 2010, 11:14:34 pm
I have done several space games before with lots of projectiles and checking every pair of objects worked perfectly.

But you can still spatialize the objects by areas if really needed, and check the collisions between objects that are in the same area.
For example imagine you have a matrix representing the screen. Each time an object is created or it's position changes, you test what cells of the matrix the object is overlapping, and inform these sells that this object is there.
Doing this you have separated all objects by areas.
Then, every frame, for each object, you check collisions only for the objects that intersects the same cells as the one you're testing. That reduces substantially the number of collision checks. Don't do a too thin matrix or you'll have tons of cells to check :wink:

I would say: go with an easier collision test first, If you notice that it's compromising the gameplay, improve collisions by implementing a more complex method  :wink:
Title: What now ?
Post by: Samyboy on February 02, 2010, 08:06:10 am
Quote from: "gsaurus"
I have done several space games before with lots of projectiles and checking every pair of objects worked perfectly.

But you can still spatialize the objects by areas if really needed, and check the collisions between objects that are in the same area.
For example imagine you have a matrix representing the screen. Each time an object is created or it's position changes, you test what cells of the matrix the object is overlapping, and inform these sells that this object is there.
Doing this you have separated all objects by areas.
Then, every frame, for each object, you check collisions only for the objects that intersects the same cells as the one you're testing. That reduces substantially the number of collision checks. Don't do a too thin matrix or you'll have tons of cells to check :wink:

I would say: go with an easier collision test first, If you notice that it's compromising the gameplay, improve collisions by implementing a more complex method  :wink:


Hello,

Thanks for your advice, will google for the circle formula.

So basically I'll treat every object as a circle? That's cool!
Title: What now ?
Post by: gsaurus on February 02, 2010, 08:55:53 pm
If projectiles are small, they can be considered as a single point :wink:
Title: What now ?
Post by: Nexus on February 02, 2010, 09:41:32 pm
An important point concerning collision detection with circles: Don't compare roots (euclidean norm), but compare the squared distances of two points, since this is faster.
Title: What now ?
Post by: Samyboy on February 06, 2010, 02:08:05 pm
Hello,

So the collision detection is working pretty fine, thanks for your help!

I bumped into another question tho:

How would you go on and save/move all the projectiles? I currently save them all into a vector and move them in the game loop every frame. Is that a good way of doing it? Are there better ways?
Title: What now ?
Post by: Nexus on February 06, 2010, 03:04:19 pm
Quote from: "Samyboy"
How would you go on and save/move all the projectiles? I currently save them all into a vector and move them in the game loop every frame. Is that a good way of doing it?
Yes, that's certainly a good way. Whether it is the optimal one, depends on the operations needed on the container. But in general, std::vector is a good choice.

For example, you can perform constant time removals if you swap positions with the last element (because pop_back() has O(1)).