本文整理汇总了C++中window::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ window::GetWidth方法的具体用法?C++ window::GetWidth怎么用?C++ window::GetWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类window
的用法示例。
在下文中一共展示了window::GetWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getInput
void getInput(window &w, color skycolor, tank &left, tank &right, bool &leftTurn) { // gets input for 2 parameters. returns when enter key (shoot) is pressed
char k = '#'; // for key, set to a known, but useless value
tank ¤tTank = leftTurn ? left : right;
int angle = currentTank.getAngle();
int velocity = currentTank.getSpeed();
w.SetFont(50, PLAIN, ROMAN);
setBrushAndPenColor(w, BLACK);
while (k != 13) { // return key
setBrushAndPenColor(w, skycolor); // erasing up top
w.DrawRectangle(0, 0, w.GetWidth(), 200, FILLED);
w.SetFont(50, PLAIN, ROMAN); // redrawing up top
setBrushAndPenColor(w, BLACK);
w.DrawString(w.GetWidth() / 2 - 60, 100, "angle: " + to_string(angle));
w.DrawString(w.GetWidth() / 2 - 60, 150, "speed: " + to_string(velocity));
w.UpdateBuffer();
// redraw tank
setBrushAndPenColor(w, skycolor); // erasing around tank
if (leftTurn) w.DrawRectangle(currentTank.getXstart() - 3, currentTank.getYstart() + 3, currentTank.getXend() + 3, currentTank.getYend() - 3, FILLED);
else w.DrawRectangle(currentTank.getXstart() + 3, currentTank.getYstart() + 3, currentTank.getXend() - 3, currentTank.getYend() - 3, FILLED);
// letting user change parameters (w/ limits)
w.WaitKeyPress(k);
if (k == 8 && angle < 90) angle++; // up
if (k == 2 && angle > 1) angle--; // down
if (k == 6 && velocity < 35) velocity++; // right
if (k == 4 && velocity > 1) velocity--; // left
currentTank.setAngle(angle);
currentTank.setSpeed(velocity);
currentTank.drawTank(w); // changes pen color
w.UpdateBuffer();
}
}
示例2: drawLandscape
void drawLandscape(window &w, color skycolor, color groundcolor) { // creates landscape. only called once
setBrushAndPenColor(w, skycolor);
w.DrawRectangle(0, 0, w.GetWidth(), w.GetHeight(), FILLED);
RandGen r;
int ystart = r.RandInt((double) w.GetHeight() * 0.666, (double) w.GetHeight() * 0.75); // semi random height of ground near bottom of screen
setBrushAndPenColor(w, groundcolor);
for (double x = 0; x < w.GetWidth(); x++) {
int yval = ystart + sin((double) (x / 60)) * 15; // ground will be sin curve
w.DrawLine(x, yval, x, w.GetHeight()); // draws line from ground level to bottom of screen
}
}
示例3: bullet
color bullet(window &w, color skycolor, tank &left, tank &right, bool &leftTurn) { // goes through bullets path. returns color of what is hit.
setBrushAndPenColor(w, skycolor); // erasing up top to make sure it doesnt count hitting the text
w.DrawRectangle(0, 0, w.GetWidth(), 200, FILLED);
double dtime = 0.007;
int bulletRadius = 4;
int bulletX, bulletY;
double radianAngle;
tank ¤tTank = leftTurn ? left : right;
int angle = currentTank.getAngle();
if (leftTurn) {
radianAngle = angle * cdPi / 180;
bulletX = currentTank.getXend() + 3;
} else {
radianAngle = ((180 - angle) * cdPi / 180);
bulletX = currentTank.getXend() - 3;
}
int velocity = currentTank.getSpeed();
bulletY = currentTank.getYend() - 3;
leftTurn = !leftTurn;
double xVel = cos(radianAngle) * velocity;
double yVel = sin(radianAngle) * velocity;
double time = 0;
while (w.GetColor(bulletX, bulletY) == skycolor) {
setBrushAndPenColor(w, BLACK);
w.DrawCircle(bulletX, bulletY, bulletRadius, FILLED);
w.UpdateBuffer();
Sleep(1);
setBrushAndPenColor(w, skycolor);
w.DrawCircle(bulletX, bulletY, bulletRadius + 1, FILLED);
time += dtime;
bulletX += xVel * time;
bulletY += -yVel * time + 40 * time * time;
}
return w.GetColor(bulletX, bulletY);
}