ELEC2645 (2018/19) / Mbed 2 deprecated el17mtu_

Dependencies:   mbed

Committer:
el17mtu
Date:
Thu May 09 01:49:26 2019 +0000
Revision:
14:558c85380f84
Parent:
9:571f92b0211b
Child:
15:1463ebaf5c75
SCORE WORKINGGG

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17mtu 0:15b74f0f8c7f 1 #include "ModeA.h"
el17mtu 0:15b74f0f8c7f 2
el17mtu 0:15b74f0f8c7f 3 ModeA::ModeA()
el17mtu 0:15b74f0f8c7f 4 {
el17mtu 0:15b74f0f8c7f 5
el17mtu 0:15b74f0f8c7f 6 }
el17mtu 0:15b74f0f8c7f 7
el17mtu 0:15b74f0f8c7f 8 ModeA::~ModeA()
el17mtu 0:15b74f0f8c7f 9 {
el17mtu 0:15b74f0f8c7f 10
el17mtu 0:15b74f0f8c7f 11 }
el17mtu 0:15b74f0f8c7f 12
el17mtu 0:15b74f0f8c7f 13 void ModeA::screen(N5110 &lcd)
el17mtu 0:15b74f0f8c7f 14 {
el17mtu 0:15b74f0f8c7f 15
el17mtu 0:15b74f0f8c7f 16 lcd.clear();
el17mtu 0:15b74f0f8c7f 17 lcd.printString("GAME",0,0);
el17mtu 0:15b74f0f8c7f 18 lcd.printString("Back:Rules",0,2);
el17mtu 14:558c85380f84 19
el17mtu 14:558c85380f84 20 };
el17mtu 14:558c85380f84 21
el17mtu 14:558c85380f84 22 void ModeA::initialise(N5110 &lcd)
el17mtu 14:558c85380f84 23 {
el17mtu 14:558c85380f84 24 x_position = 12;
el17mtu 14:558c85380f84 25 y_position = 18;
el17mtu 14:558c85380f84 26 speed = 1;
el17mtu 0:15b74f0f8c7f 27 gravity = 1;
el17mtu 14:558c85380f84 28
el17mtu 8:d9b602e58126 29 screen_width = 80;
el17mtu 1:44f4594eacac 30 bar_width = 10;
el17mtu 14:558c85380f84 31
el17mtu 4:a81f05c8806a 32 bar_speed = 2;
el17mtu 14:558c85380f84 33 score = 1;
el17mtu 14:558c85380f84 34
el17mtu 9:571f92b0211b 35
el17mtu 14:558c85380f84 36 srand(time(NULL));
el17mtu 14:558c85380f84 37 size_top = rand() % 15;
el17mtu 14:558c85380f84 38 srand(time(NULL));
el17mtu 14:558c85380f84 39 size_bottom = rand() % 15;
el17mtu 14:558c85380f84 40
el17mtu 14:558c85380f84 41
el17mtu 14:558c85380f84 42 }
el17mtu 14:558c85380f84 43
el17mtu 14:558c85380f84 44 void ModeA::Bird(N5110 &lcd)
el17mtu 14:558c85380f84 45
el17mtu 0:15b74f0f8c7f 46 {
el17mtu 0:15b74f0f8c7f 47
el17mtu 14:558c85380f84 48 char buffer[14];
el17mtu 14:558c85380f84 49 sprintf(buffer,"%2d",score);
el17mtu 14:558c85380f84 50 lcd.printString(buffer,1,1);
el17mtu 14:558c85380f84 51 lcd.drawRect(x_position, y_position,6,6,FILL_BLACK);
el17mtu 14:558c85380f84 52 lcd.refresh();
el17mtu 14:558c85380f84 53
el17mtu 14:558c85380f84 54
el17mtu 14:558c85380f84 55
el17mtu 14:558c85380f84 56 if ( pad.check_event(Gamepad::Y_PRESSED) == true) {
el17mtu 14:558c85380f84 57
el17mtu 14:558c85380f84 58 speed = speed - gravity*5;
el17mtu 14:558c85380f84 59
el17mtu 14:558c85380f84 60 }
el17mtu 14:558c85380f84 61
el17mtu 14:558c85380f84 62 if (y_position > 44) {
el17mtu 14:558c85380f84 63
el17mtu 14:558c85380f84 64 lcd.clear();
el17mtu 14:558c85380f84 65 lcd.printString("GAME OVER",6,2);
el17mtu 9:571f92b0211b 66 lcd.printString("Press BACK",6,4);
el17mtu 14:558c85380f84 67 pad.tone(2000.0,0.3);
el17mtu 14:558c85380f84 68 lcd.refresh();
el17mtu 9:571f92b0211b 69 bar_speed = 0;
el17mtu 14:558c85380f84 70 speed = 0;
el17mtu 9:571f92b0211b 71 gravity = 0;
el17mtu 9:571f92b0211b 72 y_position = 48;
el17mtu 14:558c85380f84 73 bar_width = 0;
el17mtu 14:558c85380f84 74 size_top = 0;
el17mtu 9:571f92b0211b 75 size_bottom = 0;
el17mtu 14:558c85380f84 76
el17mtu 14:558c85380f84 77 wait(0.5);
el17mtu 14:558c85380f84 78
el17mtu 14:558c85380f84 79 }
el17mtu 14:558c85380f84 80
el17mtu 14:558c85380f84 81
el17mtu 14:558c85380f84 82
el17mtu 14:558c85380f84 83 if (y_position < 0) {
el17mtu 14:558c85380f84 84 y_position = 0;
el17mtu 14:558c85380f84 85 speed = 0;
el17mtu 14:558c85380f84 86 }
el17mtu 14:558c85380f84 87
el17mtu 14:558c85380f84 88 speed = speed + gravity;
el17mtu 14:558c85380f84 89 y_position = y_position + speed;
el17mtu 14:558c85380f84 90 wait(0.1);
el17mtu 14:558c85380f84 91
el17mtu 14:558c85380f84 92
el17mtu 14:558c85380f84 93 lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
el17mtu 14:558c85380f84 94 lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
el17mtu 14:558c85380f84 95 lcd.refresh();
el17mtu 14:558c85380f84 96
el17mtu 14:558c85380f84 97 if ((screen_width == x_position) && (size_top < y_position)) {
el17mtu 14:558c85380f84 98 score = score + 1;
el17mtu 14:558c85380f84 99 lcd.clear();
el17mtu 14:558c85380f84 100 sprintf(buffer,"%2d",score);
el17mtu 14:558c85380f84 101 }
el17mtu 14:558c85380f84 102
el17mtu 14:558c85380f84 103
el17mtu 14:558c85380f84 104 if ( pad.check_event(Gamepad::X_PRESSED) == true) {
el17mtu 14:558c85380f84 105
el17mtu 14:558c85380f84 106 srand(time(NULL));
el17mtu 14:558c85380f84 107 size_top = rand() % 15;
el17mtu 14:558c85380f84 108 srand(time(NULL));
el17mtu 14:558c85380f84 109 size_bottom = rand() % 15;
el17mtu 14:558c85380f84 110
el17mtu 0:15b74f0f8c7f 111 }
el17mtu 14:558c85380f84 112
el17mtu 14:558c85380f84 113 if ((screen_width == x_position)&& (size_top > y_position)) {
el17mtu 14:558c85380f84 114
el17mtu 14:558c85380f84 115 lcd.clear();
el17mtu 14:558c85380f84 116 lcd.printString("GAME OVER",6,2);
el17mtu 14:558c85380f84 117 lcd.printString("Press BACK",6,4);
el17mtu 14:558c85380f84 118 pad.tone(2000.0,0.3);
el17mtu 14:558c85380f84 119 lcd.refresh();
el17mtu 14:558c85380f84 120 bar_speed = 0;
el17mtu 14:558c85380f84 121 speed = 0;
el17mtu 14:558c85380f84 122 gravity = 0;
el17mtu 14:558c85380f84 123 y_position = 48;
el17mtu 14:558c85380f84 124 bar_width = 0;
el17mtu 14:558c85380f84 125 size_top = 0;
el17mtu 14:558c85380f84 126 size_bottom = 0;
el17mtu 14:558c85380f84 127
el17mtu 14:558c85380f84 128
el17mtu 0:15b74f0f8c7f 129
el17mtu 14:558c85380f84 130 wait(0.5);
el17mtu 14:558c85380f84 131
el17mtu 14:558c85380f84 132 }
el17mtu 14:558c85380f84 133
el17mtu 14:558c85380f84 134
el17mtu 14:558c85380f84 135
el17mtu 14:558c85380f84 136 screen_width = screen_width - bar_speed;
el17mtu 14:558c85380f84 137 wait(0.1);
el17mtu 14:558c85380f84 138
el17mtu 14:558c85380f84 139
el17mtu 14:558c85380f84 140
el17mtu 14:558c85380f84 141 }
el17mtu 14:558c85380f84 142
el17mtu 14:558c85380f84 143
el17mtu 14:558c85380f84 144
el17mtu 14:558c85380f84 145
el17mtu 14:558c85380f84 146