Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Complete Game Tutorial  (Read 57882 times)

0 Members and 1 Guest are viewing this topic.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #45 on: January 02, 2012, 02:17:44 am »
Quote from: "Lee R"
Quote from: "Serapth"
Part 9 is now online


I haven't looked at your code in any detail, but a quick look revealed at least four memory leaks. You're new'ing up exceptions (why?) but attempt to catch them by reference.




Oops.


The why is easy, it was a mistake.  :oops:


The why of the why is also easy, I've spent far too long using C#, and you develop a certain muscle memory when typing code...

Thanks for the catch, fixing.  One other potential leak was actually on purpose and will be resolved in the next chapter.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
State Machines
« Reply #46 on: January 02, 2012, 05:53:53 am »
I've got something useful for you Serapth if you can wrap your mind around what a state machine is.

http://
https://sites.google.com/site/onlinegameworkcjr/useful-things


The two things there those two files should help with the AI.
This code is from Digipen's game engine FunEditor1.5 so most of the codes in it are useless unless you know what you are doing.

The .txt file shows the code from the inside of a state machine I had to make for pong and I thought it might give you some ideas on how to fix up your AI in this game.

The other file is a code of the C# engine that they use in Microsoft Visual C++ 2010 Express and in mostly DirectX code if I remember right.  It has a few things that could be used to make a state machine in a compiler and has one already made and in use.  Just look for the state machine codes in these files and you should get some idea of how to make a state machine of some kind. :)


The only reason I have these things is because I'm in a game design class that has connections to Digipen. :)
I have many ideas but need the help of others to find way to make use of them.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: State Machines
« Reply #47 on: January 02, 2012, 04:01:39 pm »
Quote from: "StormWingDelta"
I've got something useful for you Serapth if you can wrap your mind around what a state machine is.

http://
https://sites.google.com/site/onlinegameworkcjr/useful-things


The two things there those two files should help with the AI.
This code is from Digipen's game engine FunEditor1.5 so most of the codes in it are useless unless you know what you are doing.

The .txt file shows the code from the inside of a state machine I had to make for pong and I thought it might give you some ideas on how to fix up your AI in this game.

The other file is a code of the C# engine that they use in Microsoft Visual C++ 2010 Express and in mostly DirectX code if I remember right.  It has a few things that could be used to make a state machine in a compiler and has one already made and in use.  Just look for the state machine codes in these files and you should get some idea of how to make a state machine of some kind. :)


The only reason I have these things is because I'm in a game design class that has connections to Digipen. :)


Thanks StormWingDelta, I will take a look.


It's not so much that AI is broken at this point; it simply hasn't been implemented.  At this point it is just a stub, I ran out of room.  Then again, in Pong, one of the keys to AI is actually making it stupid in believable ways, as frankly an AI controlled paddle will never miss.

Razzeeyy

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML Complete Game Tutorial
« Reply #48 on: January 06, 2012, 04:38:11 pm »
Hi guys (and girls if they are here :P).

First I want to thank the author for that perfectly done tutorial.

And also I want ask you about the collision detection? Is there any good tutorials and articles on that topic? I'm just starting to work on some simple but impressive (at least i think it is :P) 2D "racing - shooter" game, and I wonder how to detect collisions and build the interactions between more complicated objects.
But I'm only the beginner programmer and I have poor skills :P At least I'm trying to do something :D

(I will upload sources on github later, for now they are really butt-ugly :D)

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #49 on: January 06, 2012, 05:01:27 pm »
Quote from: "Razzeeyy"
Hi guys (and girls if they are here :P).

First I want to thank the author for that perfectly done tutorial.

And also I want ask you about the collision detection? Is there any good tutorials and articles on that topic? I'm just starting to work on some simple but impressive (at least i think it is :P) 2D "racing - shooter" game, and I wonder how to detect collisions and build the interactions between more complicated objects.
But I'm only the beginner programmer and I have poor skills :P At least I'm trying to do something :D

(I will upload sources on github later, for now they are really butt-ugly :D)



It's not specifically a tutorial, but there is a code example for doing various collision tests, axis aligned bounding boxes and per pixel detection I believe, in this sites wiki ( EDIT: link ), that would probably be a good place to start.  That said, your game might be best served looking into Box2D for 2d physics.  Generally with the way graphics work these days, you never really want to work at the per-pixel level anymore.

Keep at it, we all start out lousy. :)


SOmetime in the future I may actually do a box2d/sfml tutorial.

Razzeeyy

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML Complete Game Tutorial
« Reply #50 on: January 06, 2012, 05:41:39 pm »
Quote from: "Serapth"
your game might be best served looking into Box2D for 2d physics


I don't want to use the box2d because I want to try writing physics and etc by myself.
And Thank You for that interesting link about  working with collisions in sfml! :)

