This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:comporg:spring2024:projects:mpg0 [2024/02/05 14:43] – [Gamepad input] wgates1 | notes:comporg:spring2024:projects:mpg0 [2024/02/08 02:32] (current) – [Game loop] rspringe | ||
---|---|---|---|
Line 7: | Line 7: | ||
====Game loop==== | ====Game loop==== | ||
+ | For this project, you will be making a Snake game. | ||
+ | The game loop for Snake is simple: you will control a snake around the screen to eat pieces of food. Once a piece of food has been eaten, your score will increase, and the snake will get longer. | ||
+ | |||
+ | The game ends when the head of the snake runs into either a wall, or another part of its body. | ||
====Sprites==== | ====Sprites==== | ||
Line 14: | Line 18: | ||
* A link to GIMP download: https:// | * A link to GIMP download: https:// | ||
* You could also have a death screen for when your snake dies. | * You could also have a death screen for when your snake dies. | ||
+ | |||
+ | Another good option for designing your snake is downloading a photo off the internet(probably an animated/ | ||
====Gamepad input==== | ====Gamepad input==== | ||
There is obviously your arrow key inputs but there are other buttons available as well. At least for gamepad(0) we have button_?_ = ? for the average keyboard: | There is obviously your arrow key inputs but there are other buttons available as well. At least for gamepad(0) we have button_?_ = ? for the average keyboard: | ||
Line 23: | Line 29: | ||
* R = W | * R = W | ||
* Start = Enter Key | * Start = Enter Key | ||
+ | |||
+ | ==Using controller== | ||
+ | For those out there who want the whole experience of gaming, therein lies the ability to plug in a real video game controller, if your system allows (some laptops will at least). To that end, the controls are pretty straight-forward. Either console controller will rely upon the D-pad for movement, and the buttons should map to the controllers as well. For example, ' | ||
+ | |||
+ | ==Arrow Key Setup== | ||
+ | If you are just trying to make the input based off of your arrow keys, you can simply copy the same setup: | ||
+ | <code C> | ||
+ | // Buttons to move up, down, left, and right | ||
+ | bool mRight = (gamepad_right() == 1); | ||
+ | bool mLeft = (gamepad_left() == 1); | ||
+ | bool mUp = (gamepad_up() == 1); | ||
+ | bool mDown = (gamepad_down() == 1); | ||
+ | </ | ||
+ | |||
+ | NOTE: You'll want to do this in your game loop (the while loop) and make sure it is inside of main but outside of you game loop have the following: | ||
+ | <code C> | ||
+ | // Selects keyboard as gamepad to use for input | ||
+ | select_gamepad(0); | ||
+ | </ | ||
When making you gamepad you'll make gamepad_direction values, WalkX and WalkY for example purposes. | When making you gamepad you'll make gamepad_direction values, WalkX and WalkY for example purposes. | ||
Line 33: | Line 58: | ||
<code bash> | <code bash> | ||
if( var == 1 ) { | if( var == 1 ) { | ||
- | Snake.X -= PlayerSpeed; | + | Snake[0].X -= PlayerSpeed; |
} | } | ||
</ | </ | ||
Line 61: | Line 86: | ||
The screen on vircon32 is 640 by 360, however, you do not have to type these out every time you make a game in vircon32 as they are stored in the screen_width and screen_height variables respectively. One way of bounds checking is to see where you are about to spawn the snake' | The screen on vircon32 is 640 by 360, however, you do not have to type these out every time you make a game in vircon32 as they are stored in the screen_width and screen_height variables respectively. One way of bounds checking is to see where you are about to spawn the snake' | ||
====Handling motion==== | ====Handling motion==== | ||
+ | To handle motion you could do: | ||
+ | <code c> | ||
+ | int SnakeX; | ||
+ | |||
+ | if( Right) | ||
+ | { | ||
+ | |||
+ | SnakeX = SnakeX + 20; | ||
+ | |||
+ | |||
+ | } | ||
+ | </ | ||
====Score Display==== | ====Score Display==== | ||