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.
Dependencies: mbed
Wall.cpp
00001 #include "Wall.h" 00002 00003 00004 //health icon 00005 int healthSymbol[5][5] = { 00006 { 1,1,1,1,1 }, 00007 { 1,1,0,1,1 }, 00008 { 1,0,0,0,1 }, 00009 { 1,1,0,1,1 }, 00010 { 1,1,1,1,1 }, 00011 }; 00012 00013 00014 Wall::Wall() 00015 { 00016 00017 } 00018 00019 Wall::~Wall() 00020 { 00021 00022 } 00023 00024 void Wall::init(int maxHealth) 00025 { 00026 //set both current and max health of wall to the value in the initialiser 00027 _wallHealth.max = maxHealth; 00028 _wallHealth.current = maxHealth; 00029 00030 00031 00032 } 00033 00034 void Wall::draw(N5110 &lcd) 00035 { 00036 //draw the wall 00037 lcd.drawRect(0,28,10,20,FILL_TRANSPARENT); 00038 lcd.drawLine(0,28,10,0,1); //back top of wall 00039 lcd.drawLine(10,0,20,0,1); //side of wall 00040 lcd.drawLine(10,28,20,0,1); //front top of wall 00041 lcd.drawLine(10,48,20,20,1); //front bottom of wall 00042 lcd.drawLine(20,20,20,0,1); //front side of wall 00043 00044 //draw health symbol 00045 lcd.drawSprite(60,0,5,5,(int *)healthSymbol); 00046 00047 //draw health value text to display 00048 char life[14]; 00049 int length = sprintf(life,"%i",_wallHealth.current); // print formatted data to buffer 00050 // it is important the format specifier ensures the length will fit in the buffer 00051 if (length <= 14) { // if string will fit on display (assuming printing at x=0) 00052 lcd.printString(life,67,0); 00053 } 00054 00055 00056 00057 00058 } 00059 00060 void Wall::set_wall_health(int wall_health) { 00061 _wallHealth.current = wall_health; 00062 } 00063 00064 int Wall::get_wall_health() { 00065 return _wallHealth.current; 00066 } 00067 00068 00069 void Wall::take_damage(int damage) { 00070 _wallHealth.current -= damage; //applies damage to the wall 00071 }
Generated on Mon Nov 11 2024 22:48:00 by
