本文整理汇总了C++中DrawList::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ DrawList::push_back方法的具体用法?C++ DrawList::push_back怎么用?C++ DrawList::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrawList
的用法示例。
在下文中一共展示了DrawList::push_back方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(DrawList, draw) {
DrawList<MyData> list;
list.push_back(MyData(0,1), 0.1);
list.push_back(MyData(1,2), 0.1);
list.push_back(MyData(2,3), 0.1);
list.push_back(MyData(3,4), 0.1);
list.push_back(MyData(4,6), 0.2);
list.push_back(MyData(6,10), 0.4);
ASSERT_EQ(0, list.draw(0.00).x);
ASSERT_EQ(0, list.draw(0.05).x);
ASSERT_EQ(0, list.draw(0.09).x);
ASSERT_EQ(1, list.draw(0.11).x);
ASSERT_EQ(1, list.draw(0.15).x);
ASSERT_EQ(1, list.draw(0.19).x);
ASSERT_EQ(2, list.draw(0.201).x);
ASSERT_EQ(2, list.draw(0.25).x);
ASSERT_EQ(2, list.draw(0.299).x);
ASSERT_EQ(3, list.draw(0.30001).x);
ASSERT_EQ(3, list.draw(0.3333).x);
ASSERT_EQ(3, list.draw(0.399999).x);
ASSERT_EQ(4, list.draw(0.40001).x);
ASSERT_EQ(4, list.draw(0.4333).x);
ASSERT_EQ(4, list.draw(0.599999).x);
ASSERT_EQ(6, list.draw(0.600001).x);
ASSERT_EQ(6, list.draw(0.7).x);
ASSERT_EQ(6, list.draw(0.999999).x);
}
示例2: path
//draw the path from the map file
void path() {
for (int i = 0; i < mapSizex; i++) {
for (int j = 0; j < mapSizey; j++) {
float x = i*20;
float y = j*20;
if (Map[i][j] == '/' ) {
//draw the path where enemy's walk
Color color = { 0.47265625, 0.33203125, 0.28125 };
PointF begin1 = { x,y };
PointF begin2 = { (x),(y+20) };
PointF begin3 = { (x-20),(y+20) };
PointF begin4 = { (x - 20), (y) };
Sqaure* sq = new Sqaure(begin1, begin2, begin3, begin4, color);
Static.push_back(sq);
//drawList.push_back(sq);
}
//path where building is allowed
if (Map[i][j] == '*' || Map[i][j] == 'T') {
//draw the building site
Color color = { 0 , 0.47265625, 0.41796875 };
PointF begin1 = { x,y };
PointF begin2 = { (x),(y + 20) };
PointF begin3 = { (x - 20),(y + 20) };
PointF begin4 = { (x - 20), (y) };
Sqaure* sq = new Sqaure(begin1, begin2, begin3, begin4, color);
Static.push_back(sq);
//drawList.push_back(sq);
}
//end point of the map
if (Map[i][j] == 'E') {
//draw the end map
Color color = { 1.0f, 0.4f, 0.4f };
PointF begin1 = { x,y };
PointF begin2 = { (x),(y + 20) };
PointF begin3 = { (x - 20),(y + 20) };
PointF begin4 = { (x - 20), (y) };
Sqaure* sq = new Sqaure(begin1, begin2, begin3, begin4, color);
Static.push_back(sq);
//drawList.push_back(sq);
}
//if the map data contains nothing special
else {
continue;
}
}
}
}
示例3: drawBullet
//draw the actual bullet's as is seen on screen
void drawBullet() {
//define colors and width of the bullet
Color color = { 0.9f, 0.9f, 0.9f }; //white bullets
float lind = 2.0;
//itterate over the bullet vector
for (unsigned i = 0; i < bulletvector.size(); i++) {
PointF BulletPos = bulletvector.at(i)->Move();
// if bullet is out of screen
if (BulletPos[0] > windowWidth || BulletPos[1] > windowHeight || BulletPos[0] < 0 || BulletPos[1] < 0) {
//delete the bulelt from the vector and the pointer to the bullet
delete bulletvector.at(i);
bulletvector.erase(bulletvector.begin() + i);
}
else {
//update the movement of the bullet
bulletvector.at(i)->Update(BulletPos);
//draw the bullet +5 becuase of the width of the bullet
PointF BulletPos2 = { BulletPos[0], (BulletPos[1] + 5) };
Line* bulletline = new Line{ BulletPos , BulletPos2 , color, lind };
//push to the draw list
drawList.push_back(bulletline);
}
}
}
示例4: raster
//make a grid
void raster() {
Color color = { 0.40625,0.76171875,0.63671875 };
int rasterHoogte = windowHeight;
int rasterBreedte = windowWidth;
int res = 15;
float radius = 2.5;
int seg = 5;
float varx;
float vary;
for (int i = 0; i < (rasterBreedte/res); i++) {
for (int j = 0; j < ((rasterHoogte)/res); j++) {
varx = 20 * i;
vary = 20 * j;
//make a grid if the width still has 200 pixels
if ((windowWidth - 200) > varx) {
PointF posPixel = { varx , vary };
Circle* dots = new Circle(posPixel, color, radius, seg);
Static.push_back(dots);
}
else {
continue;
}
}
}
//draw the grid
path();
}
示例5: MyData
/** assert that cumulative values are correctly calculated when drawing the first time */
TEST(DrawList, Cumulative) {
DrawList<MyData> list;
list.push_back(MyData(), 0.11);
list.push_back(MyData(), 0.22);
list.push_back(MyData(), 0.33);
list.push_back(MyData(), 0.44);
list.push_back(MyData(), 0.55);
list.push_back(MyData(), 0.66);
for (DrawListEntry<MyData>& dle : list.entries) {
ASSERT_EQ(0, dle.cumulativeProbability);
}
list.draw();
ASSERT_FLOAT_EQ(0.11f, list.entries[0].cumulativeProbability);
ASSERT_FLOAT_EQ(0.33f, list.entries[1].cumulativeProbability);
ASSERT_FLOAT_EQ(0.66f, list.entries[2].cumulativeProbability);
ASSERT_FLOAT_EQ(1.10f, list.entries[3].cumulativeProbability);
ASSERT_FLOAT_EQ(1.65f, list.entries[4].cumulativeProbability);
ASSERT_FLOAT_EQ(2.31f, list.entries[5].cumulativeProbability);
list.set(0, MyData(), 0.22);
ASSERT_FLOAT_EQ(0.00f, list.entries[0].cumulativeProbability);
ASSERT_FLOAT_EQ(0.33f, list.entries[1].cumulativeProbability);
ASSERT_FLOAT_EQ(0.66f, list.entries[2].cumulativeProbability);
ASSERT_FLOAT_EQ(1.10f, list.entries[3].cumulativeProbability);
ASSERT_FLOAT_EQ(1.65f, list.entries[4].cumulativeProbability);
ASSERT_FLOAT_EQ(2.31f, list.entries[5].cumulativeProbability);
list.draw();
ASSERT_FLOAT_EQ(0.22f, list.entries[0].cumulativeProbability);
ASSERT_FLOAT_EQ(0.44f, list.entries[1].cumulativeProbability);
ASSERT_FLOAT_EQ(0.77f, list.entries[2].cumulativeProbability);
ASSERT_FLOAT_EQ(1.21f, list.entries[3].cumulativeProbability);
ASSERT_FLOAT_EQ(1.76f, list.entries[4].cumulativeProbability);
ASSERT_FLOAT_EQ(2.42f, list.entries[5].cumulativeProbability);
}
示例6: DrawButton
//draw the game Gui buttons -> static draw so only has to be draw once
void DrawButton() {
float x = (windowWidth - 180);
float padding = 5;
Color Textcolor = { 0.375, 0.48828125, 0.54296875 };
Color ButtonColor = { 0.99609375, 0.33984375, 0.1328125 };
//start button
PointF begin = { (x+150),375 };
PointF begin2 = { (x+150), 400};
PointF end = { x,400 };
PointF end2 = { x , 375 };
int mode = 1;
Sqaure* sq = new Sqaure(begin, begin2, end, end2, ButtonColor);
Static.push_back(sq);
PointF PosText = { (x+padding) , (end2[1] + padding) };
string text_to = "Start Game";
Text* button_text = new Text(text_to, Textcolor, PosText);
Static.push_back(button_text);
//make Button class
Button* start = new Button(text_to, mode, ButtonColor, begin, end, begin2, end2);
//add to Button vector
ButtonVector.push_back(start);
//Spawn Enemy button
PointF begin3 = { (x + 150),300 };
PointF begin4 = { (x + 150), 325 };
PointF end3 = { x,325 };
PointF end4 = { x , 300 };
int mode2 = 1;
Sqaure* sq2 = new Sqaure(begin3, begin4, end3, end4, ButtonColor);
Static.push_back(sq2);
PointF PosText2 = { (x + padding) , (end4[1] + padding) };
string text_to2 = "Spawn Enemy";
Text* button_text2 = new Text(text_to2, Textcolor, PosText2);
Static.push_back(button_text2);
//make button class
Button* spawn = new Button(text_to2,mode2,ButtonColor,begin3,end3,begin4,end4);
//add to Button vector
ButtonVector.push_back(spawn);
}
示例7: text
//draw all the text that needs to be displayed
void text() {
//definition stuff
float x = (windowWidth - 180);
float y = windowHeight - 100;
Color color = { 0.375, 0.48828125, 0.54296875 };
Color loseColor = { 1,1,1};
PointF posF = { x, (y+50) };
Text* texttodispF = new Text("FPS :", color, posF);
DrawTextList.push_back(texttodispF);
PointF pos2F = { (x + 125), (y+50) };
Text* texttodisp2F = new Text(to_string(fps), color, pos2F);
DrawTextList.push_back(texttodisp2F);
//print the plaer health -> fancy icon ?
PointF pos = { x, y };
Text* texttodisp = new Text("Player Health : ", color, pos);
DrawTextList.push_back(texttodisp);
PointF pos2 = { (x +125), y };
Text* texttodisp2 = new Text(to_string( PlayerHealth) , color, pos2);
DrawTextList.push_back(texttodisp2);
//print the player Score
PointF pos3 = { x, (y -50) };
Text* texttodisp3 = new Text("Player Score : ", color, pos3);
DrawTextList.push_back(texttodisp3);
PointF pos4 = { (x+125), (y - 50) };
Text* texttodisp4 = new Text(to_string(PlayerScore), color, pos4);
DrawTextList.push_back(texttodisp4);
//print current player map
PointF pos5 = { x, (y - 100) };
Text* texttodisp5 = new Text("Curret map : ", color, pos5);
DrawTextList.push_back(texttodisp5);
PointF pos6 = { (x + 125), (y - 100) };
Text* texttodisp6 = new Text(MapName, color, pos6);
DrawTextList.push_back(texttodisp6);
if (lose == 1) {
PointF pos6 = { (windowWidth/2 -100),(windowHeight/2) };
Text* texttodisp6 = new Text("You have lost this game ", loseColor, pos6);
DrawTextList.push_back(texttodisp6);
}
}
示例8: drawTurret
//draw all of the turrets
void drawTurret() {
//for every turret construct the corresonding turret
for (unsigned i = 0; i < turretvector.size(); i++) {
Color color = { 0.2f, 0.2f, 0.2f };
PointF pos = turretvector.at(i)->_position;
PointF begin2 = { (pos[0] - 20) ,(pos[1]) };
PointF begin3 = { (pos[0]) , (pos[1] + 40) };
PointF begin4 = { (pos[0] + 20) , (pos[1]) };
Sqaure* sq = new Sqaure(pos, begin2, begin3, begin4, color);
//put turret on the Static drawlist
Static.push_back(sq);
}
}
示例9: drawEnemy
//draw the enemy's + walk alogirthm
void drawEnemy() {
Color color = { 0.12890625, 0.5859375, 0.94921875 };
float r = 22;
//number of triganles that need to be drawn
int seg = 20;
for (unsigned i = 0; i<enenemyvector.size(); i++) {
PointF curpos = enenemyvector.at(i)->_current;
//if the enemy is out of the screen
if (curpos[0] > windowWidth || curpos[1] > windowHeight) {
//delete the enemy
delete enenemyvector.at(i);
//cout << "Deleted an enemy" << endl;
//delete the enemy from the enemy vector
enenemyvector.erase((enenemyvector.begin() + i));
}
//enemy is still in the screen
else {
PointF curpos = enenemyvector.at(i)->_current;
//decrease the enemy health if a bullet hits the enemy
for (unsigned j = 0; j < bulletvector.size(); j++) {
PointF Bullet = bulletvector.at(j)->_begin;
//calulate the diffrence in position
float dx = abs( Bullet[0] - curpos[0]);
float dy = abs( Bullet[1] - curpos[1]);
//cout << "dx :" << dx << "dy:" << dy << endl;
//bullet and enemy are at the same poition
//if the distnace is smaller tne the radius of the object
if ( dx < 20 && dy < 20 ) {
enenemyvector.at(i)->Health(10);;
//cout << "Damaged an enemy" << endl;
PlayerScore = PlayerScore + 10;
PlaySoundW(L"point.wav", NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
//delete teh bullet
delete bulletvector.at(j);
bulletvector.erase((bulletvector.begin() + j));
}
}
//walk algorithm is good but could do better
if (enenemyvector.at(i)->_health > 0) {
int curx = curpos[0] /20;
int cury = curpos[1] / 20;
// get the map character that is 20 pixels further
char nextCharXplus = Map[(curx+1)][cury];
char nextCharYplus = Map[curx][(cury + 1)];
char nextCharXmin = Map[(curx - 1)][cury];
char nextCharYmin = Map[curx][(cury - 1)];
//if the enemy is at the end of the defense
if (Map[(curx)][cury] == 'E') {
//delete the enemy
delete enenemyvector.at(i);
//delete the enemy from the enemy vector
enenemyvector.erase((enenemyvector.begin() + i));
PlayerHealth = PlayerHealth - 30;
PlaySoundW(L"loss.wav", NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
continue;
}
//once the end line is insight
if (Map[(curx + 2)][cury] == 'E') {
PointF posEnemy = enenemyvector.at(i)->Move(1, 0);
enenemyvector.at(i)->Update(posEnemy);
Circle* cirle = new Circle(posEnemy, color, r, seg);
drawList.push_back(cirle);
drawBullets(posEnemy, i);
//Bullet(posEnemy, i);
continue;
}
//once the end line is insight
if (nextCharXplus == 'E') {
PointF posEnemy = enenemyvector.at(i)->Move(1, 0);
enenemyvector.at(i)->Update(posEnemy);
Circle* cirle = new Circle(posEnemy, color, r, seg);
drawList.push_back(cirle);
drawBullets(posEnemy, i);
continue;
}
// move 20 y pixels right
if (nextCharYplus == '/' && Map[(curx)][(cury +2)] ) {
PointF posEnemy = enenemyvector.at(i)->Move(0,1);
enenemyvector.at(i)->Update(posEnemy);
Circle* cirle = new Circle(posEnemy, color, r, seg);
drawList.push_back(cirle);
drawBullets(posEnemy, i);
continue;
}
// move 20 x pixels rght
if (nextCharXplus == '/' && Map[(curx + 2)][cury]== '/' ) {
PointF posEnemy = enenemyvector.at(i)->Move(1, 0);
enenemyvector.at(i)->Update(posEnemy);
Circle* cirle = new Circle(posEnemy, color, r, seg);
drawList.push_back(cirle);
drawBullets(posEnemy, i);
continue;
//.........这里部分代码省略.........