Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Character.cpp
00001 #include "Character.h" 00002 00003 //constructor 00004 Character::Character(){} 00005 //destructor 00006 Character::~Character(){} 00007 00008 void Character::charinit(int manx, int many){ 00009 charx = manx; 00010 chary = many; 00011 } 00012 00013 //draw the character 00014 void Character::draw(N5110 &lcd){ 00015 const int user[11][12] = { 00016 {0,0,0,0,0,0,0,0,0,0,0,0}, 00017 {0,1,1,1,1,1,1,1,1,1,1,0}, 00018 {0,1,0,0,0,0,0,0,0,0,1,0}, 00019 {0,1,0,1,1,0,0,1,1,0,1,0}, 00020 {0,1,0,0,0,0,0,0,0,0,1,0}, 00021 {0,1,0,0,0,0,0,0,0,0,1,0}, 00022 {0,1,0,0,1,1,1,1,0,0,1,0}, 00023 {0,1,0,0,1,0,0,1,0,0,1,0}, 00024 {0,1,0,0,1,1,1,1,0,0,1,0}, 00025 {0,1,0,0,0,0,0,0,0,0,1,0}, 00026 {0,1,1,1,1,1,1,1,1,1,1,0}, 00027 }; 00028 00029 lcd.drawSprite(charx,chary,11,12,(int *)user); 00030 } 00031 00032 //hold A to move up the character 00033 void Character::move_up(Gamepad &pad){ 00034 if(pad.A_held()== true){ 00035 chary = chary - 5; 00036 } 00037 } 00038 00039 //the character will drop downwards because of gravity 00040 void Character::move_down(){ 00041 chary = chary + 3; 00042 } 00043 00044 //check if the character has reach the boundry 00045 void Character::boundry(){ 00046 //upper boundry 00047 if(chary < 0){ 00048 chary = 0; 00049 } 00050 00051 //bottom boundry 00052 if(chary > 36){ 00053 chary = 36; 00054 } 00055 } 00056 00057 //get the position of the character 00058 Vector2D Character::get_char_position(){ 00059 Vector2D p = {charx, chary}; 00060 return p; 00061 } 00062 00063
Generated on Sat Jul 16 2022 00:49:04 by
