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: 4DGL-uLCD-SE PinDetect mbed
Player.cpp
00001 #include "Player.h" 00002 00003 Player::Player(int x, int y, uLCD_4DGL *uLCD) { 00004 _health = 4; 00005 _x = x; 00006 _y = y; 00007 _uLCDptr = uLCD; 00008 _cockpit.init(0,0,uLCD); 00009 _cockpit.setRadius(6); 00010 _glare.init(1,-2,uLCD); 00011 _glare.setRadius(2); 00012 _body.init(-4,0,uLCD); 00013 _body.setDimensions(16,8); 00014 _leftWing.init(-14,11,uLCD); 00015 _leftWing.setDimensions(4,10); 00016 _rightWing.init(4,11,uLCD); 00017 _rightWing.setDimensions(4,10); 00018 _leftGun.init(-11,9,uLCD); 00019 _leftGun.setDimensions(2,4); 00020 _rightGun.init(8,9,uLCD); 00021 _rightGun.setDimensions(2,4); 00022 _engine1.init(-2,16,uLCD); 00023 _engine1.setDimensions(2,3); 00024 _engine2.init(-3,16,uLCD); 00025 _engine2.setDimensions(5,6); 00026 _healthBar.init(-10, -10,uLCD); 00027 _healthBar.setDimensions(1,20); 00028 } 00029 00030 void Player::addX(int dx) { 00031 if((dx > 0) && (_x + 14 <= 128)) { 00032 _x += dx; 00033 } 00034 if((dx < 0) && (_x - 14 >= 0)) { 00035 _x += dx; 00036 } 00037 } 00038 00039 void Player::addY(int dy) { 00040 if((dy > 0) && (_y + 21 <= 128)) { 00041 _y += dy; 00042 } 00043 if((dy < 0) && (_y - 3 >= 0)) { 00044 _y += dy; 00045 } 00046 } 00047 00048 Point Player::hitBoxStart() { 00049 Point hitStart; 00050 hitStart.x = _x - 3; 00051 hitStart.y = _y - 3; 00052 return hitStart; 00053 } 00054 00055 Point Player::hitBoxDim() { 00056 Point hitDim; 00057 hitDim.x = 8; 00058 hitDim.y = 24; 00059 return hitDim; 00060 } 00061 00062 Point Player::getLeftGunLoc() { 00063 Point gunLoc; 00064 gunLoc.x = _x - 10; 00065 gunLoc.y = _y + 9; 00066 return gunLoc; 00067 } 00068 00069 Point Player::getRightGunLoc() { 00070 Point gunLoc; 00071 gunLoc.x = _x + 9; 00072 gunLoc.y = _y + 9; 00073 return gunLoc; 00074 } 00075 00076 void Player::drawPlayer() { 00077 _engine2.drawRect(_x,_y,Engine1Color); 00078 _engine1.drawRect(_x,_y,Engine2Color); 00079 _leftGun.drawRect(_x,_y,GunColor); 00080 _rightGun.drawRect(_x,_y,GunColor); 00081 _leftWing.drawRect(_x,_y,WingColor); 00082 _rightWing.drawRect(_x,_y,WingColor); 00083 _body.drawRect(_x,_y,BodyColor); 00084 _cockpit.drawCircle(_x, _y, CockpitColor); 00085 _glare.drawCircle(_x,_y,GlareColor); 00086 if(_health == 4) { 00087 _healthBar.setDimensions(1,20); 00088 } 00089 else if(_health == 3) { 00090 _healthBar.setDimensions(1,15); 00091 } 00092 else if(_health == 2) { 00093 _healthBar.setDimensions(1,10); 00094 } 00095 else if(_health == 1) { 00096 _healthBar.setDimensions(1,5); 00097 } 00098 else { 00099 _healthBar.setDimensions(1,1); 00100 } 00101 _healthBar.drawRect(_x,_y, HealthColor); 00102 } 00103 00104 void Player::damage(int dmg) { 00105 _health -= dmg; 00106 } 00107 00108 int Player::getHealth() { 00109 return _health; 00110 }
Generated on Sun Jul 17 2022 07:39:56 by
1.7.2