A Collection of Musings

When I was younger I had attempted to learn C++, but after learning the basics, I became discouraged primarily by my lack of ability to make games or really anything fancier than basic programs. Thus ended my journey into programming. Many many years later after I had learned Python and R as part of my degree, I decided to take another stab at C++. I had learned that in python there was something called PyGame. I used this to make a game as discussed in my attempt at learning machine learning with 2048.

This of course, spurred the obvious question, why isn't there a PyGame for C++? Not discussed here was my first foray into C++ which was an attempt at porting an ascii map renderer from python to C++, but after this I became interested in really learning the language.

It might be rather silly but it wasn't until I learned python for my degree that I was even introduced to the concept of libraries. In my eyes, every language just was with no additional libraries or sdks. So having been armed with this obvious knowledge, I found a C++ library with which to learn how to program in C++. This was SFML. From my experience with writing, I knew that the best was to learn was lots of smaller projects. Else, you overwhelm yourself having accomplished nothing and embarked upon a project which is much to complicated and thus you will be forced to restart several times. This fact is well known to me as I have restarted one book I am writing six times. As such, I have decided to embark on a series of mini projects, which I will document on this blog.

The first project that I decided to create is a simple tag game. Afterall, such a game would only require me to learn how to draw squares, test their collision, and move them around along with user input. Such a game would be easily completable in three or four hours not including learning time. In addition, I promised myself not to vibe code which I have kept to for the most part as I will discuss below.

The game that I created is where you are a square and you have to touch targets within a certain time. Once you have touched the targets they will move and you will receive a point. There is one target where if you touch it you instantly game over. This game seemed simple enough to me to learn SFML and C++ as a mini project.

When creating this program, my experience programming in Visual Basic came more in handy than I thought. For, I could think of the screen as like thousands of cells with each cell being a pixel. The square then encompasses so many of these cells. As such, movement was no issue. I did have one issue with the movement where I first had it where when the key was pressed the character would move. This resulted in movement which was linked to the speed of the OS repeating the character. I found this out during testing when the speed was inconsistent. This lead to be changing it to where if the key was pressed the state would change so that the state of moving left was true it would move left and so on. If the key was released then it would be changed to false. Perhaps, this is an obvious observation but I am chronicling my entire journey.

I also learned a great deal of smaller facts mainly related to the syntax and such. For example, how bounding boxes worked, how to create objects in general, and how to have a timer counting down.

One mistake that I made was to accidently do pointer math upon the strings which were supposed to out put the time and score. This lead to where "score" was slowly disappearing letter by letter. As someone more familiar with higher level programming such a bug had never occurred to me and thus I had to ask AI after half an hour of trying to figure out what was wrong. In addition, I had to ask AI when it came to passing the window into a function as another place I was stuck. However, I avoided consulting AI otherwise.

Otherwise, this project was primarily one of me relearning the basics and learning the SFML library. Both of these goals were achieved with me having a much better grasp of the language in addition to have actually created a functional program. As such, I feel confident in embarking upon a new project. When I was creating the enemies system I found that I had no idea how to make an arbitrary amount of enemies through objects. After deciding that it was to much work I manually created objects for the target and the enemy. But, being able to create arbitrary amounts of objects still intrigues me, as such, my next project will be to create a particle system with a few kinds of particles. This will be useful for learning about creating and destroying arbitrary objects in addition to furthering my ability to simulate physics while still being a relatively simple project.