Lab 6 for ECE 2036,a lame version of Galiga that needs to have the bullet fixed, but focuses on the concept of polymorphism

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers graphics.cpp Source File

graphics.cpp

00001 #include "graphics.h"
00002 #include "global.h"
00003 
00004 #define STOP_D 0
00005 #define GO_RIGHT 1
00006 #define GO_LEFT 2
00007 
00008 #define GEAR_1 .3
00009 
00010 //The characters for LAME
00011 #include "Sprites/bullet.cpp"
00012 #include "Sprites/BobUp.cpp"
00013 #include "Sprites/ship.cpp"
00014 #include "Sprites/BobDown.cpp"
00015 #include "Sprites/Alice.cpp"
00016 #include "Sprites/rocket.cpp"
00017 
00018 
00019 
00020 
00021 //constructors
00022 AliceAlien::AliceAlien()
00023 {
00024     setInput(NO_HIT);
00025     setState(NO_DAMAGE);
00026 
00027 }
00028 
00029 BobAlien::BobAlien()
00030 {
00031     setInput(NO_HIT);
00032     setState(NO_DAMAGE);
00033      setDirPos(true);
00034     
00035 
00036 }
00037 
00038 Ship::Ship()
00039 {
00040     setInput(NO_HIT);
00041     setState(NO_DAMAGE);
00042     setGear(STOP);
00043 
00044 }
00045 
00046 Rocket::Rocket()
00047 {
00048     setInput(NO_HIT);
00049     //loadedRocket = false;
00050 }
00051 
00052 Bullet::Bullet()
00053 {
00054     setInput(NO_HIT);
00055     //loadedBullet = false;
00056 }
00057 
00058 //Draw Functions
00059 void BobAlien::draw(int u,int v)
00060 {
00061     //Use get state here to make bob draw the differnt types
00062     uLCD.BLIT(u,v,11,11,BobUp);
00063 }
00064 
00065 void AliceAlien::draw(int u,int v)
00066 {
00067     //Use get state here to make bob draw the differnt types
00068     uLCD.BLIT(u,v,11,11,Alice);
00069 }
00070 
00071 void Ship::draw(int u,int v)
00072 {
00073     //Use get state here to make bob draw the differnt types
00074     uLCD.BLIT(u,v,11,11,ship);
00075 }
00076 
00077 void Bullet::draw(int u,int v)
00078 {
00079     //Use get state here to make bob draw the differnt types
00080     uLCD.BLIT(u,v,11,11,bullet);
00081 }
00082 
00083 void Rocket::draw(int u,int v)
00084 {
00085     //Use get state here to make bob draw the differnt types
00086     uLCD.BLIT(u,v,11,11,rocket);
00087 }
00088 
00089 //Screen Object Base functions
00090 
00091 void ScreenObjects::setState(StateType currState)
00092 {
00093     state = currState;
00094 }
00095 
00096 void ScreenObjects::setInput(InputType Input)
00097 {
00098     input = Input;
00099 }
00100 
00101 int ScreenObjects::getHealth()
00102 {
00103     return health;
00104 }
00105 
00106 void ScreenObjects::setHealth(int HP)
00107 {
00108     health = HP;
00109 }
00110 
00111 int * ScreenObjects::getPosition()
00112 {
00113     int * positionPointer = NULL;
00114     positionPointer = Position;
00115     return positionPointer;
00116 }
00117 
00118 int * ScreenObjects::getPrevPosition()
00119 {
00120     return previousPosition;
00121 }
00122 
00123 void ScreenObjects::setPosition(int posx,int posy)
00124 {
00125     Position[0] = posx;
00126     Position[1] = posy;
00127 }
00128 
00129 void ScreenObjects::setPrevPosition(int * newPos)
00130 {
00131     previousPosition = newPos;
00132 }
00133 
00134 void ScreenObjects::erase(int u, int v)
00135 {
00136     uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
00137 }
00138 
00139 
00140 int ScreenObjects::getDirection()
00141 {
00142 
00143     return direction;
00144 
00145 }
00146 
00147 void ScreenObjects::setDirection(int num)
00148 {
00149 
00150     direction = num;
00151 
00152 }
00153 
00154 bool ScreenObjects::getDirPos()
00155 {
00156 
00157     return dirPos;
00158 
00159 }
00160 
00161 void ScreenObjects::setDirPos(bool val)
00162 {
00163 
00164     dirPos = val;
00165 
00166 }
00167 
00168 //Bullet Class Functions
00169 
00170 
00171 bool Bullet::getLoaded()
00172 {
00173     load = loadedBullet;
00174     return load;
00175 }
00176 
00177 void Bullet::update()
00178 {
00179     setPrevPosition(getPosition());
00180 
00181     if(getLoaded()) {
00182         setPosition(getShipPosition()[0],getShipPosition()[1]-1);
00183     }
00184 
00185 }
00186 
00187 
00188 
00189 //Rocket Class Functions
00190 
00191 //
00192 
00193 //Ship Class Functions
00194 
00195 void Ship::setGear(GearShift Gears)
00196 {
00197     gear = Gears;
00198 }
00199 
00200 GearShift Ship::getGear()
00201 {
00202     return gear;
00203 }
00204 
00205 
00206 int Ship::move(double tiltDirection)
00207 {
00208     if (tiltDirection>GEAR_1) {
00209         setGear(GEAR1);
00210         return GO_RIGHT;
00211     }
00212     if (tiltDirection<-1*GEAR_1) {
00213         setGear(GEAR1);
00214         return GO_LEFT;
00215     }
00216 
00217     else {
00218         setGear(STOP);
00219         return STOP_D;
00220     }
00221 }
00222 
00223 
00224 int * Ship::getShipPosition()
00225 {
00226     return shipPos;
00227 }
00228 
00229 void Ship::setShipPos(int * val)
00230 {
00231     shipPos = val;
00232 }
00233 
00234 
00235 void Ship::update()
00236 {
00237     setPrevPosition(getPosition());
00238 
00239     //Stop
00240     if(getGear() == STOP || getPosition()[0] <=11 || getPosition()[0] > 117) {
00241         setPosition((getPosition()[0]),getPosition()[1]);
00242         setShipPos(getPosition());
00243     }
00244 
00245     //Gear1
00246     if(getGear() == GEAR1 && getPosition()[0] <= 117) {
00247         erase(getPosition()[0],getPosition()[1]);//move
00248         if(getDirection() == GO_LEFT) {
00249             setPosition((getPosition()[0]-2),getPosition()[1]);
00250            setShipPos(getPosition());
00251         }
00252         if(getDirection() == GO_RIGHT) {
00253             setPosition((getPosition()[0]+2),getPosition()[1]);
00254             setShipPos(getPosition());
00255         }
00256     }
00257 
00258 }
00259 
00260 //Bob ALien Class Functions
00261 void BobAlien::update()
00262 {
00263     setPrevPosition(getPosition());
00264     erase(getPosition()[0],getPosition()[1]);//move
00265     
00266     if(getPosition()[0] < 117 && getDirPos() )
00267         {
00268          setDirection(GO_RIGHT);   
00269         }
00270     
00271     if(getPosition()[0] > 117)
00272     {
00273         setDirPos(false);
00274         setDirection(STOP_D);
00275     }
00276     
00277     if(getDirection() == STOP_D)
00278     {
00279      setPosition((getPosition()[0]),getPosition()[1]+5); 
00280      setDirection(GO_LEFT);  
00281     }
00282     
00283     if(getPosition()[0] <= 10 && getDirPos() == false)
00284     {
00285         setDirPos(true);
00286     }
00287     
00288    
00289     
00290     if(getDirection() == GO_LEFT && getDirPos() == false) {
00291         setPosition((getPosition()[0]-1),getPosition()[1]);    
00292     }
00293     if(getDirection() == GO_RIGHT) {
00294         setPosition((getPosition()[0]+1),getPosition()[1]);
00295     }
00296     
00297 }
00298 
00299 
00300 //Alice Alien Class Functions
00301 void AliceAlien::update()
00302 {
00303     setPrevPosition(getPosition());
00304     erase(getPosition()[0],getPosition()[1]);//move
00305     
00306     if(getPosition()[0] < 117 && getDirPos() )
00307         {
00308          setDirection(GO_RIGHT);   
00309         }
00310     
00311     if(getPosition()[0] > 117)
00312     {
00313         setDirPos(false);
00314         setDirection(STOP_D);
00315     }
00316     
00317     if(getDirection() == STOP_D)
00318     {
00319      setPosition((getPosition()[0]),getPosition()[1]+5); 
00320      setDirection(GO_LEFT);  
00321     }
00322     
00323     if(getPosition()[0] <= 10 && getDirPos() == false)
00324     {
00325         setDirPos(true);
00326     }
00327     
00328    
00329     
00330     if(getDirection() == GO_LEFT && getDirPos() == false) {
00331         setPosition((getPosition()[0]-1),getPosition()[1]);    
00332     }
00333     if(getDirection() == GO_RIGHT) {
00334         setPosition((getPosition()[0]+1),getPosition()[1]);
00335     }
00336 }
00337 
00338 //Rocket Class Functions
00339 void Rocket::update()
00340 {
00341     setPrevPosition(getPosition());
00342 
00343 }