Uses accompanying Basket, Objects and Fruit libraries to create Fruit Basket game. If an object is caught, points are added; if an object in missed, a 'life' is lost.

Dependents:   Game_Controller_Project

Revision:
4:84e29254b988
Parent:
3:fc9133faec7a
Child:
5:7db3e43e5aca
--- a/Catch_Model.cpp	Tue Mar 21 11:12:18 2017 +0000
+++ b/Catch_Model.cpp	Thu Mar 23 15:26:39 2017 +0000
@@ -10,15 +10,15 @@
     
 }
 
-void Catch_Model::init(int basket_y, int basket_width, int objects_speed)
+void Catch_Model::init(int basket_y, int basket_width, int objects_speed, int lives)
 {
     _basket_y = basket_y;
     _basket_width = basket_width;
-    
     _objects_speed = objects_speed;
+    _lives = lives;
     
-    _basket.Basket_init(_basket_y, _basket_width);
-    _objects.Objects_init(_objects_speed);
+    basket.init(_basket_y, _basket_width);
+    objects.init(_objects_speed);
 }
 
 void Catch_Model::input(Gamepad &pad)
@@ -32,57 +32,86 @@
     check_basket_catch(lcd, pad);
     check_basket_miss(lcd, pad);
     
-    print_score(lcd);
-    
-    _basket.Basket_move(_d, _mag);
-    _objects.Objects_move();
+    basket.move(_d, _mag, pad);
+    objects.move();
 }
 
 void Catch_Model::draw(N5110 &lcd)
 {
-    _basket.Basket_draw(lcd);
-    _objects.Objects_draw(lcd);
+    basket.draw(lcd);
+    objects.draw(lcd);
+    print_score(lcd);
+    print_lives(lcd);
 }
 
 void Catch_Model::check_basket_catch(N5110 &lcd, Gamepad &pad)
 {
-   int b_x_pos = _basket.get_Basket_x();
-   int b_y_pos = _basket.get_Basket_y();
-   int o_x_pos = _objects.get_Objects_x();
-   int o_y_pos = _objects.get_Objects_y();
+   int b_x_pos = basket.get_x();
+   int b_y_pos = basket.get_y();
+   int o_x_pos = objects.get_x();
+   int o_y_pos = objects.get_y();
     
     if(
        (o_y_pos >= b_y_pos) &&
        (o_x_pos > b_x_pos) &&
        (o_x_pos <= (b_x_pos + 5))
        ) {
-           _objects.Objects_undraw(lcd);
-           _basket.Basket_score();
-           _objects.Objects_init(_objects_speed);
+           objects.undraw(lcd);
+           basket.add_score();
+           objects.init(_objects_speed);
     }
 }
 
 void Catch_Model::check_basket_miss(N5110 &lcd, Gamepad &pad)
 {
-   int b_x_pos = _basket.get_Basket_x();
-   int b_y_pos = _basket.get_Basket_y();
-   int o_x_pos = _objects.get_Objects_x();
-   int o_y_pos = _objects.get_Objects_y();
+   int b_x_pos = basket.get_x();
+   int b_y_pos = basket.get_y();
+   int o_x_pos = objects.get_x();
+   int o_y_pos = objects.get_y();
    
    if (o_y_pos > b_y_pos) {
-       _objects.Objects_undraw(lcd);
-       _objects.Objects_init(_objects_speed);
+       objects.undraw(lcd);
+       objects.init(_objects_speed);
+       _lives--;
    } 
 }
 
+int Catch_Model::get_lives() 
+{
+    return _lives;
+}
+
+void Catch_Model::print_lives(N5110 &lcd)
+{
+    char buffer[14];
+    int lives = get_lives();
+    
+    int print_lives = sprintf(buffer, "LIVES:%d", lives);
+    if (print_lives <= 14) {
+        lcd.printString(buffer,0,0);
+        lcd.refresh();
+    }
+}
+
 void Catch_Model::print_score(N5110 &lcd)
 {
     char buffer[14];
+    int score = basket.get_score();
     
-    int score = _basket.get_Basket_score();
-    int print_score = sprintf(buffer, "SCORE: %2d", score);
+    int print_score;
+    
+    if ((score == 0)||(score <= 9)) {
+        print_score = sprintf(buffer, "000%d", score);
+    } else if (score <= 99) {
+        print_score = sprintf(buffer, "00%2d", score);
+    } else if (score <= 999 ) {
+        print_score = sprintf(buffer, "0%3d", score);
+    } else {
+        print_score = sprintf(buffer, "%4d", score);
+    }
+    
     if (print_score <= 14) {
-        lcd.printString(buffer,0,0);
+        lcd.printString(buffer,59,0);
         lcd.refresh();
     }
 }