Here is the current - draft state of my project: http://ompldr.org/vYzNvYw
It don't do much, but what it do for now is pretty interesting XD
I don't know if it works and compiles on windows (I'm develop on linux, and develop mainly for linux, coz I like linux :P).
But it should compile and run on windows due to SFML :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6267
  • Thor Developer
    • View Profile
    • Bromeon
SFML Complete Game Tutorial
« Reply #51 on: January 07, 2012, 03:09:00 pm »
Code: [Select]
sf::SoundBuffer mySound;
mySound.LoadFromFile("MySound.wav");
if(mySound)
  {
    sf::Sound sound;
    sound.SetBuffer(mySound);
    sound.Play();
  }
if (mySound) doesn't work, the loading statement should be inside the if. Furthermore, this code is problematic because the sound must be alive as long as it is played.

Maybe it's too advanced for that tutorial, but you could consider to use std::unique_ptr instead of manual memory management. That would often remove the need for destructors and deletes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
SFML Complete Game Tutorial
« Reply #52 on: January 07, 2012, 11:59:36 pm »
Why not try a 3D form of Pong next with a third person view from just above and behind the player paddle? With a table and walls to make things interesting. :idea:


Just throwing out an idea where to go next when this one is done. :)
I have many ideas but need the help of others to find way to make use of them.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #53 on: January 08, 2012, 12:12:51 am »
Quote from: "Nexus"
Code: [Select]
sf::SoundBuffer mySound;
mySound.LoadFromFile("MySound.wav");
if(mySound)
  {
    sf::Sound sound;
    sound.SetBuffer(mySound);
    sound.Play();
  }
if (mySound) doesn't work, the loading statement should be inside the if. Furthermore, this code is problematic because the sound must be alive as long as it is played.

Maybe it's too advanced for that tutorial, but you could consider to use std::unique_ptr instead of manual memory management. That would often remove the need for destructors and deletes.



Truth told, I am not a big fan of how this section was done.  It was my intention to introduce the various pointer options at this point, but the chapter was already wayyyyyyyyy too long.   I intend to cover unique_ptr and auto_ptr, although it might be wise to skip auto_ptr completely with it's wonky as hell rules.


That's why I'm kinda looking forward to the next chapter, as I can use it to address various mistakes I've made, as well as cover a general mish mash of features.

Nice catch.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #54 on: January 08, 2012, 12:13:27 am »
Quote from: "StormWingDelta"
Why not try a 3D form of Pong next with a third person view from just above and behind the player paddle? With a table and walls to make things interesting. :idea:


Just throwing out an idea where to go next when this one is done. :)



Truth told, I am sooooooo sick of Pong at this point. ;)

eot

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML Complete Game Tutorial
« Reply #55 on: January 10, 2012, 07:53:48 pm »
I just found your tutorial and I'm going through it. It's been a while since I worked with C++ and I never really used static variables or functions much (well, at all really) so I'm just wondering about the use of the scope operator ("::"). You use it for the enum (GameState) that's defined inside the class (Game) even though the functions in which you use it belong to the very same class. Is that simply because those are static functions and they can be accessed without an instanced object of the class?

Maybe it's a dumb question but I've never seen that operator used like that before :P

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
SFML Complete Game Tutorial
« Reply #56 on: January 11, 2012, 03:43:05 am »
I was going through part 6 and ended up with a strange error that I can't trace for some reason.



Code: [Select]

c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C2146: syntax error : missing ';' before identifier '_gameObjectManager'
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int



I was going through the code and the only changes in mine are where I'm getting files from.
I have many ideas but need the help of others to find way to make use of them.

FallenShard

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML Complete Game Tutorial
« Reply #57 on: January 11, 2012, 04:40:25 pm »
I'm enjoying the tutorial, but I'm just wondering is there any difference between writing it starting from "Empty Project" rather than "Win32 Console Application"?

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #58 on: January 11, 2012, 11:08:53 pm »
Without seeing your code, I'm willing to bet you have a rogue semicolon. Check each of your.h Files for a class definition closed with a semicolon. Sadly it could be any of them.


Quote from: "StormWingDelta"
I was going through part 6 and ended up with a strange error that I can't trace for some reason.



Code: [Select]

c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C2146: syntax error : missing ';' before identifier '_gameObjectManager'
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\roland.user-6fef0ae329\my documents\visual studio 2010\projects\sfml1p6testing\sfml1p6testing\game.h(31): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int



I was going through the code and the only changes in mine are where I'm getting files from.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #59 on: January 11, 2012, 11:11:00 pm »
Quote from: "FallenShard"
I'm enjoying the tutorial, but I'm just wondering is there any difference between writing it starting from "Empty Project" rather than "Win32 Console Application"?


Not much. It creates a few files for you, main, stdafx and sets the subsystem to console.

 

anything