# Programming in LOLGraphics 3.4/Making a simple game in LOLGraphics
## Introduction

In this tutorial we will make a simple WASD controlled game where you control a square. If you fall in the lava pool, you lose, and if you get to the purple carpet, you will be asked a multiple-choice trivia question (who was the first president of the United States). If you answer it correctly, you win. If you answer it wrong, you lose. Simple enough.
Since the code will be written in parts, this chapter will follow the following conventions: new lines that didn’t exist in the previous version will be colored by green, lines that should be removed will be colored by red, and lines that should stay as they are will be colored by blue.

## Drawing the field

You will start of with an empty program. Let’s start by drawing the field. Yeh background will be green like grass, there will be one red square representing a pool of lava, and one magenta square.
Notice that the delay was set to 1. This is the lowest possible and was done on purpose so that the game will run as smoothly as possible.

## Drawing the player

The player will be an orange square that can move around the screen.
Notice how the drawing happens in the same subprogram where the default variables are set. This will change.

## Player movement

As it is, we don’t have much of a game. Let’s implement player movement:
Notice that the player drawing routine was moved to the field, and that the program now sets default values before it starts drawing. Also in the switch/case statement, it compares the variables to the ASCII values of WASD and 8462 keys.

## Detecting Lava

Now we have completed the movement, but you can walk wherever you want including on top of lava. Let’s fix that. Let’s add code that detects when you fell in lava and end the game.
Now if you fall in the lava, you get a message informing you about this, and the game ends. Notice that because the player starts at coordinates (200,150) and moves at a speed of 10 pixels/iteration, both the x and y values will always be numbers that can evenly be divided by 10.

## Detecting Carpet

Now we can detect when the player enters lava, let’s also detect when the player steps on the carpet.

## Trivia question

Now when you step on the carpet, you win instantly. Let’s make it so that you will get a trivia question and only win if you answered correctly.
Now when you step on the carpet, you will get asked who was the first president of the United States. Also, when you fall im lava, the text “You lose” is displayed in addition to “You fell in lava”. This “game” can be considered complete, however there’s one more thing we are going to add.

## Slight improvement

You would expect that after the player falls in lava, he would not be drawn on the screen. However this is not what happens in the game as of now. Let’s fix this. There are multiple ways to do so:
* One way, is to set the x and y values of the player to something out of bounds and then redraw the screen. This will cause the player to be “drawn” but because it will be out of the screen you won’t see him. Feel free to use this way, but this is not what we are going to use in this book.
* The second way is it to create a one-byte variable called IN_LAVA, set it to 0, and when the player falls in lava, set it to 1. The drawing routine will check the value of this variable and set if it’s equal to 1, the player won’t be drawn. Feel free to use it in your code, but this isn’t what we will be doing in this book.
* The third way would be to set the value of x or y to a number like -1 and then in the drawing routine to check if x==-1, and if yes then the player won’t be drawn. You can use any number that can’t be evenly divided by 10 and it won’t have any effect on how the code runs because the player moves at a speed of 10 pixel/iteration and starts with x,y coordinates that can be evenly divided by 10. This is what we will do.
So here’s the improved code:
Notice that the label “END” is the same one in the carpet subprogram. This doesn’t matter since after it there’s IM OUTTA UR CODE which ends the program.