ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

main.cpp

Committer:
lewisgw
Date:
2019-03-13
Revision:
2:16ae940b0aee
Parent:
1:ded7ddd826ce
Child:
3:28a3c118e071

File content as of revision 2:16ae940b0aee:

/*
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;  

int skate_right[17][12] =   {
    
    { 0,0,0,0,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,1,1,1,0,0,0,0 },
    { 0,0,1,1,1,1,1,1,0,0,0,0 },
    { 0,0,0,0,1,0,1,1,0,0,0,0 },
    { 0,0,0,0,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,1,1,1,0,0,0 },
    { 0,1,1,0,1,1,0,0,1,1,0,0 },
    { 0,1,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,0,1,0,1,0,0,0,0,0 },
    { 0,0,0,0,1,0,0,1,0,0,0,0 },
    { 0,1,0,0,1,0,0,0,1,0,1,0 },
    { 0,0,1,1,1,1,1,1,1,1,0,0 },
    { 0,0,0,1,0,0,0,0,1,0,0,0 },
    
    
};

int skate_left[17][12] =   {
    
    { 0,0,0,0,1,1,1,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,1,1,0,0,0 },
    { 0,0,0,1,1,0,1,0,0,0,0,0 },
    { 0,0,0,0,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,0,1,1,0,0,0,0,0 },
    { 0,0,0,0,0,1,1,1,0,0,0,0 },
    { 0,1,1,1,1,1,1,1,0,0,0,0 },
    { 0,0,0,1,1,1,1,1,1,0,0,0 },
    { 0,0,0,0,1,1,0,0,1,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,1,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,0,1,0,0,0,0,0,0 },
    { 0,0,1,0,0,1,0,0,0,0,0,0 },
    { 1,1,0,0,0,1,0,0,0,1,0,0 },
    { 0,1,1,1,1,1,1,1,1,0,0,0 },
    { 0,0,0,1,0,0,0,0,1,0,0,0 },
    
    
};

int skate_standing_left[17][12] =   {
    
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,1,1,0,0,0 },
    { 0,0,0,1,0,0,1,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,1,0,0,0,0 },
    { 1,1,0,1,1,1,0,1,0,0,0,0 },
    { 0,0,0,1,1,1,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0 },
    { 1,0,1,0,0,1,0,0,0,0,0,0 },
    { 1,1,0,0,0,1,0,0,0,0,0,0 },
    { 0,1,0,0,0,1,0,0,0,0,0,0 },
    { 1,0,1,0,0,1,0,0,0,0,0,0 },
    { 0,0,0,1,0,1,0,0,0,0,0,0 },
    { 0,0,1,0,1,1,1,0,0,0,0,0 },
    
    
};

int skate_standing_right[17][12] =   {
    
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,1,1,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,1,0,0,1,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,0,0,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,1,0,0,0,0 },
    { 0,1,0,1,1,1,0,0,1,0,0,0 },
    { 0,1,0,1,1,1,0,0,0,0,0,0 },
    { 0,0,0,1,1,1,1,1,0,0,0,0 },
    { 0,0,0,1,0,0,0,1,0,1,0,0 },
    { 0,0,0,1,0,0,0,1,1,0,0,0 },
    { 0,0,0,1,0,0,0,1,0,1,0,0 },
    { 0,0,0,1,0,0,1,0,0,0,0,0 },
    { 0,0,0,1,0,1,0,0,0,0,0,0 },
    { 0,0,1,1,1,0,1,0,0,0,0,0 },
    
    
};

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 jump_counter = 0; 
    Skate_Direction direction;
    Sprite_value sprite;
       
    while(1){
        lcd.clear();
        Vector2D coord = gamepad.get_mapped_coord(); 
        
        skater.set_y_position( gamepad.check_event(Gamepad::A_PRESSED), jump_counter );
        y = skater.get_y_position();
        jump_counter = skater.get_jump_counter();
        
        skater.set_x_position( coord.x, moving_counter, direction );
        x = skater.get_x_position();
        moving_counter = skater.get_moving_counter();
        sprite = skater.get_sprite();
        
        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) {
    if(sprite == Skate_right){
    lcd.drawSprite(x,y,17,12,(int *)skate_right);
    } else if(sprite == Skate_left){
    lcd.drawSprite(x,y,17,12,(int *)skate_left);
    } else if(sprite == Stand_left){
    lcd.drawSprite(x,y,17,12,(int *)skate_standing_left);
    } else if (sprite == Stand_right){
    lcd.drawSprite(x,y,17,12,(int *)skate_standing_right);
    }
    lcd.drawLine(5,40,80,40,FILL_BLACK);  
    }