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:
- 42:ee13e1d103d8
- Parent:
- 41:e1fa36c0492e
--- a/RosenEngine/RosenEngine.cpp Wed May 08 09:22:16 2019 +0000 +++ b/RosenEngine/RosenEngine.cpp Wed May 08 11:18:40 2019 +0000 @@ -14,26 +14,30 @@ } -void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos) +void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos,N5110 *lcd, Gamepad *pad) { // initialise the game parameters - _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos); + // initialize classes + _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos,_lcd,_pad); + _enemy.init(_no_shooters,_no_seekers,_lcd,_pad); + _menu.init(16,_lcd,_pad); + _health.init(_shipno,_lcd,_pad); + // initialize objects _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 = 2.25; + _lcd = lcd; + _pad = pad; } void RosenEngine::reset() { - _enemy.init(_no_shooters,_no_seekers); - _health.init(_shipno); + _enemy.init(_no_shooters,_no_seekers,_lcd,_pad); + _health.init(_shipno,_lcd,_pad); _wait_time = 2.25; _times_run = 0; _score = 0; @@ -42,31 +46,31 @@ _no_seekers = 0; } -void RosenEngine::read_input(Gamepad &pad) +void RosenEngine::read_input() { - Vector2D mapped_coord = pad.get_coord(); + Vector2D mapped_coord = _pad->get_coord(); _joystick.x = mapped_coord.x; _joystick.y = mapped_coord.y; - _d = pad.get_direction(); + _d = _pad->get_direction(); wait(0.1); // printf("_joystick.x ,_joystick.y = %f , %f\n",_joystick.x, _joystick.y); } -void RosenEngine::draw(N5110 &lcd, Gamepad &pad) +void RosenEngine::draw() { - lcd.drawRect(0,0,78,48,FILL_TRANSPARENT); - _health.draw_health(lcd,_shipno); - _health.draw_shields(lcd); - _enemy.draw_seeker(lcd); - _enemy.draw_shooter(lcd); - _enemy.draw_shw(lcd,pad); - draw_ship(lcd,pad); + _lcd->drawRect(0,0,78,48,FILL_TRANSPARENT); + _health.draw_health(_shipno); + _health.draw_shields(); + _enemy.draw_seeker(); + _enemy.draw_shooter(); + _enemy.draw_shw(); + draw_ship(); if(_dead == true) { - game_over(lcd); + game_over(); } - disp_points(lcd); + disp_points(); } -void RosenEngine::draw_ship(N5110 &lcd, Gamepad &pad) +void RosenEngine::draw_ship() { // find the closest enemy (used in orions firing) Vector2D inde = find_closest1(); @@ -76,46 +80,46 @@ switch (_shipno) { case 0: _ship.set_dimensions(9,6); - _ship.draw_ship(lcd,_shipno); - _weapons.draw(lcd,pad,_shipno,closest); + _ship.draw_ship(_shipno); + _weapons.draw(_shipno,closest); break; case 1: _ship.set_dimensions(7,10); - _ship.draw_ship(lcd,_shipno); - _weapons.draw(lcd,pad,_shipno,closest); + _ship.draw_ship(_shipno); + _weapons.draw(_shipno,closest); break; case 2: _ship.set_dimensions(7,10); - _ship.draw_ship(lcd,_shipno); - _weapons.draw(lcd,pad,_shipno,closest); + _ship.draw_ship(_shipno); + _weapons.draw(_shipno,closest); break; } } -void RosenEngine::update(Gamepad &pad) +void RosenEngine::update() { _enemy.update_seeker(_shipPos.x, _shipPos.y); _enemy.update_shooter(_shipPos.x, _shipPos.y); _enemy.update_shw(); - update_shooter_weapon(pad); - shooter_ship_collision(pad); - seeker_ship_collision(pad); - shooterw_ship_collision(pad); - imperionw_seeker_collision(pad); - kestrelw_shooter_collision(pad); - imperionw_shooter_collision(pad); - orionw_collision(pad); + update_shooter_weapon(); + shooter_ship_collision(); + seeker_ship_collision(); + shooterw_ship_collision(); + imperionw_seeker_collision(); + kestrelw_shooter_collision(); + imperionw_shooter_collision(); + orionw_collision(); check_health(); rand_no(); scaling(timer(12)); } -void RosenEngine::update_shooter_weapon(Gamepad &pad) +void RosenEngine::update_shooter_weapon() { if(_shipno == 0) { _ship.update_ship(_joystick.x,_joystick.y); _weapons.update(); - kestrelw_seeker_collision(pad); + kestrelw_seeker_collision(); } //printf("if shipno == 0\n"); if(_shipno == 1 && A == false) { @@ -141,7 +145,7 @@ _shooterWPos[1] = _enemy.get_shwpos(2); _shooterWPos[2] = _enemy.get_shwpos(3); - _weapons.init(_shipPos.x, _shipPos.y, _shipWidth); + _weapons.init(_shipPos.x, _shipPos.y, _shipWidth,_lcd,_pad); _ycursor = _menu.get_ycursor(); set_ship_size(); } @@ -163,9 +167,11 @@ } } -void RosenEngine::title(N5110 &lcd) +void RosenEngine::title() { - _menu.title(lcd,_shipno); + printf("title...\n"); + _menu.title(_shipno); + printf("update...\n"); _menu.update(_d); } int RosenEngine::get_ycursor() @@ -178,10 +184,10 @@ _shipno = _menu.get_xcursor(); return _shipno; } -void RosenEngine::ship_select(N5110 &lcd) +void RosenEngine::ship_select() { _menu.update(_d); - _menu.disp_ships(lcd); + _menu.disp_ships(); } bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2) { @@ -259,7 +265,7 @@ } // make function resemble test -void RosenEngine::seeker_ship_collision(Gamepad &pad) +void RosenEngine::seeker_ship_collision() { bool col1,col2,col3; @@ -279,13 +285,13 @@ } // printf("col1 = %d, col2 = %d, col3 = %d, no_seekers = %d\n",col1,col2,col3,_no_seekers); if(sel != 0) { - _health.update(5,pad); + _health.update(5); _health.seekerh_update(sel,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } } -void RosenEngine::shooter_ship_collision(Gamepad &pad) +void RosenEngine::shooter_ship_collision() { bool col1,col2,col3; int sel = 0; @@ -303,13 +309,13 @@ sel = 3; } if(sel != 0) { - _health.update(1,pad); + _health.update(1); _health.shooterh_update(sel,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } } -void RosenEngine::shooterw_ship_collision(Gamepad &pad) +void RosenEngine::shooterw_ship_collision() { bool col1,col2,col3; int sel = 0; @@ -327,12 +333,12 @@ sel = 3; } if(sel != 0) { - _health.update(1,pad); - pad.tone(500,0.05); + _health.update(1); + _pad->tone(500,0.05); wait(0.05); } } -void RosenEngine::kestrelw_seeker_collision(Gamepad &pad) +void RosenEngine::kestrelw_seeker_collision() { bool col1, col2, col3; int sel = 0; @@ -350,12 +356,12 @@ sel = 3; } if(sel != 0) { - pad.tone(500,0.05); + _pad->tone(500,0.05); _health.seekerh_update(sel,5); wait(0.05); } } -void RosenEngine::imperionw_seeker_collision(Gamepad &pad) +void RosenEngine::imperionw_seeker_collision() { bool col1,col2,col3; int sel = 0; @@ -381,11 +387,11 @@ } if(sel != 0) { _health.seekerh_update(sel,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } } -void RosenEngine::kestrelw_shooter_collision(Gamepad &pad) +void RosenEngine::kestrelw_shooter_collision() { Vector2D missle_pos = _weapons.get_pos(_shipno); bool col1, col2, col3; @@ -404,12 +410,12 @@ } // printf("col1 = %d,col2 = %d,col3 = %d, no_shooters = %d\n",col1,col2,col3,_no_shooters); if(sel != 0) { - pad.tone(500,0.05); + _pad->tone(500,0.05); _health.shooterh_update(sel,5); wait(0.05); } } -void RosenEngine::imperionw_shooter_collision(Gamepad &pad) +void RosenEngine::imperionw_shooter_collision() { bool col1,col2,col3; int sel = 0; @@ -435,11 +441,11 @@ } if(sel != 0) { _health.shooterh_update(sel,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } } -void RosenEngine::orionw_collision(Gamepad &pad) +void RosenEngine::orionw_collision() { Vector2D inde = find_closest1(); int index1 = inde.x; @@ -449,13 +455,13 @@ // enemy 1,2 and 3 are shooters if(_no_shooters >= index1 && A == true && distance < 15) { _health.shooterh_update(index1,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } // enemy 4,5 and 6 are seekers so 3 is subtracted from inde.x to compensate if(_no_seekers >= index2 && A == true && distance < 15) { _health.seekerh_update(index2,10); - pad.tone(500,0.05); + _pad->tone(500,0.05); wait(0.05); } @@ -562,21 +568,21 @@ _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) +void RosenEngine::game_over() { // Display random tips after every loss - _lore.display(lcd,rand_no()); + _lore.display(rand_no()); } -void RosenEngine::intro(N5110 &lcd) +void RosenEngine::intro() { - _lore.intro(lcd); + _lore.intro(); _intro = true; } -void RosenEngine::disp_points(N5110 &lcd) +void RosenEngine::disp_points() { char buffer[10]; sprintf(buffer,"%d",_score); - lcd.printString(buffer,2,0); + _lcd->printString(buffer,2,0); } Vector2D RosenEngine::get_enemynum() {