# Ship, Captain, and Crew: Ready to set sail!

Well, for better or worse, it’s finally finished! That’s right, my first, from scratch, no tutorial, 3D dice game, “Ship, Captain, and Crew” is now in Beta stage! Be sure to give it a try!

You can find all the source code here:

Be sure to let me know in the comments if you find any bugs or have any suggestions. The game is not really for playing by oneself, although there is a player vs computer setting. However, the key point of this game is a sort of paper/rock/scissors game with your friends when you need to decide something, like who’s buying, or who gets to pick where/what/etc. next.

You can also read the official rules on Wikipedia, which my game follows. I mention this, because some play where you must roll a 4,5, then 6 for ship, captain, and crew, and others play 6, 5, then 4 instead. Either way, the mechanics of the game are the same, just which order you must roll the dice. In this game, I set it to follow the official 6, 5, and 4 rule-set.

Let me know if you tried it out!

Linux – keep it simple.

# Ship, Captain, and Crew: Give it a spin!

Well, I suppose “roll” would be a more popular dice game term, but spin is actually more accurate in this case! I’m actually rotating the dice in a spin maneuver, and having them fall on the table, rather than rolling them across it from an angle or the side.

The first question I had to tackle was what type of object to use for the game. The three types are Static Body, Kinematic Body, and Rigid Body. Each have their own uses, and here I put into words my limited understanding. Be sure to comment if you can clarify any of these.

Static Body is an object that is not supposed to react to any force. It should instead stay right where it is when it is struck by another object. In this game, I used a static body for the table top. This way the force of being struck by objects, such as the dice, and physics powers, like gravity, have no affect on it. In fact, I didn’t even give the table legs, because nothing is needed to “hold” the table up, since it is a static body.

Kinematic Body is an object that is often used for making the main player of a game, or something like that. It is not affected by physics unless you program it too. Gravity and such have no affect on it until you tell it to through code. So, if I had a kinematic ball roll across the table, when it gets to the edge, it would keep rolling on air, as if the table were still under it. This is what we used in BornCG’s great video game tutorial for the main player. It is very easy to control movement of this object.

Rigid Body is a type of object that by nature is fully affected by physics. Gravity and inertia all come into play on this type of object. If the table were not there, a rigid body object would fall indefinitely. These objects are difficult to move in one sense, because you can’t just say, “go that way” like you do with kinematic bodies, instead you have to exert force against them in a direction to cause them to move that way.

To make the dice game as realistic as possible, I used rigid bodies for the dice. When they fall to the table, they can bounce, tumble, or bump and shove other dice. The big question was how to move them. Of course, once in the air, they fall to the table and tumble, etc. That was the easy movement, because it is not programmed by me at all, it is simply the engine physics taking place. The tough movement was what to do with them after they hit the table.

Originally, I was planning to move them aside, and set them out of the way so I could roll the remaining dice. Not having any 3D experience, I thought this wouldn’t be too hard, but it became a nightmare for rigid bodies. Here are several methods I tried after reading hours of documentation and QA forums:

```var oldPosition = get_node("LowPolyDiceC").get("dicePosition")
var targetPostion = get_node("pirateShip").get("shipPosition")
var newDirection = targetPostion-oldPosition
print(newDirection)
\$LowPolyDiceC.apply_impulse(Vector3(),newDirection)
#translate(translation.direction_to(newDirection))
# This one only moves a tiny bit, and not in the right direction.
#translation.direction_to(newDirection)
# This one doesn't move at all.
#apply_impulse(Vector3(),newDirection)
# This one rockets it towards the ship, then it falls off the table.
#translate(newDirection)
# This one does not go to the ship, but goes up in the sky near it.```

I found several ways to translate, or “teleport” the dice somewhere else, but not where I wanted them. And, once transported, they didn’t work with physics anymore. I also found ways to whack them with a force, but they arced up through the air and fell off the table (think golf club hitting golf ball). None of those would do. I tried asking my issue as a question on Godot’s QA forums, but I didn’t get a response from anyone, so I had to give this idea up.

Instead, I used the impulse (force) to send the dice straight up into the air again. Then, as they go up into the air, I perform several “spins” of the dice to randomize the result. Here’s my code:

```func _make_dice_random (diceName):
var x = randi() % 365 + 1
var y = randi() % 365 + 1
var z = randi() % 365 + 1

func _spin_dice():
if tumbler > 0 :
tumbler = tumbler - 1
#print (tumbler)
var upAmmount = 4
if takenA != 1:
\$LowPolyDiceA.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
_make_dice_random("LowPolyDiceA")
if takenB != 1:
\$LowPolyDiceB.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
_make_dice_random("LowPolyDiceB")
if takenC != 1:
\$LowPolyDiceC.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
_make_dice_random("LowPolyDiceC")
if takenD != 1:
\$LowPolyDiceD.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
_make_dice_random("LowPolyDiceD")
if takenE != 1:
\$LowPolyDiceE.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
_make_dice_random("LowPolyDiceE")
\$spinTimer.start()
else :
\$spinTimer.stop()
\$Timer.start()

func _roll_dice():
\$ControlHUD/HUDrollButton.hide()
remainingRolls = remainingRolls - 1
get_node("ControlHUD/HUDrollsNumLabel").set("howManyRolls", remainingRolls)
tumbler = 3
var upAmmount = 6
if takenA != 1:
\$LowPolyDiceA.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
if takenB != 1:
\$LowPolyDiceB.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
if takenC != 1:
\$LowPolyDiceC.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
if takenD != 1:
\$LowPolyDiceD.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
if takenE != 1:
\$LowPolyDiceE.apply_impulse(Vector3(),Vector3(0,upAmmount,0))
\$spinTimer.start()
```

It reads from the bottom up. First I call the _roll_dice() function to send any dice up that are not “taken” or in use by the player for their ship, captain, or crew. Then a timer is started, to allow the dice time to rise up off the table. Once the timer ends, it calls the _spin_dice() function, which has several calls to the _make_dice_random(dicename) function, picking random numbers of 365 degrees*. This is done as many times as the “tumbler” variable is set to, or in this case, 3 times. Since the dice are rotated on the x, y, and z axis, they get very randomly arranged, and then fall to the table, tumbling around to their final position.

Each dice has 6 small invisible cube areas on the faces of the dice that correspond to the opposing sides number. So, when they hit the table, that reports the number the dice has face up to the variables, so the dice number is set and known. That looks like this:

```func _on_AreaA2_body_entered(body):
if body.name == "TableObject" :
\$diceSoundPlayer.play()
diceA = 2
#print (diceA)
```

And finally, once the dice have come to rest, they are checked for their number:

```func _check_all_dice():
\$Timer.stop()
#print ("dice check")
#print (diceA, diceB, diceC, diceD, diceE)
# Check for Ship
if hasShip == 0 :
if diceA == 4 :
hasShip = 1
\$pirateShip.show()
takenA = 1
elif diceB == 4 :
hasShip = 1
\$pirateShip.show()
takenB = 1
elif diceC == 4 :
hasShip = 1
\$pirateShip.show()
takenC = 1
elif diceD == 4 :
hasShip = 1
\$pirateShip.show()
takenD = 1
elif diceE == 4 :
hasShip = 1
\$pirateShip.show()
takenE = 1
# Now check for captain
if hasShip == 1 :
if diceA == 5 :
hasCapt = 1
\$pirateHat.show()
takenA = 1
elif diceB == 5 :
hasCapt = 1
\$pirateHat.show()
takenB = 1
elif diceC == 5 :
hasCapt = 1
\$pirateHat.show()
takenC = 1
elif diceD == 5 :
hasCapt = 1
\$pirateHat.show()
takenD = 1
elif diceE == 5 :
hasCapt = 1
\$pirateHat.show()
takenE = 1
# Now check for crew
if hasCapt == 1 :
if diceA == 6 :
hasCrew = 1
\$piratecrewHat.show()
takenA = 1
elif diceB == 6 :
hasCrew = 1
\$piratecrewHat.show()
takenB = 1
elif diceC == 6 :
hasCrew = 1
\$piratecrewHat.show()
takenC = 1
elif diceD == 6 :
hasCrew = 1
\$piratecrewHat.show()
takenD = 1
elif diceE == 6 :
hasCrew = 1
\$piratecrewHat.show()
takenE = 1
# Now check cargo
if hasCrew == 1:
if remainingRolls > 0:
\$ControlHUD/HUDkeepButton.show()
else:
\$ControlHUD/HUDkeepButton.hide()
_update_score(diceA + diceB + diceC + diceD + diceE - 15)
else :
_update_score(0)

if remainingRolls > 0:
\$ControlHUD/HUDrollButton.show()
if theCurrentPlayer == 0:
\$computerTimer.start()
else :
\$ControlHUD/HUDrollButton.hide()
\$updateTimer.start()
```

This string of if/elif statements is really ugly, but gdScript doesn’t have a “switch” or “case” block method. It does have a “match” method, but I couldn’t understand how to implement it properly.

Hopefully that was interesting and or helpful to other newbies like myself. You can always check out the full source code for the game at my GitLab.

Linux – keep it simple.

* Yes, I know there are really only 360 degrees in a circle, but this actually improved the random factor, based on my research, because I was under the impression that the random number generator seemed to favor slightly lower numbers, so I added a few. If it goes over 360, it just keeps rotating, as if from 0.

# Collector3D! My First Ever 3D Game, Programmed in Godot!

Well, I finished the online YouTube tutorial by BornCG, which you can check out here. His tutorial is great and I learned a lot. I did make several changes along the way, and I used this as an opportunity to practice my work in Blender, making my own graphics for everything, as opposed to using the material he presented.

Code wise, it is the same game, but I did code several things differently, as I worked on expanding my knowledge of programming. An example would be the player ball rotation. In the tutorial, he shows how to use a variable and a set number to change the degrees to radii of the ball when it rotates.

However, This had several drawbacks. The first was that you needed to fiddle with it in relation to the variable of the ball’s speed. In other words, if you changed the speed of the ball, you would need to watch it move and guesstimate the change needed to the variable for rotation. Secondly, if you use his method, then when you stop pressing the arrow keys to move the ball, the ball stops rotating, but still “slides” until it comes to a stop.

To fix this, I changed the rendering of the ball rotation to be based off of vector speed. This makes the ball look very natural when it rolls. E.g., if it rolls forward, the degrees of roll looks naturally like the distance it is rolling over, and gives it a more realistic look. This also allows me to change the ball speed without having to adjust it’s degrees of roll. The best part, though, is when you release the arrow keys, and the ball is slowing to a stop, it now rolls, in accordance with it’s speed, slowing it’s roll as it slows to a halt in speed. It just look much more realistic.

I do believe that the author, BornCG knows how to do all this, and was just making a simpler tutorial for the viewers to follow. Or perhaps more specifically was trying to show the relationships of variables to those new to programming.

Other examples were just style points, adding timers and effects when you “die”, rather than the simple “cut to end screen” approach, and other such small things. Overall, the game mechanics and idea came from BornCG’s great tutorial. For a free resource that is widely available, I’d say this tutorial was a 5 star product, and I highly recommend it for anyone looking to start using Godot. I found numerous 2D tutorials for Godot on YouTube, but this is one of the very few 3D tutorials for Godot. Certainly worthy of your time if you are looking to start using Godot.

That said, here are some great links for my game:

* Notes: I did not try the Windows executable, since I didn’t have a Windows machine to test it on. I did try out the Linux executable on two different Ubuntu machines (17 and 18). If you try the Linux executable, be sure to chmod a+x the file so you can run it. Also, if you try out any of the executable files, be sure to comment below how well they worked and what OS you tried them on!

Linux – keep it simple.

# Dice, anyone?

Now that I’ve completed the low poly course from Udemy, I’m ready to start using my fledgling, but newfound skills in some form of application. That said, the most fun and easiest way that I can imagine using 3D models is in some kind of game. The question is, what to make?

If you’ve been reading this blog for a while, you may remember that I once made a dice game app called “Ship, Captain, and Crew”, based on the sailor dice game of the same name. So, I’ve decided to revamp that project by creating a 3D version of the app. Essentially, I’ll be starting from scratch, but utilizing the same game mechanics that are in the first game.

The two big things I think I will need are the 3D objects and then some form of 3D game engine to render it. Today I completed the first part, which was making the dice. It took me about an hour to throw this together, but I think it will do as a low-poly die for the game. In theory, I will just use 5 of them during the game itself.

Now the big question is what game engine to use. There may be many to choose from, but from a mobile app perspective, there seem to be only 4 that I would want to use. Of course, I’m ruling out Unity, because it is not open source. I’m trying to make an open source game, and I’d like to use open source tools so that anyone can openly tinker with it. I’m also ruling out several that work for Android, but the sdk is only available on Windows computers (irrlicht for example). That leaves the four main options of LibGDX, GoDot, Ogre, and jMonkeyEngine. There may be others, these are just the ones I know about.

So, now I need to do some research and see which one will work best for me. I’ve never made a 3D game before, so this might take a while….

Linux – keep it simple.

# Arduino Asteroids Game: Randomly!

I wanted to post a video, but sadly the free version of WordPress doesn’t allow this. So, you can click here to watch the video of me playing “Asteroids Game!” on my Uno with the LCD Keypad Shield. Sorry for the low quality of the video, but I’m sure you’ll enjoy it all the same.

The game is complete, and you are welcome to head over to my GitLab and download the ino file and compile it yourself. Remember, you will need the LCD Keypad Shield library as well. Some stats about the game and program:

Sketch uses 7510 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 473 bytes (23%) of dynamic memory, leaving 1575 bytes for local variables. Maximum is 2048 bytes.

Also, the entire game is programmed in less than 600 lines (would be significantly less without all the explanation blocks I put in there), and the ino file is less than 20 kb!

One of the biggest parts of the game is making sure that the asteroids show up in a random fashion. With only 4 asteroids, it is important that the pattern is not discernible by the player, or they will easily be able to win over and over again. Here is how I called it:

gameAsteroidOne = get_random(4);

I am calling the “get_random” function with an integer (in this case) of 4. That will make more sense once I show you the function:

srand(millis()+addOn); // Use time since turned on and add on number as seed for random number.
int r = rand() % 10; // Returns a random integer between 0 and 10.
r += 10; // Add 10 to keep it off of the display screen.
return r;
}

You see, computers can’t actually make random numbers, so you have to “seed” it with something to grow a number from. As a “seed” I input the time in milliseconds that the game has been running. From this it makes a “random” number from 1 to 10. It then adds 10 to that number to place the asteroid off of the screen, giving the appearance that it existed before and slowly came into view.

The problem is that sometimes the game loop runs fast enough where two asteroids are asking for a new random number at the exact same time. If they do, they will both receive the exact same “random” number. This will cause them to “overlap” or be in the same physical spot, which means that they will both go off screen at the same time, and request a new random number at the same time, receiving the same “random” number again. It’s a loop.

To solve this, I added the integer “addOn” to the milliseconds to make a new number. This “addOn” number is passed with each asteroid, and each one has a different number, creating a new instance of “seed” for the random number generator. That way no two should return the exact same “random” number. Although it can still happen.

Just like rolling two dice can sometimes give you the same number, the random function can still randomly return the same number. The smaller the number pool, a six sided dice would have a pool of 6, our game has a pool of 10, the more likely a repeat of a random number happens.

Another case scenario is when asteroid one, for say, goes off screen, while asteroid two is 2 steps behind. Asteroid one gets a random number of, let’s say 6, which added to 10 makes 16. Now the asteroids move. One is 15, two is 1. Then one is 14, and two is 0. Then one is 13, and two falls off screen, getting a new number, which randomly could be 3, which, when added to 10, makes 13, and the two asteroids now occupy the same space.

A programmer could add a check for this, and if the asteroids are in the same space, cause a new random number to be chosen, or add or subtract a number to it, but in this simple game, it happens so rarely that it isn’t really a problem. The player just gets a bonus when those two asteroids pass next time.

Either way, I hope that you have enjoyed the game itself, and more so the creation of it. The game is open source and feel free to put it to good use!

Linux – keep it simple.

# Arduino Asteroids Game: Play mode and pause state!

Today was the big push! It took a while to figure out how to implement what I wanted to do, but now it’s done! The game play mode and pause state are completed! You can, of course, check out the full commits on my GitLab, but I plan to go over some of the most important parts here.

if (gameState == 3) { // Play state.
// The player has entered play mode.

gameTime++;
if (gameTime > 1){
gameTime = 0;
gamePaused = false;
}

This portion allows the game to pause. An odd occurrence is that you cannot press the pause button and release it fast enough. It will essentially get pressed and check that it is pressed about 1000 times per second, so I needed to add an “unpause” delay, and this is how I did it. If the buttons were software buttons, I could have done this differently, but they are physical buttons, so I needed this to make it work every time.

gameShoot = true; // you have not shot yet this round.
gameAsteroidOne–; // First asteroid starting space.
gameAsteroidTwo–; // Second asteroid starting space.
gameAsteroidThree–; // Third asteroid starting space.
gameAsteroidFour–; // Fourth Asteroid starting space.

Here, we increment (or move) each asteroid by one space.

if (gameAsteroidOne == -1) {
if (gamePosition == 0) {
// Game over, you lose.
gameState = 6;
gameLineNum = 0;
} else {
gameScore++; // get a point!
gameSpeed = set_gameSpeed(gameScore);
gameAsteroidOne = get_random(4);
}
} // end gameAsteroidOne.

In this block, I am figuring out everything for asteroid number one. So, if it’s position (which we moved just the block before this) is now -1, then it is at the position on the screen where the player’s ship is. It now checks if it is on the same row as the ship (gamePosition is the position of the ship, 0 for upper, 1 for lower). If they both are on the same row, then a collision has occurred. So, you switch to the lose screen.

If they are not on the same row, then the player gets a point for passing the asteroid. Then the game speed is increased (there are some other factors that change it as well), and the asteroid is moved to a random new location.

if (gameAsteroidTwo == -1) {
if (gamePosition == 0) {
// Game over, you lose.
gameState = 6;
gameLineNum = 0;
} else {
gameScore++; // get a point!
gameSpeed = set_gameSpeed(gameScore);
gameAsteroidTwo = get_random(2);
}
} // end gameAsteroidTwo.

if (gameAsteroidThree == -1) {
if (gamePosition == 1) {
// Game over, you lose.
gameState = 6;
gameLineNum = 0;
} else {
gameScore++; // get a point!
gameSpeed = set_gameSpeed(gameScore);
gameAsteroidThree = get_random(3);
}
} // end gameAsteroidThree.

if (gameAsteroidFour == -1) {
if (gamePosition == 1) {
// Game over, you lose.
gameState = 6;
gameLineNum = 0;
} else {
gameScore++; // get a point!
gameSpeed = set_gameSpeed(gameScore);
gameAsteroidFour = get_random(1);
}
} // end gameAsteroidFour.

if (gameScore > 99){
// You win! Great job!
gameState = 5;
gameLineNum = 0;
}

These are the portions for asteroids two through four, which work identically to asteroid one. Note that there are two asteroids on row 0, and two asteroids on row 1. Four asteroids total. It seems rather limited, but it is appropriate for such a small screen.

// Set up our display.
// The space ship
String shipUpper = ” “;
String shipLower = ” “;
if (gamePosition == 0){
shipUpper = “>”;
shipLower = ” “;
} else {
shipUpper = ” “;
shipLower = “>”;
}

Here we check the location of the player’s space ship and set the upper and lower icons appropriate for the display.

// Upper blocks.
lcd.setCursor(0,0);
lcd.print(“00”);
lcd.setCursor(2,0);
lcd.print(gameBullets);
lcd.setCursor(3,0);
lcd.print(“|”);
lcd.setCursor(4,0);
lcd.print(shipUpper);

for (int a = 5; a < 17; a++){
lcd.setCursor(a,0);
if (a == gameAsteroidOne+5){
lcd.print(“*”);
} else if (a == gameAsteroidTwo+5){
lcd.print(“*”);
} else {
lcd.print(” “);
}
}

Now we draw the upper blocks. As you can see, I just set the LCD cursor to the correct spot and print the text to display what I want displayed. The “for” loop cycles through the remaining display area, or “asteroid field” and checks for asteroids. If there is one, it displays an asterisk, if not, then a blank space.

// Lower blocks.
lcd.setCursor(0,1);
lcd.print(gameScore);
if (gameScore < 10) {
lcd.setCursor(1,1);
lcd.print(” “);
} else if (gameScore < 100) {
lcd.setCursor(2,1);
lcd.print(” “);
}

lcd.setCursor(3,1);
lcd.print(“|”);
lcd.setCursor(4,1);
lcd.print(shipLower);

for (int a = 5; a < 17; a++){
lcd.setCursor(a,1);
if (a == gameAsteroidThree+5){
lcd.print(“*”);
} else if (a == gameAsteroidFour+5){
lcd.print(“*”);
} else {
lcd.print(” “);
}
}

Here we draw the lower line of the screen. It works basically the same as the upper line, but with the score instead of the number of bullets.

gameDelay = 0;
while (gameDelay < 1000){
// Add a delay in the loop.
delay(1);
gameDelay+=gameSpeed;

switch (lcd_key){

case btnRIGHT:{
// Shoot command
if (gameBullets > 0 && gameShoot) {
if (gamePosition == 0){
lcd.setCursor(5,0);
lcd.print(“————“);
gameBullets–;
gameShoot = false; // You already shot.
gameAsteroidOne = get_random(4);
gameAsteroidTwo = get_random(2);
} else {
lcd.setCursor(5,1);
lcd.print(“————“);
gameBullets–;
gameShoot = false; // You already shot.
gameAsteroidThree = get_random(3);
gameAsteroidFour = get_random(1);
}
}
break;
}
case btnLEFT:{
if (!gamePaused) {
gameState = 4;
gameLineNum = 0;
gamePaused = true;
}
break;
}
case btnUP:{
gamePosition = 0;
break;
}
case btnDOWN:{
gamePosition = 1;
break;
}
case btnSELECT:{
gameState = 0;
gameLineNum = 0;
break;
}
}
}
} // End gameState 3, play state.

The remainder is the delayed “while” loop, which checks the status of the buttons every millisecond and increments towards ending this “round” of display. Because it is using a counter that is based on game speed, the game will speed up as the game increases. At first, an entire game loop takes about 1 second, then .5 seconds, then .33 seconds, and finally, .25 seconds towards the end of the game.

The pause mode is much simpler:

if (gameState == 4) { // Pause state.
// The player paused the game.

switch (lcd_key){

case btnLEFT:{
gameState = 3;
gameLineNum = 0;
break;
}
case btnSELECT:{
gameState = 0;
gameLineNum = 0;
break;
}
}
} // End gameState 4, pause state.

The pause mode doesn’t actually draw anything, which is good, because then the screen displays what it was displaying last. Hence the game still visually appears, but no calculations are made to move anything.

Next post I’ll discuss the random number generator and some background information, as well as try to post a video of the game being played. If you have an LCD Keypad Shield and Arduino Uno, feel free to download my GitLab repository and play the game! You will need the LCD Keypad Shield library as well. Be sure to let me know if you tried it out!

Linux – keep it simple.

# Arduino Asteroids Game: Win some, Lose some!

It isn’t really a game if you can’t win or lose. You need some driving force to make the game worth playing. With that, I also needed a way to inform the user that they either won or lost the game. Hence enter these win and lose game states. Almost identical to the credits or information screens, these win/lose screens just display that the winner won or the loser lost.

