void CPointer::Render() { int cell_x, cell_y; vec3 p; vec3 pos = CameraPosition(); glPushAttrib( GL_POLYGON_BIT | GL_LIGHTING_BIT | GL_FOG_BIT ); glDisable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_2D ); glDisable( GL_FOG ); glEnable( GL_BLEND ); glEnable( GL_ALPHA ); glBindTexture( GL_TEXTURE_2D, m_texture ); glDisable( GL_CULL_FACE ); glBlendFunc( GL_ONE, GL_ONE ); glLineWidth( 3.5f ); glColor3f( 1.0f, 0.5f, 0.0f ); cell_x = ( int )( pos.x - 0.5f ) + MapSize() / 2; cell_y = ( int )( pos.z - 0.5f ) + MapSize() / 2; cell_x = static_cast<int>(m_last_cell.x); cell_y = static_cast<int>(m_last_cell.y); glBegin( GL_QUADS ); glTexCoord2f( 0.0f, 0.0f ); p = MapPosition( cell_x - PT_HALF, cell_y - PT_HALF ); p.x -= m_pulse; p.y += 2.0f; p.z -= m_pulse; glVertex3fv( &p.x ); glTexCoord2f( 0.0f, 1.0f ); p = MapPosition( cell_x - PT_HALF, cell_y + PT_HALF ); p.x -= m_pulse; p.y += 2.0f; p.z += m_pulse; glVertex3fv( &p.x ); glTexCoord2f( 1.0f, 1.0f ); p = MapPosition( cell_x + PT_HALF, cell_y + PT_HALF ); p.x += m_pulse; p.y += 2.0f; p.z += m_pulse; glVertex3fv( &p.x ); glTexCoord2f( 1.0f, 0.0f ); p = MapPosition( cell_x + PT_HALF, cell_y - PT_HALF ); p.x += m_pulse; p.y += 2.0f; p.z -= m_pulse; glVertex3fv( &p.x ); glEnd(); glPopAttrib(); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_DEPTH_TEST ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glEnable( GL_CULL_FACE ); }
static vec2 DrawGrid( void ) { int x, y; int block; int hits; uint32_t buffer[512]; // Set Up A Selection Buffer vec3 v1, v2, v3, v4; vec2 cell; memset( buffer, 0, sizeof( buffer ) ); // Tell OpenGL To Use Our Array For Selection glSelectBuffer( 512, buffer ); // Put OpenGL In Selection Mode. glRenderMode( GL_SELECT ); glInitNames(); glPushName( 0 ); block = 0; glDisable( GL_CULL_FACE ); for( y = 0; y < MapSize(); y += PT_SIZE ) { for( x = 0; x < MapSize(); x += PT_SIZE ) { block = x + y * MapSize(); glLoadName( block ); v1 = MapPosition( x, y ); v2 = MapPosition( x, y + PT_SIZE ); v3 = MapPosition( x + PT_SIZE, y + PT_SIZE ); v4 = MapPosition( x + PT_SIZE, y ); glBegin( GL_QUADS ); glVertex3fv( &v1.x ); glVertex3fv( &v2.x ); glVertex3fv( &v3.x ); glVertex3fv( &v4.x ); glEnd(); } } hits = glRenderMode( GL_RENDER ); cell.x = cell.y = -1; if( hits > 0 ) { block = buffer[3]; cell.x = static_cast<float>(block % MapSize() + PT_HALF); cell.y = static_cast<float>(( block - cell.x ) / MapSize() + PT_HALF); } return cell; }
void Player::updateWalkPath(Game& game, LevelMap& map) { currentWalkTime += game.getElapsedTime(); while (currentWalkTime >= speed.walk) { currentWalkTime -= speed.walk; auto newDrawPos = drawPosA; if (drawPosA == drawPosB) { if (walkPath.empty() == true && hasWalkingAnimation() == true) { setStandAnimation(); resetAnimationTime(); playerStatus = PlayerStatus::Stand; } while (walkPath.empty() == false) { const auto& nextMapPos = walkPath.back(); if (walkPath.size() == 1) { const auto levelObj = map[nextMapPos].front(); if (levelObj != nullptr) { levelObj->executeAction(game); walkPath.pop_back(); setStandAnimation(); resetAnimationTime(); playerStatus = PlayerStatus::Stand; return; } } if (nextMapPos == mapPosition) { walkPath.pop_back(); continue; } playSound(walkSound); setWalkAnimation(); setDirection(getPlayerDirection(mapPosition, nextMapPos)); MapPosition(map, nextMapPos); currPositionStep = 0.025f; updateWalkPathStep(newDrawPos); break; } } else { updateWalkPathStep(newDrawPos); } LevelObject::updateDrawPosition(map, newDrawPos); } }
void Player::updateAI(Level& level) { switch (playerStatus) { case PlayerStatus::Walk: return; default: break; } auto plr = level.getCurrentPlayer(); if (plr != nullptr) { setWalkPath(level.Map().getPath(mapPosition, plr->MapPosition())); } }
void MapObject::OnControllerEvent(SControllerEvent Event) { float ax,ay,az,aw; Matrix MVP; int mx=0; int my=0; float fx=0; float fy=0; __INT32 distance=0; TowerObject* tower; if (Event.Type == ECE_POINTER) { switch (Event.PointerData.Event) { case EPE_PRESSED: isPressed = true; dragDistanceX = 0; dragDistanceY = 0; break; case EPE_DRAGGED: distance= dragDistanceX*dragDistanceX + dragDistanceY*dragDistanceY; if (distance>50) isDrag=true; break; case EPE_RELEASED: if (isPressed) { MVP.LoadIdentity(); MVP.Multiply(*(CCamera3D::GetInstance()->GetProjectMatrix())); MVP.Multiply(*(CCamera3D::GetInstance()->GetViewMatrix())); ScreenPos2MapPos(Event.PointerData.X,Event.PointerData.Y,MVP,fx,fy); mx = __INT32(fx/scale); my = __INT32(fy/scale); if ((!isDrag)/* && ((mLogicMap[my*mWidth+mx]==OBJECT_NONE) || (mLogicMap[my*mWidth+mx]==OBJECT_TOWER))*/) { if (mx>=0 && mx<mWidth &&my>=0 && my<mHeight) { if (mLogicMap[my*mWidth+mx]==OBJECT_NONE) //click len vung dat trong' { ScreenPos2TowerPos(Event.PointerData.X,Event.PointerData.Y,MVP,mx,my); Log("Logic map position: %d %d", mx, my); if ((mx<mWidth) && (my<mHeight) && (mx>=0) && (my>=0)) { if (selected == my * mWidth + mx) { selected =-1; drawRange = 0; CList<__INT32> NullList; UpdateTowerBuildBar(&NullList); return; } selected = my * mWidth + mx; if ((mLogicMap[selected]==OBJECT_NONE) && (mLogicMap[selected+1]==OBJECT_NONE) && (mLogicMap[selected+mWidth]==OBJECT_NONE) && (mLogicMap[selected+mWidth+1]==OBJECT_NONE) && CPathManagement::GetInstance()->IsStillExist(selected)) //Vung dat 2x2 trong' { CStateIngame::currentBuildBar->sellButton->SetVisible(false); //kiem tra so button xay tru can hien CStateIngame::currentBuildBar->Tower1->SetVisible(true); Log("Truoc calc boundary"); CalculateBoundary(mx, my, SELECTED_BUILDABLE_CELL_COLOR,0); Log("Sau calc boundary"); CList<__INT32> towerList;//sau nay de thong tin cac tower co the xay tu dat' trong vao day towerList.AddItem(TOWER_GUN); UpdateTowerBuildBar(&towerList); } else //2x2 khong trong' { CStateIngame::currentBuildBar->sellButton->SetVisible(false); CalculateBoundary(mx, my, SELECTED_UNBUILDABLE_CELL_COLOR,0); //an het cac button xay tru CStateIngame::currentBuildBar->Tower1->SetVisible(false); CStateIngame::currentBuildBar->Tower2->SetVisible(false); CStateIngame::currentBuildBar->Tower3->SetVisible(false); CStateIngame::currentBuildBar->Tower4->SetVisible(false); } } } else if(mLogicMap[my*mWidth+mx]==OBJECT_TOWER)//click len TOWER { CStateIngame::currentBuildBar->sellButton->SetVisible(true); tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx,my))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx-1,my))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx-1,my-1))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx,my-1))); if (selected == tower->mPosition.mY * mWidth + tower->mPosition.mX) { selected =-1; drawRange = 0; CList<__INT32> NullList; UpdateTowerBuildBar(&NullList); return; } selected = tower->mPosition.mY * mWidth + tower->mPosition.mX; CalculateBoundary( tower->mPosition.mX, tower->mPosition.mY, SELECTED_TOWER_CELL_COLOR, tower->mProperties->mRange); UpdateTowerBuildBar(tower->mProperties->mLstChildren); } else //click len Enemy hoac tree { CStateIngame::currentBuildBar->sellButton->SetVisible(false); ScreenPos2TowerPos(Event.PointerData.X,Event.PointerData.Y,MVP,mx,my); CalculateBoundary(mx, my, SELECTED_UNBUILDABLE_CELL_COLOR,0); //an het cac button xay tru CStateIngame::currentBuildBar->Tower1->SetVisible(false); CStateIngame::currentBuildBar->Tower2->SetVisible(false); CStateIngame::currentBuildBar->Tower3->SetVisible(false); CStateIngame::currentBuildBar->Tower4->SetVisible(false); } } else selected = -1; } isPressed = false; } isDrag = false; break; } } }