ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

main.cpp

Committer:
lewisgw
Date:
2019-03-17
Revision:
4:ce4eea1c2a28
Parent:
3:28a3c118e071
Child:
5:eda40cdde3e7

File content as of revision 4:ce4eea1c2a28:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering University of Leeds
Name: Lewis Wooltorton
Username: el17lw
Student ID Number: 201122085 Date: March 2019
*/

#include "N5110.h"
#include "Gamepad.h"
#include "Skateboarder.h"
#include <cmath>

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad gamepad;
Skateboarder skater;  

void init_game();
void process_inputs();
void update_lcd(int x, int y, Sprite_value sprite);

int main(){
    
    init_game();
    int moving_counter = 0;
    int x; 
    int y;
    int level = 0; 
    int jump_counter = 0; 
    Skate_Direction direction = Left;
    Sprite_value sprite;
       
    while(1){
        lcd.clear();
        Vector2D coord = gamepad.get_mapped_coord(); 
        
        if((x >= 1 && x <= 30 && y < 15) || (x >= 45 && x <= 80 && y < 15)){
        level = 1;    
        } else {
        level = 0;
        }
        
        skater.set_y_position( gamepad.check_event(Gamepad::A_PRESSED), jump_counter, level );
        y = skater.get_y_position();
        jump_counter = skater.get_jump_counter();
        
        skater.set_x_position( coord.x, moving_counter, direction, coord.y );
        x = skater.get_x_position();
        moving_counter = skater.get_moving_counter();
        sprite = skater.get_sprite_value();
        direction = skater.get_direction();
                    
        update_lcd(x, y, sprite);
       
        lcd.refresh();
        wait(0.01); 
}     
}  
 
void init_game() {
    gamepad.init();
    lcd.init(); 
    lcd.setContrast(0.5); 
    lcd.normalMode();      
    lcd.setBrightness(0.5); 
}
    
void update_lcd(int x, int y, Sprite_value sprite) {
    int* skate_sprite = skater.get_sprite(sprite);
    lcd.drawSprite(x,y,17,10,(int *)skate_sprite);
    lcd.drawLine(5,40,80,40,FILL_BLACK);
    lcd.drawLine(5,22,30,22,FILL_BLACK);
    lcd.drawLine(50,22,80,22,FILL_BLACK);     
}