Thursday, 20 January 2022

Chapter 23 // Exercise 1 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 1

Get the email file example to run; test it using a large file of your own creation. Be sure to include messages that are likely to trigger errors, such as messages with two address lines, several messages with the same address and/or same subject, and empty messages. Also test the program with something that simply isn't a message according to that program's specification, such as a large file contain no ---- lines.


I used the given website from the book to create a text file containing all the email examples:

I had to change the pointer to a reference in find_from_addr() to get the iterators to work with the for each loop but other than that, the code is exactly what's given in the book and it works.

I tested it with 2 files, the first contains lots of different emails from the website as well as messages that aren't emails (but still separated by ----) and it worked fine, finding all 7 emails sent from John Doe. 

The second text file has all the ---- lines removed and that found no emails from John Doe as it needs the ---- to tell it when to push back a message.

Monday, 17 January 2022

LP's 12 Months of Games // Alien Invaders Part 2 [C++ & SFML]

Completed Independently

In part 1, I got a basic game loop going and you could shoot invaders as they descended upon you. In part 2 there's now shields, sounds and a flying saucer!

It's almost there but there's still some bugs and finishing touches such as:
  • Background music. The famous "dun dun dun dun" has not been implemented as I haven't managed to recreate the sounds to a satisfactory standard and increasing the step as you destroy invaders is a task in itself as I'm not a sound engineer person.
  • The arcade style surrounding and background as well as the CRT shader. A colleague showed me a different way to implement the disintegration effect using shaders so I'll be implementing that as well as messing around with some other shader effects.
  • 2 Player mode
  • Demo mode
  • Taito Cop Easter Egg
  • Different Invader shots. Right now they're all just using 1 shot and will fire every couple of seconds or so. That needs changing.
  • The flying saucer is every 3 seconds which isn't correct. I haven't figured out from the assembly yet though what the actual timing mechanic is for it to appear.
  • The Credit Inserted and Start Game animations haven't been created.
  • The states don't really play with each other nicely
  • Bugs
I'm shocked that the original developer managed to create this game in a year but not just the game; he also built the hardware that the game ran on. This is a level of engineering that I can only dream of reaching. 

Result:
LP's 12 Months of Games // Alien Invaders Part 2 [C++ & SFML]

It doesn't look like much but I'm quite proud of myself for sticking to a project and getting it to a somewhat finished state. That in itself is an achievement for me. I am feeling a bit burnt out on SFML though having done 5 back-to-back projects with it and I'm looking forward to a bit of Unreal and Blueprints for the next project.

This is far from over though. I have a new project now to recreate Space Invaders with as many APIs as I can. Making it that first time though is the kicker; now it's almost out of the way, I can focus on refining the code and then re-implementing it using other libraries.

Code:
https://github.com/l-paz91/AlienInvaders2/tree/main/AlienInvaders2

The code is quite honestly, awful in places lol. But I don't care. I think that's one of the hardest lessons I've learnt whilst doing this exercise; just do it and worry about how shit your code is when it's done. I do enjoy refactoring and optimising but they don't help you get a project finished.

Thursday, 6 January 2022

Chapter 23 // Drills 1,2,3 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Drill 1

Find out if regex is shipped as part of your standard library. Hint: Try std::regex and tr1::regex.


For this I used the example posted on ccp reference for std::regex:

I've set Visual Studio to use the ISO C++17 Standard.

Chapter 23 // Drill 2, 3

Get the little program from section 23.7 to work; that may involve figuring out how to set the project and/or command-line options to link to the regex library and use the regex headers.

Use the program from drill 2 to test the patterns from section 23.7.


Fortunately, I'm doing these exercises far in the future where it's been a part of the standard for many years.

Tuesday, 4 January 2022

Chapter 22 // Exercise 16 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 22 // Exercise 16

Modify the program from the previous exercise so that it reads a file (name,year(ancestors)) tuples, such as (Fortran,1956()), (Algol,1960,(Fortran)), and (C++,1985,(C,Simula)), and graphs them on a timeline with arrows from ancestors to descendants. Use this program to draw improved versions of the diagrams in section 22.2.2 and section 22.2.7.

Github: 

Out of all the exercises and drills we've done so far; this is the one I hate the most. It's stuff like this that makes me detest graphics programming and so for the second time in 6 years of trying to finish this book I'm skipping an exercise.

I did go back and finish the other one though so eventually I'll finish this one too. I will say, I went back and tried to use my scattergraph class and what a mess. I don't know how it worked in the first place.

To be continued...

Friday, 31 December 2021

LP's 12 Months of Games // Alien Invaders Part 1 [C++ & SFML]

Completed Independently

So the final game of "Beginning C++ Games Programming" by John Horton was a clone of "Space Invaders". I skimmed the first chapter of the project and he starts talking about Entity component systems, Factory class designs etc and I just completely zoned out and decided to make it myself. 

This took me a while as Back 4 Blood added an offline mode and there's nothing quite like hitting zombies with a baseball bat. Also the Witcher season 2 and Lost In Space season 3.

So anyway, I kept getting annoyed with myself whilst making this game; I was trying to make the code as beautiful as possible right off the bat; which is impossible unless your Bjarne or Scott Meyers or something. I asked many colleagues how they would go about implementing Space Invaders and amusingly, the more senior the engineer the more the answer became "just do it all in main, who cares?"

So, I've written some terribly hacky code that only gets worse as time goes on but I have a game! This is labelled part 1 because it's not finished however, there is a title screen, a game and a game over. It saves the high score between runs and loops after game over so it is a game...regardless of how finished.

I'm quite into the task now and the shields are ready to be implemented, as are the sounds. Then the flying saucer needs some attention as do the shot exploding animations but then I'll have a full Space Invaders clone!

I've given myself a few little extras that involve creating a CRT shader and making it look as though you're playing the game on an arcade machine.

Result:
Space Invaders Clone Using C++ and SFML

I'm extremely happy with what I've done so far. I'm really trying my best to make it look and feel exactly like the original. I'm going so far as implementing the same bugs using this site which comments all the assembly:

There are some issues which you may have already noticed; my game over text isn't displaying and the high score isn't updating. That will be fixed next but the code is in place.

I just really wanted to get something uploaded for this month and I've already learnt so much from attempting to do this by myself. I'm glad I ignored the book as this game is deceptively hard but a great place to start when making a complete game from scratch for the first time.

I almost gave up a couple weeks ago as I find it difficult to find the motivation to finish things. I have about 70 started projects but I thought to myself, the whole point of this challenge is to get better at making games and I won't get better if I don't at least try! So I managed to scrape the code together enough to call it a "game".

It also made me realise that I hate UI programming with a burning passion.

Code: