当前位置: 首页>>代码示例>>C++>>正文


C++ TextInput::drawText方法代码示例

本文整理汇总了C++中TextInput::drawText方法的典型用法代码示例。如果您正苦于以下问题:C++ TextInput::drawText方法的具体用法?C++ TextInput::drawText怎么用?C++ TextInput::drawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextInput的用法示例。


在下文中一共展示了TextInput::drawText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** args)
{
	srand(time(0));

	SDL_Init(SDL_INIT_EVERYTHING);
	TTF_Init();
	SDL_WM_SetCaption(W_TITLE, 0);
	SDL_Surface* screen = SDL_SetVideoMode(W_WIDTH, W_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	SDL_Surface* bground = IMG_Load("bground.bmp");
	//Create new Text objects.
    Text* scoreTxt = new Text("Score: 0", 0, 0, {0, 255, 0}, 20);
    Text* livesTxt = new Text("Lives: 24", 520, 0, {0, 255, 0}, 20);
    Text* bulletTxt = new Text("Bullets: 199", 160, 0, {0, 255, 0}, 20);
    Text* rocketTxt = new Text("Rockets: 100", 320, 0, {0, 255, 0}, 20);
	Text* gameTxt = new Text("Game Over", 150, 220, {255, 0, 0}, 60);
	Text* msgTxt = new Text("Enter Name: ", 130, 120, {255, 0, 0}, 22);

	//Create new SpaceShip object.
    SpaceShip* objShip = new SpaceShip("rocket.bmp", SHIP_X, SHIP_Y);
    objShip->setColorKey(0, 0, 0);
    //Create new Meteor objects.
    meteorVec.push_back(new Meteor("meteor1.bmp", 50, rand()%300));
    meteorVec.push_back(new Meteor("meteor2.bmp", 100, rand()%300));
    meteorVec.push_back(new Meteor("meteor3.bmp", 150, rand()%300));
    meteorVec.push_back(new Meteor("meteor1.bmp", 200, rand()%300));
    meteorVec.push_back(new Meteor("meteor2.bmp", 250, rand()%300));
    meteorVec.push_back(new Meteor("meteor3.bmp", 300, rand()%300));

    //Create new Bullet objects.
    for(int i = 0; i < 200; i++) {
        bulletVec.push_back(new Bullet("bullet.bmp"));
    }
    for(int i = 0; i < 100; i++) {
        rocketVec.push_back(new Bullet("rckt.bmp"));
    }
    for(int i = 0; i < 100; i++) {
        rocketVec2.push_back(new Bullet("rckt.bmp"));
    }

    Intro(screen);

    //Start drawing the game.
    SDL_BlitSurface(bground, NULL, screen, NULL);
    for(unsigned i = 0; i < meteorVec.size(); i++) {
    	meteorVec[i]->setColorKey(255, 255, 255);
    	meteorVec[i]->setSpeed((rand()%8 - 4), (1 + rand()%5));
    	meteorVec[i]->drawObject(screen, bground);
    }

//    bonusVec.push_back(new Meteor("rBonus.bmp", 350, rand()%300));
//    for(unsigned i = 0; i < bonusVec.size(); i++) {
//   		bonusVec[i]->setColorKey(255, 0, 255);
//   		bonusVec[i]->setSpeed((rand()%8 - 4), (1 + rand()%5));
//   		bonusVec[i]->drawObject(screen, bground);
//   	}

//    Text* tt = new Text("TIME: 0", 100, 190, {255, 0, 0}, 22);
    //Start timer for bonuses
    tb.start();

    objShip->drawObject(screen, bground);
    scoreTxt->drawText(screen);
//    tt->drawText(screen);

    bulletTxt->drawText(screen);
    //rocketTxt->drawText(screen);
    livesTxt->drawText(screen);

	SDL_UpdateRect(screen, 0, 0, 0, 0);

	bool keysHold[323] = {false};
	SDL_Event event;

    //Start the game.
	while(true) {
		if(SDL_PollEvent(&event)) {
			if(event.type == SDL_QUIT) {
				break;
			}
			if(objShip->isColision(bonusVec,screen)){
				bonus=true;
				rocketTxt->drawText(screen);
			}

		    if(tb.getTicks()/1000 >= 10){
		    	tb.stop();
		    	bonusState=true;
		    	tb.start();
		    }
		    else if(tb.getTicks()/1000 < 10){bonusState=false;}

		    if(bonusState==true && bonus==false){

		    	bonusVec.push_back(new Meteor("rBonus.bmp", 350, rand()%300));
		        for(unsigned i = 0; i < bonusVec.size(); i++) {
		        	bonusVec[i]->setColorKey(255, 0, 255);
		        	bonusVec[i]->setSpeed((rand()%8 - 4), (1 + rand()%5));
		        	bonusVec[i]->drawObject(screen, bground);
		        }

//.........这里部分代码省略.........
开发者ID:NCSU,项目名称:Asteroid-Field-Game,代码行数:101,代码来源:AsteroidField.cpp


注:本文中的TextInput::drawText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。