Musallam Bseiso / Engine

Files at this revision

API Documentation at this revision

Comitter:
musallambseiso
Date:
Thu Apr 06 09:38:06 2017 +0000
Parent:
6:cae24a40ab34
Child:
8:1c0bc1a08153
Commit message:
Added 6th ship

Changed in this revision

Engine.cpp Show annotated file Show diff for this revision Revisions of this file
Engine.h Show annotated file Show diff for this revision Revisions of this file
--- a/Engine.cpp	Sun Apr 02 17:47:21 2017 +0000
+++ b/Engine.cpp	Thu Apr 06 09:38:06 2017 +0000
@@ -22,7 +22,7 @@
     _ship3.init(_ship_size,_speed);
     _ship4.init(_ship_size,_speed);
     _ship5.init(_ship_size,_speed);
-    _bullet.init(lcd,pad,_speed);
+    _ship6.init(_ship_size,_speed);
 }
 
 void Engine::read_input(Gamepad &pad)
@@ -34,53 +34,50 @@
 void Engine::draw(N5110 &lcd)
 {
     lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+    lcd.drawLine(0,39,84,39,1);
     _friendly.draw(lcd);
-    _bullet.draw(lcd);
-}
-
-void Engine::ship1_gen(N5110 &lcd)
-{
-    _ship1.draw(lcd);
-}
-
-void Engine::ship2_gen(N5110 &lcd)
-{
-    _ship2.draw(lcd);
+    _stats.draw_health(lcd);
 }
 
-void Engine::ship3_gen(N5110 &lcd)
+void Engine::ships_gen(N5110 &lcd)
 {
+    _ship1.draw(lcd);
+    _ship2.draw(lcd);
     _ship3.draw(lcd);
+    _ship4.draw(lcd);
+    _ship5.draw(lcd);
+    _ship6.draw(lcd);
 }
 
-void Engine::ship4_gen(N5110 &lcd)
-{
-    _ship4.draw(lcd);
-}
-
-void Engine::ship5_gen(N5110 &lcd)
+void Engine::checker(N5110 &lcd, Gamepad &pad)
 {
-    _ship5.draw(lcd);
-}
-
-void Engine::bullet_gen(N5110 &lcd)
-{
-    _bullet.draw(lcd);
+    check_pass(pad);
+    check_death(lcd, pad);
 }
 
 void Engine::update(N5110 &lcd, Gamepad &pad)
 {
-    check_pass(pad);
-
     _friendly.update(_d,_mag);
     _ship1.update();
     _ship2.update();
     _ship3.update();
     _ship4.update();
     _ship5.update();
-    _bullet.update();
+    _ship6.update();
+}
+
+void Engine::shoot(N5110 &lcd, Gamepad &pad, int speed)
+{
+    _speed = speed;
     
-    check_death(lcd, pad);
+    if (pad.check_event(Gamepad::A_PRESSED) == true) 
+    {    
+    pad.tone(1200.0,0.1);
+    //_bullet.init(lcd, pad, _speed);
+    //_bullet.draw(lcd);
+    //_bullet.update();
+    }
+    
 }
 
 void Engine::check_pass(Gamepad &pad)
@@ -114,11 +111,22 @@
     if (ship5_pos.x + _ship_size < 0) {
         _ship5.init(_ship_size,_speed);
     }
+    
+    Vector2D ship6_pos = _ship6.get_pos();
+    
+    if (ship6_pos.x + _ship_size < 0) {
+        _ship6.init(_ship_size,_speed);
+    }
 }
 
-void Engine::death(Gamepad &pad)
+void Engine::death(N5110 &lcd, Gamepad &pad)
 {
-    
+    if (dead == true) {
+        lcd.clear();
+        lcd.printString("lol u ded",0,1);
+        wait(2);    
+        dead = false;
+    }
 }
 
 void Engine::check_death1(N5110 &lcd, Gamepad &pad)
@@ -134,6 +142,7 @@
     ) {
 
         pad.tone(800.0,0.1);
+        dead = true;
     }
 }
 
@@ -201,6 +210,21 @@
     }
 }
 
+void Engine::check_death6(N5110 &lcd, Gamepad &pad)
+{
+    Vector2D friendly_pos = _friendly.get_pos();
+    Vector2D ship6_pos = _ship6.get_pos();
+    
+    if (
+        (friendly_pos.y >= ship6_pos.y-5) && // change 5 to friendly size and 6 to ship size
+        (friendly_pos.y <= ship6_pos.y+5) && 
+        (friendly_pos.x+6 >= ship6_pos.x) && 
+        (friendly_pos.x+6 <= ship6_pos.x+5)  
+    ) {
+
+        pad.tone(800.0,0.1);
+    }
+}
 void Engine::check_death(N5110 &lcd, Gamepad &pad)
 {
     check_death1(lcd, pad);
@@ -208,4 +232,5 @@
     check_death3(lcd, pad);
     check_death4(lcd, pad);
     check_death5(lcd, pad);
+    check_death6(lcd, pad);
 }
\ No newline at end of file
--- a/Engine.h	Sun Apr 02 17:47:21 2017 +0000
+++ b/Engine.h	Thu Apr 06 09:38:06 2017 +0000
@@ -9,8 +9,10 @@
 #include "Ship3.h"
 #include "Ship4.h"
 #include "Ship5.h"
+#include "Ship6.h"
 #include "Friendly.h"
 #include "Bullet.h"
+#include "Stats.h"
 
 // gap from edge of screen
 #define GAP 2
@@ -21,17 +23,17 @@
 public:
     Engine();
     ~Engine();
+    
+    bool dead;
 
     void init(int friendly_width,int friendly_height,int ship_size,int speed,N5110 &lcd, Gamepad &pad);
     void read_input(Gamepad &pad);
+    void checker(N5110 &lcd, Gamepad &pad);
     void update(N5110 &lcd, Gamepad &pad);
-    void draw(N5110 &lcd);
-    void ship1_gen(N5110 &lcd);
-    void ship2_gen(N5110 &lcd);
-    void ship3_gen(N5110 &lcd);
-    void ship4_gen(N5110 &lcd);
-    void ship5_gen(N5110 &lcd);
-    void bullet_gen(N5110 &lcd);
+    void draw(N5110 &lcd);    
+    void ships_gen(N5110 &lcd);
+    void shoot(N5110 &lcd, Gamepad &pad, int speed);
+    void death(N5110 &lcd, Gamepad &pad);
     
 private:
 
@@ -43,8 +45,8 @@
     void check_death3(N5110 &lcd, Gamepad &pad);
     void check_death4(N5110 &lcd, Gamepad &pad);
     void check_death5(N5110 &lcd, Gamepad &pad);
+    void check_death6(N5110 &lcd, Gamepad &pad);
     void check_death(N5110 &lcd, Gamepad &pad);
-    void death(Gamepad &pad);
     
     Friendly _friendly;
      
@@ -60,7 +62,9 @@
     Ship3 _ship3;
     Ship4 _ship4;
     Ship5 _ship5;
+    Ship6 _ship6;
     Bullet _bullet;
+    Stats _stats;
          
     Direction _d;
     float _mag;