ELEC2645 (2018/19) / Mbed 2 deprecated el17mtu_

Dependencies:   mbed

Committer:
el17mtu
Date:
Wed May 08 19:15:06 2019 +0000
Revision:
8:d9b602e58126
Parent:
6:f7484a2f32fd
Child:
9:571f92b0211b
ball game over

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 0:15b74f0f8c7f 19
el17mtu 0:15b74f0f8c7f 20 };
el17mtu 0:15b74f0f8c7f 21
el17mtu 0:15b74f0f8c7f 22 void ModeA::initialise(N5110 &lcd)
el17mtu 0:15b74f0f8c7f 23 {
el17mtu 0:15b74f0f8c7f 24 x_position = 5;
el17mtu 0:15b74f0f8c7f 25 y_position = 18;
el17mtu 8:d9b602e58126 26 speed = 1;
el17mtu 0:15b74f0f8c7f 27 gravity = 1;
el17mtu 1:44f4594eacac 28
el17mtu 8:d9b602e58126 29 screen_width = 80;
el17mtu 1:44f4594eacac 30 bar_width = 10;
el17mtu 2:6ee8616695d1 31
el17mtu 4:a81f05c8806a 32 bar_speed = 2;
el17mtu 3:8e6950aeec8a 33
el17mtu 5:1c56acecc96e 34 size_top = 10;
el17mtu 4:a81f05c8806a 35 size_bottom = 7;
el17mtu 3:8e6950aeec8a 36
el17mtu 0:15b74f0f8c7f 37 }
el17mtu 0:15b74f0f8c7f 38
el17mtu 0:15b74f0f8c7f 39
el17mtu 0:15b74f0f8c7f 40 void ModeA::Bird(N5110 &lcd)
el17mtu 0:15b74f0f8c7f 41
el17mtu 0:15b74f0f8c7f 42 {
el17mtu 0:15b74f0f8c7f 43
el17mtu 0:15b74f0f8c7f 44
el17mtu 0:15b74f0f8c7f 45 lcd.drawRect(x_position, y_position,6,6,FILL_BLACK);
el17mtu 3:8e6950aeec8a 46 //lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
el17mtu 3:8e6950aeec8a 47 //lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
el17mtu 0:15b74f0f8c7f 48 lcd.refresh();
el17mtu 0:15b74f0f8c7f 49
el17mtu 0:15b74f0f8c7f 50
el17mtu 0:15b74f0f8c7f 51
el17mtu 0:15b74f0f8c7f 52 if ( pad.check_event(Gamepad::Y_PRESSED) == true) {
el17mtu 8:d9b602e58126 53
el17mtu 0:15b74f0f8c7f 54 speed = speed - gravity*5;
el17mtu 0:15b74f0f8c7f 55
el17mtu 0:15b74f0f8c7f 56 }
el17mtu 0:15b74f0f8c7f 57
el17mtu 8:d9b602e58126 58 if (y_position > 44) {
el17mtu 6:f7484a2f32fd 59
el17mtu 6:f7484a2f32fd 60 lcd.clear();
el17mtu 6:f7484a2f32fd 61 lcd.printString("GAME OVER",6,2);
el17mtu 6:f7484a2f32fd 62 lcd.printString("Press BACK",6,4);
el17mtu 6:f7484a2f32fd 63 pad.tone(2000.0,0.3);
el17mtu 6:f7484a2f32fd 64 lcd.refresh();
el17mtu 6:f7484a2f32fd 65 bar_speed = 0;
el17mtu 6:f7484a2f32fd 66 speed = 0;
el17mtu 6:f7484a2f32fd 67 gravity = 0;
el17mtu 6:f7484a2f32fd 68 y_position = 48;
el17mtu 6:f7484a2f32fd 69 bar_width = 0;
el17mtu 6:f7484a2f32fd 70 size_top = 0;
el17mtu 6:f7484a2f32fd 71 size_bottom = 0;
el17mtu 6:f7484a2f32fd 72
el17mtu 6:f7484a2f32fd 73 wait(0.5);
el17mtu 6:f7484a2f32fd 74
el17mtu 0:15b74f0f8c7f 75 }
el17mtu 0:15b74f0f8c7f 76
el17mtu 0:15b74f0f8c7f 77 if (y_position < 0) {
el17mtu 0:15b74f0f8c7f 78 y_position = 0;
el17mtu 0:15b74f0f8c7f 79 speed = 0;
el17mtu 0:15b74f0f8c7f 80 }
el17mtu 0:15b74f0f8c7f 81
el17mtu 0:15b74f0f8c7f 82 speed = speed + gravity;
el17mtu 0:15b74f0f8c7f 83 y_position = y_position + speed;
el17mtu 0:15b74f0f8c7f 84 wait(0.1);
el17mtu 2:6ee8616695d1 85
el17mtu 3:8e6950aeec8a 86
el17mtu 3:8e6950aeec8a 87 lcd.drawRect(screen_width,0,bar_width,size_top,FILL_BLACK);
el17mtu 3:8e6950aeec8a 88 lcd.drawRect(screen_width,48-size_bottom,bar_width,size_bottom,FILL_BLACK);
el17mtu 3:8e6950aeec8a 89 lcd.refresh();
el17mtu 3:8e6950aeec8a 90
el17mtu 8:d9b602e58126 91 if (screen_width > 50) {
el17mtu 3:8e6950aeec8a 92 srand(time(NULL));
el17mtu 3:8e6950aeec8a 93 size_top = rand() % 48;
el17mtu 3:8e6950aeec8a 94 srand(time(NULL));
el17mtu 3:8e6950aeec8a 95 size_bottom = rand() % 48;
el17mtu 3:8e6950aeec8a 96 // bar_width = 50;
el17mtu 3:8e6950aeec8a 97 // bar_speed = 0;
el17mtu 2:6ee8616695d1 98 }
el17mtu 2:6ee8616695d1 99
el17mtu 8:d9b602e58126 100 if (screen_width == 5) {
el17mtu 3:8e6950aeec8a 101 srand(time(NULL));
el17mtu 3:8e6950aeec8a 102 size_top = rand() % 48;
el17mtu 3:8e6950aeec8a 103 srand(time(NULL));
el17mtu 3:8e6950aeec8a 104 size_bottom = rand() % 48;
el17mtu 3:8e6950aeec8a 105 }
el17mtu 4:a81f05c8806a 106
el17mtu 4:a81f05c8806a 107
el17mtu 8:d9b602e58126 108 if (size_top == 5) {
el17mtu 4:a81f05c8806a 109 lcd.clear();
el17mtu 4:a81f05c8806a 110 lcd.printString("GAME OVER",6,2);
el17mtu 4:a81f05c8806a 111 lcd.printString("Press BACK",6,4);
el17mtu 4:a81f05c8806a 112 pad.tone(2000.0,0.3);
el17mtu 4:a81f05c8806a 113 lcd.refresh();
el17mtu 4:a81f05c8806a 114 bar_speed = 0;
el17mtu 4:a81f05c8806a 115 speed = 0;
el17mtu 4:a81f05c8806a 116 gravity = 0;
el17mtu 4:a81f05c8806a 117 y_position = 48;
el17mtu 4:a81f05c8806a 118 wait(0.5);
el17mtu 4:a81f05c8806a 119
el17mtu 4:a81f05c8806a 120 }
el17mtu 0:15b74f0f8c7f 121
el17mtu 1:44f4594eacac 122 screen_width = screen_width - bar_speed;
el17mtu 3:8e6950aeec8a 123 wait(0.1);
el17mtu 4:a81f05c8806a 124
el17mtu 4:a81f05c8806a 125
el17mtu 0:15b74f0f8c7f 126
el17mtu 0:15b74f0f8c7f 127 }
el17mtu 0:15b74f0f8c7f 128
el17mtu 0:15b74f0f8c7f 129
el17mtu 0:15b74f0f8c7f 130
el17mtu 0:15b74f0f8c7f 131
el17mtu 0:15b74f0f8c7f 132
el17mtu 0:15b74f0f8c7f 133