Exemple #1
0
void Hud::draw(const std::string& s, unsigned score) const{
  Draw_AALine(screen, start[0], start[1]+height/2, 
                      start[0]+width, start[1]+height/2, 
                      height, 0xff, 0xff, 0xff, 0xff/2);
  // Two Horizontal lines
  Draw_AALine(screen, start[0], start[1], 
                      start[0]+width, start[1], 
                      1.0, RED);
  Draw_AALine(screen, start[0], start[1]+height, 
                      start[0]+width, start[1]+height, 
                      1.0, RED);
  // Two Vertical lines
  Draw_AALine(screen, start[0], start[1], 
                      start[0], start[1]+height, 
                      2.0, RED);
  Draw_AALine(screen, start[0]+width, start[1], 
                      start[0]+width, start[1]+height, 
                      2.0, RED);

   io.printMessageAt(s, start[0]+2, start[1]+5);
   io.printMessageValueAt("your score is: ", score, start[0]+5, start[1]+25);
   io.printMessageAt("press key R to restart.", start[0]+2, start[1]+50);



}
Exemple #2
0
void Hud::drawHud(Uint32 liveNum, Uint32 freeNum, int enemyLeft)
{
    const Uint32 col = SDL_MapRGB(screen->format, 
            Gamedata::getInstance().getXmlInt("hud/red"),
            Gamedata::getInstance().getXmlInt("hud/green"),
            Gamedata::getInstance().getXmlInt("hud/blue"));
    Draw_AALine(screen, x, y +HUD_HEIGHT/2,
            x + HUD_WIDTH, y+ HUD_HEIGHT/2,
            HUD_HEIGHT, 0xff, 0xff, 0xff, 0xff/2);
    Draw_AALine(screen, x, y, x + HUD_WIDTH, y, 3, col);
    Draw_AALine(screen, x, y, x , y + HUD_HEIGHT, 3, col);
    Draw_AALine(screen, x + HUD_WIDTH, y ,x + HUD_WIDTH, y + HUD_HEIGHT, 3, col);
    Draw_AALine(screen, x, y + HUD_HEIGHT, x + HUD_WIDTH, y + HUD_HEIGHT, 3, col);

    IOManager::getInstance().printMessageValueAt("Sec: ",Clock::getInstance().getSeconds(), 2*x, 2*y);
    IOManager::getInstance().printMessageValueAt("FPS: ", Clock::getInstance().getFps(), 2*x, 2*y + interval);
    IOManager::getInstance().printMessageAt("A:  Move left", 2*x, 2*y + 2*interval);
    IOManager::getInstance().printMessageAt("D:  Move right", 2*x, 2*y + 3*interval);
    IOManager::getInstance().printMessageAt("W:  Move up", 2*x, 2*y + 4*interval);
    IOManager::getInstance().printMessageAt("S:  Move down", 2*x, 2*y + 5*interval);
    IOManager::getInstance().printMessageAt("G:  God Mode", 2*x, 2*y + 6*interval);
    IOManager::getInstance().printMessageAt("R:  reset", 2*x, 2*y + 7*interval);
    IOManager::getInstance().printMessageAt("F1: help", 2*x, 2*y + 8*interval);
    IOManager::getInstance().printMessageValueAt("live num: ",liveNum, 2*x, 2*y + 9*interval);
    IOManager::getInstance().printMessageValueAt("free num: ",freeNum, 2*x, 2*y + 10*interval);
    IOManager::getInstance().printMessageValueAt("enemy left: ",enemyLeft, 2*x, 2*y + 11*interval);
    IOManager::getInstance().printMessageAt("shoot: space", 2*x, 2*y + 12*interval);
}
Exemple #3
0
void Hud::draw() const {
  Draw_AALine(screen, start[0], start[1]+height/2, 
                      start[0]+width, start[1]+height/2, 
                      height, 0xff, 0xff, 0xff, 0xff/2);
  // Two Horizontal lines
  Draw_AALine(screen, start[0], start[1], 
                      start[0]+width, start[1], 
                      1.0, RED);
  Draw_AALine(screen, start[0], start[1]+height, 
                      start[0]+width, start[1]+height, 
                      1.0, RED);
  // Two Vertical lines
  Draw_AALine(screen, start[0], start[1], 
                      start[0], start[1]+height, 
                      2.0, RED);
  Draw_AALine(screen, start[0]+width, start[1], 
                      start[0]+width, start[1]+height, 
                      2.0, RED);

   io.printMessageValueAt("Seconds: ", clock.getSeconds(), start[0]+2, start[1]+5);
   io.printMessageValueAt("fps: ", clock.getAvgFps(), start[0]+5, start[1]+20);
   io.printMessageAt("Press F1 to toggle Hud", start[0]+5, start[1]+35);
   io.printMessageAt("Press key AWSD to move", start[0]+5, start[1]+50);
   io.printMessageAt("Press key F2 to toggle god mode", start[0]+5, start[1]+65);
   io.printMessageAt("Press key R to reset", start[0]+5, start[1]+80);
   io.printMessageAt("Press key Space to shoot", start[0]+5, start[1]+95);
   io.printMessageAt("Press key Q to quit", start[0]+5, start[1]+110);

}
void Hud::drawHUD() {
  const Uint32 RED = SDL_MapRGB(screen->format, 0xff, 0, 0);
  IOManager &io = IOManager::getInstance();
if(gameStarted){
  Draw_AALine(screen, startX, startY+HUD_HEIGHT/2,
                      startX+HUD_WIDTH,startY+HUD_HEIGHT/2,
                      HUD_HEIGHT, 0xff, 0xff, 0xff, 0xff/2);
   Draw_AALine(screen, startX,startY, startX+HUD_WIDTH,startY, RED);
        std::ostringstream oss;    
        oss <<" : "<< playerScore;  
        io.printMessageAt("score"+oss.str(), 10,60); 
        oss.str("");
        oss.clear(); 
        oss <<" : "<<wave;
        io.printMessageAt("wave"+oss.str(), 10,80); 
}

if(!gameStarted){
        TTF_Font * font = TTF_OpenFont(
                Gamedata::getInstance().getXmlStr("font/file").c_str(), 
                30);
io.printMessageAtF("CONTROLS",550,10,font);
io.printMessageAtF(Gamedata::getInstance().getXmlStr("pressASDW"),pressASDWMsgLoc[0],pressASDWMsgLoc[1],font);
io.printMessageAtF(Gamedata::getInstance().getXmlStr("pressRotate"),pressRotateMsgLoc[0],pressRotateMsgLoc[1],font);
io.printMessageAtF(Gamedata::getInstance().getXmlStr("fireBullets"),fireBulletsMsgLoc[0],fireBulletsMsgLoc[1],font);
TTF_CloseFont(font);
        Draw_AALine(screen, 0, 430, 
                      1500,430 , 
                      1500, 0x20,0xFF,0xFF,0x90);
  
        font = TTF_OpenFont(
                Gamedata::getInstance().getXmlStr("font/file").c_str(), 
                40);
        IOManager::getInstance().printMessageAtF("Press B to begin game", 300,300,font); 
        IOManager::getInstance().printMessageAtF("and survive 15 waves of enemies", 300,380,font); 

    TTF_CloseFont(font);
}

if(winner){

        TTF_Font * font = TTF_OpenFont(
                Gamedata::getInstance().getXmlStr("font/file").c_str(), 
                60);
io.printMessageAtF("WINNER",550,200,font);
TTF_CloseFont(font);
        Draw_AALine(screen, 0, 430, 
                      1500,430 , 
                      1500, 0x20,0xFF,0xFF,0x90);
  
        font = TTF_OpenFont(
                Gamedata::getInstance().getXmlStr("font/file").c_str(), 
                60);
        IOManager::getInstance().printMessageAtF("Press R to replay", 300,300,font); 

    TTF_CloseFont(font);
}
}
Exemple #5
0
void Hud::drawBord() const {
	// Two Horizontal lines
	Draw_AALine(this->screen, x, y, x + width, y, 3, this->bordColor);

	Draw_AALine(this->screen, x, y + height, x + width, y + height, 3,
			this->bordColor);

	// Two Vertical lines
	Draw_AALine(this->screen, x, y, x, y + height, 3, this->bordColor);
	Draw_AALine(screen, x + width, y, x + width, y + height, 3,
			this->bordColor);
}
Exemple #6
0
void Manager::showInformation() const {
  	unsigned int fontSize = Gamedata::getInstance().getXmlInt("fontSize"); 
  	const Uint32 RED = SDL_MapRGB(screen->format, 0xff, 0, 0);
  	io.printMessageValueAt("Level: ", level, 5, 0 * fontSize + 5);
  	io.printMessageValueAt("Enemy: ", enemies.size(), 250, 0 * fontSize + 5);
  	io.printMessageValueAt("Life: ", life, 460, 0 * fontSize + 5);
  	io.printMessageValueAt("Score: ", score, 665, 0 * fontSize + 5);
  	io.printMessageAt("Player: ", 5, 2 * fontSize);
	Draw_AALine(screen, 0, 0, 960, 0, 3, RED);
  	Draw_AALine(screen, 0, 0, 0, 1 * fontSize + 5, 3, RED);
  	Draw_AALine(screen, 960, 0, 960, 1 * fontSize + 5, 3, RED);
  	Draw_AALine(screen, 0, 1 * fontSize + 5, 960, 1 * fontSize + 5, 3, RED);
}
Exemple #7
0
void Bullet::draw() const {
	//std::cout << "draw -- "  << this->getPosition()[0] << ", " << this->getPosition()[1]<< std::endl;
	Vector2f pos = this->getPosition() - Viewport::getInstance().getPosition();

	Draw_AALine(screen, pos[0], pos[1],
			pos[0], pos[1] + 20, 20,
			SDL_MapRGB(screen->format, 255, 255, 255));
}
Exemple #8
0
void Health::drawBox() const {
  Draw_AALine(screen, start[0], start[1], 
                      start[0]+totalLength, start[1], 
                      thick, GRAY);
  // Two Horizontal lines
  Draw_AALine(screen, start[0], start[1]-(thick/2 + 1), 
                      start[0]+totalLength, start[1]-(thick/2 + 1), 
                      1.0, BLACK);
  Draw_AALine(screen, start[0], start[1]+(thick/2 + 1), 
                      start[0]+totalLength, start[1]+(thick/2 + 1), 
                      1.0, BLACK);
  // Two Vertical lines
  Draw_AALine(screen, start[0]-1, start[1]-(thick/2 + 1), 
                      start[0]-1, start[1]+(thick/2 + 1), 
                      2.0, BLACK);
  Draw_AALine(screen, start[0]+totalLength+1, start[1]-(thick/2 + 1), 
                      start[0]+totalLength+1, start[1]+(thick/2 + 1), 
                      2.0, BLACK);
}
Exemple #9
0
void Obj3DDrawable::draw()const{
//todo
	
	const Uint32 BLACK= SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);

	for(std::vector<Line2d>::const_iterator i = projectedLines.begin(); i != projectedLines.end(); i ++){
		Draw_AALine(screen, round(screen->w/2- (*i).p1.x),round(screen->h/2-(*i).p1.y), round(screen->w/2-(*i).p2.x), round(screen->h/2-(*i).p2.y) , 0.1, BLACK);
	}

}
Exemple #10
0
void LSystem::fillSprite() { 
  SDL_LockSurface(spriteSurface);
  // WHITE is the background that looks good with most other colors,
  // but feel free to use another color for your background.
  // Above, I've defined BLACK and MAGENTA, as well as WHITE.
  SDL_FillRect(spriteSurface, NULL, MAGENTA);
  state.x = startX;
  state.y = startY;
  for (unsigned int i = 0; i < sentence.size(); ++i) {
    switch ( sentence[i] ) {
      case '-' :  state.facing -= angle; break;
      case '+' :  state.facing += angle; break;
      case '[' :  stateStack.push(state); break;
      case ']' :  {
        state = stateStack.top();
        stateStack.pop();
        break;
      }
      case 'X' : case 'Y' : case 'f' :  {
        int x1 = state.x +
            static_cast<int>(strokeLength * cos(state.facing*PI/180));
        int y1 = state.y + 
            static_cast<int>(strokeLength * sin(state.facing*PI/180));
        state.x = state.x + (x1-state.x);
        state.y = state.y + (y1-state.y);
        break;
      }
      case 'F' :  case 'A' : case 'B' : {
        int x1 = state.x + 
            static_cast<int>(strokeLength * cos(state.facing*PI/180));
        int y1 = state.y + 
            static_cast<int>(strokeLength * sin(state.facing*PI/180));
        if ( state.x < 0 || state.y < 0 || x1 < 0 || y1 < 0 ) {
          throw string("x, y, x1, or x2 negative; length too long?");
        }
        Draw_AALine(spriteSurface, state.x,state.y, x1,y1, strokeWidth,
                    strokeColor);
        state.x = state.x + (x1-state.x);
        state.y = state.y + (y1-state.y);
        break;
      }
      default : {
        cout << "sentence size is: " << sentence.size() << endl;
        cout << "i is: " << i << endl;
        throw string("Unhandled switch/case: ")+sentence[i];
      }
    }
  }
  SDL_UnlockSurface(spriteSurface);
}
Exemple #11
0
void Hud::drawHUD() {
  const Uint32 RED = SDL_MapRGB(screen->format, 0xff, 0, 0);
  Draw_AALine(screen, startX, startY+HUD_HEIGHT/2,
                      startX+HUD_WIDTH,startY+HUD_HEIGHT/2,
                      HUD_HEIGHT, 0xff, 0xff, 0xff, 0xff/2);
  Draw_AALine(screen, startX,startY, startX+HUD_WIDTH,startY, RED);
  
if(!gameStarted){
  	Draw_AALine(screen, 0, 430, 
                      1500,430 , 
                      1500, 0x20,0xFF,0xFF,0x90);
  
 	TTF_Font * font = TTF_OpenFont(
        	Gamedata::getInstance().getXmlStr("font/file").c_str(), 
         	60);
  	IOManager::getInstance().printMessageAtF("Press B to begin game", 300,300,font); 

    TTF_CloseFont(font);
}
  	IOManager &io = IOManager::getInstance();
   	std::ostringstream oss;    
   	oss <<" : "<< playerScore;  
  	io.printMessageAt(score+oss.str(), scoreLoc[0],scoreLoc[1]); 
}
Exemple #12
0
void Health::draw() const {
  drawBox();
  Draw_AALine(screen, start[0], start[1], 
                      start[0] + currentLength, start[1], 
                      thick, color);
}
void Draw_AALine(SDL_Surface* screen, float x0, float y0, float x1, float y1, uint32_t color){
	Uint8 r, g, b;
	SDL_GetRGB(color, screen->format, &r, &g, &b);
	Draw_AALine(screen, x0+0.5f, y0+0.5f, x1+0.5f, y1+0.5f, 1.0f, r, g, b, 0xFF);
}
Exemple #14
0
void Manager::draw() const {
  float linePos;
  const Uint32 BLUE = SDL_MapRGB(screen->format, 0, 0, 0xFF);

  world_back.draw();
  world_front.draw();
  bar.draw();

  for (unsigned i = 0; i < sprites.size(); ++i) {
    sprites[i]->draw();
  }
  
  linePos = 20;

  io.printMessageAt("press 'F1' to show the huds", 20, linePos);
  linePos +=30; 

  if(isShowHug){
    //draw the contents
    
    io.printMessageValueAt("Seconds: ", clock.getSeconds(), 20, linePos);
    linePos +=30; 

    io.printMessageValueAt("fps: ", clock.getAvgFps(), 20, linePos);
    linePos +=30; 

    io.printMessageAt("Author: Chao Huang", 20, linePos);
    linePos +=30; 

    io.printMessageAt("current birds stored in usedVector", 20, linePos);
    linePos +=30; 

    io.printMessageAt("broken birds stored in freeVector", 20, linePos);
    linePos +=30; 

    io.printMessageAt("Press T to switch sprites", 20, linePos);
    linePos +=30; 

    io.printMessageAt("press e to make game easier", 20, linePos);
    linePos +=30;

    io.printMessageAt("press a/d to turn left/right", 20, linePos);
    linePos +=30;

    io.printMessageAt("press w to jump", 20, linePos);
    linePos +=30;

    io.printMessageAt("press s to crawl", 20, linePos);
    linePos +=30;

    io.printMessageAt("press f to fight", 20, linePos);
    linePos +=30;

    io.printMessageAt("press r to reset game", 20, linePos);
    linePos +=30;

    io.printMessageAt("press F2 to make bird strong", 20, linePos);
    linePos +=30;

    //draw the lines
    float left = (float)Gamedata::getInstance().getXmlInt("myhud/start/left"); 
    float top = (float)Gamedata::getInstance().getXmlInt("myhud/start/top");
    float right = (float)Gamedata::getInstance().getXmlInt("myhud/start/right"); 
    float buttom = linePos + top;

    Draw_AALine(screen, left, top, left, buttom, 2.0f, BLUE);
    Draw_AALine(screen, left, buttom, right, buttom, 2.0f, BLUE);
    Draw_AALine(screen, right, buttom, right, top, 2.0f, BLUE);
    Draw_AALine(screen, right, top, left, top, 2.0f, BLUE);

  }
  if(unlimitedMode){
    io.printMessageAt("unlimited health mode", 500, 50);
  }
  else{
    io.printMessageAt("limited health mode", 500, 50);
  }

  viewport.draw();

  SDL_Flip(screen);
}
Exemple #15
0
void Hud::drawRect() const {
	Draw_AALine(this->screen, this->x, this->y, this->x + this->width, this->y,
			this->thickness, this->rectColors[0], this->rectColors[1],
			this->rectColors[2], this->alpha);
}