Toluwalakin Owoso 201231164
Dependencies: mbed ELEC2645_Project_el18to
CCar.cpp
00001 #include "CCar.h" 00002 00003 00004 const int ccar[10][10]{ 00005 { 0,0,0,0,1,1,0,0,0,0 }, 00006 { 0,0,0,1,1,1,1,0,0,0 }, 00007 { 0,0,1,0,1,1,0,1,0,0 }, 00008 { 0,0,1,0,1,1,0,1,0,0 }, 00009 { 0,0,0,1,1,1,1,0,0,0 }, 00010 { 0,0,0,1,0,0,1,0,0,0 }, 00011 { 0,0,1,1,0,0,1,1,0,0 }, 00012 { 0,0,1,1,0,0,1,1,0,0 }, 00013 { 0,0,0,1,0,0,1,0,0,0 }, 00014 { 0,0,0,0,1,1,0,0,0,0 }, 00015 }; 00016 00017 volatile int x=1; 00018 volatile int y=1; 00019 00020 // nothing doing in the constructor and destructor 00021 CCar::CCar() 00022 { 00023 00024 } 00025 00026 CCar::~CCar() 00027 { 00028 00029 } 00030 00031 00032 00033 void CCar::draw(N5110 &lcd) 00034 { 00035 // draw Cop car in screen buffer. 00036 lcd.drawSprite(40,20,10,10, (int *)ccar); 00037 } 00038 00039 void CCar::update(Gamepad &pad) 00040 { 00041 Direction d = pad.get_direction(); 00042 float mag = pad.get_mag(); 00043 00044 if(d == E && mag > 0.3){ 00045 x = x+2; 00046 wait_ms(10); 00047 } 00048 if(d == W && mag > 0.3){ 00049 x = x-2; 00050 wait_ms(10); 00051 } 00052 if(d == N && mag > 0.3){ 00053 y = y-2; 00054 wait_ms(10); 00055 } 00056 if(d == S && mag > 0.3){ 00057 y = y+2; 00058 wait_ms(10); 00059 } 00060 //printf("x = %i\n",x); 00061 //printf("y = %i\n",y); 00062 00063 }
Generated on Sun Jul 17 2022 01:15:51 by
1.7.2