Li Ruofan 201199450

Dependencies:   mbed Gamepad Joystick

Revision:
6:cbd9e1f26a10
Parent:
5:e3a9f0548922
--- a/myShip/spaceship.cpp	Fri May 15 19:57:40 2020 +0000
+++ b/myShip/spaceship.cpp	Fri May 15 21:16:14 2020 +0000
@@ -29,7 +29,7 @@
 void Spaceship::draw(N5110 &lcd)
 {
     // draw Spaceship in screen of N5110. 
-int Spaceship[15][10] = {
+int _Spaceship[] = {
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,1,1,0,0,0,0,
    0,0,0,0,1,1,0,0,0,0,
@@ -47,57 +47,34 @@
    0,0,0,1,1,1,1,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    
-   lcd.drawSprite(lcd, _x,_y,_height,_width,(int)Spaceship);// Specify rows and columns in sprite
+    Bitmap sprite(_Plane, _sizeX, _sizeY);
+    sprite.render(lcd, _x, _y); 
 };
 
-void loop() {
-  display.clearDisplay();   // clears the screen and start new
+void Spaceship::update(int d)
+{
 
-  gamescreen(); //Displays the box, score and speed values
-  
-  //Get input from user  
-  Joy_X = analogRead(A1); //It will read the X value from Joystick
-  if (Joy_X < 312 && POS!=1 && control==true) //If joy stick moves right
-  { POS--; control = false;} //Decreace position of spaceship
-  else if (Joy_X > 712 && POS!=3 && control==true) //If joy stick moves right
-  { POS++; control = false;} //Increace position of spaceship
-  else if (Joy_X >502 && Joy_X<522) //If joystick back to initial position
-  control = true; //Prepare for next move
-  //Input from user received
+    if(d == 3){
+        //turn right
+        _x+=_speed;
+        
+        if(_x>75){
+            
+            _x = 75;
+        }
+    }else if(d == 7){
+        //turn left
+        _x-=_speed;
+        
+        if(_x<0) {
+            _x = 0;
+        }
+    }
+}
 
 // get the position of the spaceship
-Vector2D Spaceship::get_pos()
+Vector2D Spaceship::get_Pos()
 {
     Vector2D p = {_x,_y};
     return p;
-}
-// set the position of the spaceship
-void Spaceship::set_pos(Vector2D p)
-{
-    _x = p.x;
-    _y = p.y;
-}
-
-// add score when pass pillars
-void Spaceship::add_score()
-{
-    _score++;
-}
-
-// get score
-int Spaceship::get_score()
-{
-    return _score;
-}
-
-// the life of the spaceship
-void Spaceship::set_life()
-{
-    _life++;
-}
-
-// get life
-int Spaceship::get_life()
-{
-    return _life;
 }
\ No newline at end of file