Feel free to check out the latest commit on this, but there isn’t much to see that is different from the info/credits commits.

Linux – keep it simple.

# Arduino Asteroids Game: Info and Credit Screens!

While not very exciting from the gamer standpoint, the information and credits screens are really important for several reasons. The main one being that it tells you how to play the game. It also lets you know how to contact the developer and who made the game. In the event you want to find more great material to play with!

Essentially, I have set up a scrolling screen that scrolls information over and over again. Pretty boring. However, I found a useful gem that I’d like to share with you here.

You see, as the information scrolls by, you might decide to click a button to do something, e.g., go back to the main menu, start the game, or what not. Well, the original method I was using was:

• Loop through displayed data.
• Check if they clicked a button.

This is a problem because you may have to hold the button for 1.5 seconds before it is picked up by the program. So, how do we include a delay, but constantly check for button presses? Well, with a “while” loop of course! Check it out:

```gameDelay = 0;
while (gameDelay < 2000){
// Add a delay in the loop.
delay(1);
gameDelay++;

switch (lcd_key){ // depending on which button was pushed, we perform an action

case btnSELECT:{
gameState = 0;
gameLineNum = 0;
break;
}
}
}
```

So, instead of 2 seconds of delay all at once, I have a while loop that delays 1 ms, checks for button pushes, and then repeats for 2000 times, or roughly 2 seconds. This allows the player to press the button at any time, and only delays by 1 ms before reading it. Not only is this more functional, but it looks cooler in code too!

You can check out the full commit for the credits screen and info screens on my GitLab if you want more information.

Linux – keep it simple.

# Qt 5 and C++ meet in a graphical user interface!

Section 2 is complete of the “Beginning Qt 5 C++ GUI Development” course! This course is great! I’m really learning a lot from the instructor. Section 2 was sort of a C++ primer, for those who were not familiar with it. As you know, if you’ve been following along here, I already learned C++ in another course. However, in this “primer” of C++, I gained a much deeper understanding of what exactly classes are, how to properly use constructors and all sorts of great stuff!

###### Check out my “Guess the number” game!

I’m not sure if I think the course is so great because I already know a little about C++, or if it just is that informative, but it seems to me that it moves at a great pace for beginners like myself.

You can check out my completed game, although it’s not much to see yet. The object is to guess the number which is between 1 and 10. You’ll have to import it into Qt-Creator and then compile it. I haven’t started making executables yet.

As an aside, if you are familiar with Android Studio, Qt-Creator is somewhat similar in feel and use. I like how you can right click on an object and add code directly to your cpp files, which is really handy!

Linux – keep it simple.

# JelloStorm.cpp:198:58: error: ?createBackground? was not declared in this scope

After the rough time I had completing section 6 of the course, I was not looking forward to section 7. However, it turned out that section 6 was just tough, and section 7 was pretty easy. That doesn’t mean I didn’t have any trouble though.

JelloStorm.cpp: In function ?int main()?:
JelloStorm.cpp:198:58: error: ?createBackground? was not declared in this scope
int tileSize = createBackground(tileBackground, arena);
^

Turns out when you make a header file, you have to be sure to include it! Yes, I forgot that line, so I fixed it as such:

#include <SFML/Graphics.hpp>
#include <sstream>
#include <SFML/Audio.hpp>
#include <Player.h>
#include <JelloStorm.h>

And now that it is fixed, my archer has a nice grassy field to walk around in! You can check out the game thus far or the commit at my GitLab!

Linux – keep it simple.