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