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.
Fork of fy15raf by
Spaceship.cpp
00001 #include "Spaceship.h" 00002 00003 Spaceship::Spaceship() 00004 { 00005 00006 } 00007 00008 Spaceship::~Spaceship() 00009 { 00010 00011 } 00012 00013 void Spaceship::init() 00014 { 00015 //initialise the Spaceship position, speed and collisions 00016 _x = 15 ; 00017 _y = HEIGHT/2 ; 00018 _speed = 1; 00019 _collision=0; 00020 } 00021 00022 void Spaceship::draw(N5110 &lcd) 00023 { 00024 int sprite[7][10] = { 00025 00026 { 0,1,1,1,1,0,0,0,0,0, }, 00027 { 0,0,1,0,0,1,1,0,0,0, }, 00028 { 0,0,0,1,0,0,0,1,1,0, }, 00029 { 0,0,0,1,1,1,1,1,1,1, }, 00030 { 0,0,0,1,0,0,0,1,1,0, }, 00031 { 0,0,1,0,0,1,1,0,0,0, }, 00032 { 0,1,1,1,1,0,0,0,0,0, }, 00033 }; 00034 lcd.drawSprite(_x,_y,7,10,(int *)sprite); 00035 } 00036 00037 void Spaceship::update(Direction d,float mag) 00038 { 00039 _speed = int(mag*10.0f); //shows how far from the center does the Spaceship move based on the joystick 00040 00041 // update y and x values based on direction of joystick movement 00042 if (d == N) { 00043 _y-=_speed; 00044 } else if (d == S) { 00045 _y+=_speed; 00046 } else if (d == W) { 00047 _x-=_speed; 00048 } else if (d == E) { 00049 _x+=_speed; 00050 } 00051 00052 00053 // check the Spaceship coordinates so it doesn't go off screen 00054 if (_y < 1) { 00055 _y = 1; 00056 } 00057 if (_y > HEIGHT - 7) { 00058 _y = HEIGHT - 7; 00059 } 00060 if (_x < 1) { 00061 _x = 1; 00062 } 00063 if (_x > WIDTH - 9) { 00064 _x = WIDTH - 9; 00065 } 00066 } 00067 00068 Vector2D Spaceship::get_pos() 00069 { 00070 Vector2D p = {_x,_y}; 00071 return p; 00072 } 00073 00074 void Spaceship::add_collisions() 00075 { 00076 _collision++; 00077 } 00078 00079 int Spaceship::get_collisions() 00080 { 00081 return _collision; 00082 } 00083 00084 void Spaceship::drawFullHearts(N5110 &lcd) 00085 { 00086 int sprite[5][17] = { 00087 00088 { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, }, 00089 { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, }, 00090 { 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, }, 00091 { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0, }, 00092 { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, }, 00093 }; 00094 lcd.drawSprite(0,0,5,17,(int *)sprite); 00095 } 00096 00097 void Spaceship::drawTwoHearts(N5110 &lcd) 00098 { 00099 int sprite[5][17] = { 00100 00101 { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, }, 00102 { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1, }, 00103 { 1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,1, }, 00104 { 0,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,0, }, 00105 { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, }, 00106 }; 00107 lcd.drawSprite(0,0,5,17,(int *)sprite); 00108 } 00109 00110 void Spaceship::drawOneHeart(N5110 &lcd) 00111 { 00112 int sprite[5][17] = { 00113 00114 { 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, }, 00115 { 1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1, }, 00116 { 1,1,1,1,1,0,1,0,0,0,1,0,1,0,0,0,1, }, 00117 { 0,1,1,1,0,0,0,1,0,1,0,0,0,1,0,1,0, }, 00118 { 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, }, 00119 }; 00120 lcd.drawSprite(1,1,5,17,(int *)sprite); 00121 }
Generated on Thu Jul 14 2022 18:15:41 by
