summaryrefslogtreecommitdiff
path: root/AmpelJonas/cCar.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/cCar.cpp
downloadtermgl-2c12d19204aa198bf8537bcdb137b40f0c7317e9.tar.gz
Initial
Diffstat (limited to 'AmpelJonas/cCar.cpp')
-rw-r--r--AmpelJonas/cCar.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/AmpelJonas/cCar.cpp b/AmpelJonas/cCar.cpp
new file mode 100644
index 0000000..212cd7c
--- /dev/null
+++ b/AmpelJonas/cCar.cpp
@@ -0,0 +1,84 @@
+#include "cCar.h"
+
+cCar::cCar(int _direction, int *_phase)
+{
+ pPhase = _phase;
+ iDirection = _direction;
+ if (iDirection ==_CAR_DIR_NORTH) { //South or north
+ car = new cObject(4, 4);
+ car->setPosition(_SIZE_X_ / 2 - 4, - 4 );
+ car->drawRectangle('+', 'X', sPos{ 0,0 }, sPos{3,3}, _COL_RED, _COL_RED);
+ }
+ else if (iDirection == _CAR_DIR_SOUTH) { //South or north
+ car = new cObject(4, 4);
+ car->setPosition(_SIZE_X_ / 2 +1, _SIZE_Y_);
+ car->drawRectangle('+', 'X', sPos{ 0,0 }, sPos{ 3,3 }, _COL_RED, _COL_RED);
+ }
+ else if(iDirection == _CAR_DIR_WEST){
+ car = new cObject(6, 3);
+ car->setPosition( -6, _SIZE_Y_ / 2 + 1);
+ car->drawRectangle('+', ' ', sPos{ 0,0 }, sPos{5, 2}, _COL_BLUE, _COL_BLUE);
+ car->drawText("AUTO", sPos{ 1,1 }, _COL_BLUE);
+ }
+ else if (iDirection == _CAR_DIR_EAST)
+ {
+ car = new cObject(6, 3);
+ car->setPosition(_SIZE_X_, _SIZE_Y_ / 2 -3);
+ car->drawRectangle('+', ' ', sPos{ 0,0 }, sPos{ 5, 2 }, _COL_BLUE, _COL_BLUE);
+ car->drawText("AUTO", sPos{ 1,1 }, _COL_BLUE);
+ }
+}
+
+cCar::~cCar()
+{
+ delete car;
+}
+
+cObject *cCar::getObject()
+{
+ return car;
+}
+
+void cCar::drive()
+{
+ sPos oldPos;
+ switch(iDirection)
+ {
+ case _CAR_DIR_EAST:
+ oldPos = car->getPosition();
+ if (!((*pPhase != 5 && *pPhase != 4) && oldPos.x == (_SIZE_X_ / 2) + 11)){
+ car->setPosition(oldPos.x - 1, oldPos.y);
+ }
+ if (oldPos.x < -6) {
+ car->setPosition(_SIZE_X_, oldPos.y);
+ }
+ break;
+ case _CAR_DIR_WEST:
+ oldPos = car->getPosition();
+ if (!((*pPhase != 5 && *pPhase != 4) && oldPos.x == (_SIZE_X_ / 2) - 15)){
+ car->setPosition(oldPos.x + 1, oldPos.y);
+ }
+ if (oldPos.x > _SIZE_X_) {
+ car->setPosition(-6 , oldPos.y);
+ }
+ break;
+ case _CAR_DIR_NORTH:
+ oldPos = car->getPosition();
+ if (!((*pPhase != 0 && *pPhase != 9 && *pPhase != -1) && oldPos.y == (_SIZE_Y_ / 2) - 11)) {
+ car->setPosition(oldPos.x, oldPos.y + 1);
+ }
+ if (oldPos.y > _SIZE_Y_) {
+ car->setPosition(oldPos.x, -4);
+ }
+ break;
+ case _CAR_DIR_SOUTH:
+ oldPos = car->getPosition();
+ if (!((*pPhase != 0 && *pPhase != 9 && *pPhase != -1) && oldPos.y == (_SIZE_Y_ / 2) + 8)) {
+ car->setPosition(oldPos.x, oldPos.y - 1);
+ }
+ if (oldPos.y < -4) {
+ car->setPosition(oldPos.x, _SIZE_Y_);
+ }
+ break;
+ }
+} \ No newline at end of file