diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/3d.cpp | 28 | ||||
-rw-r--r-- | example/collision.cpp | 42 | ||||
-rw-r--r-- | example/pong.cpp | 136 | ||||
-rw-r--r-- | example/test.cpp | 110 |
4 files changed, 158 insertions, 158 deletions
diff --git a/example/3d.cpp b/example/3d.cpp index e488da1..1b7e9e1 100644 --- a/example/3d.cpp +++ b/example/3d.cpp @@ -14,27 +14,27 @@ class testobject : cObject { public: - testobject() - { - setSize(10,5); - cc = 0; + testobject() + { + setSize(10,5); + cc = 0; - drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); - } + drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); + } - ~testobject() { destruct(); } + ~testobject() { destruct(); } - virtual void onClick(sPos _pos, unsigned int _button) - { - cc++; - drawText(std::to_string(cc), {2,2}, _COL_RED); + virtual void onClick(sPos _pos, unsigned int _button) + { + cc++; + drawText(std::to_string(cc), {2,2}, _COL_RED); - drawPoint('Q', _pos, _COL_YELLOW); - } + drawPoint('Q', _pos, _COL_YELLOW); + } virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1}, _COL_BLUE); } private: - int cc; + int cc; }; int main(int argc, char* argv[]) diff --git a/example/collision.cpp b/example/collision.cpp index e46c423..3dd823f 100644 --- a/example/collision.cpp +++ b/example/collision.cpp @@ -14,35 +14,35 @@ class testobject : cObject { public: - testobject() - { - setSize(10,5); - cc = 0; - kc = 0; + testobject() + { + setSize(10,5); + cc = 0; + kc = 0; - drawRectangle('#', 0, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); - } + drawRectangle('#', 0, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); + } - ~testobject() { destruct(); } + ~testobject() { destruct(); } - virtual void onClick(sPos _pos, unsigned int _button) - { - cc++; - drawText(std::to_string(cc), {2,2}, _COL_RED); + virtual void onClick(sPos _pos, unsigned int _button) + { + cc++; + drawText(std::to_string(cc), {2,2}, _COL_RED); - drawPoint('Q', _pos, _COL_YELLOW); - } + drawPoint('Q', _pos, _COL_YELLOW); + } - virtual bool onCollisionActive(sPos _hit, int _passiveObject){ - kc++; - drawText(std::to_string(kc), {0,0}, _COL_RED); - return true; - } + virtual bool onCollisionActive(sPos _hit, int _passiveObject){ + kc++; + drawText(std::to_string(kc), {0,0}, _COL_RED); + return true; + } virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1}, _COL_BLUE); } private: - int cc; - int kc; + int cc; + int kc; }; int main(int argc, char* argv[]) diff --git a/example/pong.cpp b/example/pong.cpp index df91b53..2716fa7 100644 --- a/example/pong.cpp +++ b/example/pong.cpp @@ -7,93 +7,93 @@ class ball : public cObject { public: - ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, _COL_RED); } - ~ball() { destruct(); } - virtual bool onCollisionActive(sPos _hit, int _passiveObject) - { - if(_passiveObject == 1) - v.y = v.y * (-1); - else if (_passiveObject == 2) - v.x = v.x * (-1); - - drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN); - return true; - } - sPos getV() { return v; } + ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, ansi_color_fg(0,0,255) | ansi_color_bg(255,0,0)); } + ~ball() { destruct(); } + virtual bool onCollisionActive(sPos _hit, int _passiveObject) + { + if(_passiveObject == 1) + v.y = v.y * (-1); + else if (_passiveObject == 2) + v.x = v.x * (-1); + + //drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN); + return true; + } + sPos getV() { return v; } private: - sPos v; + sPos v; }; class bar : public cObject { public: - bar() { setSize(1,5); drawLine('|', {0,0},{0,4}, _COL_BLUE);} - ~bar() { destruct(); } - virtual int onCollisionPassive(sPos _hit){ return 2; } - virtual bool onCollisionActive(sPos _hit, int _passiveObject){ return true; } + bar() { setSize(1,5); drawLine('|', {0,0},{0,4}, _COL_BLUE);} + ~bar() { destruct(); } + virtual int onCollisionPassive(sPos _hit){ return 2; } + virtual bool onCollisionActive(sPos _hit, int _passiveObject){ return true; } }; class edge : public cObject { public: - edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{(int)x-1,(int)y-1}, _COL_DEFAULT);} - ~edge() { destruct(); } - virtual int onCollisionPassive(sPos _hit) - { - if(getSize().x > getSize().y) - return 1; - else - return 2; - } + edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{(int)x-1,(int)y-1}, _COL_DEFAULT);} + ~edge() { destruct(); } + virtual int onCollisionPassive(sPos _hit) + { + if(getSize().x > getSize().y) + return 1; + else + return 2; + } }; int main() { - cRender render(' ', _COL_DEFAULT); - cObjectHandler screen(&render); - cInput input; + cRender render(' ', _COL_DEFAULT); + cObjectHandler screen(&render); + cInput input; - render.render(); - render.setTargetFPS(20); + render.render(); + render.setTargetFPS(20); - sPos size = render.getSize(); + sPos size = render.getSize(); - bar barLeft; - bar barRight; - ball aball; - edge edgeLeft(1,size.y - 2); - edge edgeRight(1,size.y - 2); - edge edgeTop(size.x - 2,1); - edge edgeBottom(size.x - 2,1); + bar barLeft; + bar barRight; + ball aball; + edge edgeLeft(1,size.y - 2); + edge edgeRight(1,size.y - 2); + edge edgeTop(size.x - 2,1); + edge edgeBottom(size.x - 2,1); - int iEdgeTop = screen.createObject(&edgeTop); - screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeTop = screen.createObject(&edgeTop); + screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE); - int iEdgeBottom = screen.createObject(&edgeBottom); - screen.moveObject(iEdgeBottom, {0,size.y - 3}, _MOVE_FORCE_ABSOLUTE); + int iEdgeBottom = screen.createObject(&edgeBottom); + screen.moveObject(iEdgeBottom, {0,size.y - 3}, _MOVE_FORCE_ABSOLUTE); - int iEdgeLeft = screen.createObject(&edgeLeft); - screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeLeft = screen.createObject(&edgeLeft); + screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE); - int iEdgeRight = screen.createObject(&edgeRight); - screen.moveObject(iEdgeRight, {size.x - 2,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeRight = screen.createObject(&edgeRight); + screen.moveObject(iEdgeRight, {size.x - 2,0}, _MOVE_FORCE_ABSOLUTE); - int iAball= screen.createObject(&aball); - screen.moveObject(iAball, {size.x/2,size.y/2}, _MOVE_FORCE_ABSOLUTE); + int iAball= screen.createObject(&aball); + screen.moveObject(iAball, {size.x/2,size.y/2}, _MOVE_FORCE_ABSOLUTE); - unsigned int iBarLeft = screen.createObject(&barLeft); - screen.moveObject(iBarLeft, {10,4}, _MOVE_FORCE_ABSOLUTE); + unsigned int iBarLeft = screen.createObject(&barLeft); + screen.moveObject(iBarLeft, {10,4}, _MOVE_FORCE_ABSOLUTE); - unsigned int iBarRight = screen.createObject(&barRight); - screen.moveObject(iBarRight, {size.x - 10,4}, _MOVE_FORCE_ABSOLUTE); + unsigned int iBarRight = screen.createObject(&barRight); + screen.moveObject(iBarRight, {size.x - 10,4}, _MOVE_FORCE_ABSOLUTE); - unsigned int cc = 0; + unsigned int cc = 0; - while(1) - { - sInputEvent ie = input.poll(); + while(1) + { + sInputEvent ie = input.poll(); if(ie.type != _EVENT_NULL) { @@ -124,22 +124,22 @@ int main() break; case 's': screen.moveObject(iBarLeft, {0,1}, _MOVE_RELATIVE); - break; - case 'g': - render.enableDebugInfo(true); + break; + case 'g': + render.enableDebugInfo(true); }; } else if (ie.type == _EVENT_TERM) { return 0; } - } - if(!(++cc % 3)) - screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE); + } + if(!(++cc % 3)) + screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE); - screen.write(); - render.render(); - } + screen.write(); + render.render(); + } - return 0; + return 0; } diff --git a/example/test.cpp b/example/test.cpp index 7c1e3a0..034c365 100644 --- a/example/test.cpp +++ b/example/test.cpp @@ -6,88 +6,88 @@ class ball : public cObject { public: - ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, _COL_RED); } - ~ball() { destruct(); } - virtual bool onCollisionActive(sPos _hit, int _passiveObject) - { - if(_passiveObject == 1) - v.y = v.y * (-1); - else if (_passiveObject == 2) - v.x = v.x * (-1); - - drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN); - return true; - } - sPos getV() { return v; } + ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, _COL_RED); } + ~ball() { destruct(); } + virtual bool onCollisionActive(sPos _hit, int _passiveObject) + { + if(_passiveObject == 1) + v.y = v.y * (-1); + else if (_passiveObject == 2) + v.x = v.x * (-1); + + drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN); + return true; + } + sPos getV() { return v; } private: - sPos v; + sPos v; }; class edge : public cObject { public: - edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{(int)x-1,(int)y-1}, _COL_DEFAULT);} - ~edge() { destruct(); } - virtual int onCollisionPassive(sPos _hit) - { - if(getSize().x > getSize().y) - return 1; - else - return 2; - } + edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{(int)x-1,(int)y-1}, _COL_DEFAULT);} + ~edge() { destruct(); } + virtual int onCollisionPassive(sPos _hit) + { + if(getSize().x > getSize().y) + return 1; + else + return 2; + } }; int main() { - cRender render(' ', _COL_DEFAULT); - cObjectHandler screen(&render); - cInput input; + cRender render(' ', _COL_DEFAULT); + cObjectHandler screen(&render); + cInput input; - render.forceScreenSize({20,20}); - render.mute(true); + render.forceScreenSize({20,20}); + render.mute(true); - ball aball; - edge edgeLeft(1,10); - edge edgeRight(1,10); - edge edgeTop(10,1); - edge edgeBottom(10,1); + ball aball; + edge edgeLeft(1,10); + edge edgeRight(1,10); + edge edgeTop(10,1); + edge edgeBottom(10,1); - int iEdgeTop = screen.createObject(&edgeTop); - screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeTop = screen.createObject(&edgeTop); + screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE); - int iEdgeBottom = screen.createObject(&edgeBottom); - screen.moveObject(iEdgeBottom, {0,10}, _MOVE_FORCE_ABSOLUTE); + int iEdgeBottom = screen.createObject(&edgeBottom); + screen.moveObject(iEdgeBottom, {0,10}, _MOVE_FORCE_ABSOLUTE); - int iEdgeLeft = screen.createObject(&edgeLeft); - screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeLeft = screen.createObject(&edgeLeft); + screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE); - int iEdgeRight = screen.createObject(&edgeRight); - screen.moveObject(iEdgeRight, {9,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeRight = screen.createObject(&edgeRight); + screen.moveObject(iEdgeRight, {9,0}, _MOVE_FORCE_ABSOLUTE); - int iAball= screen.createObject(&aball); - screen.moveObject(iAball, {2,2}, _MOVE_FORCE_ABSOLUTE); + int iAball= screen.createObject(&aball); + screen.moveObject(iAball, {2,2}, _MOVE_FORCE_ABSOLUTE); - render.render(); + render.render(); - for(unsigned int cc = 0; cc < 9999; cc++) - { + for(unsigned int cc = 0; cc < 9999; cc++) + { - sInputEvent ie = input.poll(); + sInputEvent ie = input.poll(); if(ie.type != _EVENT_NULL) { - if (ie.type == _EVENT_TERM) + if (ie.type == _EVENT_TERM) { return 0; } - } + } - if(!(++cc % 3)) - screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE); + if(!(++cc % 3)) + screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE); - screen.write(); - render.render(); - } + screen.write(); + render.render(); + } - return 0; + return 0; } |