How to Make Cheat Codes for a PC Game
Making cheat codes for a PC game that players can enter not only might help them win, the codes might also give them some additional incentive to replay your game. You can program the cheat codes after you have created the other elements of the game, such as the player's health, score, lives, ammo or whatever other variables your game will use. Regardless of the programming language you use to create your game, you can make cheat codes using "if-then-else" functions.
Instructions
-
-
1
Create the basic framework of your game. You cannot create cheat codes that modify elements of your game if those elements don't exist in the first place. For example, if you are making a game where players have multiple lives, you will need to create a "lives" variable.
-
2
Add a text box control and a button control to a part of your game, whether it's at the title screen or during game play. Change the text on the button to show "OK." Change their visibility properties to "hidden" so they cannot be seen during regular play.
-
-
3
Create a key press function. When the user presses a key you specify, such as the "Enter" key, the text box and "OK" button controls will become visible and wait for the player to enter a cheat code. By default, the text box will accept user input, but you need to program the button to call your cheat code checker function when the user clicks it. For example, the following pseudocode for the "OK" command will call the cheat code function and pass the player's cheat code entry to it:
function okButton pressed() {
call cheatCode(string textbox.Text)
}
-
4
Write a function that accepts the player-entered code as a string variable. Create an "if-then-else" block that checks if the code is valid and, if so, edits the player's attributes. For example, the following psuedocode opens the cheat code function and checks for two different cheat codes:
function cheatCode(string cheat) {
if cheat = "morelives" then
playerLives += 1
else if cheat = "bigmoney"
playerCash += 10000
end if
}
-
5
Add nested conditional checks to your "if-then-else" block for cheat codes that can be turned on and off, such as invincibility. The following expanded pseudocode will accomplish this:
function cheatCode(string cheat) {
if cheat = "morelives" then
playerLives += 1
else if cheat = "bigmoney"
playerCash += 10000
else if cheat = "canthurtme"
if playerInvincible = False then
playerInvincible = True
write("Cheat turned ON")
else
playerInvincible = False
write("Cheat turned OFF")
end if
end if
}
-
6
Reset the cheat code components. Clear the contents of the text box and hide it and the "OK" button controls. Add the following to your "okButton" function. These lines will execute after your game checks the player's cheat code:
function okButton pressed() {
call cheatCode(string textbox.Text)
textbox.Text = ""
textbox.Visible = False
okButton.Visible = False
}
-
1