Пример #1
0
void AccelerometerTest::didAccelerate(CCAcceleration* pAccelerationValue)
{
//     double fNow = pAccelerationValue->timestamp;
// 
//     if (m_fLastTime > 0.0)
//     {
//         CCPoint ptNow = convertToUI
//     }
// 
//     m_fLastTime = fNow;

    CCDirector* pDir = CCDirector::sharedDirector();

    /*FIXME: Testing on the Nexus S sometimes m_pBall is NULL */
    if ( m_pBall == NULL ) {
        return;
    }

    CCSize ballSize  = m_pBall->getContentSize();

    CCPoint ptNow  = m_pBall->getPosition();
    CCPoint ptTemp = pDir->convertToUI(ptNow);

    ptTemp.x += pAccelerationValue->x * 9.81f;
    ptTemp.y -= pAccelerationValue->y * 9.81f;

    CCPoint ptNext = pDir->convertToGL(ptTemp);
    FIX_POS(ptNext.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0));
    FIX_POS(ptNext.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0));
    m_pBall->setPosition(ptNext);
}
Пример #2
0
void AccelerometerTest::onAcceleration(Acceleration* acc, Event* event)
{
//     double fNow = pAccelerationValue->timestamp;
// 
//     if (_lastTime > 0.0)
//     {
//         auto ptNow = convertToUI
//     }
// 
//     _lastTime = fNow;

    auto pDir = Director::getInstance();

    /*FIXME: Testing on the Nexus S sometimes _ball is NULL */
    if ( _ball == NULL ) {
        return;
    }

    auto ballSize  = _ball->getContentSize();

    auto ptNow  = _ball->getPosition();
    auto ptTemp = pDir->convertToUI(ptNow);

    ptTemp.x += acc->x * 9.81f;
    ptTemp.y -= acc->y * 9.81f;

    auto ptNext = pDir->convertToGL(ptTemp);
    FIX_POS(ptNext.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0));
    FIX_POS(ptNext.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0));
    _ball->setPosition(ptNext);
}
Пример #3
0
void BattleView::updataPosition(Acceleration* acc)
{
    auto ballSize  = m_plSprite->getContentSize();
    
    auto ptNow  = m_plSprite->getPosition();
    
    log("acc: x = %lf, y = %lf", acc->x, acc->y);
    
    double speed = 30.00f;
    
    Vec2 movePos = Vec2(ptNow.x + acc->x * speed,ptNow.y + acc->y * speed);
    
    //updating angle and pos
    double offsetX = acc->x * speed;
    double offsetY = acc->y * speed;
    
    if(offsetX*offsetX > 0.1 && offsetY*offsetY > 0.1)
    {
        this->updataAngle(offsetX,offsetY);
    }

    FIX_POS(movePos.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0));
    FIX_POS(movePos.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0));
    m_plSprite->setPosition(movePos);
    
}
void ShootingGameScene::didAccelerate(CCAcceleration* pAccelerationValue) {
	CCDirector* pDir = CCDirector::sharedDirector();
	if (_aim == NULL)
		return;
	CCSize aimsize = _aim->getContentSize();

	CCPoint aimNow = _aim->getPosition();
	CCPoint aimTemp = pDir->convertToUI(aimNow);

	aimTemp.x += pAccelerationValue->x * 50.0f;
	aimTemp.y -= pAccelerationValue->y * 50.0f;//9.81f;

	CCPoint aimNext = pDir->convertToGL(aimTemp);
	FIX_POS(aimNext.x,(aimsize.width/2.0),(winsize.width  - aimsize.width/2.0f));
	FIX_POS(aimNext.y,(aimsize.height/2.0),(winsize.height  - aimsize.height/2.0f));

	_aim->setPosition(aimNext);
}
Пример #5
0
void AccelerometerTest::onAcceleration(Acceleration* acc, Event* event)
{
    /*FIXME: Testing on the Nexus S sometimes _ball is NULL */
    if ( _ball == nullptr ) {
        return;
    }

    auto ballSize  = _ball->getContentSize();

    auto pos  = _ball->getPosition();

    pos.x += acc->x * 9.81f;
    pos.y += acc->y * 9.81f;

    FIX_POS(pos.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0));
    FIX_POS(pos.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0));
    _ball->setPosition(pos);
}
Пример #6
0
/* Insert task_env * in queue */
static void task_queue_insert(task_queue *q, task_env *t)
{
	assert(t->heap_pos == 0);
	assert(q->curn < MAXTASKS);
	/* assert(is_heap(q)); */
	q->curn++;
	q->x[q->curn] = t;
	FIX_POS(q->curn);
	/* Heap(1,n-1) */
	task_queue_siftup(q, q->curn);
	/* Heap(1,n) */
	/* assert(is_heap(q)); */
}
Пример #7
0
void PlaceItDrawer::drawStatusOfStructureAtCell(cBuildingListItem *itemToPlace, int cell) {
	assert(itemToPlace);
	if (cell < 0)
		return;

	cStructureUtils structureUtils;
	int structureId = itemToPlace->getBuildId();
	assert(structureId > -1);

	bool bOutOfBorder = true;
	bool bMayPlace = true;

	int iTile = PLACE_ROCK; // rocky placement = ok, but bad for power

	BITMAP *temp;
	temp = create_bitmap(structures[structureId].bmp_width, structures[structureId].bmp_height);
	clear_bitmap(temp);

	int width = structureUtils.getWidthOfStructureTypeInCells(structureId);
	int height = structureUtils.getHeightOfStructureTypeInCells(structureId);

	int iTotalBlocks = width * height;

	int iTotalRocks = 0.0f;

#define SCANWIDTH	1

	CellCalculator * cellCalculator = new CellCalculator(map);

	int iCellX = cellCalculator->getX(cell);
	int iCellY = cellCalculator->getY(cell);

	delete cellCalculator;

	// check
	int iStartX = iCellX - SCANWIDTH;
	int iStartY = iCellY - SCANWIDTH;

	int iEndX = iCellX + SCANWIDTH + width;
	int iEndY = iCellY + SCANWIDTH + height;

	// Fix up the boundaries
	FIX_POS(iStartX, iStartY);
	FIX_POS(iEndX, iEndY);

	// Determine if the structure may be placed or not (true/false)
	for (int iX = iStartX; iX < iEndX; iX++) {
		for (int iY = iStartY; iY < iEndY; iY++) {
			int iCll = createCellWithoutMapBorders(iX, iY);
			if (map->cell[iCll].gameObjectId[MAPID_STRUCTURES] > -1) {
				int iID = map->cell[iCll].gameObjectId[MAPID_STRUCTURES];

				if (structure[iID]->isOwnerHuman()) {
					bOutOfBorder = false; // connection!
				} else {
					bMayPlace = false;
				}
			}

			if (map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_WALL || map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_SLAB) {
				bOutOfBorder = false;
				// TODO: here we should actually find out if the slab is ours or not??
			}
		}
	}

	if (bOutOfBorder) {
		bMayPlace = false;
	}

	int iDrawX = map->mouse_draw_x();
	int iDrawY = map->mouse_draw_y();

	// Draw over it the mask for good/bad placing (decorates temp bitmap)
	for (int iX = 0; iX < width; iX++) {
		for (int iY = 0; iY < height; iY++) {
			iTile = PLACE_ROCK;

			if ((iCellX + iX > 62) || (iCellY + iY > 62)) {
				bOutOfBorder = true;
				bMayPlace = false;
				break;
			}

			int iCll = createCellWithoutMapBorders((iCellX + iX), (iCellY + iY));

			if (map->cell[iCll].passable == false)
				iTile = PLACE_BAD;

			if (map->cell[iCll].terrainTypeGfxDataIndex != TERRAIN_ROCK)
				iTile = PLACE_BAD;

			if (map->cell[iCll].terrainTypeGfxDataIndex == TERRAIN_SLAB)
				iTile = PLACE_GOOD;

			// occupied by units or structures
			if (map->cell[iCll].gameObjectId[MAPID_STRUCTURES] > -1)
				iTile = PLACE_BAD;

			int unitIdOnMap = map->cell[iCll].gameObjectId[MAPID_UNITS];
			if (unitIdOnMap > -1) {
				if (!unit[unitIdOnMap].bPickedUp) // only when not picked up, take this in (fixes carryall carrying this unit bug)
					iTile = PLACE_BAD;
			}

			// DRAWING & RULER
			if (iTile == PLACE_BAD && structureId != SLAB4)
				bMayPlace = false;

			// Count this as GOOD stuff
			if (iTile == PLACE_GOOD)
				iTotalRocks++;

			// Draw bad gfx on spot
			draw_sprite(temp, (BITMAP *) gfxdata[iTile].dat, iX * 32, iY * 32);
		}

		if (bOutOfBorder) {
			clear_to_color(temp, makecol(160, 0, 0));
		}
	}

	// draw temp bitmap
	set_trans_blender(0, 0, 0, 64);

	draw_trans_sprite(bmp_screen, temp, iDrawX, iDrawY);

	// reset to normal
	set_trans_blender(0, 0, 0, 128);

	destroy_bitmap(temp);

	// clicked mouse button
	if (Mouse::getInstance()->isLeftButtonClicked()) {
		if (bMayPlace && bOutOfBorder == false) {
			int iHealthPercent = 50; // the minimum is 50% (with no slabs)

			if (iTotalRocks > 0) {
				iHealthPercent += health_bar(50, iTotalRocks, iTotalBlocks);
			}

			play_sound_id(SOUND_PLACE, -1);

			//cStructureFactory::getInstance()->createStructure(iMouseCell, iStructureID, 0, iHealthPercent);

			player[HUMAN].getStructurePlacer()->placeStructure(cell, structureId, iHealthPercent);

			/*game.bPlaceIt = false;*/

			itemToPlace->decreaseTimesToBuild();
			itemToPlace->setPlaceIt(false);
			itemToPlace->setIsBuilding(false);
			itemToPlace->setProgress(0);
			if (itemToPlace->getTimesToBuild() < 1) {
				player[HUMAN].getItemBuilder()->removeItemFromList(itemToPlace);
			}
		}
	}
	//iDrawX *=32;
	//iDrawY *=32;

	//rect(bmp_screen, iDrawX, iDrawY, iDrawX+(iWidth*32), iDrawY+(iHeight*32), makecol(255,255,255));
}