ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_ll17lrc_v2

Dependencies:   mbed

Imposs/ImpossEngine.cpp

Committer:
ll17lrc
Date:
2020-05-18
Revision:
8:10eb578dd754
Parent:
7:35465b3bf586
Child:
9:e2dd152867d1

File content as of revision 8:10eb578dd754:

#include "ImpossEngine.h"


ImpossEngine::ImpossEngine()
{

}

ImpossEngine::~ImpossEngine()
{

}

StartMenu _start;

void ImpossEngine::complete(Gamepad &pad,N5110 &lcd)
{
    _start.complete(pad,lcd); 
    int x = 0;
    int y = 21;
    _ball.init(x,y);
}
 
void ImpossEngine::read_input(Gamepad &pad)
{
    _d = pad.get_direction();
    _mag = pad.get_mag();
}

void ImpossEngine::draw(N5110 &lcd,Gamepad &pad)
{
    // draw the elements in the LCD buffer
    // pitch   
    
    
    if (level == 0){
        _zero.draw(lcd);
    }

    if (level == 1){
        _one.draw(lcd);
    } 
    
    if (level == 2){
        _two.draw(lcd);
    }
    
     _ball.update(_d,pad);
    
    _ball.draw(lcd);

}

void ImpossEngine::update(Gamepad &pad,N5110 &lcd)
{

    check_collision(pad,lcd);
    
    check_finish();
}

void ImpossEngine::set_level_zero(){
    level = 0;
    }
    
void ImpossEngine::set_level_one(){
    level = 1;
    }

void ImpossEngine::check_collision(Gamepad &pad,N5110 &lcd)
{
    int _x = 0;
    int _y = 0;
    int i = 0;
    int x_pos = _ball.get_ball_x_pos() - 1;
    int y_pos = _ball.get_ball_y_pos() - 1;
    bool collision = false;
    //check around ball to see if it has made contact with anything
    
    while(i < 3){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _x ++;
        
    }
    
    i = 0;
     
    while(i < 3){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _y ++;
        
    }
    
    i = 0;
    
    while(i < 3){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _x --;
        
    }
    
    i = 0;
    
    while(i < 3){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _y --;
        
    if(collision == true){
        _ball.level_finish();
        }
    }
}

void ImpossEngine::check_finish()
{
    
    int pos = _ball.get_ball_x_pos();
    
    if(pos == 82){
        level++;
        _ball.level_finish();
        }
        
}