Dependencies:   mbed FATFileSystem

Revision:
19:065207c07c3c
Parent:
18:14e5391beccf
Child:
20:01efa2bce75d
--- a/SceneCreator/SceneCreator.cpp	Wed May 08 01:49:54 2019 +0000
+++ b/SceneCreator/SceneCreator.cpp	Wed May 08 02:45:11 2019 +0000
@@ -21,47 +21,53 @@
 
 //Primary Function
 void SceneCreator::Scenesp(Bitmap &lcd, CaMove &CM,short int spl,short int spx,short int spy, Direction spd, int rng,WDplayer &wav) {
+    this->setup(lcd,CM,spl,spx,spy,spd,wav);
+    this->set_sreg(CM,spl);
+    bool p[6] = {true,true,true,true,true,true};  //Array to allow Pos Events to disable or enable Pre Events
+    while(!dead && CM.in_screen()) {
+        dynatime.start();
+        lcd.clear();
+        wav.ISRpreload();
+        lcd.renderBMP(SCN[spl],0,0);
+        this->Core_1(lcd, CM,spl,rng,p);  //CORE_1 (Pre Events Engine)
+        this->update_charaters(lcd,CM,spl,wav);
+        this->Core_2(lcd, CM,spl,rng,p,wav);  //CORE_2 (Pos Event Engine)
+        if (CM.is_caught()) {
+            dead = true;
+        }
+        lcd.refresh();
+        this->dynamic_wait();
+    };
+    wav.ISRreset();
+    CM.delete_regions();
+};
+
+void SceneCreator::update_charaters(Bitmap &lcd,CaMove &CM,short int spl,WDplayer &wav) {
+    //Charater and Chaser Model Update
+    CM.move(lcd);
+    CM.chase(lcd,spl);
+    wav.ISRpreload();
+}
+
+void SceneCreator::dynamic_wait() {
+    //Will aim for 7 frames per second if too heavy of performance impacting frame rate will drop
+    dynatime.stop();
+    float waittime = 0.15f - dynatime.read();
+    if (waittime > 0.00000f) {
+        wait(waittime);
+    }
+    dynatime.reset();
+}
+
+void SceneCreator::setup(Bitmap &lcd,CaMove &CM,short int spl,short int spx,short int spy, Direction spd,WDplayer &wav) {
     //Setting up WDplayer, CaMove and Scene interative regions
     wav.ISRset();
     CM.init(spx,spy,spd);
     CM.AIinit(spl);
     lcd.normalMode();
     this->set_sreg(CM,spl);
-    //Array to allow Pos Events to disable or enable Pre Events
-    bool p[6] = {true,true,true,true,true,true};
-    //Main Loop exit if charater dead or leaves screen
-    while(!dead && CM.in_screen()) {
-        //start timer
-        dynatime.start();
-        lcd.clear();
-        //reload WDplayer data then Load map data
-        wav.ISRpreload();
-        lcd.renderBMP(SCN[spl],0,0);
-        //CORE_1 (Pre Events Engine)
-        this->Core_1(lcd, CM,spl,rng,p);
-        //Charater and Chaser Model Update
-        CM.move(lcd);
-        CM.chase(lcd,spl);
-        wav.ISRpreload();
-        //CORE_2 (Pos Event Engine)
-        this->Core_2(lcd, CM,spl,rng,p,wav);
-        if (CM.is_caught()) {
-            dead = true;
-        }
-        lcd.refresh();
-        //Dynamic Wait
-        dynatime.stop();
-        float waittime = 0.15f - dynatime.read();
-        if (waittime > 0.00000f) {
-            wait(waittime);
-        }
-        dynatime.reset();
-        //Will aim for 7 frames per second if too heavy of performance impacting frame rate will drop
-    };
-    //reset WDplayer and Delete interative regions
-    wav.ISRreset();
-    CM.delete_regions();
-};
+}
+
 
 //CORE_1 (Pre EVENTS)
 void SceneCreator::Core_1(Bitmap &lcd, CaMove &CM,short int spl,int rng,bool p[6]) {
@@ -80,75 +86,41 @@
         if (p[4]) {
             this->pre_func4(spl,lcd,CM,rng);
         }
-        if (p[5]) {
-            this->pre_func5(spl,lcd,CM,rng);
-        }
 }
 
 //CORE_2 (Pos EVENTs)
 void SceneCreator::Core_2(Bitmap &lcd, CaMove &CM,short int spl,int rng,bool (&p)[6],WDplayer &wav) {
-    //Checks which region triggered
-    switch(CM.get_treg()) {
+    switch(CM.get_treg()) {  //Checks which region triggered
             case 0:
-                //pause Music
-                wav.ISRpause();
-                //Signal to player he is progressing by flashing screen (only occurs once)
-                if(p[0]) {
-                    p[0] *= false;
-                    this->flash(lcd);
-                }
-                //Do this
+                this->onetimeflash(p[0],wav,lcd);
                 this->pos_func0(spl,lcd,CM,rng);
-                //Resume Music
-                wav.ISRresume();
             break;
-            //Same For All Cases
             case 1:
-                wav.ISRpause();
-                if(p[1]) {
-                    p[1] *= false;
-                    this->flash(lcd);
-                }
+                this->onetimeflash(p[1],wav,lcd);
                 this->pos_func1(spl,lcd,CM,rng);
-                wav.ISRresume();
             break;
             case 2:
-                wav.ISRpause();
-                if(p[2]) {
-                    p[2] *= false;
-                    this->flash(lcd);
-                }
+                this->onetimeflash(p[2],wav,lcd);
                 this->pos_func2(spl,lcd,CM,rng);
-                wav.ISRresume();
             break;
             case 3:
-                wav.ISRpause();
-                if(p[3]) {
-                    p[3] *= false;
-                    this->flash(lcd);
-                }
+                this->onetimeflash(p[3],wav,lcd);
                 this->pos_func3(spl,lcd,CM,rng);
-                wav.ISRresume();
             break;
             case 4:
-                wav.ISRpause();
-                if(p[4]) {
-                    p[4] *= false;
-                    this->flash(lcd);
-                }
+                this->onetimeflash(p[4],wav,lcd);
                 this->pos_func4(spl,lcd,CM,rng);
-                wav.ISRresume();
-            break;
-            case 5:
-                wav.ISRpause();
-                if(p[5]) {
-                    p[5] *= false;
-                    this->flash(lcd);
-                }
-                this->pos_func5(spl,lcd,CM,rng);
-                wav.ISRresume();
             break;
         };
+        wav.ISRresume();
+}
+
+void SceneCreator::onetimeflash(bool uno, WDplayer &wav,Bitmap &lcd) {
+    wav.ISRpause();
+    if(uno) {
+        uno *= false;
+        this->flash(lcd);
+    }
 }
 
 //settings
@@ -262,20 +234,6 @@
     }
 }
 
-void SceneCreator::pre_func5(int sce,Bitmap &lcd,CaMove &CM,int rng) {
-    switch(sce) {
-        case 0:
-        break;
-        case 1:
-        break;
-        case 2:
-        break;
-        case 3:
-        break;
-        case 4:
-        break;
-    }
-}
 //pos func
 
 void SceneCreator::pos_func0(int sce,Bitmap &lcd,CaMove &CM,int rng) {
@@ -364,21 +322,6 @@
     }
 }
 
-void SceneCreator::pos_func5(int sce,Bitmap &lcd,CaMove &CM,int rng) {
-    switch(sce) {
-        case 0:
-        break;
-        case 1:
-        break;
-        case 2:
-        break;
-        case 3:
-        break;
-        case 4:
-        break;
-    }
-}
-
 bool SceneCreator::get_dead() {
     return dead;
 }