Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Engine.cpp
- Revision:
- 9:0efc8d7cdcf7
- Parent:
- 8:1c0bc1a08153
- Child:
- 10:b2dd5f484f98
diff -r 1c0bc1a08153 -r 0efc8d7cdcf7 Engine.cpp --- a/Engine.cpp Sun Apr 09 12:46:39 2017 +0000 +++ b/Engine.cpp Mon Apr 10 16:44:12 2017 +0000 @@ -9,6 +9,7 @@ } int collisions = 0; +int wave_counter = 0; void Engine::init(int friendly_width,int friendly_height,int ship_size,int speed,N5110 &lcd, Gamepad &pad) { @@ -25,6 +26,7 @@ _ship4.init(_ship_size,_speed); _ship5.init(_ship_size,_speed); _ship6.init(_ship_size,_speed); + _bullet.init(_speed); } void Engine::read_input(Gamepad &pad) @@ -33,16 +35,36 @@ _mag = pad.get_mag(); } +// DRAWING FUNCTIONS + void Engine::draw(N5110 &lcd) { - lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); - lcd.drawLine(0,39,84,39,1); + grid_draw(lcd); + ships_draw(lcd); _friendly.draw(lcd); _stats.draw_health(lcd); _stats.check_health(lcd, collisions); + _bullet.draw(lcd); + wave_draw(lcd); } -void Engine::ships_gen(N5110 &lcd) +void Engine::grid_draw(N5110 &lcd) +{ + lcd.drawRect(0, 0, WIDTH, HEIGHT-8, FILL_TRANSPARENT); + lcd.drawLine(WIDTH-1, HEIGHT-8, WIDTH-1, HEIGHT, 1); + lcd.drawLine(WIDTH-11, HEIGHT-8, WIDTH-11, HEIGHT, 1); + lcd.drawLine(12, HEIGHT-1, WIDTH, HEIGHT-1, 1); + lcd.drawLine(12, HEIGHT-8, 12, HEIGHT, 1); +} + +void Engine::wave_draw(N5110 &lcd) +{ + char buffer[14]; + int length = sprintf(buffer,"%2d",wave_counter); + lcd.printString(buffer,0,5); +} + +void Engine::ships_draw(N5110 &lcd) { _ship1.draw(lcd); _ship2.draw(lcd); @@ -52,6 +74,8 @@ _ship6.draw(lcd); } + + void Engine::checker(N5110 &lcd, Gamepad &pad) { check_pass(pad); @@ -68,9 +92,10 @@ _ship4.update(); _ship5.update(); _ship6.update(); + _bullet.update(); } -void Engine::shoot(N5110 &lcd, Gamepad &pad, int speed) +/*void Engine::shoot(N5110 &lcd, Gamepad &pad, int speed) { _speed = speed; @@ -82,7 +107,7 @@ //_bullet.update(); } -} +}*/ void Engine::check_pass(Gamepad &pad) { @@ -90,6 +115,7 @@ if (ship1_pos.x + _ship_size < 0) { _ship1.init(_ship_size,_speed); + wave_counter = wave_counter + 1; } Vector2D ship2_pos = _ship2.get_pos(); @@ -123,16 +149,6 @@ } } -void Engine::death(N5110 &lcd, Gamepad &pad) -{ - if (dead == true) { - lcd.clear(); - lcd.printString("lol u ded",0,1); - wait(2); - dead = false; - } -} - void Engine::check_death1(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); @@ -146,8 +162,7 @@ ) { pad.tone(800.0,0.1); - //collisions = collisions + 1; - dead = true; + collisions = collisions + 1; } } @@ -230,7 +245,6 @@ (friendly_pos.x+6 >= ship6_pos.x) && (friendly_pos.x+6 <= ship6_pos.x+5) ) { - pad.tone(800.0,0.1); collisions = collisions + 1; } @@ -254,10 +268,15 @@ lcd.printString(" You Lose! ",0,1); lcd.printString(" Press Start! ",0,4); lcd.refresh(); + while (pad.check_event(Gamepad::START_PRESSED) == false) { wait(0.1); } + init(_friendly_width, _friendly_height, _ship_size, _speed, lcd, pad); collisions = 0; + wave_counter = 0; } -} \ No newline at end of file +} + +