// Ball.C -- written 16 Mar 1996 by Max Hailperin // // Implementation of the Photon game's Ball class #include "Ball.h" #include "Photon.h" #include #include #include Ball::Ball(Photon *p, int x, int y, int direction, int vertical) : game(p), xpos(x), ypos(y), dir(direction), vert(vertical) { char s[128]; ostrstream strm(s, 128); // The diameter of the ball is 30% of the size of a "cell" on the playing // field, as determined by the + and - 0.15 below. strm << "create oval " << p->mapX(x-0.15f) << ' ' << p->mapY(y-0.15f) << ' ' << p->mapX(x+0.15f) << ' ' << p->mapY(y+0.15f) << " -fill black" << ends; p->draw(s); // The result of drawing is the canvas item's id, which we get so // we can later delete it. Tcl_GetInt(p->interpreter(), p->interpreter()->result, &id); } void Ball::move(){ int newX = vert ? xpos : xpos + dir; int newY = vert ? ypos + dir : ypos; game->moveCanvasItem(id, xpos, ypos, newX, newY); xpos = newX; ypos = newY; } Ball::~Ball(){ game->deleteCanvasItem(id); }