ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_ll17lrc_v2

Dependencies:   mbed

Imposs/ImpossEngine.cpp

Committer:
ll17lrc
Date:
2020-05-17
Revision:
4:a9d5fca3b7ba
Parent:
3:4494e6928194
Child:
5:5c132202b642

File content as of revision 4:a9d5fca3b7ba:

#include "ImpossEngine.h"


ImpossEngine::ImpossEngine()
{

}

ImpossEngine::~ImpossEngine()
{

}

StartMenu _start;

void ImpossEngine::complete(Gamepad &pad,N5110 &lcd)
{
    _start.complete(pad,lcd);   
}

void ImpossEngine::read_input(Gamepad &pad)
{
    _d = pad.get_direction();
    _mag = pad.get_mag();
}

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

    if (level == 1){
        _one.draw(lcd);
    }

}

void ImpossEngine::update(Gamepad &pad,N5110 &lcd,int level)
{
    _ball.update(_d);

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

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();
    int y_pos = _ball.get_ball_y_pos();
    bool collision = false;
    //check around ball to see if it has made contact with anything
    
    while(i < 4){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _x ++;
        
    }
    
    i = 0;
     
    while(i < 4){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _y ++;
        
    }
    
    i = 0;
    
    while(i < 4){
        
        i++;
        
        if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){
            collision = true;
            }
            
        _x --;
        
    }
    
    i = 0;
    
    while(i < 4){
        
        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 level)
{
    
    int x_pos = _ball.get_ball_x_pos();
    
    if(x_pos == 82){
        level++;
        _ball.level_finish();
        }
        
}