aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/pong.cpp71
1 files changed, 33 insertions, 38 deletions
diff --git a/example/pong.cpp b/example/pong.cpp
index 093338c..21d0d43 100644
--- a/example/pong.cpp
+++ b/example/pong.cpp
@@ -7,7 +7,7 @@
class ball : public cObject
{
public:
- ball() : v({1,1}), cc(0) { setSize(1,1); drawPoint('O', {0,0}, true, _COL_RED); }
+ ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, true, _COL_RED); }
~ball() { destruct(); }
virtual bool onCollisionActive(sPos _hit, int _passiveObject)
{
@@ -15,14 +15,14 @@ public:
v.y = v.y * (-1);
else if (_passiveObject == 2)
v.x = v.x * (-1);
- cc++;
+
drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN);
return true;
}
sPos getV() { return v; }
private:
sPos v;
- int cc;
+
};
class bar : public cObject
@@ -30,28 +30,15 @@ class bar : public cObject
public:
bar() { setSize(1,5); drawLine('|', {0,0},{0,4}, true, _COL_BLUE);}
~bar() { destruct(); }
- virtual int onCollisionPassive(){ return 2; }
-};
-
-class edges : public cObject
-{
-public:
- edges() { setSize(1,20); drawLine('#', {0,0},{0,19}, true, _COL_DEFAULT);}
- ~edges() { destruct(); }
- virtual int onCollisionPassive(sPos _hit)
- {
- if(getSize().x > getSize().y)
- return 1;
- else
- return 2;
- }
+ virtual int onCollisionPassive(sPos _hit){ return 2; }
+ virtual bool onCollisionActive(sPos _hit, int _passiveObject){ return true; }
};
-class edget : public cObject
+class edge : public cObject
{
public:
- edget() { setSize(40,1); drawLine('#', {0,0},{39, 0}, true, _COL_DEFAULT);}
- ~edget() { destruct(); }
+ edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{x-1,y-1}, true, _COL_DEFAULT);}
+ ~edge() { destruct(); }
virtual int onCollisionPassive(sPos _hit)
{
if(getSize().x > getSize().y)
@@ -67,34 +54,42 @@ int main()
cObjectHandler screen(&render);
cInput input;
- //bar barLeft, barRight;
+ bar barLeft;
+ bar barRight;
ball aball;
- edges edgeLeft;
- edges edgeRight;
- edget edgeTop;
- edget edgeBottom;
+ edge edgeLeft(1,30);
+ edge edgeRight(1,30);
+ edge edgeTop(100,1);
+ edge edgeBottom(100,1);
int iEdgeTop = screen.createObject(&edgeTop);
screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE);
int iEdgeBottom = screen.createObject(&edgeBottom);
- screen.moveObject(iEdgeBottom, {0,20}, _MOVE_FORCE_ABSOLUTE);
+ screen.moveObject(iEdgeBottom, {0,30}, _MOVE_FORCE_ABSOLUTE);
int iEdgeLeft = screen.createObject(&edgeLeft);
screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE);
int iEdgeRight = screen.createObject(&edgeRight);
- screen.moveObject(iEdgeRight, {40,0}, _MOVE_FORCE_ABSOLUTE);
-
+ screen.moveObject(iEdgeRight, {99,0}, _MOVE_FORCE_ABSOLUTE);
int iAball= screen.createObject(&aball);
- screen.moveObject(iAball, {9,6}, _MOVE_FORCE_ABSOLUTE);
+ screen.moveObject(iAball, {50,6}, _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, {90,4}, _MOVE_FORCE_ABSOLUTE);
render.render();
//printf ("%i %i %i %i %i", iEdgeTop, iEdgeBottom, iEdgeLeft, iEdgeRight, iAball);
/*return 0;*/
+ unsigned int cc = 0;
+
while(1)
{
@@ -107,17 +102,17 @@ int main()
switch (ie.c)
{
case 'A'://up
- //handler.setCameraPosition({0,-1}, _MOVE_RELATIVE);
+ screen.moveObject(iBarRight, {0,-1}, _MOVE_RELATIVE);
break;
case 'B'://down
- //handler.setCameraPosition({0,1}, _MOVE_RELATIVE);
+ screen.moveObject(iBarRight, {0,1}, _MOVE_RELATIVE);
break;
};
}
else if (ie.type == _EVENT_MOUSE)
{
- if(ie.b == 0);
- //handler.clickEvent({ie.x, ie.y}, 0);
+ if(ie.b == 0)
+ screen.clickEvent({ie.x, ie.y}, 0);
}
else if (ie.type == _EVENT_CHAR)
{
@@ -125,10 +120,10 @@ int main()
switch(ie.c)
{
case 'w':
- //handler.moveObject(iobj2, {0,-1}, _MOVE_RELATIVE);
+ screen.moveObject(iBarLeft, {0,-1}, _MOVE_RELATIVE);
break;
case 's':
- //handler.moveObject(iobj2, {0,1ngine (the most creative name I could come up with)}, _MOVE_RELATIVE);
+ screen.moveObject(iBarLeft, {0,1}, _MOVE_RELATIVE);
break;
};
}
@@ -137,8 +132,8 @@ int main()
return 0;
}
}
-
- screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE);
+ if(!(++cc % 3))
+ screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE);
screen.write();
render.render();