RUOFAN LI / Mbed 2 deprecated el17rl

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spaceship.cpp Source File

spaceship.cpp

00001 /* SPACE RACE Game using Arduino and Nokia 5110 LCD
00002  * Coded by: Ruofan Li
00003  * Date: 28-4-2020
00004  * Input -> Joystick (x0,y0)
00005 */
00006 
00007 #include <spaceship.h> // Library for spaceship.cpp
00008 
00009 //*Construct and Destruct
00010 Spaceship::Spaceship()
00011 {
00012  
00013 }
00014  
00015 Spaceship::~Spaceship()
00016 {
00017  
00018 }
00019  
00020 void Spaceship::init(int x,int y,int width,int height)
00021 {
00022     _x = x; //x value is fixed
00023     _y = y; //y is also fixed
00024     _width = width;
00025     _height = height;
00026     _speed = 4;
00027 }
00028 
00029 void Spaceship::draw(N5110 &lcd)
00030 {
00031     // draw Spaceship in screen of N5110. 
00032 int _Spaceship[] = {
00033    0,0,0,0,0,0,0,0,0,0,
00034    0,0,0,0,1,1,0,0,0,0,
00035    0,0,0,0,1,1,0,0,0,0,
00036    0,0,1,1,0,0,1,1,0,0,
00037    0,1,1,1,1,1,1,1,1,0,
00038    0,1,1,1,1,1,1,1,1,0,
00039    1,1,1,1,1,1,1,1,1,1,
00040    1,1,1,1,1,1,1,1,1,1,
00041    1,1,1,1,1,1,1,1,1,1,
00042    1,1,1,1,1,1,1,1,1,1,
00043    1,1,1,1,1,1,1,1,1,1,
00044    1,1,1,1,0,0,1,1,1,1,
00045    0,1,1,1,0,0,1,1,1,0,
00046    0,0,1,1,0,0,1,1,0,0,
00047    0,0,0,1,1,1,1,0,0,0,
00048    0,0,0,0,0,0,0,0,0,0,
00049    
00050     Bitmap sprite(_Plane, _sizeX, _sizeY);
00051     sprite.render(lcd, _x, _y); 
00052 };
00053 
00054 void Spaceship::update(int d)
00055 {
00056 
00057     if(d == 3){
00058         //turn right
00059         _x+=_speed;
00060         
00061         if(_x>75){
00062             
00063             _x = 75;
00064         }
00065     }else if(d == 7){
00066         //turn left
00067         _x-=_speed;
00068         
00069         if(_x<0) {
00070             _x = 0;
00071         }
00072     }
00073 }
00074 
00075 // get the position of the spaceship
00076 Vector2D Spaceship::get_Pos()
00077 {
00078     Vector2D p = {_x,_y};
00079     return p;
00080 }