void keyboard(unsigned char key, int x, int y) { if (key == 'q') { tank1.RotateBarrel(-5); } else if (key == 'e') { tank1.RotateBarrel(5); } else if (key == 'a') { tank1.ChangeBulletPower(1); std::cout << "Bullet power: " << tank1.GetBulletPower() << std::endl; } else if (key == 'd') { tank1.ChangeBulletPower(-1); std::cout << "Bullet power: " << tank1.GetBulletPower() << std::endl; } else if (key == 'z') { bullet.Fire( tank1.GetEndOfBarrelPosition(), tank1.GetBulletPower(), tank1.GetBarrelAngle() ); } }
static void display(void) { // clear the scene glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); tank1.Draw(); tank2.Draw(); bullet.Draw(); glPopMatrix(); glutSwapBuffers(); }
int main(int argc, char *argv[]) { przeszkoda.push_back(new CPrzeszkoda(0.5, 0.5)); przeszkoda.push_back(new CPrzeszkoda(0.5, 0.5)); przeszkoda.push_back(new CPrzeszkoda(0.5, 0.5)); przeszkoda.push_back(new CPrzeszkoda(0.5, 0.5)); srand(time(NULL)); list<CPrzeszkoda *>::iterator tmp = przeszkoda.begin(); // pierwszy element (*tmp)->SetPosition(-1.0, -1.0, 0.0); tmp++; (*tmp)->SetPosition(-1.0, 1.0, 0.0); tmp++; (*tmp)->SetPosition(1.0, 1.0, 0.0); tmp++; (*tmp)->SetPosition(1.0, -1.0, 0.0); boost.SetPosition(0, 0, 0); glutInitWindowSize(800, 600); glutInitWindowPosition(40, 40); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutCreateWindow("OpenGLUT Shapes"); tank1.SetPosition(2.0, 2.0, 0.0); tank2.SetPosition(2.0, -2.0, 0.0); glutReshapeFunc(resize); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboard); glutTimerFunc(gameLogicUpdateIntervalInMs, gameLogic, 0); // set white as clear colour glClearColor(1, 1, 1, 1); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glutMainLoop(); return 0; }
void CTankBSP :: Spawn( void ) { Precache(); pev->solid = SOLID_BSP; pev->movetype = MOVETYPE_PUSH; SET_MODEL( ENT(pev), STRING(pev->model) ); UTIL_SetSize( pev, pev->mins, pev->maxs ); UTIL_SetOrigin( pev, pev->origin ); pev->flags |= FL_MONSTER; pev->takedamage = DAMAGE_YES; pev->rendermode = kRenderTransTexture; pev->renderamt = 0; pev->view_ofs = Vector ( 0,0,100 ); pev->health = TANK_LIFE; m_pTankModel = GetClassPtr( (CTank*)NULL ); UTIL_SetOrigin( m_pTankModel->pev, pev->origin ); m_pTankModel->pev->angles = pev->angles; m_pTankModel->m_pTankBSP = this; m_pTankModel->Spawn(); SetThink ( TankThink ); SetTouch ( TouchPlayer ); pev->nextthink = pev->ltime + 0xFF; }
/** * Processes the state * changes the tower's state to attack if enemy is close * * @author Cameron MacIntosh * @param _fDeltaTick Time between frames */ void CTowerIdle::Process(float32 _fDeltaTick) { // check through all tanks that are on the same face as this player. for (uint32 ui = 0; ui < 8; ++ui) { CTank* pTank = CPlayerManager::GetPlayerManagerInstance().GetPlayer(ui)->GetTank(); if ((pTank->GetFacePosition() == m_pTower->GetFacePosition()) && (pTank->GetTeam() != m_pTower->GetTeam()) ) { m_pTower->SetAIState(TOWERAI_STATE_ATTACK); } } //if an enemy moves close, switch to Attack m_pTower->SetAIState(TOWERAI_STATE_ATTACK); }
void CTankBSP :: TouchPlayer ( CBaseEntity *pOther ) { if ( !pOther->IsPlayer() ) return; // le joueur n active le tank que s il le touche et qu il est a peu pres au meme niveau que le tank pour eviter que le joueur sortant sur le toit du tank ne l active a nouveau if ( pOther->pev->origin.z > pev->origin.z + 48 ) return; // m_pTankModel->UseTank( pOther, pOther, USE_TOGGLE, 0 ); edict_t *pent = FIND_ENTITY_BY_CLASSNAME ( NULL, "info_tank_model" ); if ( pent == NULL ) return; CTank *pTank = (CTank*) CBaseEntity::Instance(pent); pTank->UseTank( pOther, pOther, USE_TOGGLE, 0 ); }
static void display(void) { // clear the scene glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); if (tank1.GetLife() > 0 && tank2.GetLife() > 0) { tank1.Draw(); tank2.Draw(); tank1.DrawAllBullets(); tank2.DrawAllBullets(); for (list<CPrzeszkoda *>::iterator it = przeszkoda.begin(); it != przeszkoda.end(); it++) { (*it)->Draw(); } boost.Draw(); } else { glRasterPos2i(0, 0); glColor3f(1, 0, 0); unsigned char tekst[] = "Koniec gry"; glutBitmapString(GLUT_BITMAP_HELVETICA_18, tekst); } glPopMatrix(); glutSwapBuffers(); }
static void idle(void) { for (list<CPrzeszkoda *>::iterator it = przeszkoda.begin(); it != przeszkoda.end(); it++) { tank1.WykryjKolizje(*it); tank2.WykryjKolizje(*it); } double Kolizja_z_Boostem; Kolizja_z_Boostem = tank1.WykryjKolizje_z_Boostem(boost); if (Kolizja_z_Boostem == 0 && boost.CzyAktywny()) { boost.LosujBoost(); tank1.AktywujBoost(boost, tank1, tank2); czasPodniesieniaBoosta = clock(); boost.Dezaktywuj(); } Kolizja_z_Boostem = tank2.WykryjKolizje_z_Boostem(boost); if (Kolizja_z_Boostem == 0 && boost.CzyAktywny()) { boost.LosujBoost(); tank2.AktywujBoost(boost, tank1, tank2); czasPodniesieniaBoosta = clock(); boost.Dezaktywuj(); } if (czasPodniesieniaBoosta != 0 && (clock() - czasPodniesieniaBoosta) / (double)CLOCKS_PER_SEC >= 5) { boost.LosujPozycje();//dodac timer juz w funkcji czasPodniesieniaBoosta = 0; } glutPostRedisplay(); }
/* * Initialises the class instance * * @author Cameron MacIntosh * @param _pOwner the owning AIPlayer * @param _pMove an address of an instance of the Move substate * @param _pFlee an address of an instance of the Flee substate * @param Attack an address of an instance of the Attack substate * @return if it succeded. Don't use the instance if it returns false. */ bool CAIStateProtectPlayer::Initialise(CAIPlayer* _pOwner, CAISubstateMove* _pMove, CAISubstateFlee* _pFlee, CAISubstateAttack* _pAttack) { if(_pOwner!=0) { m_pOwner = _pOwner; m_pTank = m_pOwner->GetTank(); m_pMove = _pMove; m_pFlee = _pFlee; m_pAttack = _pAttack; InitGeneral(); for(uint32 i=0; i<8; ++i) { CTank* pTank = CPlayerManager::GetPlayerManagerInstance().GetPlayer(i)->GetTank(); if((m_eEnemyTeam!=pTank->GetTeam())&&(pTank!=m_pTank)) { if(pTank->HasFlag()) { //carrier has flag m_pFlagCarrier = pTank; D3DXVECTOR2 vec2 = pTank->GetPosition2D(); m_TTargetLastPos2.x = static_cast<int32>(vec2.x); m_TTargetLastPos2.y = static_cast<int32>(vec2.y); m_pMove->SetTarget(m_TTargetLastPos2.x, m_TTargetLastPos2.y, pTank->GetFacePosition()); } } } if(m_pFlagCarrier==0) { m_pOwner->RequestState(AI_STATE_IDLE); return(false); } return(true); } return(false); }
int main(int argc, char *argv[]) { // it's still possible to use console to print messages printf("Hello openGL world!"); // the same can be done with cout / cin glutInitWindowSize(800, 600); glutInitWindowPosition(40, 40); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutCreateWindow("OpenGLUT Shapes"); tank1.SetPosition(-2.0, -2.0, 0.0); tank2.SetPosition(2.0, -2.0, 0.0); glutReshapeFunc(resize); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboard); glutTimerFunc(gameLogicUpdateIntervalInMs, gameLogic, 0); // set white as clear colour glClearColor(1, 1, 1, 1); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glutMainLoop(); return 0; }
void gameLogic(int value) { for (list<CBullet *>::iterator it = tank1.BulletListBegin(); it != tank1.BulletListEnd(); it++) { tank2.WykryjKolizjeZPociskiem(*it); } for (list<CBullet *>::iterator it = tank2.BulletListBegin(); it != tank2.BulletListEnd(); it++) { tank1.WykryjKolizjeZPociskiem(*it); } tank1.FlyAllBullets(gameLogicUpdateIntervalInMs); tank2.FlyAllBullets(gameLogicUpdateIntervalInMs); glutTimerFunc(gameLogicUpdateIntervalInMs, gameLogic, value); }
void CTankCam :: CamThink ( void ) { pev->nextthink = gpGlobals->time + BSP_NEXTTHINK_TIME; // fonction appelée tous les 1/20 de seconde // le skin des chenilles a besoin d un taux de rafraichissement eleve pour etre realiste // skin des chenilles // nombre d images : 9 if ( m_pTankModel == NULL ) return; m_skin += m_pTankModel->pev->velocity.Length() / 20; if ( (int)m_skin != m_pTankModel->pev->skin ) { while ( (int)m_skin > 8 ) //de 0 à 8 : 9 images { m_skin -= 8; } m_pTankModel->pev->skin = (int)m_skin; } if ( gpGlobals->time < m_flNextFrameTime ) { float flDifY = m_pTankModel->pev->v_angle.y - m_vecTourelleAngle.y; float flDifX = m_pTankModel->pev->v_angle.x - m_vecTourelleAngle.x; float flNewAngleY = ( ( gpGlobals->time - ( m_flNextFrameTime - NEXTTHINK_TIME ) ) * flDifY ) / NEXTTHINK_TIME; float flNewAngleX = ( ( gpGlobals->time - ( m_flNextFrameTime - NEXTTHINK_TIME ) ) * flDifX ) / NEXTTHINK_TIME; m_pTankModel->SetBoneController(1, m_vecTourelleAngle.y + flNewAngleY ); m_pTankModel->SetBoneController(0, m_vecTourelleAngle.x + flNewAngleX ); } // if ( m_pTankModel->bSetView == TRUE ) // SetPlayerTankView(TRUE); // rafraichissement de la positon de la camera pour le client if ( m_pTankModel->bTankOn == TRUE ) SetPlayerTankView(TRUE); // rafraichissement de la positon de la camera pour le client }
int CTankBSP :: TakeDamage ( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ) { m_pTankModel->m_flTempHealth = pev->health; if ( m_pTankModel->bTankOn == FALSE ) return 1; // le joueur ne le blesse pas - debug if ( FClassnameIs(pevInflictor, "player") ) return 1; // que des dégâts par explosifs if ( !(bitsDamageType & DMG_BLAST) ) return 1; // ne se blesse pas lui meme if ( pevInflictor == m_pTankModel->pev ) return 1; // déjà mort if ( pev->health == 0 ) return 1; // mine antichar if ( FClassnameIs(pevInflictor,"monster_mine_ac" ) || FClassnameIs(pevAttacker,"monster_mine_ac" ) ) pev->health = 0; pev->health -= flDamage; // pas quand le tank est eteint if ( m_pTankModel->m_pCam != NULL ) { m_pTankModel->m_pCam->SetPlayerTankView(TRUE); // rafraichissement de la vie côté client if (pev->health <= 0 ) { pev->health = 0; m_pTankModel->TankDeath(); return 0; } } return 1; }
//overall code by rigardt, turret rotation by Cameron void CAISubstate::FireAtEnemy() { //#ifndef _AI_NOSHOOT // should probably be placed in substate.cpp, or substateAttack.cpp // as this is supposed to only be a container for the current state(s),\ // and not make decisions itself. D3DXVECTOR3 vec3Distance; D3DXVECTOR3 vec3ShootDir; D3DXVECTOR3 vec3ShootRight; CTank* pTankTarget = 0; bool m_bWillShoot = false; // check through all tanks that are on the same face as this player. for (uint32 ui = 0; ui < 8; ++ui) { // get pointer to a tank. CTank* pTank = CPlayerManager::GetPlayerManagerInstance().GetPlayer(ui)->GetTank(); // make sure that the tank is not equal to this one. if (m_pTank != CPlayerManager::GetPlayerManagerInstance().GetPlayer(ui)->GetTank() ) { if (pTank->GetAlive() && pTank->GetPowerUp() != POWERUP_INVISIBILITY && pTank->GetTeam() != m_pTank->GetTeam() && pTank->GetFacePosition() == m_pTank->GetFacePosition() && !m_pTank->HasFlag()) { // the tank found a target and will shoot at it at this point. m_bWillShoot = true; vec3ShootDir = pTank->GetPosition() - m_pTank->GetPosition(); if (D3DXVec3Length(&vec3Distance) > D3DXVec3Length(&vec3ShootDir) ) { // sets the shoot directions and the target tank. vec3Distance = vec3ShootDir; pTankTarget = pTank; } } } } // transforms the right coords. D3DXMATRIX mat; D3DXMatrixRotationAxis(&mat, &g_atUpRightDirectionVecs[m_pTank->GetFacePosition()].vec3Up, D3DXToRadian(90) ); D3DXVec3TransformCoord(&vec3ShootRight, &vec3Distance, &mat); //vec3Distance += (vec3ShootRight*((RandomFloat()-0.5f)*0.5f)); std::vector<CWall*> rvecWalls; if (!m_pTank->HasFlag()) { // checks if the target exsists. if (pTankTarget) { std::vector<CWall*> rvecWallsOnFace; // declare some base variables. float32 fXTarget = pTankTarget->GetPosition2D().x; float32 fYTarget = pTankTarget->GetPosition2D().y; float32 fXPosition = m_pTank->GetPosition2D().x; float32 fYPosition = m_pTank->GetPosition2D().y; float32 fXMin = 0.0f; float32 fXMax = 0.0f; float32 fYMin = 0.0f; float32 fYMax = 0.0f; // set the x min and max if (fXTarget < fXPosition) { fXMin = fXTarget - 0.5f; fXMax = fXPosition + 0.5f; } else { fXMax = fXTarget + 0.5f; fXMin = fXPosition - 0.5f; } // set the y min and max if (fYTarget < fYPosition) { fYMin = fYTarget - 0.5f; fYMax = fYPosition + 0.5f; } else { fYMax = fYTarget + 0.5f; fYMin = fYPosition - 0.5f; } // local variable is destroyed after these braces { std::vector<CWall*> rvecWalls = CPathfinder::GetInstance().GetCube()->GetWalls(); for (uint32 ui = 0; ui < rvecWalls.size(); ++ui) { // checks the wall is on the same face as the tank. if (rvecWalls[ui]->GetFacePosition() == m_pTank->GetFacePosition() ) { // adds the wall in the vector of walls to be referenced. rvecWallsOnFace.push_back(rvecWalls[ui]); } } } // checks through all the walls that are on the same face as the tank. for (uint32 ui = 0; ui < rvecWallsOnFace.size(); ++ui) { // This is the check to see if the walls are inside the square made by the two tanks. if (rvecWallsOnFace[ui]->GetX() >= fXMin && rvecWallsOnFace[ui]->GetX() <= fXMax && rvecWallsOnFace[ui]->GetY() >= fYMin && rvecWallsOnFace[ui]->GetY() <= fYMax) { // adds the wall into the a new vector of walls. rvecWalls.push_back(rvecWallsOnFace[ui]); } } } // checks if the vector is empty. if (!rvecWalls.empty() ) { //for (uint32 ui = 0; ui < rvecWalls.size(); ++ui) //{ // // checks if the shoot direction ray intersects with any of the wall // // that are in the vector. // if (TRUE == D3DXBoxBoundProbe(&rvecWalls[ui]->GetBoundingBox().m_vec3Min, // &rvecWalls[ui]->GetBoundingBox().m_vec3Max, // &m_pTank->GetPosition(), &vec3ShootDir) ) // { // if even one wall intersects the tank will not shoot. m_bWillShoot = false; //break; //} //} } // actually shoot now if (m_bWillShoot == true) { D3DXVec3Normalize(&vec3ShootDir, &vec3Distance); D3DXVec3Normalize(&vec3ShootRight, &vec3ShootRight); //m_pTank->SetShootRightAndDir(vec3ShootDir, vec3ShootRight); //rotates the turret - Cameron D3DXVECTOR2 vec2; EFacePosition eFace = m_pTank->GetFacePosition(); vec2.x = D3DXVec3Dot(&vec3ShootDir, &g_atUpRightDirectionVecs[eFace].vec3Right); vec2.y = D3DXVec3Dot(&vec3ShootDir, &g_atUpRightDirectionVecs[eFace].vec3Direction); m_pTank->RotateTurret(vec2.x, vec2.y, 0.5f); // int32 iRandomChanceValue = static_cast<int32>(RandomFloat() * 300); if (m_pTank->GetEMPCount() == 0) { m_pTank->ShootPlasma(); } else if (iRandomChanceValue >= 1) { m_pTank->ShootPlasma(); } else if (D3DXVec3LengthSq(&vec3Distance) <= 18.0f) { m_pTank->ShootEMP(); } else { m_pTank->ShootPlasma(); } } } //#endif //_AI_NOSHOOT }
void keyboard(unsigned char key, int x, int y)//poszukac czegos na wzor qt { if (tank1.GetLife() > 0 && tank2.GetLife() > 0) { //przód if (key == 'w') { tank1.Move(0, +0.1, 0); } if (key == 'i') { tank2.Move(0, +0.1, 0); } //ty³ if (key == 's') { tank1.Move(0, -0.1, 0); } if (key == 'k') { tank2.Move(0, -0.1, 0); } //prawo if (key == 'd') { tank1.switchAngle(-5); } if (key == 'l') { tank2.switchAngle(-5); } //lewo if (key == 'a') { tank1.switchAngle(5); } if (key == 'j') { tank2.switchAngle(5); } // zmiana mocy pocisku dla czolgu pierwszego if (key == 'q') { tank1.ChangeBulletPower(1); std::cout << "Bullet power: " << tank1.GetBulletPower() << std::endl; } else if (key == 'z') { tank1.ChangeBulletPower(-1); std::cout << "Bullet power: " << tank1.GetBulletPower() << std::endl; } // strzal dla czolgu pierwszego else if (key == 'e') { tank1.FireBullet(); } // si³a pocisku drugiego if (key == 'u') { tank2.ChangeBulletPower(1); std::cout << "Bullet power: " << tank2.GetBulletPower() << std::endl; } else if (key == 'n') { tank2.ChangeBulletPower(-1); std::cout << "Bullet power: " << tank2.GetBulletPower() << std::endl; } // strzal drugiego pocisku else if (key == 'o') { tank2.FireBullet(); } } }
int CTank::Restore( CRestore &restore ) // s execute lors du chargement rapide { if ( !CBaseMonster::Restore(restore) ) return 0; int status = restore.ReadFields( "CTank", this, m_SaveData, ARRAYSIZE(m_SaveData) ); //----------------------- ALERT ( at_console,"TANK RESTORE -----------------\n" ); // restoration de la camera bSetView = 1; // restoration du tank CBaseEntity *pFind = UTIL_FindEntityByClassname( NULL, "info_tank_model" ); while ( pFind != NULL && pFind == this ) pFind = UTIL_FindEntityByClassname( pFind, "info_tank_model" ); // chargement if ( pFind == NULL ) { ALERT ( at_console, "TANK RESTORE : il n'y a qu'un tankmodel : simple chargement\n" ); return status; } // changement de niveau ALERT ( at_console, "TANK RESTORE : autre tankmodel : changement de niveau\n" ); CTank *pModelFound = (CTank*)pFind; m_pTankBSP = pModelFound->m_pTankBSP; // changement de tankbsp m_pTankBSP->m_pTankModel = this; pModelFound->SetThink ( SUB_Remove ); // destruction du tankmodel inutile pModelFound->pev->nextthink = gpGlobals->time + 0.1; pModelFound->pev->rendermode = kRenderTransTexture; pModelFound->pev->renderamt = 0; m_pTankBSP->pev->angles = pev->angles; m_pTankBSP->pev->origin = pev->origin; // tite boite edict_t *pentTrouve; CBaseEntity *pTrouve; CBasePlayer *pPlayer = (CBasePlayer*) UTIL_FindEntityByClassname ( NULL, "player" ); pentTrouve = FIND_ENTITY_BY_CLASSNAME( NULL, "info_teleport_destination" ); if ( pentTrouve == NULL ) { ALERT ( at_console , "info_tank_model : pas de teleport destination !!!\n" ); return status; } else { pTrouve = CBaseEntity :: Instance ( pentTrouve ); Vector vecTeleport = pTrouve->pev->origin; UTIL_SetOrigin( pPlayer->pev, vecTeleport ); } return status; }