Wednesday, 1 June 2022

Chapter 24 // 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 24 // Drill 1

Print the size of a char, a short, an int, a long, a float, a double, an int*, and a double* (use sizeof, not <limits>).

Chapter 24 // Drill 2

Print out the size as reported by sizeof of Matrix<int> a(10), Matrix<int> b(100), Matrix<double> c(10), Matrix<int, 2> d(10,10), Matrix<int, 3> e(10,10,10).

Chapter 24 // Drill 3

Print out the number of elements of each of the Matrixes from 2.


Dear god, reading this chapter almost sent me to sleep several times...there's just something about matrices that bores the shit out of me.

Matrix.h is a file made up by Bjarne. You can find a copy of it in here:
or here:

The ones with 11 on them I think are for the second edition of the book??




Tuesday, 31 May 2022

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

So after part 1, I had the bare bones of a slenderman game. In this part I wanted to flesh out the mechanics a little more and make it start to look more like a "game". My Goals for part 2 were:
  1. Replace the cubes with actual "notes"
  2. Create random spawn points for the notes
  3. Create a sprint mechanic + realistic jump
  4. Add sprint and notes to HUD widget
  5. Change it to night time
  6. Create a flashlight
  7. Create a battery mechanic
  8. Executable
1. Replace the cubes with actual "notes"
2. Create random spawn points for the notes
For this I opened up blender and made the shittest piece of paper. Took about 1 minute. Made sure to resize the plane to A4, curled the edges slightly and gave it a material slot for the front and back and then exported it to Unreal.

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

I downloaded the note textures used in one of the slenderman games off google images and created materials from them. Then created a way for the notes to pick one of the materials at runtime. There are 8 different textures and each note is unique:

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

I created a new blueprint which now handles the spawning of the notes and what material they get. This blueprint contains 16 locations where the notes could spawn. More can be added but only 8 locations will be picked at runtime. You can change the number of locations in the details panel in the editor.

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

3. Create a sprint mechanic and realistic jump
Default unreal man jumps like Princess Peach; in fact it's more floating than jumping and greatly annoys me. Fixing it is quite simple though by just changing the Z Jump Velocity in the Character Movement.

The sprint mechanic is also relatively simple. When shift is held, it reduces the sprint each second and when it reaches 0 (from 100), you can no longer sprint. It takes 10 seconds to replenish fully. I achieved this by using timers instead of ticking. That way, we're not constantly checking to see if we're sprinting (or replenishing sprint value) every frame; only when we need to.

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

4. Add sprint and notes collected to the HUD widget
Using icons from the Android library (they're free to use) I added a progress bar and text to the HUD:

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

The progress bar does use a binding to update itself which is expensive but barely anything is ticking in this game so I didn't really care. In UE5, the progress bars now come with a default animation as well which is snazzy. The notes text is updated when a note is destroyed and the blueprint sends a message to the HUD.

5. Change to night time
This was one of the most difficult parts as lighting in Unreal Engine is unbelievably difficult. You need to change colours determined by sun, override sky colours, change the post process volume and exponential height fog....it's never ending. Also, as the scene is so dark afterwards; I duplicated BP_Sky_Sphere so I could add a tick box which would allow me to switch between day and night in real time.

In the construction script I added this mess:
[Dev Log] Generic Slenderman Clone Part 2 // UE5 & Blueprint

Which toggles between "soft day" and night:

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

6. Adding a flashlight
For this I simply add a spot light to the character and attached it to the head socket so it moves with the character. I thought about a doing a torch you hold in your hand but couldn't be bothered with the hand animations as this is true first person so instead, the player is wearing a head torch. I added some nodes to allow the player to toggle the flashlight on and off with F.

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

The flashlight is its own blueprint and spawns on the player as a child component. I gave it a light profile as well using one of the default UE ones so it's softer when far away from objects; but then the cone shape starts to appear when you get closer. It always annoys me in games when the flashlight is just a circle in the centre of the screen.

7. Adding a battery mechanic
This didn't take long as it was almost copy and paste on the sprint mechanic. I added some timers to the flashlight so when it's in use it begins to lose power and it updates the HUD with the new power level. I added a cylinder to game which acts as a "battery". When you pick it up it replenishes the battery power; regardless of how much power you have left. So batteries should be used wisely as you can't store them in an inventory.

8. Executable
In the gif, "slenderman" is motionless as I disabled it's "AI" for the moment whilst testing (and I forgot to remove the debug output from sprinting) but it's starting to look more like a spooky game now!

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

In part 3, I'll actually create the forest map, add sounds like footsteps, cracking twigs and some story elements. By the end of part 3 it will look like a proper slenderman game but it still won't act like one.

Monday, 30 May 2022

Chapter 23 // Exercises 15 , 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 23 // Exercise 15

Describe a pattern that cannot be expressed as a regular expression.

HTML.

Chapter 23 // Exercise 16

For experts only: Prove that the pattern found in the previous exercise really isn't a regular expression.

Sunday, 29 May 2022

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

Write a program that, like the one in section 23.8.7, can be used to experiment with pattern matching by typing in a pattern. However, have it read a file into memory (representing a line break with the new line character, '\n'), so that you can experiment with patterns spanning line breaks. Test it and document a dozen test patterns.


So I was confused with this one. I'm not sure if he meant, "create a new file with newlines replaced by \n" or "have a file with newlines in it". In the first case, the newline will need to be put as '\\n' in the regex pattern otherwise it will just match to the characters \ n, so the slash needs escaping. But in the second you can just have it as \n and it will continue searching the next line for the pattern.

With this in mind I decided to do both. Interestingly I discovered that if you type out a regex pattern at compile time, it will add the escape to the slash. Whereas if you type it in the console at runtime, it won't.

Saturday, 28 May 2022

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

Does dot (.) match '\n'? Write a program to find out.


Using regex101.com, it shouldn't match. (.) and '\n' are completely seperate. I used regex_replace to also show how they don't match. 

A part of me though feels like this is trick question. Maybe it's not, it's one of those seemingly simple things designed to catch you out....or maybe I'm just overthinking.