Tag Archives: c++

Game AI – C++ Graphs and Pathfinding

This was an assignment I had been looking forward to, It was time to learn about AI! Unfortunately it was less like the matrix and more like complex Ideas and plenty of looping through lists.

You can download and view the final here

New concepts included:

  • Graphs
  • Nodes
  • Path finding algorithms and their implementation

Learning about these path finding algorithms was fascinating, how they differ and how they can be implemented for game mechanics.

Alongside the implementation of these algorithms was the structure of the program itself, I learnt a lot about modular design in the way classes are structured.

Presentation is key

Agents finding a path between selected nodes

Writing on the wall

I wanted a nice UI to give information to the user, this required a font library to be installed. While I respect the power of C++ having to spend a chunk of time to do something as simple as display text is never going to be fun.

Drawing the line

Another feature that I often take for granted is drawing lines… if you want anything above a single pixel line. Say a nice thick line with a subtle fall of gradient,  you have to go and create that yourself, enjoy!

Math Library

This project used my own math library from previous projects, after using almost every over a few projects it’s pretty solid. (Building my own allowed me to approach Monogames matrice library with confidence in a later project)

Debug lines

For both this and the previous projects I have learnt that debug lines and debug images are so very helpful, I had debug circles around every agent, and lines showing there intended direction. This kind of visual debugging allowed me to hone in obviously bad behavior.

As with all my learning projects A big thank you to all my Mentors, you know who you are.

Mouse Hunter – C++ Console Game

Woah now, what did mice ever do to us? and why make a game about hunting them?

Depending on their fighting ability

Depends on their fighting ability image from: http://www.darkswordminiatures.com/shop/index.php/mouse-warrior.html

I’m happy to say that learning c++ is coming along nicely and will continue to. It’s no small thing for someone to say “I know all of c++”.

Pointers, references, lists and iterators, I’ve had the pleasure of using them all and more so far.

I am getting what I want from learning c++. A deeper understanding of programming for creating full blown applications and games and knowing how to approach the structure of these applications, classes and headers… Lots of them.

Base game play (straight from the tutorial)

The player can shoot fireballs at “evil monkeys”, these evil monkeys hunt the player relentlessly. This tutorial from 3D buzz was recommended to my by a colleague and mentor.

After working through it I can see why. It’s solid learning material.

New game play (It’s mouse hunting time)

Doing tutorials are great, Do them, do lots of them. But don’t’ “just” do them. Take the knowledge you have gained doing a tutorial and apply that to create something new and your own.

My own version has the following additions to the game you have on completing the tutorial:

  1. Game states (splash, win, lose, game)
  2. Mice
  3. Leader board that loads from disk
  4. modified player
  5. Game mode
Mouse hunter splash screen

Mouse hunter splash screen

The gameplay is based around either defeating the mice or collecting the cheese before they do. Once a mouse has cheese they cannot be hurt.

The player loses lives every time a mouse gets cheese, pretty simple!

Hunt mice, collect cheese!

Hunt mice, collect cheese!

And you can play this cheese eating, mouse hunting fun here

If you happen to play it and find any bugs or feedback i’d love to hear it, although it definitely has some balance issues.

Learning resources

3Dbuzz tutorial – This tutorial stands the test of time, it’s still a fantastic intro to programming in 2014 and I recommend it to anyone wanting a friendly introduction to c++ with a focus on games development.

The Academy of Interactive Entertainment – As staff at AIE I have access to the programming curriculum, all the lectures etc. This has been great to see how an introduction to programming has been structured.

Mentors

9-dog-professor

image from: https://www.pinterest.com/pin/2111131050743242/

I’m in a pretty lucky position, I’ve got three mentors available who love it when I corner them with coding roadblocks. I find I am able to move quickly when I bring my roadblocks  to a mentor, whether in person or online.

The main thing you get from a mentor is feedback and the mind expanding experience of approaching a problem from a different angle. Pen and paper often comes into play as we work our way through each new obstacle.

It also good to have people with experience guiding you through program construction, why things are done a certain way and what the repercussions might be if that certain way isn’t followed.

Everybody should seek feedback from their peers and people with experience who can provide constructive feedback.

Extending the game play (resources)

sqlite370_banner

The only additional resource needed to create my version of the game was SQLite to allow database use. I’ve done plenty of web dev but this was my first c++ Library I installed purely from the documentation.

SQLite database

Working with a c++ library for the first time was an experience in itself, it assumes you know your way around Visual studio and know how to get a library going… I did not.

After stumbling around with code implementations I can safely say that the “five minutes or less” introduction tutorial took me significantly longer. As soon as the database was up and running though, awesome! I got it working all by myself, taking a few baby steps out from under my mentors wings.

 

Errors, simple not complex – Part One

Programming, it’s a complex beast. While I haven’t talked much about my current studies in C++ you can safely assume I’m knew to the language and it’s intricacies.

The current assessment i’m working on requires an SQL database. All well and good I think to myself. I’ve done plenty of PHP and MySQL web dev.This will be a breeze.

That's pretty breezy

That’s pretty breezy image from: https://www.pinterest.com/vivamune/windy-dogs/

I knew I needed to use SQLite as defined by the assessment. So I need a library or something? Heading over to SQLite.org has everything you need to get going.

So, I added the .h and .c files through the right click “Add existing item” menu. Then i’m presented with the below error.

Cannot open source file

Cannot open include file

Looks can be scary

Looks can be scary

What is going on? I start looking deeper, maybe there is more involved to getting this going than I first thought.

I spent hours over two days looking for a solution, I tried building libraries including everything and altering so many settings of the project. Pro tip: do not alter settings because you feel like a good tweaking can fix everything, it doesn’t.

The solution

Copy the .h and .c files into my visual studio project.

I twigged that I might be barking up the wrong tree when I read the following.

stack overflow solution

I love you stack overflow

The solution explorer doesn’t show if stuff is usable! how helpful, knowing that I brought the files into the project and re-added them. Including the header no longer broke stuff. Progress!

Take it from me

So many times I have been caught out by this. The error is not cryptic at all, Visual Studio has no idea that i’m not going to link to the assets through one of the many methods it has for this.

So it told me it has no idea where to actually open the files, only that it knows I want them open. I feel you Visual studio and i’m sorry I didn’t understand.

Let’s not assume

I’m used to using 3D applications, for the most part these applications allow you to drag and drop assets into a content/project manager where they will either:

  • Import the asset into the project

Easy for asset management, common in game engines

  • Create a link/reference to the assets location and load it from there

Forces you to manage your assets wisely or rue the day you laughed as you linked assets from several different hard drives.

I assumed that by showing the files in the project solution VS could use them, this turns out to not be the case.

No I do not want to add includes to the project to work around this or setup a central place to include from. That’s for future me.

As with all lessons it’s well learned, learning them faster would be nice though.