![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
SnakevsBlock/SnakevsBlock.h@18:b391caa5754c, 2019-04-08 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Mon Apr 08 05:57:04 2019 +0000
- Revision:
- 18:b391caa5754c
- Parent:
- 16:7b474f873683
- Child:
- 19:05cc9f801468
Dont know if this is the best way? but this makes the game easier to operate near the edges but makes the snake look distorted
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AhmedPlaymaker | 7:48ba87cd79b5 | 1 | #ifndef SNAKEVSBLOCK_H |
AhmedPlaymaker | 7:48ba87cd79b5 | 2 | #define SNAKEVSBLOCK_H |
AhmedPlaymaker | 7:48ba87cd79b5 | 3 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 4 | #include "mbed.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 5 | #include "N5110.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 6 | #include "Gamepad.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 7 | #include "Snake.h" |
AhmedPlaymaker | 9:d1d79d4ee673 | 8 | #include "SnakeFood.h" |
AhmedPlaymaker | 10:751bd953fa27 | 9 | #include "Blocks.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 10 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 11 | class SnakevsBlock |
AhmedPlaymaker | 7:48ba87cd79b5 | 12 | { |
AhmedPlaymaker | 7:48ba87cd79b5 | 13 | public: |
AhmedPlaymaker | 7:48ba87cd79b5 | 14 | SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 15 | ~SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 16 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 17 | /** Initialise Game Machine |
AhmedPlaymaker | 7:48ba87cd79b5 | 18 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 19 | * This function initialises the game machine. |
AhmedPlaymaker | 7:48ba87cd79b5 | 20 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 21 | void init( ); |
AhmedPlaymaker | 7:48ba87cd79b5 | 22 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 23 | /** Read Input |
AhmedPlaymaker | 7:48ba87cd79b5 | 24 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 25 | * This function obtains numeric data from the gamepads joystick. |
AhmedPlaymaker | 7:48ba87cd79b5 | 26 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 27 | void read_input(Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 28 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 29 | /** Update |
AhmedPlaymaker | 7:48ba87cd79b5 | 30 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 31 | * This function contains the update functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 32 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 33 | void update(Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 34 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 35 | /** Draw |
AhmedPlaymaker | 7:48ba87cd79b5 | 36 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 37 | * This function contains the draw functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 38 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 39 | void draw(N5110 &lcd, Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 40 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 41 | /** Get Position |
AhmedPlaymaker | 7:48ba87cd79b5 | 42 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 43 | * This function contains the Get Position functions of the otehr libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 44 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 45 | void get_pos(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 46 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 47 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 48 | int snakex; |
AhmedPlaymaker | 7:48ba87cd79b5 | 49 | int snakey; |
AhmedPlaymaker | 7:48ba87cd79b5 | 50 | int length; |
AhmedPlaymaker | 9:d1d79d4ee673 | 51 | int foodbuff; //this makes food 1,2,and 3 come at seperate times |
AhmedPlaymaker | 12:1e601b176437 | 52 | int blocknum; |
AhmedPlaymaker | 16:7b474f873683 | 53 | int blockgap; |
AhmedPlaymaker | 12:1e601b176437 | 54 | int srn; |
AhmedPlaymaker | 12:1e601b176437 | 55 | int send; //makes sure that the block number is only updated when send is activated. |
AhmedPlaymaker | 13:9785f2404045 | 56 | int speed; //makes sure that snake only moves if not colliding to block walls |
AhmedPlaymaker | 18:b391caa5754c | 57 | int b0; |
AhmedPlaymaker | 18:b391caa5754c | 58 | int b1; |
AhmedPlaymaker | 18:b391caa5754c | 59 | int b2; |
AhmedPlaymaker | 18:b391caa5754c | 60 | int b3; |
AhmedPlaymaker | 18:b391caa5754c | 61 | int b4; |
AhmedPlaymaker | 18:b391caa5754c | 62 | int b5; |
AhmedPlaymaker | 18:b391caa5754c | 63 | int b6; |
AhmedPlaymaker | 18:b391caa5754c | 64 | int b7; |
AhmedPlaymaker | 18:b391caa5754c | 65 | int b8; |
AhmedPlaymaker | 18:b391caa5754c | 66 | int b9; |
AhmedPlaymaker | 18:b391caa5754c | 67 | int b10; |
AhmedPlaymaker | 18:b391caa5754c | 68 | int b11; |
AhmedPlaymaker | 18:b391caa5754c | 69 | int b12; |
AhmedPlaymaker | 18:b391caa5754c | 70 | int b13; |
AhmedPlaymaker | 18:b391caa5754c | 71 | int b14; |
AhmedPlaymaker | 18:b391caa5754c | 72 | int b0_to_b14[15]; |
AhmedPlaymaker | 7:48ba87cd79b5 | 73 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 74 | private: |
AhmedPlaymaker | 7:48ba87cd79b5 | 75 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 76 | Snake _s; |
AhmedPlaymaker | 9:d1d79d4ee673 | 77 | SnakeFood _f; |
AhmedPlaymaker | 9:d1d79d4ee673 | 78 | SnakeFood _ff; |
AhmedPlaymaker | 9:d1d79d4ee673 | 79 | SnakeFood _fff; |
AhmedPlaymaker | 10:751bd953fa27 | 80 | Blocks _b; |
AhmedPlaymaker | 7:48ba87cd79b5 | 81 | int _speed; |
AhmedPlaymaker | 7:48ba87cd79b5 | 82 | Direction _d; |
AhmedPlaymaker | 7:48ba87cd79b5 | 83 | float _mag; |
AhmedPlaymaker | 7:48ba87cd79b5 | 84 | int n; |
AhmedPlaymaker | 7:48ba87cd79b5 | 85 | |
AhmedPlaymaker | 9:d1d79d4ee673 | 86 | /** Check for Snake and Food collision |
AhmedPlaymaker | 9:d1d79d4ee673 | 87 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 88 | * This function checks if the Snake has come into contact with it's food. |
AhmedPlaymaker | 9:d1d79d4ee673 | 89 | */ |
AhmedPlaymaker | 9:d1d79d4ee673 | 90 | void CheckSnakeFoodCollision(Gamepad &pad); |
AhmedPlaymaker | 9:d1d79d4ee673 | 91 | |
AhmedPlaymaker | 12:1e601b176437 | 92 | /** Check for Snake and Block collision |
AhmedPlaymaker | 12:1e601b176437 | 93 | * |
AhmedPlaymaker | 12:1e601b176437 | 94 | * This function checks if the Snake has come into contact with any Block. |
AhmedPlaymaker | 12:1e601b176437 | 95 | */ |
AhmedPlaymaker | 12:1e601b176437 | 96 | void CheckSnakeBlockCollision(Gamepad &pad); |
AhmedPlaymaker | 13:9785f2404045 | 97 | |
AhmedPlaymaker | 13:9785f2404045 | 98 | /** Check for Snake and Block Sides collision |
AhmedPlaymaker | 13:9785f2404045 | 99 | * |
AhmedPlaymaker | 13:9785f2404045 | 100 | * This function checks if the Snake has come into contact with any the sides of the block and stops it moving. |
AhmedPlaymaker | 13:9785f2404045 | 101 | */ |
AhmedPlaymaker | 13:9785f2404045 | 102 | void CheckSnakeBlockSidesCollision(Gamepad &pad, Direction d); |
AhmedPlaymaker | 7:48ba87cd79b5 | 103 | }; |
AhmedPlaymaker | 7:48ba87cd79b5 | 104 | #endif |