aboutsummaryrefslogtreecommitdiff
path: root/AmpelJonas/cCrossroad.cpp
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2016-09-25 18:38:34 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2016-09-25 18:38:34 +0200
commit2c12d19204aa198bf8537bcdb137b40f0c7317e9 (patch)
tree2b0ea3e0feb0df50449fdd99e0b1dfa3a2f82c16 /AmpelJonas/cCrossroad.cpp
downloadtermgl-2c12d19204aa198bf8537bcdb137b40f0c7317e9.tar.gz
Initial
Diffstat (limited to 'AmpelJonas/cCrossroad.cpp')
-rw-r--r--AmpelJonas/cCrossroad.cpp177
1 files changed, 177 insertions, 0 deletions
diff --git a/AmpelJonas/cCrossroad.cpp b/AmpelJonas/cCrossroad.cpp
new file mode 100644
index 0000000..10718f6
--- /dev/null
+++ b/AmpelJonas/cCrossroad.cpp
@@ -0,0 +1,177 @@
+#include "cCrossroad.h"
+
+cCrossroad::cCrossroad()
+{
+ render = new cRender(' ', _COL_GREEN, _SIZE_X_, _SIZE_Y_);
+ //handler = new cObjectHandler(render);
+}
+
+cCrossroad::~cCrossroad()
+{
+ delete render;
+ //delete handler;
+}
+
+void cCrossroad::run()
+{
+ int iWait = 4;
+ int iPhase = -1;
+ int iFrames = 0;
+
+ cObjectHandler handler(render);
+ cObject *backround = new cObject(_SIZE_X_, _SIZE_Y_);
+
+ //Objects
+ cTrafficLight tlNorth(_TL_NORTH_, _TL_COL_GREEN_);
+ cTrafficLight tlSouth(_TL_SOUTH_, _TL_COL_GREEN_);
+ cTrafficLight tlEast(_TL_EAST_, _TL_COL_RED_);
+ cTrafficLight tlWest(_TL_WEST_, _TL_COL_RED_);
+
+ cPeasantTrafficLight ptl1(_CTL_1, _CTL_COL_GREEN);
+ cPeasantTrafficLight ptl2(_CTL_2, _CTL_COL_RED);
+ cPeasantTrafficLight ptl3(_CTL_3, _CTL_COL_RED);
+ cPeasantTrafficLight ptl4(_CTL_4, _CTL_COL_GREEN);
+ cPeasantTrafficLight ptl5(_CTL_5, _CTL_COL_GREEN);
+ cPeasantTrafficLight ptl6(_CTL_6, _CTL_COL_RED);
+ cPeasantTrafficLight ptl7(_CTL_7, _CTL_COL_RED);
+ cPeasantTrafficLight ptl8(_CTL_8, _CTL_COL_GREEN);
+
+ cCar carSouth(_CAR_DIR_SOUTH, &iPhase);
+ cCar carNorth(_CAR_DIR_NORTH, &iPhase);
+ cCar carEast(_CAR_DIR_EAST, &iPhase);
+ cCar carWest(_CAR_DIR_WEST, &iPhase);
+
+ cPeasant peasantNorth(_PE_DIR_NORTH, &iPhase);
+ cPeasant peasantWest(_PE_DIR_WEST, &iPhase);
+
+ //init
+ backround->setPosition(0, 0);
+ backround->drawRectangle('°', '°', sPos{ 0, _SIZE_Y_ / 2 - 4 }, sPos{ _SIZE_X_ - 1, _SIZE_Y_ / 2 + 4 }, _COL_DEFAULT, _COL_DEFAULT);
+ backround->drawRectangle('°', '°', sPos{ _SIZE_X_ / 2 - 6, 0 }, sPos{ _SIZE_X_ / 2 + 6, _SIZE_Y_ }, _COL_DEFAULT, _COL_DEFAULT);
+
+ //add objects to handler
+ handler.createObject(backround);
+
+ handler.createObject(tlNorth.getObject());
+ handler.createObject(tlSouth.getObject());
+ handler.createObject(tlEast.getObject());
+ handler.createObject(tlWest.getObject());
+
+ handler.createObject(ptl1.getObject());
+ handler.createObject(ptl2.getObject());
+ handler.createObject(ptl3.getObject());
+ handler.createObject(ptl4.getObject());
+ handler.createObject(ptl5.getObject());
+ handler.createObject(ptl6.getObject());
+ handler.createObject(ptl7.getObject());
+ handler.createObject(ptl8.getObject());
+
+ handler.createObject(carSouth.getObject());
+ handler.createObject(carNorth.getObject());
+ handler.createObject(carEast.getObject());
+ handler.createObject(carWest.getObject());
+
+ handler.createObject(peasantNorth.getObject());
+ handler.createObject(peasantWest.getObject());
+
+ handler.write();
+ render->render();
+
+ //main Loop
+
+ //Starting with vertical Green, horizontal red
+
+ while(1)
+ {
+ if (iWait <= 0)
+ {
+ iPhase++;
+ switch (iPhase)
+ {
+ case 0: //ptls to red
+ ptl1.next();
+ ptl4.next();
+ ptl5.next();
+ ptl8.next();
+ iWait = 4;
+ break;
+ case 1: //switch to yellow
+ tlNorth.next();
+ tlSouth.next();
+ iWait = 4;
+ break;
+ case 2: //to red
+ tlNorth.next();
+ tlSouth.next();
+ iWait = 4;
+ break;
+ case 3: //Yellow-Red
+ tlEast.next();
+ tlWest.next();
+ iWait = 4;
+ break;
+ case 4: //Green
+ tlEast.next();
+ tlWest.next();
+ ptl2.next();
+ ptl3.next();
+ ptl7.next();
+ ptl6.next();
+ iWait = 10;
+ break;
+ case 5: //vert ptls to red
+ ptl2.next();
+ ptl3.next();
+ ptl7.next();
+ ptl6.next();
+ iWait = 4;
+ break;
+ case 6: //Yellow-red
+ tlEast.next();
+ tlWest.next();
+ iWait = 4;
+ break;
+ case 7: //red
+ tlEast.next();
+ tlWest.next();
+ iWait = 4;
+ break;
+ case 8: //yellow-red
+ tlNorth.next();
+ tlSouth.next();
+ iWait = 4;
+ break;
+ case 9: //green
+ tlNorth.next();
+ tlSouth.next();
+ ptl1.next();
+ ptl4.next();
+ ptl5.next();
+ ptl8.next();
+ iPhase = -1;
+ iWait = 10;
+ break;
+ }
+ }
+
+
+ carWest.drive();
+ carEast.drive();
+ carNorth.drive();
+ carSouth.drive();
+
+ if (iFrames % 2 == 0) { //Run every 2nd frame
+ peasantNorth.run();
+ peasantWest.run();
+ }
+
+
+
+ handler.write();
+ render->render();
+
+ iWait--;
+ iFrames++;
+ backround->drawText(to_string(iFrames) , sPos{ 0,0 }, _COL_DEFAULT); //Framecounter
+ }
+} \ No newline at end of file