// Obstacle.h -- written 16 Mar 1996 by Max Hailperin // // Fixed a comment mis-statement 28 Mar 1996 Max Hailperin // // This file defines the Obstacle class and its subclasses. // An Obstacle is something that the ball can hit, such as a wall, mirror, or // target. Each kind of Obstacle is responsible for drawing itself in its // constructor, erasing itself in its destructor, and in the mean time // responding to questions as to whether it is erasable or not and dealing // with being hit. // // The coordinate system used throughout has x increasing to the right and // y increasing as you go up, with (0,0) being in the middle of the lower // left hand corner cell. The unit of measure is the cell size, so (1,0) // is the middle of the second cell from the left in the bottom row, // (2,5) is the middle of the third cell from the left in the 6th row // from the bottom, etc. When coordinates are floats, they can be used // to specify positions other than in the middle of cells; for example, // the boundaries between cells are at positions ending in .5 . // // Work wasn't quite complete on this module when your predecessor at the // game company quit his job. (Even where "complete" is taken to mean even a // succesful clone of your competitor's game -- let alone the bigger, better // game you hope to turn it into.) #ifndef OBSTACLE_H #define OBSTACLE_H class Photon; class Ball; class Obstacle{ public: Obstacle(Photon *p, int xpos, int ypos) : game(p), x(xpos), y(ypos) {}; virtual int beHitBy(Ball *) = 0; // returns amount to add to score virtual int erasable() {return 0;} // override in erasable subclasses virtual ~Obstacle() {} protected: int x, y; Photon *game; }; class LinearObstacle : public Obstacle{ public: LinearObstacle(Photon *p, int x, int y, float x0, float y0, float x1, float y1); ~LinearObstacle(); protected: int id; }; class Wall : public LinearObstacle{ public: Wall(Photon *p, int x, int y, float x0, float y0, float x1, float y1) : LinearObstacle(p, x, y, x0, y0, x1, y1) {}; int beHitBy(Ball *); }; class HWall : public Wall{ public: HWall(Photon *p, int x, int y) : Wall(p, x, y, x-0.5f, y, x+0.5f, y) {} }; class VWall : public Wall{ public: // Fill this in. }; class Corner : public Obstacle{ public: // (x0, y0) should be on the top or bottom and (x1, y1) on the left or right Corner(Photon *p, int x, int y, float x0, float y0, float x1, float y1); int beHitBy(Ball *); ~Corner(); protected: int id; }; class LLCorner : public Corner{ // Lower Left public: // Fill this in. }; class ULCorner : public Corner{ // Upper Left public: // Fill this in. }; class LRCorner : public Corner{ // Lower Right public: // Fill this in. }; class URCorner : public Corner{ // Upper Right public: // Fill this in. }; class Mirror : public LinearObstacle{ public: Mirror(Photon *p, int x, int y, int directionMultiplier, float x0, float y0, float x1, float y1) : LinearObstacle(p, x, y, x0, y0, x1, y1), mult(directionMultiplier) {} int beHitBy(Ball *); int erasable() {return 1;} private: int mult; }; class PMirror : public Mirror{ // P = Positive slope public: // Fill this in. }; class NMirror : public Mirror{ // N = Negative slope public: // Fill this in. }; class Target : public Obstacle{ public: Target(Photon *p, int x, int y); int beHitBy(Ball *); ~Target(); protected: int id; }; #endif