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.
Dependencies: mbed
Diff: RosenEngine/RosenEngine.cpp
- Revision:
- 39:7824f9080f59
- Parent:
- 38:4571537238ed
- Child:
- 40:90c7a893d513
--- a/RosenEngine/RosenEngine.cpp Sun May 05 08:50:15 2019 +0000 +++ b/RosenEngine/RosenEngine.cpp Mon May 06 16:49:53 2019 +0000 @@ -1,4 +1,5 @@ #include "RosenEngine.h" + DigitalIn A(PTB9); // Constructor @@ -18,23 +19,28 @@ // initialise the game parameters _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos); // place seeker above the ship - _no_shooters = 1; - _enemy.init(_no_shooters); + _no_shooters = 0; + _no_seekers = 0; + _enemy.init(_no_shooters,_no_seekers); _menu.init(16); _health.init(_shipno); _times_run = 0; _score = 0; _dead = false; + _intro = false; + _wait_time = 10.25; } void RosenEngine::reset() { - _enemy.init(_no_shooters); + _enemy.init(_no_shooters,_no_seekers); _health.init(_shipno); + _wait_time = 10.25; _times_run = 0; _score = 0; - _no_shooters = 1; + _no_shooters = 0; _dead = false; + _no_seekers = 0; } void RosenEngine::read_input(Gamepad &pad) @@ -73,6 +79,7 @@ if(_dead == true){ game_over(lcd); } + disp_points(lcd); } void RosenEngine::update(Gamepad &pad) @@ -113,6 +120,10 @@ Vector2D ship_pos = _ship.get_pos(); ship_xpos = ship_pos.x; ship_ypos = ship_pos.y; + + _seeker1_pos = _enemy.get_seekerpos(1); + _seeker2_pos = _enemy.get_seekerpos(2); + _seeker3_pos = _enemy.get_seekerpos(3); _shooter1_pos = _enemy.get_shooterpos(1); _shooter2_pos = _enemy.get_shooterpos(2); @@ -229,40 +240,52 @@ void RosenEngine::seeker_ship_collision(Gamepad &pad) { - Vector2D seeker_pos = _enemy.get_seekerpos(); - bool collision; - collision = check_collision(seeker_pos.x,seeker_pos.y,5,5,ship_xpos,ship_ypos,5,5); - if (collision == true) { - _health.update(1,pad); - _enemy.reset_seeker(); + bool col1,col2,col3; + + col1 = check_collision(ship_xpos,ship_ypos,9,6,_seeker1_pos.x, _seeker1_pos.y,10,7); + col2 = check_collision(ship_xpos,ship_ypos,9,6,_seeker2_pos.x, _seeker2_pos.y,10,7); + col3 = check_collision(ship_xpos,ship_ypos,9,6,_seeker3_pos.x, _seeker3_pos.y,10,7); + int sel = 0; + + if (col1 == true && _no_seekers >= 1) { + sel = 1; + } + if (col2 == true && _no_seekers >= 2) { + sel = 2; + } + if (col3 == true && _no_seekers >= 3) { + sel = 3; + } + // printf("col1 = %d, col2 = %d, col3 = %d, no_seekers = %d\n",col1,col2,col3,_no_seekers); + if(sel != 0){ + _health.update(5,pad); + _health.seekerh_update(sel,10); pad.tone(500,0.05); wait(0.05); } } void RosenEngine::shooter_ship_collision(Gamepad &pad) { - bool collision1; - bool collision2; - bool collision3; + bool col1,col2,col3; + int sel = 0; + col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7); + col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7); + col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7); - collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7); - collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7); - collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7); - - if(collision1 == true && _no_shooters == 1) { + if(col1 == true && _no_shooters >= 1) { + sel = 1; + } + if(col2 == true && _no_shooters >= 2) { + sel = 2; + } + if(col3 == true && _no_shooters >= 3) { + sel = 3; + } + if(sel != 0){ _health.update(1,pad); + _health.shooterh_update(sel,10); pad.tone(500,0.05); - wait(0.05); - } - if(collision2 == true && _no_shooters == 2) { - _health.update(1,pad); - pad.tone(500,0.05); - wait(0.05); - } - if(collision3 == true && _no_shooters == 3) { - _health.update(1,pad); - pad.tone(500,0.05); - wait(0.05); + wait(0.05); } } void RosenEngine::shooterw_ship_collision(Gamepad &pad) @@ -271,137 +294,184 @@ Vector2D _shooterw2_pos = _enemy.get_shwpos(2); Vector2D _shooterw3_pos = _enemy.get_shwpos(3); - bool collision1; - bool collision2; - bool collision3; + bool col1,col2,col3; + int sel = 0; + col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2); + col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2); + col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2); - collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2); - collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2); - collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2); - - if(collision1 == true && _no_shooters == 1) { + if(col1 == true && _no_shooters >= 1) { + sel = 1; + } + if(col2 == true && _no_shooters >= 2) { + sel = 2; + } + if(col3 == true && _no_shooters >= 3) { + sel = 3; + } + if(sel != 0){ _health.update(1,pad); pad.tone(500,0.05); - wait(0.05); - } - if(collision2 == true && _no_shooters == 2) { - _health.update(1,pad); - pad.tone(500,0.05); - wait(0.05); - } - if(collision3 == true && _no_shooters == 3) { - _health.update(1,pad); - pad.tone(500,0.05); - wait(0.05); + wait(0.05); } } void RosenEngine::kestrelw_seeker_collision(Gamepad &pad) { - Vector2D seeker_pos = _enemy.get_seekerpos(); + bool col1, col2, col3; + int sel = 0; Vector2D missle_pos = _weapons.get_pos(_shipno); - bool collision; - collision = check_collision(seeker_pos.x,seeker_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); - if (collision == true) { - _health.seekerh_update(5); + col1 = check_collision(_seeker1_pos.x,_seeker1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); + col2 = check_collision(_seeker2_pos.x,_seeker2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); + col3 = check_collision(_seeker3_pos.x,_seeker3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); + if (col1 == true && _no_seekers >= 1) { + sel = 1; + } + if (col2 == true && _no_seekers >= 2) { + sel = 2; + } + if (col3 == true && _no_seekers >= 3) { + sel = 3; + } + if(sel != 0){ pad.tone(500,0.05); + _health.seekerh_update(sel,5); wait(0.05); } } void RosenEngine::imperionw_seeker_collision(Gamepad &pad) { - Vector2D seeker_pos = _enemy.get_seekerpos(); - bool collision; - if(ship_ypos > seeker_pos.y + 6) { - collision = check_collision1(seeker_pos.x,9,ship_xpos + 2,3); - if (collision == true && A == true) { - _health.seekerh_update(5); - pad.tone(500,0.05); - wait(0.05); + bool col1,col2,col3; + int sel = 0; + if(ship_ypos > _seeker1_pos.y + 6) { + col1 = check_collision1(_seeker1_pos.x,9,ship_xpos + 2,3); + if (col1 == true && A == true && _no_seekers >= 1) { + sel = 1; } } + if(ship_ypos > _seeker2_pos.y + 6) { + col2 = check_collision1(_seeker2_pos.x,9,ship_xpos + 2,3); + if (col2 == true && A == true && _no_seekers >= 2) { + sel = 2; + } + } + if(ship_ypos > _seeker1_pos.y + 6) { + col3 = check_collision1(_seeker3_pos.x,9,ship_xpos + 2,3); + if (col3 == true && A == true && _no_seekers >= 3) { + sel = 3; + } + } + if(sel != 0){ + _health.seekerh_update(sel,10); + pad.tone(500,0.05); + wait(0.05); + } } void RosenEngine::kestrelw_shooter_collision(Gamepad &pad) { Vector2D missle_pos = _weapons.get_pos(_shipno); bool col1, col2, col3; + int sel = 0; col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); - if (col1 == true && _no_shooters == 1) { - pad.tone(500,0.05); - _health.shooterh_update(1,5); - wait(0.05); + if (col1 == true && _no_shooters >= 1) { + sel = 1; + } + if (col2 == true && _no_shooters >= 2) { + sel = 2; } - if (col2 == true && _no_shooters == 2) { - _health.shooterh_update(2,5); + if (col3 == true && _no_shooters >= 3) { + sel = 3; + } + // printf("col1 = %d,col2 = %d,col3 = %d, no_shooters = %d\n",col1,col2,col3,_no_shooters); + if(sel != 0){ pad.tone(500,0.05); - wait(0.05); - } - if (col3 == true && _no_shooters == 3) { - _health.shooterh_update(3,5); - pad.tone(500,0.05); + _health.shooterh_update(sel,5); wait(0.05); } } void RosenEngine::imperionw_shooter_collision(Gamepad &pad) { - bool col1; - bool col2; - bool col3; + bool col1,col2,col3; + int sel = 0; if(ship_ypos > _shooter1_pos.y + 6) { col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3); - if (col1 == true && A == true && _no_shooters == 1) { - _health.shooterh_update(1,5); - pad.tone(500,0.05); - wait(0.05); + if (col1 == true && A == true && _no_shooters >= 1) { + sel = 1; } } if(ship_ypos > _shooter2_pos.y + 6) { col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3); - if (col2 == true && A == true && _no_shooters == 2) { - _health.shooterh_update(2,5); - pad.tone(500,0.05); - wait(0.05); + if (col2 == true && A == true && _no_shooters >= 2) { + sel = 2; } } if(ship_ypos > _shooter3_pos.y + 6) { col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3); - if (col3 == true && A == true && _no_shooters == 3) { - _health.shooterh_update(3,5); - pad.tone(500,0.05); - wait(0.05); + if (col3 == true && A == true && _no_shooters >= 3) { + sel = 3; } } + if(sel != 0){ + _health.shooterh_update(sel,10); + pad.tone(500,0.05); + wait(0.05); + } } -void RosenEngine::check_health() -{ - int seeker_health = _health.get_seekerh(); - int shooter1_health = _health.get_shooterh(1); - int shooter2_health = _health.get_shooterh(2); - int shooter3_health = _health.get_shooterh(3); - - if(seeker_health == 0){ - _enemy.reset_seeker(); - _health.reset_seekerh(); - } - if(shooter1_health == 0){ - _enemy.reset_shooter(1); - _health.reset_shooterh(1); - } - if(shooter2_health == 0){ - _enemy.reset_shooter(2); - _health.reset_shooterh(2); - } - if(shooter3_health == 0){ - _enemy.reset_shooter(3); - _health.reset_shooterh(3); - } +void RosenEngine::check_health(){ + check_se_health(); + check_sh_health(); Vector2D hp = _health.get_hp(); if(hp.x <= 0){ // printf("player deaad\n"); _dead = true; } + +} +void RosenEngine::check_se_health() +{ + int sel = 0; + int seeker1_health = _health.get_seekerh(1); + int seeker2_health = _health.get_seekerh(2); + int seeker3_health = _health.get_seekerh(3); + // printf("seeker1_h = %d, seeker2_h = %d, seeker3_h = %d\n",seeker1_health,seeker2_health,seeker3_health); + if(seeker1_health == 0){ + sel = 1; + } + if(seeker2_health == 0){ + sel = 2; + } + if(seeker3_health == 0){ + sel = 3; + } + if(sel != 0){ + _enemy.reset_seeker(sel); + _health.reset_seekerh(sel); + _score = _score + 10; + } +} +void RosenEngine::check_sh_health() +{ + int sel = 0; + int shooter1_health = _health.get_shooterh(1); + int shooter2_health = _health.get_shooterh(2); + int shooter3_health = _health.get_shooterh(3); + + if(shooter1_health == 0){ + sel = 1; + } + if(shooter2_health == 0){ + sel = 2; + } + if(shooter3_health == 0){ + sel = 3; + } + if(sel != 0){ + _enemy.reset_shooter(sel); + _health.reset_shooterh(sel); + _score = _score + 20; + } } int RosenEngine::rand_no() { @@ -429,19 +499,64 @@ void RosenEngine::scaling(float time_elapsed) { - if(time_elapsed > 10){ + if(time_elapsed == _wait_time){ _no_shooters = _no_shooters + 1; + // _no_seekers = _no_seekers + 1; _enemy.sh_scaling(time_elapsed); + _wait_time = _wait_time + 10.00; } if(_no_shooters > 3){ _no_shooters = 3; - } + } + if(_no_seekers > 3){ + _no_seekers = 3; + } _enemy.set_noshooters(_no_shooters); - + _enemy.set_noseekers(_no_seekers); + // printf("time_elapsed = %f, no_shooters = %d, wait_time = %f\n",time_elapsed,_no_shooters,_wait_time); } void RosenEngine::game_over(N5110 &lcd) { + /* lcd.clear(); + lcd.refresh(); lcd.printString("Game Over ",2,2); - lcd.printString("Try dodging next time ",2,3); -} \ No newline at end of file + lcd.printString("Try dodging ",2,3); + lcd.printString("next time",2,4); + lcd.refresh(); + wait(2); + */ + _lore.display(lcd); +} +void RosenEngine::intro(N5110 &lcd) +{ + if(_intro == false){ + lcd.clear(); + lcd.refresh(); + lcd.printString("You are tasked",2,0); + lcd.printString("with holding",2,1); + lcd.printString(" the line ",2,2); + lcd.printString(" from an ",2,3); + lcd.printString("invading army ",2,4); + lcd.refresh(); + wait(2); + lcd.clear(); + lcd.refresh(); + lcd.printString(" as an ",2,0); + lcd.printString(" expendable ",2,1); + lcd.printString(" asset, ",2,2); + lcd.printString("you are not ",2,3); + lcd.printString("expected to",2,4); + lcd.printString(" survive ",2,5); + lcd.refresh(); + wait(2); + + } + _intro = true; +} +void RosenEngine::disp_points(N5110 &lcd) +{ + char buffer[10]; + sprintf(buffer,"%d",_score); + lcd.printString(buffer,2,0); +}