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

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

0 Members and 1 Guest are viewing this topic.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« on: September 09, 2011, 12:09:46 am »
I have been working on a tutorial series on using SFML 1.6 with Visual Studio 2010 to create a complete game from scratch.

One of the things I often see is when new developers share their code, the structure is absolutely horrible.  Part of this is as a result of learning from code samples that are meant to concisely demonstrate the usage of the library involved, not how to make an actual game.  Many other beginner samples are from books, where being concise is one of the most important aspects. There seem to be very few examples out there that actually explain how to bridge the gap between various library features and an creating an actual game.

That is what I am trying to provide with this example.  It is long, 5 chapters already and frankly nowhere near complete and the end result is going to be a glorified pong clone.  That said, along the process I try to teach the basics of object oriented programming.  Additionally, initial setup and configuration seems to be one of the major stumbling blocks for new developers in C++, so I spend a good deal of time focusing on that in detail.


Anyways, if you are new to SFML and are just learning C++, you are my target audience.

If you are a C++ expert and see a glaring flaw in what I have written, let me know!

Hopefully this series is useful to new developers.  Please let me know what you think.

A Game From Scratch: C++ Edition

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #1 on: September 09, 2011, 12:16:26 am »
One of the tenants I am working upon is to write code that initially fits, but in later chapters revist it to fit changing circumstances.  This is meant more as a learning exercise than as a coding template.

For example, in Part 4, I introduce the VisibleGameObject class, which owns an sf::Image class.  Then I present a PlayerPaddle class, which loads an image to represent the player's paddle.  In a future chapter, I will present an AI Paddle class, which will result in the duplicate loading of the same Image file, and will then present a class to rectify this inefficiency.

I hope that made sense.


I also should have named Gameloop() as GameloopIteration() or something similar, as the current name is misleading.  I regret how I structured that aspect of the code for clarities sake and will probably refine it.  Making the initial Game class static also probably introduced a level of complexity that could have been avoided, although by the end of the process, I think it will still prove to be the right decision.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
SFML Complete Game Tutorial
« Reply #2 on: September 09, 2011, 07:18:31 am »
Clicking on the title of an article on the main page is not working. The link is broken.

I don't have the time to read all the tuto, later =)

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #3 on: September 09, 2011, 02:47:10 pm »
Thanks for pointing that out, it has been fixed now.

Windows Live Writer, which is otherwise a very nice blogging tool, has this horrible glitch where it will attempt to turn a + in the title into a URL.  So every post with forbidden characters in the title I need to manually edit the page name.  I missed that one. :(

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
SFML Complete Game Tutorial
« Reply #4 on: September 10, 2011, 03:38:02 pm »
This is nice! That was my problem too, SFML does not provide complete examples, rather snippets.

I think you should rather put this topic to 'Project Announcements'!

Keep it up! :D

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
SFML Complete Game Tutorial
« Reply #5 on: September 10, 2011, 08:18:29 pm »
Indeed this is good, looking forward to the next installment.
{much better code}

ephaitch

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML Complete Game Tutorial
« Reply #6 on: September 10, 2011, 09:20:40 pm »
Is Part 5 not written yet or is the link broken?

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
SFML Complete Game Tutorial
« Reply #7 on: September 10, 2011, 11:36:25 pm »
I believe it's not written yet.

ephaitch

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML Complete Game Tutorial
« Reply #8 on: September 11, 2011, 12:54:58 am »
Bummer.. I'm trying to continue on my own to finish the game, but I'm probably noting doing things correctly. =(

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #9 on: September 11, 2011, 01:04:55 am »
Hi everybody,

Thanks for the kind words.  Section 5 is being written as we speak ( all sample code for 5 & 6 is complete ).  I am currently doing a bit of a revision based on some feedback I've received so that distracted things a bit.

Also, death nearly laid her hands on me  ( Ok... I got a flu ), so writing cohesively hasn't been my strong suit the last couple days.  Should have part 5 up very soon, most likely Monday at the latest, perhaps tomorrow if my immune system decides to stop sucking.  It's kinda funny, I am able to code sick, but stringing two cohesive sentences together seems to be beyond me!


EDIT: BTW, did I post this thread to the wrong forum?  If so, sorry.  I didn't post to Announcements based on the fact it's not "done" per say.

Azurus

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML Complete Game Tutorial
« Reply #10 on: September 11, 2011, 08:43:31 pm »
I have a little problem. In part 1, you mention a "sfml_main-d.dll" that you're supposed to copy to the debug folder. However, this dll doesn't exist. For me, anyway.

Also, in Part 2, in game.cpp, you call sf::color twice on line 38, why would that be? Also, a little matter of consistency, in line 6 you just have Uninitialized, but in line 52 you have Game::Uninitialized.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML Complete Game Tutorial
« Reply #11 on: September 11, 2011, 08:57:49 pm »
It has never existed, sfml-main is always a static library.
Laurent Gomila - SFML developer

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #12 on: September 11, 2011, 10:23:28 pm »
Yeah, my bad.  It should have been sfml-main-d.lib not sfml-main.dll, fixed now.

As to the two other things, the double colour call was a cut and paste error that survived to live, while the fully resolved enum is the C# developer in me expressing himself! :)  I've fixed both now, thanks for the catch.

I actually allowed a ton of little errors to pop up between projects that I should have caught but didn't because I wrote the 5 source projects, then wrote the blogs to go with them, but in writing the blogs I found little glitches and errors, or decided I didn't like the way it was put together, resulting in a change having to be propagated across 5 separate projects.  

This...  was stupid. :)  Now, I am working to get everything at parity, then will keep the posts in closer sync to the code to prevent such problems.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #13 on: September 14, 2011, 06:55:50 pm »
Sorry for the delay, but Part Five is now completed.


In this part we put together a very simple game object manager, it might be overkill in a pong clone, but if your game becomes any larger, a class like this is almost essential.  To a degree the complexity level of the code ramped up a bit from Part 4, so if I did a poor job explaining something or you see an error, please let me know!


Alright, off to work on Part 6.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #14 on: September 25, 2011, 01:38:41 am »
Took way longer than expected, but Part 6 is live


We are still in sub-game territory, but we are getting closer and closer!   In this part, we added a player controllable paddle and the game ball. Again, if you encounter and mistakes or have any questions, please let me know!

Next up, we will get the ball rolling ( sorry, bad pun ) and cover off collision detection.