Pages

Friday, 12 November 2021

LP's 12 Months of Games // Zombie Arena [C++ & SFML]

Completed Via Tutorial

Another tutorial finished from "Beginning C++ Games Programming" by John Horton. 

Please do not use this book to learn C++. Some things boggled the mind when following this tutorial like:
  • variable + 0 (???)
  • Creating a header, only for it to contain functions that are neither marked as extern or static or within a namespace. One function returns a raw pointer which is deleted somewhere else...
  • #pragma once #ifndef #define combo (pick one. I like ifndef define because it's slightly more portable).
  • Constant float to int/int to float with no casting or safety in place. For example, he'll choose to make an int variable but only use it with a float???
  • Singleton classes. Don't get me wrong, I like singletons but this is not the best way to do it. The constructor should be private with copy and assignment deleted. There should instead be a static public function that declares and returns a reference to a static instance of the class to ensure it is destroyed properly.
  • Member functions that don't modify are not marked as const nor is anything returned by const reference if it can be.
  • Initialises class members in the constructor body instead of via initialiser list; this causes the member variable to be default initialised and then assigned again.
  • Const member variables are initialised in the class body definition??? static const integral types yes, but otherwise for linking sake, it's best to initialise const members in the constructor.
One thing that really bugged me was all the event handling for input was done in main. I am a firm believer that objects should handle input events themselves. That said, the author promised at the end of this game that there will be better code handling in the next two projects so I'll hold further judgement until I finish the book.

Finished Result:

LP's 12 Months of Games // Zombie Arena [C++ & SFML]

I was having fun with this one by the end. I quite like "Demakes" and I think this style would make a good Left 4 Dead demake. The hitboxes on the zombies are a bit janky and I'd like some background music but other than that I'm actually pretty happy with this one. 

It taught some solid SFML concepts that I can take away to personal projects. I'm itching now to start Tetris or my own version of pong to apply what I've learnt but I'm going to finish the book first as he mentioned using more advanced sound features, particle effects an split-screen in the upcoming chapters.

Code:

There's a code drop for this one as I feel I changed it enough. Assets haven't been included for copyright reasons but here is the authors repository:
https://github.com/PacktPublishing/Beginning-Cpp-Game-Programming-Second-Edition

No comments:

Post a Comment