Elements used in the Balls and Things games for the RETRO.
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles
Shapes.h@8:19dd2a538cbe, 2015-03-02 (annotated)
- Committer:
- maxint
- Date:
- Mon Mar 02 09:58:53 2015 +0000
- Revision:
- 8:19dd2a538cbe
- Parent:
- 4:f421e34313d3
more clean-up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maxint | 0:3d0db4e183ee | 1 | #pragma once |
maxint | 8:19dd2a538cbe | 2 | #include <algorithm> // required for min() and max(), see http://www.cplusplus.com/reference/algorithm/ |
maxint | 0:3d0db4e183ee | 3 | #include "mbed.h" |
maxint | 0:3d0db4e183ee | 4 | #include "Vector.h" |
maxint | 0:3d0db4e183ee | 5 | |
maxint | 8:19dd2a538cbe | 6 | //#define MAX(x, y) (((x) > (y)) ? (x) : (y)) |
maxint | 8:19dd2a538cbe | 7 | //#define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
maxint | 3:441dc90d10ce | 8 | |
maxint | 0:3d0db4e183ee | 9 | class Point |
maxint | 0:3d0db4e183ee | 10 | { |
maxint | 0:3d0db4e183ee | 11 | protected : |
maxint | 0:3d0db4e183ee | 12 | int x1, y1; |
maxint | 0:3d0db4e183ee | 13 | |
maxint | 0:3d0db4e183ee | 14 | public : |
maxint | 0:3d0db4e183ee | 15 | Point(); |
maxint | 0:3d0db4e183ee | 16 | Point(int x, int y); |
maxint | 0:3d0db4e183ee | 17 | int getX(); |
maxint | 0:3d0db4e183ee | 18 | int getY(); |
maxint | 0:3d0db4e183ee | 19 | void set(int x, int y); |
maxint | 0:3d0db4e183ee | 20 | }; |
maxint | 0:3d0db4e183ee | 21 | |
maxint | 3:441dc90d10ce | 22 | class Rectangle; // predefinition needed by Line class |
maxint | 3:441dc90d10ce | 23 | |
maxint | 3:441dc90d10ce | 24 | class Line |
maxint | 3:441dc90d10ce | 25 | { |
maxint | 3:441dc90d10ce | 26 | protected : |
maxint | 3:441dc90d10ce | 27 | int x1, x2, y1, y2; |
maxint | 3:441dc90d10ce | 28 | |
maxint | 3:441dc90d10ce | 29 | public : |
maxint | 3:441dc90d10ce | 30 | Line(int x1,int y1, int x2, int y2); |
maxint | 3:441dc90d10ce | 31 | Line(Point p1, Point p2); |
maxint | 3:441dc90d10ce | 32 | Point get1(); |
maxint | 3:441dc90d10ce | 33 | Point get2(); |
maxint | 3:441dc90d10ce | 34 | float getSizeFloat(); |
maxint | 3:441dc90d10ce | 35 | int getSize(); |
maxint | 3:441dc90d10ce | 36 | Rectangle getBoundingRectangle(); |
maxint | 3:441dc90d10ce | 37 | int getDistance(Point pt); |
maxint | 3:441dc90d10ce | 38 | }; |
maxint | 3:441dc90d10ce | 39 | |
maxint | 0:3d0db4e183ee | 40 | class Rectangle |
maxint | 0:3d0db4e183ee | 41 | { |
maxint | 0:3d0db4e183ee | 42 | protected : |
maxint | 0:3d0db4e183ee | 43 | int x1, x2, y1, y2; |
maxint | 0:3d0db4e183ee | 44 | |
maxint | 0:3d0db4e183ee | 45 | public : |
maxint | 0:3d0db4e183ee | 46 | Rectangle(int x,int y, int x2, int y2); |
maxint | 0:3d0db4e183ee | 47 | Rectangle(Point pt1, Point pt2); |
maxint | 0:3d0db4e183ee | 48 | bool collides(Point pt); |
maxint | 0:3d0db4e183ee | 49 | bool collides(Rectangle r); |
maxint | 0:3d0db4e183ee | 50 | |
maxint | 0:3d0db4e183ee | 51 | void set(Rectangle rNew); |
maxint | 0:3d0db4e183ee | 52 | |
maxint | 0:3d0db4e183ee | 53 | Point get1(); |
maxint | 0:3d0db4e183ee | 54 | Point get2(); |
maxint | 0:3d0db4e183ee | 55 | Point get3(); |
maxint | 0:3d0db4e183ee | 56 | Point get4(); |
maxint | 0:3d0db4e183ee | 57 | Point getCenter(); |
maxint | 0:3d0db4e183ee | 58 | |
maxint | 0:3d0db4e183ee | 59 | int getX1(); |
maxint | 0:3d0db4e183ee | 60 | int getX2(); |
maxint | 0:3d0db4e183ee | 61 | int getY1(); |
maxint | 0:3d0db4e183ee | 62 | int getY2(); |
maxint | 0:3d0db4e183ee | 63 | int getCenterX(); |
maxint | 0:3d0db4e183ee | 64 | int getCenterY(); |
maxint | 4:f421e34313d3 | 65 | bool isHorizontal(); |
maxint | 0:3d0db4e183ee | 66 | void move(Vector v); |
maxint | 0:3d0db4e183ee | 67 | }; |
maxint | 0:3d0db4e183ee | 68 | |
maxint | 0:3d0db4e183ee | 69 | class Circle |
maxint | 0:3d0db4e183ee | 70 | { |
maxint | 0:3d0db4e183ee | 71 | protected : |
maxint | 0:3d0db4e183ee | 72 | int x1, y1, r1; |
maxint | 0:3d0db4e183ee | 73 | |
maxint | 0:3d0db4e183ee | 74 | public : |
maxint | 0:3d0db4e183ee | 75 | Circle(int x,int y, int r); |
maxint | 0:3d0db4e183ee | 76 | Point getCenter(); |
maxint | 0:3d0db4e183ee | 77 | int getRadius(); |
maxint | 0:3d0db4e183ee | 78 | int getX(); |
maxint | 0:3d0db4e183ee | 79 | int getY(); |
maxint | 0:3d0db4e183ee | 80 | void setX(int x); |
maxint | 0:3d0db4e183ee | 81 | void setY(int y); |
maxint | 0:3d0db4e183ee | 82 | void setXY(int x, int y); |
maxint | 0:3d0db4e183ee | 83 | void move(int x, int y); |
maxint | 0:3d0db4e183ee | 84 | void move(Vector v); |
maxint | 0:3d0db4e183ee | 85 | Rectangle getBoundingRectangle(); |
maxint | 3:441dc90d10ce | 86 | bool collides(Line l); |
maxint | 0:3d0db4e183ee | 87 | }; |
maxint | 0:3d0db4e183ee | 88 |