1 / 12

The Snake Game

The Snake Game. Lesson 14. How the Snake Game Draws the Snake!. The snake is drawn one pixel at a time. Uses the PSet command. User click on one of the path’s directional command buttons to change the path of the snake.

trung
Download Presentation

The Snake Game

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Snake Game Lesson 14

  2. How the Snake Game Draws the Snake! • The snake is drawn one pixel at a time. • Uses the PSet command. • User click on one of the path’s directional command buttons to change the path of the snake.

  3. The variable sngX and sngY, specify the point on the form where the next pixel will appear. • The sngXFactor and sngYFactor specifies the number of pixels that are to be added to • sngX to advance the head of the snake in the X direction. • sngY to advance the head of the snake in the Y direction.

  4. sngXFactor is zero because there is no change to the X coorodinate. • Example: sngXFactor = 0 sngYFactor = 1 sngYFactor is one because with each repetition of the loop the Y coordinate must increase by one pixel.

  5. sngXFactor = 1 sngYFactor = 0 sngXFactor is one because the X coordinate must increase by one pixel with each repetition of the loop. The Y does not change because it is horizontal!

  6. sngXFactor = 0 sngYFactor = -1 Moving the snake up and left requires a negativenumber because it is moving to the top or left.

  7. Move the snake to the left the sngXFactor must be a negative number. This will move the snake to the left. sngXFactor = -1 sngYFactor = 0

  8. How the game works: • The user runs the snake into the wall or into its tail. • The user clicks the Stop Game button. • The user click the Quit button.

  9. Lets make some changes! • Open the snake game from lesson 1. • Change the value of lngSnakeColor to vbRed. • Add the following code to your program: lngSnakeColor = vbRed • Run your program! • What happens?

  10. Let’s create faster button! • Add a command button above the Up button. • Set the Name property to cmdSpeed. • Set the Caption property to Faster. • Double click the Faster command button and add code to toggle the speed at which the snake moves and to change the caption of the command button.

  11. If cmdSpeed.Caption = "Faster" Then lngMySpeed = 100000 cmdSpeed.Caption = "Slower" Else lngMySpeed = 200000 cmdSpeed.Caption = "Faster" End If

  12. Move the code Dim lngMySpeed from the cmdStart section to the General Declaration section. • Save your program! • Run your program! • What happens?

More Related