Doxygen comments added

Dependencies:   mbed Gamepad N5110

Committer:
rafeh
Date:
Thu May 02 18:42:43 2019 +0000
Revision:
5:3a0948f56de0
Parent:
4:e98b22e5d5e8
Child:
6:bc580b480ac8
check for collisions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rafeh 0:43364ffd7cf6 1 /*
rafeh 0:43364ffd7cf6 2 ELEC2645 Embedded Systems Project
rafeh 0:43364ffd7cf6 3 School of Electronic & Electrical Engineering
rafeh 0:43364ffd7cf6 4 University of Leeds
rafeh 0:43364ffd7cf6 5 Name: Rafeh Ishtiaq
rafeh 0:43364ffd7cf6 6 Username: el17ri
rafeh 0:43364ffd7cf6 7 Student ID Number: 201062291
rafeh 0:43364ffd7cf6 8 Date: 20/03/2019
rafeh 0:43364ffd7cf6 9 */
rafeh 0:43364ffd7cf6 10
rafeh 0:43364ffd7cf6 11 #include "mbed.h"
rafeh 0:43364ffd7cf6 12 #include "N5110.h"
rafeh 0:43364ffd7cf6 13 #include "Gamepad.h"
rafeh 3:5409b50b01b0 14 #include "Pipes.h"
rafeh 3:5409b50b01b0 15 //#include "Bird.h"
rafeh 0:43364ffd7cf6 16
rafeh 0:43364ffd7cf6 17 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
rafeh 0:43364ffd7cf6 18 Gamepad pad;
rafeh 3:5409b50b01b0 19 //Bird bird;
rafeh 3:5409b50b01b0 20 Pipes pipes;
rafeh 3:5409b50b01b0 21
rafeh 3:5409b50b01b0 22 const int intro [40][40] =
rafeh 1:beceda7046fb 23 {
rafeh 1:beceda7046fb 24 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 25 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 26 0,0,0,0,0,0,0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,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 58 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 59 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 60 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 61 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 62 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 1:beceda7046fb 63 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
rafeh 0:43364ffd7cf6 64
rafeh 1:beceda7046fb 65 };
rafeh 0:43364ffd7cf6 66
rafeh 3:5409b50b01b0 67 const int moving [6][6] =
rafeh 2:9f5714571c41 68 {
rafeh 3:5409b50b01b0 69 0,0,1,1,0,0,
rafeh 3:5409b50b01b0 70 0,1,0,1,1,0,
rafeh 3:5409b50b01b0 71 1,0,1,1,1,1,
rafeh 3:5409b50b01b0 72 1,1,1,1,1,0,
rafeh 3:5409b50b01b0 73 0,1,1,1,1,0,
rafeh 3:5409b50b01b0 74 0,0,0,0,0,0,
rafeh 2:9f5714571c41 75
rafeh 2:9f5714571c41 76 };
rafeh 2:9f5714571c41 77
rafeh 0:43364ffd7cf6 78 void welcome();
rafeh 4:e98b22e5d5e8 79 void checkcollisions(int hor, int ver);
rafeh 5:3a0948f56de0 80 int generate_height();
rafeh 5:3a0948f56de0 81 bool check_collisions(int f, int xx, int yy);
rafeh 3:5409b50b01b0 82
rafeh 3:5409b50b01b0 83 int xaxis=25;
rafeh 3:5409b50b01b0 84 int yaxis=20;
rafeh 3:5409b50b01b0 85
rafeh 0:43364ffd7cf6 86 int main() {
rafeh 0:43364ffd7cf6 87 lcd.init();
rafeh 0:43364ffd7cf6 88 pad.init();
rafeh 0:43364ffd7cf6 89 lcd.clear();
rafeh 1:beceda7046fb 90 lcd.setContrast(0.5);
rafeh 1:beceda7046fb 91 welcome();
rafeh 2:9f5714571c41 92 if (pad.check_event(Gamepad::START_PRESSED) == false) {
rafeh 2:9f5714571c41 93 lcd.clear();
rafeh 2:9f5714571c41 94
rafeh 3:5409b50b01b0 95 int xvalue=84;
rafeh 5:3a0948f56de0 96 //int height = rand() % (19 + 1 - 0) + 0;
rafeh 5:3a0948f56de0 97 int height = generate_height();
rafeh 3:5409b50b01b0 98 int score = 0;
rafeh 3:5409b50b01b0 99 char scoredisplay[3];
rafeh 2:9f5714571c41 100 while(1) {
rafeh 3:5409b50b01b0 101 lcd.drawRect(0,45,84,3,FILL_BLACK);
rafeh 3:5409b50b01b0 102
rafeh 3:5409b50b01b0 103 pipes.init(xvalue,height);
rafeh 3:5409b50b01b0 104 pipes.draw(lcd);
rafeh 3:5409b50b01b0 105 xvalue=xvalue-1;
rafeh 3:5409b50b01b0 106 sprintf(scoredisplay,"%d",score);
rafeh 3:5409b50b01b0 107 lcd.printString(scoredisplay,60,0);
rafeh 3:5409b50b01b0 108
rafeh 3:5409b50b01b0 109 if(xvalue<20 && xvalue>17) {
rafeh 3:5409b50b01b0 110 score=score+1;
rafeh 3:5409b50b01b0 111 }
rafeh 3:5409b50b01b0 112
rafeh 3:5409b50b01b0 113
rafeh 3:5409b50b01b0 114 if(xvalue<1) {
rafeh 5:3a0948f56de0 115 //height=rand() % (19 + 1 - 0) + 0;
rafeh 5:3a0948f56de0 116 height=generate_height();
rafeh 3:5409b50b01b0 117 xvalue=84;
rafeh 3:5409b50b01b0 118 }
rafeh 3:5409b50b01b0 119
rafeh 3:5409b50b01b0 120 //pipes(xvalue,height);
rafeh 3:5409b50b01b0 121 //bird.init(xaxis,yaxis);
rafeh 3:5409b50b01b0 122 //bird.draw(lcd);
rafeh 3:5409b50b01b0 123 lcd.drawSprite(xaxis,yaxis,6,6,(int*)moving);
rafeh 2:9f5714571c41 124 yaxis=yaxis+2;
rafeh 2:9f5714571c41 125 if (pad.check_event(Gamepad::A_PRESSED) == true) {
rafeh 4:e98b22e5d5e8 126 yaxis=yaxis-14;
rafeh 2:9f5714571c41 127 }
rafeh 4:e98b22e5d5e8 128
rafeh 3:5409b50b01b0 129 wait(0.075);
rafeh 3:5409b50b01b0 130 xvalue=xvalue-1;
rafeh 5:3a0948f56de0 131 if (check_collisions(yaxis,xvalue,height)) {
rafeh 5:3a0948f56de0 132 wait(1);
rafeh 5:3a0948f56de0 133 welcome();
rafeh 5:3a0948f56de0 134 }
rafeh 4:e98b22e5d5e8 135 //checkcollisions(xaxis,yaxis);
rafeh 2:9f5714571c41 136 //wait(0.1);
rafeh 2:9f5714571c41 137 lcd.refresh();
rafeh 2:9f5714571c41 138 lcd.clear();
rafeh 2:9f5714571c41 139 }
rafeh 2:9f5714571c41 140 }
rafeh 3:5409b50b01b0 141
rafeh 3:5409b50b01b0 142
rafeh 2:9f5714571c41 143 }
rafeh 0:43364ffd7cf6 144
rafeh 2:9f5714571c41 145
rafeh 0:43364ffd7cf6 146
rafeh 0:43364ffd7cf6 147 void welcome() {
rafeh 3:5409b50b01b0 148 lcd.drawSprite(0,0,40,40,(int*)intro);
rafeh 1:beceda7046fb 149 lcd.printString(" Flappy ",40,0);
rafeh 1:beceda7046fb 150 lcd.printString(" Bird ",40,1);
rafeh 1:beceda7046fb 151 lcd.printString(" Press ",40,3);
rafeh 1:beceda7046fb 152 lcd.printString(" Start ",40,4);
rafeh 1:beceda7046fb 153 lcd.refresh();
rafeh 1:beceda7046fb 154 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
rafeh 1:beceda7046fb 155 pad.leds_on();
rafeh 1:beceda7046fb 156 wait(0.1);
rafeh 1:beceda7046fb 157 pad.leds_off();
rafeh 1:beceda7046fb 158 wait(0.1);
rafeh 1:beceda7046fb 159 }
rafeh 2:9f5714571c41 160 }
rafeh 1:beceda7046fb 161
rafeh 5:3a0948f56de0 162 bool check_collisions(int f, int xx, int yy) {
rafeh 5:3a0948f56de0 163 if((xx>17 && xx<32)&&((f<(yy)) || (f>(yy+26))))
rafeh 5:3a0948f56de0 164 return true;
rafeh 5:3a0948f56de0 165 else
rafeh 5:3a0948f56de0 166 return false;
rafeh 5:3a0948f56de0 167 }
rafeh 5:3a0948f56de0 168
rafeh 5:3a0948f56de0 169 int generate_height() {
rafeh 5:3a0948f56de0 170 int random_height=rand() % (19 + 1 - 0) + 0;
rafeh 5:3a0948f56de0 171 return random_height;
rafeh 3:5409b50b01b0 172 }
rafeh 3:5409b50b01b0 173
rafeh 3:5409b50b01b0 174