ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

RosenEngine/RosenEngine.cpp

Committer:
ikenna1
Date:
2019-04-11
Revision:
15:009ccc07bb57
Parent:
14:88ca5b1a111a
Child:
17:e65a9f981834

File content as of revision 15:009ccc07bb57:

#include "RosenEngine.h"

DigitalIn A_button(PTB9);
// Constructor
RosenEngine::RosenEngine()
{

}
// Destructor
RosenEngine::~RosenEngine()
{

}


void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos)
{
    // initialise the game parameters
    _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos);
    // place seeker above the ship
    _enemy.init(ship_xpos, 0);
    _menu.init(16);

}

void RosenEngine::read_input(Gamepad &pad)
{
    Vector2D mapped_coord = pad.get_coord();
    _xjoystick = mapped_coord.x;
    _yjoystick = mapped_coord.y;
    _d = pad.get_direction();
    // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick);
}

void RosenEngine::draw(N5110 &lcd, Gamepad &pad)
{
    _enemy.draw_seeker(lcd);
    if(_xcursor == 0) {
        _ship.set_dimensions(9,6);
        _ship.draw_ship(lcd);
        _weapons.draw(lcd);
    }
    if(_xcursor == 1) {
        _ship.set_dimensions(7,10);
        _ship.draw_imperion(lcd);

        if((A_button) == true) {
            pad.tone(500,0.5);
            wait(0.5);
            pad.tone(1000,0.3);
            wait(0.3);
            pad.tone(1500,0.2);
            wait(0.2);
            pad.tone(1700,0.15);
            wait(0.15);
            while((A_button) == true) {
                _weapons.draw_i(lcd);
                pad.tone(2000,0.1);
                wait(0.1);
            }
        }
    }
}

void RosenEngine::update(Gamepad &pad)
{
    _enemy.update_seeker(ship_xpos, ship_ypos);
    if(_xcursor == 0) {
        _ship.update_ship(_xjoystick,_yjoystick);
        _weapons.update();
    }
    if(_xcursor == 1 && A_button == false) {
        _ship.update_ship(_xjoystick,_yjoystick);
        _weapons.update();
    }
    // _menu.update(_d);
}
void RosenEngine::get_pos()
{

    Vector2D ship_pos = _ship.get_pos();
    ship_xpos = ship_pos.x;
    ship_ypos = ship_pos.y;
    ship_width = 9;
    _weapons.init(ship_xpos, ship_ypos, ship_width);
    _ycursor = _menu.get_ycursor();
}
void RosenEngine::title(N5110 &lcd)
{
    _menu.title(lcd);
    _menu.update(_d);
}
int RosenEngine::get_ycursor()
{
    _ycursor = _menu.get_ycursor();
    return _ycursor;
}
int RosenEngine::get_xcursor()
{
    _xcursor = _menu.get_xcursor();
    return _xcursor;
}
void RosenEngine::ship_select(N5110 &lcd)
{
    _menu.update(_d);
    _menu.disp_ships(lcd);
}