Beispiel #1
0
void Game2D::paint(QPainter &p){

    drawBackground (p);

    for (std::size_t i=0; i<evec_.size(); i++) drawUnit (evec_[i], p);//evec_[i].draw (p);

    if (state_==2) ship_.setType(1);
    else ship_.setType(0);

    drawUnit (ship_, p, direction_);

    drawLabels (p);

    drawState (p);

    /*
    typedef QSharedPointer <Unit> spUnit;
    QVector < spUnit>  units;

    Ship ship;
    Enemy e;

    units.push_back((spUnit)new Ship());
    //units.push_back((spUnit)&e);

    for (int i=0; i<units.size(); i++) drawUnit (*units[i].data(), p);

    */
}
void yeseulMenkmanInstitution::draw(){
    
    unitCounter = 0;
    brickCounter = 0;
    squareCounter = 0;
    
    for (int i=0; i<dimensions.width; i+=unitSize) {
        for (int j=0; j<dimensions.height; j+=unitSize) {
            randomNumber = patternRandomNumberArray[unitCounter];
            drawUnit(i, j, randomNumber, randomNumber%4);
            unitCounter++;
        }
    }
    
    drawSquare();
    
    int numberOfBrickRows = int((numberOfBricks+numberOfBricksPerRow)/numberOfBricksPerRow);
    
    for (int j = 0; j < numberOfBrickRows; j++) {
        if (j == int(numberOfBrickRows)-1) {
            for (int i = 0; i < numberOfBricks%numberOfBricksPerRow; i++) {
                drawBrick(dimensions.width-unitSize*2-i*unitSize*2, dimensions.height-unitSize*2-j*unitSize*2);
                brickCounter++;
            }
        } else {
            for (int i = 0; i < numberOfBricksPerRow; i++) {
                drawBrick(dimensions.width-unitSize*2-i*unitSize*2, dimensions.height-unitSize*2-j*unitSize*2);
                brickCounter++;
                
            }
        }
    }
}
Beispiel #3
0
	//----------------------------------------------------------------------------
	void GameRadar::drawPeaceUnit(IdType mainId)
	{
		//其他玩家
		CSceneManager::OrdinaryBuildingEntityListIt ordinaryBuildingEntityIt =  CSceneManager::getInstance().mOrdinaryBuildingEntityList.begin();
		while ( ordinaryBuildingEntityIt != CSceneManager::getInstance().mOrdinaryBuildingEntityList.end() )
		{
			//不是自身
			COrdinaryBuildingEntity* ordinaryBuildingEntity = ordinaryBuildingEntityIt->second;
			if ( ordinaryBuildingEntity && ordinaryBuildingEntity->getEntity() )
			{
				drawUnit( ordinaryBuildingEntity->getPos(), mPeaceBuildIcon, "" );	
			}
			ordinaryBuildingEntityIt++;
		}
		
		//其他玩家
		CSceneManager::PlayerChaEntityListIt playerEntityIter =  CSceneManager::getInstance().mPlayerChaEntityList.begin();
		while ( playerEntityIter != CSceneManager::getInstance().mPlayerChaEntityList.end() )
		{
			//不是自身
			if ( playerEntityIter->first != mainId )
			{
				CPlayerCharacterEntity* playerEntity = playerEntityIter->second;
				if ( playerEntity && playerEntity->getEntity() )
				{
					drawUnit( playerEntity->getPos(), mCompanyCharIcon, "" );	
				}
			}
			playerEntityIter++;
		}

		//绘制NPC
		CSceneManager::NpcEntityListIt npcEntityIter =  CSceneManager::getInstance().mNpcEntityList.begin();
		while ( npcEntityIter != CSceneManager::getInstance().mNpcEntityList.end() )
		{
			CNpcEntity* npcEntity = npcEntityIter->second;
			if ( npcEntity && npcEntity->getEntity() )
			{
				drawUnit( npcEntity->getPos(), mNpcIcon, "" );
			}

			npcEntityIter++;
		}		
	}
