Friday, 18 March 2022

Chapter 23 // Exercise 2 - 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 2

Add a multimap and have it hold subjects. Let the program take an input string from the keyboard and print out every message with that string as its subject.


2 months after starting this chapter I had almost forgotten everything and this took me longer than expected.

The hard part had already been provided by Bjarne though so it was just a case of creating a new multimap that stores messages and subjects and loops through that instead if there is a match.

Thursday, 3 February 2022

[Dev Log] Generic Slenderman Clone Part 1 // UE5 & Blueprint

The next game on my list for the 12 months of games challenge is a straight up Slenderman clone. Slenderman is without a doubt one of my favourite games of all time due to the simplicity of the premise; you are chased around a forest by an A-Posing faceless man in a suit whilst collecting 8 items. I was always more of a console gamer and so I didn't know anything about the "indie" games scene and then 2013 hit with Slenderman and now I can't go back; indie horror games are my favourite genre.

So to ease myself into UE5 (and remind myself of how the editor works); I decided to make a straight up Slenderman clone. Once I've completed this version, I will then remake it using C++ instead of Blueprint.

In total there are 5 stages to this game, in this first part I'll be:
  1. Creating the "map" and first person mode
  2. Putting notes on the "map"
  3. Displaying the collected notes count
  4. Adding a way to collect notes
  5. Adding "slenderman"
  6. Creating a titlescreen and endscreen
  7. Creating an executable
So there will be a full "game" by the end of this stage (it helps keep me motivated) but when I say "map" I mean the default 3rd person map and "notes" will literally just be textured cubes from the starter content.

1 - Creating the "map" and first person mode
I've just synced UE5 at work and I did the "Your First Hour in UE5" tutorial from the Unreal Learning portal but other than I've not done much. I will say I like the interface upgrade and the darker colours. For this project I'm using the Early Access 2 version.

I started off with the third person project using Blueprint and starter content. My game will be imaginatively called "Default Unrealman".


I cleaned up the scene a bit by removing the text and moved things into folders. 

I added a hacky "line trace" to my character which is simply just a collision box shaped to a rectangle coming off the players face. It's not very efficient but I'm not making Halo so it doesn't really matter.


"True" first person mode is achieved my simply attaching the camera to the head socket and moving it so it's on the head. The rectangle trace is also connected to the head socket. I set the camera to move with the pawn rotation and then set the pawn rotation to use controller yaw; this way the camera doesn't do a 360 spin around the player but moves as the player moves.

2 - Putting Notes on The Map
I created a new blueprint actor for my notes which simply contains a cube with a texture on it from the starter content. The note contains a text variable with what to display on interaction and a collision box, I then placed 8 of them on the map.

3 - Displaying the Collected Notes Count
For this, I needed to override the current game mode. I created a new HUD class called BP_GameHUD. Then created a widget called W_GameHUD. BP_GameHUD contains a reference to W_GameHUD and a function that allows access to this widget.

With that out of the way, I added some text to the Widget and then added the widget to the viewport.


Currently this isn't interactable but it's simple enough to set up getters and setters in the widget to change this text.

4 - Collecting the Notes
This involved adding the usual "Press E to use" text to the screen whenever the player is looking at a note.  I added a new text component to the hud widget and 2 functions to set and stop displaying it.


Then I gave the note blueprint a reference to the hud widget and called these functions using when overlap begins and ends on the collision box. Now when playing the game it appears in the middle of the screen, directly where the player is looking and disappears when the collision stops. 

To "collect" the note, it removes the actor from the game when E key is released and to update the HUD widget, I added an int to BP_GameHUD and a function to increment which then updates the hud widget.



5 - Adding "Slenderman"
My version of slenderman is an A-Posing default unreal man:


UE5 has a couple of new components that you can add to actors called "InterpToMovement" and "RotatingMovement", however I'm going to do it the old old-fashioned way:



This will get replaced with a behaviour tree later on but for now it's fine.


Terrifying.

6 - Creating a Titlescreen and Endscreen
The most involved part of the process...at least there are widgets this time and I can just drag and move them around instead of manually typing in positions. Bless the editor. I hate doing UI stuff.

After much faffing about creating a new game mode for the menu screen and setting input controls for each screen. I finally had a "working" slenderman game....I mean technically it's a game.

7 - Creating an Executable

This was the most different part of the process from using UE4. Turns out I still haven't installed the Windows SDK on my pc; I've had it for almost a year now. The package and cook is in a completely different place as well and documentation links are broken. Very cool Epic.

For future reference, you need to install the specific .NET framework from here:

Then, just when I thought it was building, I needed to disable the Quixel Bridge plug-in due to some random shared pointer being null. I will say though Quixel did fix it back in October, I just haven't updated the Engine...

But eventually I got my application:



It's beautiful. 

It might not look like much but it's basically the bare bones of the game. Make it night time and add a spooky forest and it's pretty much done....OK maybe not completely. The next stage is to add the flashlight and sprint mechanics and make it night time. Then in Stage 3 I'll create the forest.

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.