
Yunting Zou 201199716
Dependencies: mbed MotionSensor
Diff: viper/viper.h
- Revision:
- 1:9a8033d80067
- Parent:
- 0:047e14f53977
- Child:
- 2:a2f88b2d5da4
--- a/viper/viper.h Thu May 14 16:17:30 2020 +0000 +++ b/viper/viper.h Thu May 14 16:29:22 2020 +0000 @@ -21,26 +21,26 @@ }COOR; struct Serpent { - vip head[length]; //set the length of the viper - int n; //number of snake's section + vip head[length]; //@set the length of the viper + int n; //@number of snake's section }SER; struct target{ - vip var;//set the variable of target + vip var;//@set the variable of target }target; void viper(); -void Movement(); //@set the direction control of the snake -void goal(); //@set the target food -void gameover(); //@set the failure screen -float wtime; //@related to the speed of the snake +void Movement(); //set the direction control of the snake +void goal(); //set the target food +void gameover(); //set the failure screen +float wtime; //related to the speed of the snake int score ; -int HP; //@ Snake's health point(HP), if HP=0, game over. -int D; //@set the variable of direction -int d; //@set the variable of the joystick +int HP; // Snake's health point(HP), if HP=0, game over. +int D; //set the variable of direction +int d; //set the variable of the joystick - // @define the location of the snake 1 + // define the location of the snake 1 void defineSnake(){ for(int i = 1; i < SER.n; i++){ SER.head[i].x = SER.head[i-1].x; @@ -49,7 +49,7 @@ } -//@show a snake by creating array 2 +//show a snake by creating array 2 void viper() { @@ -60,10 +60,10 @@ } -//@implement the movement function 3 +//implement the movement function 3 void Movement() { - d = pad.get_direction();//@use joystick to control the direction of snake + d = pad.get_direction();//use joystick to control the direction of snake if (d == N ){ D = 1;//up } @@ -84,25 +84,25 @@ //@let snake move for different direction if (D == 1 ){ SER.head[0].x = SER.head[0].x; - SER.head[0].y = SER.head[0].y-1; - }//@turn upwards + SER.head[0].y -= 1; + }//turn upwards else if (D == 2 ){ SER.head[0].x = SER.head[0].x; - SER.head[0].y = SER.head[0].y+1; - }//@turn downwards + SER.head[0].y += 1; + }//turn downwards else if (D == 3 ){ - SER.head[0].x = SER.head[0].x-1; + SER.head[0].x -= 1; SER.head[0].y = SER.head[0].y; - }//@turn left + }//turn left else if (D == 4 ){ - SER.head[0].x = SER.head[0].x+1; + SER.head[0].x += 1; SER.head[0].y = SER.head[0].y; - }//@turn right + }//turn right } -//@generate a random target 4 +//generate a random target 4 void goal(){ srand(unsigned (time(NULL))); target.var.x = rand() % 80; // The target appears at random location @@ -111,14 +111,14 @@ } -// @if snake get the target, change the length and the score 6 +// if snake get the target, change the length and the score 6 void gettarget(){ //juge if snake eat food if(SER.head[0].x == target.var.x && SER.head[0].y == target.var.y ){ - SER.n = SER.n+7; - goal();//@generate a new target when the previous target has been eaten + SER.n += 7; + goal();//generate a new target when the previous target has been eaten pad.tone(650,1);// @sounds - score += 1;// @when the snake get its target, the score plus one + score += 1;// when the snake get its target, the score plus one } }