Beispiel #4
0
void Thermometer::paintEvent(QPaintEvent *)
{
    painter.begin(this);

    drawTitle();
    drawUnit();
    drawLabel();
    drawDisplay();
    drawScale();
    drawMeter();
    drawRange();
    drawPointer();

    painter.end();
}
Beispiel #5
0
void MyShape::draw() {
    glPushMatrix();

    //Translate
    glTranslatef(pos[0], pos[1], pos[2]);

    //Rotate
    // TODO TURN THIS BACK ON. YOU ARE NOT ROTATING ANYTHING RIGHT NOW
    glMultMatrixf( (const GLfloat*)orientationMat);

    //Scale
    drawScale();

    glColor3fv(color);

    drawUnit();
    glPopMatrix();
}
Beispiel #6
0
	//----------------------------------------------------------------------------
	void GameRadar::drawAllUnit()
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//获取自身相关信息
		IdType mainId = 0;
		FORCE mainForce = FORCE_INIT;

		if ( CPlayer::getInstance().getActiveClan() )
			mainId = CPlayer::getInstance().getActiveClan()->getMainGenrealID();

		CPlayerCharacterEntity* mainPlayerEntity = CSceneManager::getInstance().getPlayerCharacterEntity( mainId );
		if ( mainPlayerEntity && mainPlayerEntity->getDynamicData() )
		{
			mainForce = mainPlayerEntity->getDynamicData()->force;
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		if ( mainForce != FORCE_INIT )
		{
			drawBattleUnit(mainId, mainForce);
		}
		else
		{
			drawPeaceUnit(mainId);
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//最后绘制自身
		if ( mainPlayerEntity )
		{
			drawUnit( mainPlayerEntity->getPos(), mSelfCharIcon, "" );
		}
	}
Beispiel #7
0
	void SDL_Canvas::drawUnits(list<Unit*>& units) 
	{	
		list<Unit*>::iterator it;
		for(it = units.begin(); it != units.end(); it++)
			drawUnit(**it);
	}
Beispiel #8
0
	//----------------------------------------------------------------------------
	void GameRadar::drawBattleUnit(IdType mainId, FORCE mainForce)
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		//将己方军队信息保存于此,延迟进行绘制
		std::vector<CTroopEntity*> companyTroopList;

		//绘制对方军队
		CSceneManager::TroopObjectListIt troopObjectIter =  CSceneManager::getInstance().mTroopEntityList.begin();
		while ( troopObjectIter != CSceneManager::getInstance().mTroopEntityList.end() )
		{
			CTroopEntity* troopObject = troopObjectIter->second;
			if ( troopObject )
			{
				TroopEntityData* dynamicData = troopObject->getDynamicData();
				if ( dynamicData && dynamicData->force > FORCE_INIT && dynamicData->force < FORCE_MAX )
				{	
					if ( dynamicData && dynamicData->force == mainForce )
					{
						//同伴玩家
						companyTroopList.push_back(troopObject);	
					}
					else
					{
						//对方玩家
						drawUnit( troopObject->getTroopCenterPos(), mRivalArmyIcon, "" );
					}
				}
			}

			troopObjectIter++;
		}

		//延迟绘制己方军队
		for ( U32 i = 0; i < companyTroopList.size(); i++ )
		{
			drawUnit( companyTroopList[i]->getTroopCenterPos(), mCompanyArmyIcon, "" );
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//将己方攻击建筑信息保存于此,延迟进行绘制
		std::vector<CBuildingEntity*> companyBuildList;

		CSceneManager::BattleBuildingEntityListIt  battleBuildingEntityIter =  CSceneManager::getInstance().mBattleBuildingEntityList.begin();
		while ( battleBuildingEntityIter != CSceneManager::getInstance().mBattleBuildingEntityList.end() )
		{
			CBuildingEntity* buildingEntity = battleBuildingEntityIter->second;
			if ( buildingEntity && buildingEntity->getEntity() && 
				buildingEntity->getBuildingType() == CHAR_BUILD_TYPE_FIGHT ||
				buildingEntity->getBuildingType() == CHAR_BUILD_TYPE_BARRACKS ||
				buildingEntity->getBuildingType() == CHAR_BUILD_TYPE_HEADQUARTERS )
			{
				BuildingEntityData* dynamicData = buildingEntity->getDynamicData();
				if ( dynamicData && dynamicData->force > FORCE_INIT && dynamicData->force < FORCE_MAX )
				{
					if ( dynamicData->force == mainForce )
					{
						//己方建筑
						companyBuildList.push_back(buildingEntity);		
					}
					else
					{
						//对方建筑
						drawUnit( buildingEntity->getPos(), mRivalBuildIcon, "" );
					}
				}
			}

			battleBuildingEntityIter++;
		}

		//延迟绘制己方建筑
		for ( U32 i = 0; i < companyBuildList.size(); i++ )
		{
			//drawUnit( companyBuildList[i]->getPos(), mCompanyBuildIcon, "" );
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//绘制monster
		CSceneManager::MonsterEntityListIt monsterEntityIt =  CSceneManager::getInstance().mMonsterEntityList.begin();
		while ( monsterEntityIt != CSceneManager::getInstance().mMonsterEntityList.end() )
		{
			CMonsterEntity* monsterEntity = monsterEntityIt->second;
			if ( monsterEntity && monsterEntity->getEntity() )
			{
				drawUnit( monsterEntity->getPos(), mRivalArmyIcon, "" );
			}

			monsterEntity++;
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//将己方玩家信息保存于此,延迟进行绘制
		std::vector<CPlayerCharacterEntity*> companyCharList;

		//绘制对方角色
		CSceneManager::PlayerChaEntityListIt playerEntityIter =  CSceneManager::getInstance().mPlayerChaEntityList.begin();
		while ( playerEntityIter != CSceneManager::getInstance().mPlayerChaEntityList.end() )
		{
			if ( playerEntityIter->first != mainId )
			{
				CPlayerCharacterEntity* playerEntity = playerEntityIter->second;
				if ( playerEntity && playerEntity->getEntity() )
				{
					PlayerCharacterEntityData* dynamicData = playerEntity->getDynamicData();

					if ( dynamicData && dynamicData->force > FORCE_INIT && dynamicData->force < FORCE_MAX )
					{
						if ( dynamicData && dynamicData->force == mainForce )
						{
							//同伴玩家
							companyCharList.push_back(playerEntity);		
						}
						else
						{
							//对方玩家
							drawUnit( playerEntity->getPos(), mRivalCharIcon, "" );
						}
					}		
				}
			}

			playerEntityIter++;
		}

		//延迟绘制己方角色
		for ( U32 i = 0; i < companyCharList.size(); i++ )
		{
			drawUnit( companyCharList[i]->getPos(), mCompanyCharIcon, "" );
		}

	
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//绘制NPC
		CSceneManager::NpcEntityListIt npcEntityIter =  CSceneManager::getInstance().mNpcEntityList.begin();
		while ( npcEntityIter != CSceneManager::getInstance().mNpcEntityList.end() )
		{
			CNpcEntity* npcEntity = npcEntityIter->second;
			if ( npcEntity && npcEntity->getEntity() )
			{
				drawUnit( npcEntity->getPos(), mNpcIcon, "" );
			}

			npcEntityIter++;
		}
	}
Beispiel #9
0
// drawFrame *************
// Draw the current frame on screen.
// Only return false for non-recover errors (not for lost surfaces,
// for example).
bool GameLoopCode::drawFrame()
{

    vectorListNodeStruct<playerUnitStruct>* nodeP;
    vectorListNodeStruct<enemyUnitStruct>* node;
    vectorListNodeStruct<bulletUnitStruct>* nodeB;
    vectorListNodeStruct<waveGenUnitStruct>* nodeWG;
    int x, y;

    // Draw the background
    if (!drawBackground()) {
        logger.logLine("Failed drawBackground");
        return false;
    }

    // Blt the bullets on screen...
    for (nodeB=bulletList.getFirstNode(); nodeB!=NULL; nodeB=bulletList.getNextNode(nodeB)) {
        // don't draw this unit if it's not active now
        if (!nodeB->data.nowActive) continue;
        // don't draw this utit if it's not visible now
        if (!nodeB->data.nowDrawable) continue;

        // draw this unit...
        drawUnit(&(nodeB->data));
    }

    // Blt the enemies on screen...
    for (node=enemyList.getFirstNode(); node!=NULL; node=enemyList.getNextNode(node)) {
        // don't draw this unit if it's not active now
        if (!node->data.nowActive) continue;
        // don't draw this utit if it's not visible now
        if (!node->data.nowDrawable) continue;

        // draw this unit...
        drawUnit(&(node->data));
    }

    // Blt the players on screen...
    for (nodeP=playerList.getFirstNode(); nodeP!=NULL; nodeP=playerList.getNextNode(nodeP)) {
        // don't draw this unit if it's not active now
        if (!nodeP->data.nowActive) continue;
        // don't draw this utit if it's not visible now
        if (!nodeP->data.nowDrawable) continue;

        // draw this unit...
        drawUnit(&(nodeP->data));
    }

    // Now, over anything else, blt the wave generators on screen...
    // But only draw them if required
    if (drawWaveGenerators) {
        for (nodeWG=waveGenList.getFirstNode(); nodeWG!=NULL; nodeWG=waveGenList.getNextNode(nodeWG)) {
            // don't draw this unit if it's not active now
            if (!nodeWG->data.nowActive) continue;
            // don't draw this utit if it's not visible now
            if (!nodeWG->data.nowDrawable) continue;

            // draw this unit...
            drawUnit(&(nodeWG->data));
        }
    }

    // Now draw the foreground complementary information
    if (!drawForegroundComplements())
        return false;

    // zoom if necessary
    if (gameWorld.zoomed) {
        x=int(double(DD.getWidth())/gameWorld.zoomBy);// zoom width
        y=int(double(DD.getHeight())/gameWorld.zoomBy);// zoom height

        // let's zoom
        DD.stretchBltFrom(DD, 0, 0, DD.getWidth(), DD.getHeight(),
                          gameWorld.zoomCX-(x/2), gameWorld.zoomCY-(y/2),
                          x, y, false, false, false);
    }

    // If gameWorld.srfGameScreen wasn't DD, here we should blt
    // srfGameScreen to DD...

    return true;// all ok
}// drawFrame
Beispiel #10
0
// drawUnit **********
// Draws a given unit on the screen.
// Assumes the unit is drawable and active now (that is, it has to be
// drawn really).
bool drawUnit(genericUnitStruct* unit)
{
    int x, y;// coordinates
    int cx, cy;// coordinates for collision
    genericUnitTypeDataStruct* myUnitType;
    genericUnitTypeDataStruct* typeDataList;

    // frame of this unit
    frameDataStruct* myUnitFrame;

    // we have to get this value from the unit type
    int pixelsToTrembleWhenTrembling;

    // make sure the unit isn't a null pointer
    if (unit==NULL) return false;

    // check if this unit has a slave of his own...
    if (unit->slaveUnit.objectType!=FILE_GAMEDATA_GAMEOBJECT_EMPTY) {
        // it has a slave, draw that one first
        if (!drawUnit(getUnitPointer(unit->slaveUnit)))
            return false;
    }

    // get the data specific to this kind of unit
    typeDataList=getTypeDataStruct(unit->objectType);
    if (typeDataList==NULL) return false;
    myUnitType=&(typeDataList[unit->unitType]);

    // set some data data...
    myUnitFrame=&(myUnitType->frames[unit->currentFrame]);
    pixelsToTrembleWhenTrembling=
        myUnitType->pixelsToTrembleWhenUntouchable;

    // calculate the coordinates...
    // (int)(unit->x)-(myUnitFrame->handlerX): real x
    // +gameWorld.screenX: conversion to screen position
    // -gameWorld.xCamera: conversion to camera
    x=(int)((unit->x)-(myUnitFrame->handlerX)+
            gameWorld.screenX-(gameWorld.xCamera));
    y=(int)((unit->y)-(myUnitFrame->handlerY)+
            gameWorld.screenY-(gameWorld.yCamera));

    // Check if we have to draw the bounding rectangles...
    if (drawBoundingRectangles) {
        // Let us draw the bounding rectangle of this unit
        // Calculate the coordinates...
        cx=x+myUnitFrame->cX;
        cy=y+myUnitFrame->cY;

        // draw the bounding rectangle, only if its size is bigger than
        // zero
        if (myUnitFrame->cW>0 && myUnitFrame->cH>0) {
            gameWorld.srfGameScreen->fillRect(
                0, 0, 0,// color to use
                cx, cy,// dest coordinates
                myUnitFrame->cW,// size
                myUnitFrame->cH);
        }
    }// if drawBoundingRectangles

    // if the surface is in untouchable mode, make it tremble, but
    // only if the game isn't paused and if the user hasn't disabled
    // trembling from the console
    if (unit->trembling && !gameWorld.isGamePaused
            && pixelsToTrembleWhenTrembling>0
            && letSpritesTremble) {

        // tremble!
        // (trembling is implemented only in the visualization)
        x=x-(pixelsToTrembleWhenTrembling/2)
          +rand()%(pixelsToTrembleWhenTrembling+1);
        y=y-(pixelsToTrembleWhenTrembling/2)
          +rand()%(pixelsToTrembleWhenTrembling+1);
    }

    // blt it!
    gameWorld.srfGameScreen->bltFrom(
        *(myUnitFrame->surface),
        x,// dest coordinates
        y,
        myUnitFrame->x,// source coordinates
        myUnitFrame->y,
        myUnitFrame->w,
        myUnitFrame->h,
        gameWorld.screenX, gameWorld.screenY,// clipping coordinates
        gameWorld.wCamera, gameWorld.hCamera,
        dbgClipSprites,// only stop clipping it if that debug mode is enabled
        true);

    // draw the 'going to' lines if needed
    if (drawGoingToLines) {
        if (unit->goingToPoint) {
            // some mini local variables
            int x, y;
            int x2, y2;

            // calculate the coordinates
            x=int(unit->x+gameWorld.screenX-(gameWorld.xCamera));
            y=int(unit->y+gameWorld.screenY-(gameWorld.yCamera));
            x2=int(unit->goingToPointX+
                   gameWorld.screenX-(gameWorld.xCamera));
            y2=int(unit->goingToPointY+
                   gameWorld.screenY-(gameWorld.yCamera));
            if (unit->isPosRelative) {
                x2=int(unit->goingToPointX+gameWorld.screenX);
                y2=int(unit->goingToPointY+gameWorld.screenY);
            }

            // draw it
            gameWorld.srfGameScreen->drawLine(
                x, y,// 'from' coordinates
                x2, y2,// 'to' coordinates
                255,0, 0);// color
        }
    }

    // FOLLOWERS_TEST_BEGIN
    // draw the 'following' lines if needed
    if (drawFollowingLines) {
        if (unit->objectType==FILE_GAMEDATA_GAMEOBJECT_ENEMY) {
            enemyUnitStruct* unit1;
            enemyUnitStruct* unit2;
            int x, y;
            int x2, y2;

            switch (unit->unitType) {
            case FILE_GAMEDATA_ENEMY_SHEEPCARRIER:
            case FILE_GAMEDATA_ENEMY_HEADCARRIER:
                unit1=(enemyUnitStruct*)unit;

                if (unit1->aiSpecific.flockerData.unitToFollow.objectType
                        !=FILE_GAMEDATA_GAMEOBJECT_EMPTY) {

                    // get the other unit...
                    unit2=(enemyUnitStruct*)getUnitPointer(
                              unit1->aiSpecific.flockerData.unitToFollow);

                    // check for null pointers...
                    if (unit2!=NULL) {
                        // some mini local variables
                        // calculate the coordinates
                        x=int(unit1->x+gameWorld.screenX-(gameWorld.xCamera));
                        y=int(unit1->y+gameWorld.screenY-(gameWorld.yCamera));
                        x2=int(unit2->x+gameWorld.screenX-(gameWorld.xCamera));
                        y2=int(unit2->y+gameWorld.screenY-(gameWorld.yCamera));

                        // draw it
                        gameWorld.srfGameScreen->drawLine(
                            x, y,// 'from' coordinates
                            x2, y2,// 'to' coordinates
                            0,0,255);// color
                    }
                }
                break;
            }
        }
    }
    // FOLLOWERS_TEST_END

    // draw the handler points if needed
    if (drawHandlerPoints) {
        // some mini local variables
        int x, y;
        x=int(unit->x+gameWorld.screenX-(gameWorld.xCamera));
        y=int(unit->y+gameWorld.screenY-(gameWorld.yCamera));

        // draw the handler points if needed (as a red box with a
        // white pixel inside, marking the handler)
        gameWorld.srfGameScreen->fillRect(255,0,0,
                                          x-1, y-1, 3, 3);
        gameWorld.srfGameScreen->fillRect(255,255,255,
                                          x, y, 1, 1);
    }

    // all ok
    return true;
}// drawUnit