class Circle;
class FakeLens;
+/// Base class for all "shapes" (i.e. collision primitives).
+/// This serves as an interface for game::Entity to double dispatch the
+/// collision detection algorithms.
class Shape {
public:
virtual ~Shape(void) { };
public:
+ /// Check if this shape overlaps the given and, if it does, write the
+ /// surface normal into given vector.
+ /// All shapes must override this method to dispatch to the specialized
+ /// version of Overlaps().
+ /// See AABB::Overlaps(const Shape &, Vector &normal) const for details.
virtual bool Overlaps(const Shape &, Vector &normal) const = 0;
virtual bool Overlaps(const AABB &, Vector &normal) const = 0;
Match::Match(void)
: ctrl(0)
-, scoreFont(TTF_OpenFont("data/font/Magra-Regular.ttf", 30))
+, scoreFont(TTF_OpenFont("data/font/Magra-Regular.ttf", 24))
, leftScoreText(0)
, rightScoreText(0)
+, topScoreText(0)
+, bottomScoreText(0)
+, totalScoreText(0)
, paddleSpeed(250)
, worldWidth(800)
, worldHeight(480)
, ball(10)
, secondBall(7)
, thirdBall(7)
+, fourthBall(8)
+, fifthBall(9)
+, sixthBall(11)
, leftPaddle(Entity::Vector(10, 100))
, rightPaddle(Entity::Vector(10, 100))
, topWall(Entity::Vector(800, 20))
thirdBall.SetVelocity(Entity::Vector(100, 100));
thirdBall.SetMaxVelocity(600.0f);
+ fourthBall.SetPosition(Entity::Vector(550, 250));
+ fourthBall.SetVelocity(Entity::Vector(100, 100));
+ fourthBall.SetMaxVelocity(600.0f);
+
+ fifthBall.SetPosition(Entity::Vector(340, 250));
+ fifthBall.SetVelocity(Entity::Vector(100, 100));
+ fifthBall.SetMaxVelocity(600.0f);
+
+ sixthBall.SetPosition(Entity::Vector(550, 350));
+ sixthBall.SetVelocity(Entity::Vector(100, 100));
+ sixthBall.SetMaxVelocity(600.0f);
+
leftPaddle.SetPosition(Entity::Vector(0, 200));
rightPaddle.SetPosition(Entity::Vector(790, 280));
bottomWall.SetStatic();
leftWall.SetStatic();
- entities.reserve(9);
+ entities.reserve(12);
entities.push_back(&ball);
entities.push_back(&secondBall);
entities.push_back(&thirdBall);
+// entities.push_back(&fourthBall);
+// entities.push_back(&fifthBall);
+// entities.push_back(&sixthBall);
entities.push_back(&leftPaddle);
entities.push_back(&rightPaddle);
entities.push_back(&topWall);
dest.x = screen->w - rightScoreText->w - 2;
SDL_BlitSurface(rightScoreText, 0, screen, &dest);
+
+// dest.x = 2;
+// dest.y = screen->h - topScoreText->h - 2;
+// SDL_BlitSurface(topScoreText, 0, screen, &dest);
+//
+// dest.x = screen->w - bottomScoreText->w - 2;
+// dest.y = screen->h - bottomScoreText->h - 2;
+// SDL_BlitSurface(bottomScoreText, 0, screen, &dest);
+//
+// dest.x = screen->w/2 - totalScoreText->w/2;
+// dest.y = 2;
+// SDL_BlitSurface(totalScoreText, 0, screen, &dest);
}
void Match::UpdateScore(SDL_Surface *screen) {
if (!scoreFont) return;
if (leftScoreText) SDL_FreeSurface(leftScoreText);
if (rightScoreText) SDL_FreeSurface(rightScoreText);
+ if (topScoreText) SDL_FreeSurface(topScoreText);
+ if (bottomScoreText) SDL_FreeSurface(bottomScoreText);
+ if (totalScoreText) SDL_FreeSurface(totalScoreText);
SDL_Color color;
color.r = 0xFF;
color.b = 0xFF;
stringstream s;
- s << rightWall.HitCount();
+ s << "right: " << rightWall.HitCount();
leftScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
s.str("");
- s << leftWall.HitCount();
+ s << "left: " << leftWall.HitCount();
rightScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+ s.str("");
+ s << "top: " << topWall.HitCount();
+ topScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+ s.str("");
+ s << "bottom: " << bottomWall.HitCount();
+ bottomScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+ s.str("");
+ s << "total: " << rightWall.HitCount() + leftWall.HitCount() + topWall.HitCount() + bottomWall.HitCount();
+ totalScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
}
}
private:
app::Control *ctrl;
TTF_Font *scoreFont;
- SDL_Surface *leftScoreText, *rightScoreText;
+ SDL_Surface *leftScoreText, *rightScoreText, *topScoreText, *bottomScoreText, *totalScoreText;
Sint32 paddleSpeed;
Uint32 worldWidth, worldHeight;
- Ball ball, secondBall, thirdBall;
+ Ball ball, secondBall, thirdBall, fourthBall, fifthBall, sixthBall;
Paddle leftPaddle, rightPaddle;
CountingWall topWall, bottomWall, leftWall, rightWall;
std::vector<game::Entity *> entities;