Yuheng Huo / Mbed 2 deprecated hyh_copy

Dependencies:   mbed FXOS8700CQ

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers chara.cpp Source File

chara.cpp

00001 #include "chara.h"
00002 
00003 void chara::init(){
00004     int d[56] = {
00005             0,0,1,1,1,0,0,
00006             0,0,1,0,1,0,0,
00007             0,0,1,1,1,0,0,
00008             1,1,0,1,0,0,0,
00009             1,0,1,1,1,1,0,
00010             1,0,1,1,0,0,0,
00011             1,1,0,0,1,0,0,
00012             0,0,0,0,1,0,0
00013             };
00014     for(int i = 0; i<56;i++){
00015         data[i] = d[i];
00016     }
00017     _xy.x = 0;
00018     _xy.y = 25;
00019 }
00020 
00021 void chara::update(Gamepad &pad, FXOS8700CQ &device){
00022     Data values = device.get_values();
00023               
00024     if(pad.get_direction() == N){
00025         _xy.y = _xy.y -4;
00026     }else{
00027         _xy.y = _xy.y + 2;
00028     }
00029     
00030     if(values.ay>=0){
00031         _xy.x = _xy.x - int(values.ay*10);
00032     }else if(values.ay<=0){
00033         _xy.x = _xy.x - int(values.ay*10);
00034     }
00035     
00036     if(_xy.x>=77){
00037         _xy.x = 77;
00038     }else if(_xy.x<=0){
00039         _xy.x=0;
00040     }
00041     if(_xy.y>=41){
00042         _xy.y = 41 ;
00043     }else if(_xy.y<=7){
00044         _xy.y=7;
00045     }
00046 }
00047 
00048 void chara::display(N5110 &lcd){
00049         Bitmap c(data, 8, 7);
00050         c.render(lcd, _xy.x, _xy.y);
00051 }
00052 
00053 xy chara::getxy(){return _xy;}
00054 
00055