Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Mon Apr 22 05:28:37 2019 +0000
Revision:
39:210ac915e0a0
Parent:
38:30e4e6191762
Child:
41:4edac50f010d
Removed some unnecessary get pos functions.

Who changed what in which revision?

UserRevisionLine numberNew 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 38:30e4e6191762 6 #include "FXOS8700CQ.h"
AhmedPlaymaker 7:48ba87cd79b5 7 #include "Gamepad.h"
AhmedPlaymaker 7:48ba87cd79b5 8 #include "Snake.h"
AhmedPlaymaker 9:d1d79d4ee673 9 #include "SnakeFood.h"
AhmedPlaymaker 10:751bd953fa27 10 #include "Blocks.h"
AhmedPlaymaker 33:249cf423fb18 11 #include "StartScreen.h"
AhmedPlaymaker 33:249cf423fb18 12 #include "Stats.h"
AhmedPlaymaker 33:249cf423fb18 13 #include "SDFileSystem.h"
AhmedPlaymaker 7:48ba87cd79b5 14
AhmedPlaymaker 7:48ba87cd79b5 15 class SnakevsBlock
AhmedPlaymaker 7:48ba87cd79b5 16 {
AhmedPlaymaker 7:48ba87cd79b5 17 public:
AhmedPlaymaker 7:48ba87cd79b5 18 SnakevsBlock();
AhmedPlaymaker 7:48ba87cd79b5 19 ~SnakevsBlock();
AhmedPlaymaker 7:48ba87cd79b5 20
AhmedPlaymaker 7:48ba87cd79b5 21 /** Initialise Game Machine
AhmedPlaymaker 7:48ba87cd79b5 22 *
AhmedPlaymaker 7:48ba87cd79b5 23 * This function initialises the game machine.
AhmedPlaymaker 7:48ba87cd79b5 24 */
AhmedPlaymaker 7:48ba87cd79b5 25 void init( );
AhmedPlaymaker 7:48ba87cd79b5 26
AhmedPlaymaker 7:48ba87cd79b5 27 /** Read Input
AhmedPlaymaker 7:48ba87cd79b5 28 *
AhmedPlaymaker 7:48ba87cd79b5 29 * This function obtains numeric data from the gamepads joystick.
AhmedPlaymaker 7:48ba87cd79b5 30 */
AhmedPlaymaker 38:30e4e6191762 31 void read_input(Gamepad &pad, FXOS8700CQ &device, int gm);
AhmedPlaymaker 7:48ba87cd79b5 32
AhmedPlaymaker 7:48ba87cd79b5 33 /** Update
AhmedPlaymaker 7:48ba87cd79b5 34 *
AhmedPlaymaker 7:48ba87cd79b5 35 * This function contains the update functions of the other libraries used in the game.
AhmedPlaymaker 7:48ba87cd79b5 36 */
AhmedPlaymaker 33:249cf423fb18 37 int update(Gamepad &pad, SDFileSystem &sd);
AhmedPlaymaker 7:48ba87cd79b5 38
AhmedPlaymaker 7:48ba87cd79b5 39 /** Draw
AhmedPlaymaker 7:48ba87cd79b5 40 *
AhmedPlaymaker 7:48ba87cd79b5 41 * This function contains the draw functions of the other libraries used in the game.
AhmedPlaymaker 7:48ba87cd79b5 42 */
AhmedPlaymaker 7:48ba87cd79b5 43 void draw(N5110 &lcd, Gamepad &pad);
AhmedPlaymaker 7:48ba87cd79b5 44
AhmedPlaymaker 39:210ac915e0a0 45 /** Print Length on the nokia screen
AhmedPlaymaker 39:210ac915e0a0 46 *
AhmedPlaymaker 39:210ac915e0a0 47 * This function is called in draw and just signifies the length to be displayed.
AhmedPlaymaker 39:210ac915e0a0 48 */
AhmedPlaymaker 39:210ac915e0a0 49 void print_length_on_screen(N5110 &lcd);
AhmedPlaymaker 39:210ac915e0a0 50
AhmedPlaymaker 7:48ba87cd79b5 51 /** Get Position
AhmedPlaymaker 7:48ba87cd79b5 52 *
AhmedPlaymaker 7:48ba87cd79b5 53 * This function contains the Get Position functions of the otehr libraries used in the game.
AhmedPlaymaker 7:48ba87cd79b5 54 */
AhmedPlaymaker 7:48ba87cd79b5 55 void get_pos();
AhmedPlaymaker 7:48ba87cd79b5 56
AhmedPlaymaker 29:c6358c39a70e 57 /** Check Block
AhmedPlaymaker 29:c6358c39a70e 58 *
AhmedPlaymaker 29:c6358c39a70e 59 * This function returns the srn of the block we are colliding with;
AhmedPlaymaker 29:c6358c39a70e 60 */
AhmedPlaymaker 29:c6358c39a70e 61 int CheckBlock(int Block);
AhmedPlaymaker 29:c6358c39a70e 62
AhmedPlaymaker 27:3b4775a0d0bb 63 /** Implement Collision
AhmedPlaymaker 27:3b4775a0d0bb 64 *
AhmedPlaymaker 27:3b4775a0d0bb 65 * This function allows the appropriate maths to take place after every collision.
AhmedPlaymaker 27:3b4775a0d0bb 66 */
AhmedPlaymaker 27:3b4775a0d0bb 67 void ImplementCollision(Gamepad &pad);
AhmedPlaymaker 27:3b4775a0d0bb 68
AhmedPlaymaker 7:48ba87cd79b5 69
AhmedPlaymaker 7:48ba87cd79b5 70 int snakex;
AhmedPlaymaker 7:48ba87cd79b5 71 int snakey;
AhmedPlaymaker 7:48ba87cd79b5 72 int length;
AhmedPlaymaker 39:210ac915e0a0 73 int velocity; //this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.
AhmedPlaymaker 19:05cc9f801468 74 int level;
AhmedPlaymaker 38:30e4e6191762 75 int garbage; //to save the angle at the point button A is pressed.
AhmedPlaymaker 38:30e4e6191762 76 float angle; //saves the angle of tilt.
AhmedPlaymaker 9:d1d79d4ee673 77 int foodbuff; //this makes food 1,2,and 3 come at seperate times
AhmedPlaymaker 12:1e601b176437 78 int blocknum;
AhmedPlaymaker 19:05cc9f801468 79 int blockgap; //to change frequency of fall
AhmedPlaymaker 19:05cc9f801468 80 int blockbuff; // to manage the fall of food relative to the blocks
AhmedPlaymaker 12:1e601b176437 81 int srn;
AhmedPlaymaker 12:1e601b176437 82 int send; //makes sure that the block number is only updated when send is activated.
AhmedPlaymaker 13:9785f2404045 83 int speed; //makes sure that snake only moves if not colliding to block walls
AhmedPlaymaker 25:e827f1a8fadc 84 int back; //enables the player to go back on main menu if back is pressed.
AhmedPlaymaker 22:ee698f66146f 85 int b[15];
AhmedPlaymaker 18:b391caa5754c 86 int b0_to_b14[15];
AhmedPlaymaker 24:1c118b071430 87 Vector2D snake_pos[15];
AhmedPlaymaker 7:48ba87cd79b5 88
AhmedPlaymaker 7:48ba87cd79b5 89 private:
AhmedPlaymaker 7:48ba87cd79b5 90
AhmedPlaymaker 7:48ba87cd79b5 91 Snake _s;
AhmedPlaymaker 9:d1d79d4ee673 92 SnakeFood _f;
AhmedPlaymaker 9:d1d79d4ee673 93 SnakeFood _ff;
AhmedPlaymaker 9:d1d79d4ee673 94 SnakeFood _fff;
AhmedPlaymaker 10:751bd953fa27 95 Blocks _b;
AhmedPlaymaker 33:249cf423fb18 96 Stats _statset;
AhmedPlaymaker 7:48ba87cd79b5 97 int _speed;
AhmedPlaymaker 7:48ba87cd79b5 98 Direction _d;
AhmedPlaymaker 7:48ba87cd79b5 99 float _mag;
AhmedPlaymaker 37:ee47699915b8 100 int _detect_slowly; //this makes sure that when the length is more than 10, the colliding block doesnt decrease the all the length in a single itteration.
AhmedPlaymaker 7:48ba87cd79b5 101 int n;
AhmedPlaymaker 7:48ba87cd79b5 102
AhmedPlaymaker 9:d1d79d4ee673 103 /** Check for Snake and Food collision
AhmedPlaymaker 9:d1d79d4ee673 104 *
AhmedPlaymaker 9:d1d79d4ee673 105 * This function checks if the Snake has come into contact with it's food.
AhmedPlaymaker 9:d1d79d4ee673 106 */
AhmedPlaymaker 9:d1d79d4ee673 107 void CheckSnakeFoodCollision(Gamepad &pad);
AhmedPlaymaker 9:d1d79d4ee673 108
AhmedPlaymaker 12:1e601b176437 109 /** Check for Snake and Block collision
AhmedPlaymaker 12:1e601b176437 110 *
AhmedPlaymaker 12:1e601b176437 111 * This function checks if the Snake has come into contact with any Block.
AhmedPlaymaker 12:1e601b176437 112 */
AhmedPlaymaker 12:1e601b176437 113 void CheckSnakeBlockCollision(Gamepad &pad);
AhmedPlaymaker 13:9785f2404045 114
AhmedPlaymaker 39:210ac915e0a0 115 /** Implement velocity alteration.
AhmedPlaymaker 39:210ac915e0a0 116 *
AhmedPlaymaker 39:210ac915e0a0 117 * this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock.
AhmedPlaymaker 39:210ac915e0a0 118 */
AhmedPlaymaker 39:210ac915e0a0 119 void _set_velocity();
AhmedPlaymaker 39:210ac915e0a0 120
AhmedPlaymaker 13:9785f2404045 121 /** Check for Snake and Block Sides collision
AhmedPlaymaker 13:9785f2404045 122 *
AhmedPlaymaker 13:9785f2404045 123 * This function checks if the Snake has come into contact with any the sides of the block and stops it moving.
AhmedPlaymaker 13:9785f2404045 124 */
AhmedPlaymaker 38:30e4e6191762 125 void CheckSnakeBlockSidesCollision(Gamepad &pad);
AhmedPlaymaker 7:48ba87cd79b5 126 };
AhmedPlaymaker 7:48ba87cd79b5 127 #endif