test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Converter.cpp

Committer:
kaku_jyoko
Date:
2016-12-13
Revision:
39:e8d6dd3c75c7
Parent:
38:63b99151e218
Child:
40:ec5c1b305b9a

File content as of revision 39:e8d6dd3c75c7:

#include "convert.h"
#include "models.h"
#include "point.h"
#include "C12832_lcd.h" 
#include <math.h>

int pow(int x, int y){
    int ans = 1;
    for(int i = 0; i < y; i++){
        ans *= x;
    }
    return ans;   
}

int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

Bitmap Converter::convert(int map[][LCD_X]){
    int len = LCD_Y*LCD_X/CHAR_SIZE;
    int count = 0;
    int tmp = 0;
    char char_map[len];
    for(int i = 0; i < len; i++ ){
        char_map[i] = 0;
    }
    
//    for(int i = 0; i < LCD_X; i++){
//        printf("line %d  height: ",i);
//        for(int j = 0; j < LCD_Y; j++){
//            printf("%d ",map[j][i]);
//        }
//        printf("\n");
//    }
//    printf("\n");
    
    
    for(int i = 0; i < LCD_Y; i++){
        for(int j = 0; j < LCD_X; j++){
            int index = (i*LCD_X + j)/CHAR_SIZE;
            //char_map[index] |= map[i][j] << ((CHAR_SIZE - 1) - index % CHAR_SIZE);
            char_map[index] |= map[i][j] << ((CHAR_SIZE - 1) - (i*LCD_X + j) % CHAR_SIZE);   
        }
    }
    
//    for(int i = 0; i < len; i++){
//        if(i % 16 == 0){
//            printf("\n");
//            printf("line %d  ", i);
//        }
//        printf("%d ", char_map[i]);
//    }
//    
//     printf("\n");
    
    //return char_map;
    Bitmap bitmap_converted = {
        LCD_X,
        LCD_Y,
        LCD_X/CHAR_SIZE,
        char_map,
    };
    return bitmap_converted;
}