ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Engine/Engine.cpp

Committer:
lewisgw
Date:
2019-03-20
Revision:
7:bbc2b75c1418
Parent:
5:eda40cdde3e7
Child:
8:5327418f823a

File content as of revision 7:bbc2b75c1418:

#include "Engine.h"

Engine::Engine(){} 

Engine::~Engine(){}

void Engine::init() {
    _moving_counter = 0;
    _jump_counter = 0;
    _direction = Left;
    _level = 0;
    _x = 40;
    _y = 40;
    
    _map.init();
    srand(time(NULL));
    }

void Engine::read_input(Gamepad &gamepad) {
    _input.coord = gamepad.get_mapped_coord(); 
    _input.A_flag = gamepad.check_event(Gamepad::A_PRESSED);
    } 

void Engine::process_y() {
    _skater.set_y_position( _input.A_flag, _jump_counter, _level );
    _y = _skater.get_y_position();
    _jump_counter = _skater.get_jump_counter();
    }
    
void Engine::process_x(int t) {
    _skater.set_x_position( _input.coord.x, _moving_counter, _direction, _input.coord.y );
    _x = _skater.get_x_position();
    _moving_counter = _skater.get_moving_counter();
    
    if( (t % 6 == 0 || t % 8 == 0) && (_input.coord.x > -0.1) ) {
    _moving_counter--;
    }
    }
    
void Engine::process_sprite() {
    _sprite = _skater.get_sprite_value();
    _direction = _skater.get_direction();
    }


void Engine::find_level() {
    if((_x >= 1 && _x <= 30 && _y < 15) || (_x >= 45 && _x <= 80 && _y < 15)){
    _level = 1;    
    } else {
    _level = 0;
    }
    }
    
void Engine::generate_map() {
    _length_1 = (rand() %20)+10;
    _length_2 = (rand() %20)+10;
    _length_3 = (rand() %20)+10;
    
    _map.generate_line_1(_length_1);
    _line_1 = _map.get_line_1();
        
    _map.generate_line_2(_length_2);
    _line_2 = _map.get_line_2();
        
    _map.generate_line_3(_length_3);
    _line_3 = _map.get_line_3();
    
    }


void Engine::update_lcd(N5110 &lcd){
    _skate_sprite = _skater.get_sprite(_sprite);
    lcd.drawSprite(_x,_y,17,10,(int *)_skate_sprite);
    lcd.drawLine(_line_2.x_start,_line_2.y,_line_2.x_end,_line_2.y,FILL_BLACK);
    lcd.drawLine(_line_1.x_start,_line_1.y,_line_1.x_end,_line_1.y,FILL_BLACK);
    lcd.drawLine(_line_3.x_start,_line_3.y,_line_3.x_end,_line_3.y,FILL_BLACK);
    }