//----------------------------------------------------------------------------------- void World::makeBullets() { float _rotation = getPlayerRotation(); Vec4 position = getPlayerPosition(); Vec4 offset = getPlayerPosition(); Vec4 colour = Vec4(1.0f, 1.0f, 1.0f); Vec4 size = Vec4(0.2f, 0.2f, 0.2f); Vec4 destination( (0.1*sin((PI *_rotation)/180)), 0, (0.1*cos((PI *_rotation)/180)) ); Bullet* tmp = new Bullet(position, offset, colour, size, destination); //Vec4(position.m_x - 0.1, position.m_y - 0.1, position.m_z - 0.1), //Vec4(position.m_x + 0.1,position.m_y + 0.1,position.m_z + 0.1)); m_bodies.push_back(tmp); }
void Model::drawMiniMap() { unsigned int IMAGE_SIZE = gamerImg.GetWidth(); double h = 50; //app->GetHeight()/2-FIELD_SIZE*IMAGE_SIZE/2; double w = 50; //app->GetWidth()/2-FIELD_SIZE*IMAGE_SIZE/3*2; pair<int,int> pos = getPlayerPosition(); int i_now = pos.first/FIELD_SIZE*FIELD_SIZE; int j_now = pos.second/FIELD_SIZE*FIELD_SIZE; int max_value_j = j_now+FIELD_SIZE; int cells_count = MAP_SIZE/FIELD_SIZE + static_cast<bool> (MAP_SIZE%FIELD_SIZE); int mini_map_w = w+(max_value_j-j_now)*IMAGE_SIZE+10, mini_map_h = h-2; int mutable_w = mini_map_w, mutable_h = mini_map_h; if (cells_count>1) { sf::String miniText("Mini Map:",sf::Font::GetDefaultFont(),FONT_SIZE/2); miniText.SetPosition(mini_map_w,mini_map_h-miniText.GetRect().GetHeight()); app->Draw(miniText); for (int i=0;i<cells_count;++i) { mutable_w = mini_map_w; for (int j=0;j<cells_count;++j) { if (i_now/FIELD_SIZE == i && j_now/FIELD_SIZE == j) { miniMapPlayerSpr.SetPosition(mutable_w,mutable_h); app->Draw(miniMapPlayerSpr); } else { miniMapSpr.SetPosition(mutable_w,mutable_h); app->Draw(miniMapSpr); } mutable_w += miniMapImg.GetWidth(); } mutable_h += miniMapImg.GetHeight(); } sf::String finishText("<-Finish!",sf::Font::GetDefaultFont(),FONT_SIZE/3); finishText.SetPosition(mutable_w+4,mutable_h-miniMapImg.GetHeight()); app->Draw(finishText); } drawLogStrings(mini_map_w,mutable_h); }
void PlayerImplStandalone::update( float deltaTime ) { // first update the physics entity getPlayerPhysics()->updateEntity( deltaTime ); // update player's actual position and rotation once per frame getPlayerEntity()->setPosition( _currentPos ); getPlayerEntity()->setRotation( _currentRot ); // adjust the camera to updated position and rotation. the physics updates the translation of player. if ( _p_camera ) _p_camera->setCameraTransformation( getPlayerPosition(), getPlayerRotation() ); getChatManager()->update( deltaTime ); // update sound getPlayerSound()->updatePosition( _currentPos ); }
POINTS Board::makeMove(Players playerName, const Move& move) { Coordinate first = move.getPosition(PHASE_FIRST); Coordinate second = move.getPosition(PHASE_SECOND); Coordinate begPos = getPlayerPosition(playerName); FieldType playerField = F_PLAYER_A; FieldType opponentField = F_PLAYER_B; if(playerName == PLAYER_B) { playerField = F_PLAYER_B; opponentField = F_PLAYER_A; } Coordinate halfwayPoint; if(std::abs(second.col-first.col) + std::abs(second.row-first.row) > 1){ //second phase move is longer than first phase move halfwayPoint.col = (first.col+second.col)>>1; halfwayPoint.row = (first.row+second.row)>>1; }
void SpecialZone::onCheckpoint(const int slot_id) { if (PlayerManager->is_client()) return; //no checkpoints on client GameType game_type = RTConfig->game_type; PlayerSlot &slot = PlayerManager->get_slot(slot_id); slot.need_sync = true; if (game_type == GameTypeRacing) { const SpecialZone &zone = PlayerManager->get_next_checkpoint(slot); if (zone.name != name) { LOG_DEBUG(("wrong checkpoint, next checkpoint: %s", zone.name.c_str())); GameMonitor->displayMessage("messages", "wrong-checkpoint", 3, false); return; } PlayerManager->fix_checkpoints(slot, zone); //remove all wrong checkpoints from list } slot.position = getPlayerPosition(slot_id); //v3<int> spawn_pos(_zones[c].position + checkpoint_size.convert2v3(0) / 2); //slot.position = spawn_pos; if (final()) { GameMonitor->game_over("messages", "mission-accomplished", 5, true); return; } if (slot.visible) { if (game_type != GameTypeRacing) GameMonitor->displayMessage("messages", "checkpoint-reached", 3, false); } else { if (slot.remote != -1 && PlayerManager->is_server() ) { Message m(Message::TextMessage); m.channel = slot_id; m.set("hint", "0"); m.set("area", "messages"); m.set("message", "checkpoint-reached"); m.set("duration", "3"); PlayerManager->send(slot, m); } } }
void PlayerImplClient::update( float deltaTime ) { // first update the physics entity getPlayerPhysics()->updateEntity( deltaTime ); if ( !_isRemoteClient ) { // update player's actual position and rotation once per frame getPlayerEntity()->setPosition( _currentPos ); getPlayerEntity()->setRotation( _currentRot ); getPlayerNetworking()->updatePosition( _currentPos._v[ 0 ], _currentPos._v[ 1 ], _currentPos._v[ 2 ] ); getPlayerNetworking()->updateRotation( _rotZ + osg::PI ); getPlayerNetworking()->updateAnimationFlags( getPlayerAnimation()->getAnimationFlags() ); // adjust the camera to updated position and rotation. the physics updates the translation of player. _p_camera->setCameraTranslation( getPlayerPosition(), getPlayerRotation() ); // update chat gui getChatManager()->update( deltaTime ); } else { // update remote client's rotation and position osg::Vec3f lastpos = _currentPos; float lastrot = _rotZ; osg::Vec3f clientpos; getPlayerNetworking()->getPosition( clientpos._v[ 0 ], clientpos._v[ 1 ], clientpos._v[ 2 ] ); getPlayerNetworking()->getRotation( _rotZ ); _currentRot.makeRotate( -_rotZ + osg::PI, osg::Vec3f( 0.0f, 0.0f, 1.0f ) ); getPlayerEntity()->setRotation( _currentRot ); getPlayerEntity()->setPosition( _currentPos ); // calculate the current velocity osg::Vec3f vel( clientpos - lastpos ); // do we need a hard position correction? if ( vel.length2() > NW_POS_CORRECTION_THRESHOLD ) { osg::Matrix mat; mat.makeRotate( _currentRot ); //mat.setTrans( lastpos + vel * deltaTime ); mat.setTrans( clientpos ); getPlayerPhysics()->setTransformation( mat ); getPlayerPhysics()->setDirection( 0.0f, 0.0f ); } else { vel._v[ 2 ] = 0.0f; // limit velocity if ( vel.length2() > 1.0f ) vel.normalize(); getPlayerPhysics()->setDirection( vel.x(), vel.y() ); } // set animation depending on position and rotation changes if ( ( ( clientpos.z() - lastpos.z() ) > NW_JUMP_THRESHOLD ) && !getPlayerPhysics()->isJumping() ) { getPlayerPhysics()->jump(); getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle ); getPlayerAnimation()->setAnimation( EnPlayerAnimation::eJump ); } else if ( vel.length2() > NW_WALK_THRESHOLD ) { getPlayerAnimation()->setAnimation( EnPlayerAnimation::eWalk ); } else { getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle ); } if ( fabs( lastrot - _rotZ ) > NW_ROT_THRESHOLD ) getPlayerAnimation()->setAnimation( EnPlayerAnimation::eTurn ); } // update sound getPlayerSound()->updatePosition( _currentPos ); }
void Model::drawMap() { app->Clear(sf::Color(100,100,100)); unsigned int height = app->GetHeight(); unsigned int IMAGE_SIZE = gamerImg.GetWidth(); double h = 50; //height/2-FIELD_SIZE*IMAGE_SIZE/2; double w = 50; //app->GetWidth()/2-FIELD_SIZE*IMAGE_SIZE/3*2; pair<int,int> pos = getPlayerPosition(); int i_now = pos.first/FIELD_SIZE*FIELD_SIZE; int j_now = pos.second/FIELD_SIZE*FIELD_SIZE; int max_value_i = i_now+FIELD_SIZE; int max_value_j = j_now+FIELD_SIZE; if (max_value_i > MAP_SIZE) max_value_i = MAP_SIZE; if (max_value_j > MAP_SIZE) max_value_j = MAP_SIZE; app->Draw(sf::Shape::Rectangle(w-2, h-2, w+(max_value_j-j_now)*IMAGE_SIZE+2, h+(max_value_i-i_now)*IMAGE_SIZE+2, sf::Color(200,200,149))); app->Draw(sf::Shape::Rectangle(w, h, w+(max_value_j-j_now)*IMAGE_SIZE, h+(max_value_i-i_now)*IMAGE_SIZE, sf::Color(50,50,50))); drawMiniMap(); //Draws mini map in front of the rectangles above for (int i=i_now;i<max_value_i;++i) { for (int j=j_now;j<max_value_j;++j) { if (getState(i,j) == GAME_EMPTY_CELL) continue; if (getState(i,j) == GAME_WALL) { boxSpr.SetPosition(w+(j%FIELD_SIZE)*IMAGE_SIZE,h+(i%FIELD_SIZE)*IMAGE_SIZE); app->Draw(boxSpr); } else if (getState(i,j) == GAME_PLAYER) { double rot = players.begin()->get()->rotation; gamerSpr.SetCenter(gamerImg.GetWidth()/2,gamerImg.GetHeight()/2); gamerSpr.SetRotation(rot); gamerSpr.SetPosition(w+(j%FIELD_SIZE+0.5)*IMAGE_SIZE,h+(i%FIELD_SIZE+0.5)*IMAGE_SIZE); app->Draw(gamerSpr); } else if (getState(i,j) == GAME_ENEMY) { for(vector<PlayerPtr>::iterator it = players.begin()+1; it!=players.end(); ++it) { if (it->get()->getX() == i && it->get()->getY() == j) { double rot = it->get()->rotation; computerSpr.SetCenter(gamerImg.GetWidth()/2,gamerImg.GetHeight()/2); computerSpr.SetRotation(rot); computerSpr.SetPosition(w+(j%FIELD_SIZE+0.5)*IMAGE_SIZE,h+(i%FIELD_SIZE+0.5)*IMAGE_SIZE); break; } } app->Draw(computerSpr); } } } app->Display(); }
// All key events are processed here void WorldDrawer::keyOperations() { if (keyStates[KEY_ESC]) // On Escape, program exits glutExit(); float rotateStep = 0.04f; float moveStep = 0.25f; if (camera.mode == MODE_FPS) { if (keySpecialStates[KEY_UP]) // Rotate FPS up { camera.rotateFPS_OX(-rotateStep); } if (keySpecialStates[KEY_DOWN]) // Rotate FPS down { camera.rotateFPS_OX(rotateStep); } if (keySpecialStates[KEY_LEFT]) // Rotate FPS left { camera.rotateFPS_OY(-rotateStep); } if (keySpecialStates[KEY_RIGHT]) // Rotate FPS right { camera.rotateFPS_OY(rotateStep); } } else if (camera.mode == MODE_TPS) { if (keySpecialStates[KEY_UP]) // Rotate TPS up { camera.rotateTPS_OX(-rotateStep, distanceToTPSTarget); } if (keySpecialStates[KEY_DOWN]) // Rotate TPS down { camera.rotateTPS_OX(rotateStep, distanceToTPSTarget); } if (keySpecialStates[KEY_LEFT]) // Rotate TPS left { camera.rotateTPS_OY(-rotateStep, distanceToTPSTarget); } if (keySpecialStates[KEY_RIGHT]) // Rotate TPS right { camera.rotateTPS_OY(rotateStep, distanceToTPSTarget); } } else if (camera.mode == MODE_TOP) { if (keySpecialStates[KEY_LEFT]) // Rotate left { camera.rotateTPS_OY(-rotateStep, distanceToTop); } if (keySpecialStates[KEY_RIGHT]) // Rotate right { camera.rotateTPS_OY(rotateStep, distanceToTop); } } float eyeDistanceStep = 1.f; // Zoom closer if (keyStates['[']) { eyeDistance -= eyeDistanceStep; // Move closer to the viewer if (camera.mode == MODE_TPS && distanceToTPSTarget - zoomSensivity > 0) { distanceToTPSTarget -= zoomSensivity; camera.translate_ForwardFree(zoomSensivity); } else if (camera.mode == MODE_TOP && distanceToTop - zoomSensivity * 20 > 0) { distanceToTop -= zoomSensivity * 20; camera.translate_ForwardFree(zoomSensivity * 20); } } if (keyStates[']']) { eyeDistance += eyeDistanceStep; // Move farther from the viewer if (camera.mode == MODE_TPS) { distanceToTPSTarget += zoomSensivity; camera.translate_ForwardFree(-zoomSensivity); } else if (camera.mode == MODE_TOP) { distanceToTop += zoomSensivity * 20; camera.translate_ForwardFree(-zoomSensivity * 20); } } if (keyStates['w']) // Move forward { camera.translate_Forward(moveStep); // Check colision Vector3D newPos = getPlayerPosition(); std::vector<Point2d> neighbours = labyrinth.getNeighbours(labyrinth.playerPos); bool updatedCell = labyrinth.updateCell(neighbours, newPos); if (labyrinth.foundPortal()) { Sleep(1000); int mode = camera.mode; switchCameraMode(MODE_FPS); init(); switchCameraMode(mode); } if (!updatedCell) { for (unsigned int i = 0; i < neighbours.size(); ++i) if (labyrinth.isColision(neighbours[i], newPos)) { camera.translate_Forward(-moveStep); } } } if (keyStates['s']) // Move backwards { camera.translate_Forward(-moveStep); // Check colision Vector3D newPos = getPlayerPosition(); std::vector<Point2d> neighbours = labyrinth.getNeighbours(labyrinth.playerPos); bool updatedCell = labyrinth.updateCell(neighbours, newPos); if (labyrinth.foundPortal()) { Sleep(1000); int mode = camera.mode; switchCameraMode(MODE_FPS); init(); switchCameraMode(mode); } if (!updatedCell) { for (unsigned int i = 0; i < neighbours.size(); ++i) if (labyrinth.isColision(neighbours[i], newPos)) { camera.translate_Forward(moveStep); } } } if (keyStates['a']) // Move left { camera.translate_Right(-moveStep); // Check colision Vector3D newPos = getPlayerPosition(); std::vector<Point2d> neighbours = labyrinth.getNeighbours(labyrinth.playerPos); bool updatedCell = labyrinth.updateCell(neighbours, newPos); if (labyrinth.foundPortal()) { Sleep(1000); int mode = camera.mode; switchCameraMode(MODE_FPS); init(); switchCameraMode(mode); } if (!updatedCell) { for (unsigned int i = 0; i < neighbours.size(); ++i) if (labyrinth.isColision(neighbours[i], newPos)) { camera.translate_Right(moveStep); } } } if (keyStates['d']) // Move right { camera.translate_Right(moveStep); // Check colision Vector3D newPos = getPlayerPosition(); std::vector<Point2d> neighbours = labyrinth.getNeighbours(labyrinth.playerPos); bool updatedCell = labyrinth.updateCell(neighbours, newPos); if (labyrinth.foundPortal()) { Sleep(1000); int mode = camera.mode; switchCameraMode(MODE_FPS); init(); switchCameraMode(mode); } if (!updatedCell) { for (unsigned int i = 0; i < neighbours.size(); ++i) if (labyrinth.isColision(neighbours[i], newPos)) { camera.translate_Right(-moveStep); } } } }
void PlayerImplStandalone::postInitialize() { log_info << " setup player implementation Standalone ..." << std::endl; // attach camera entity log_debug << " - searching for camera entity '" << PLAYER_CAMERA_ENTITIY_NAME << "'..." << std::endl; // get camera entity _p_camera = dynamic_cast< EnCamera* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_CAMERA, PLAYER_CAMERA_ENTITIY_NAME ) ); if ( _p_camera ) { log_debug << " - camera entity successfully attached" << std::endl; } else { log_error << " could not attach player camera entity" << std::endl; } // attach physics entity log_debug << " - searching for physics entity '" << _playerAttributes._physicsEntity << "' ..." << std::endl; // find and attach physics component _p_playerPhysics = dynamic_cast< EnPlayerPhysics* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLPHYS, _playerAttributes._physicsEntity ) ); if ( _p_playerPhysics ) { _p_playerPhysics->setPlayer( this ); _p_playerPhysics->initializePhysics( _currentPos, _currentRot ); log_debug << " - physics entity successfully attached" << std::endl; } else { log_error << " could not attach player physics entity" << std::endl; } // attach animation entity log_debug << " - searching for animation entity '" << _playerAttributes._animationEntity << "' ..." << std::endl; // find and attach animation component _p_playerAnimation = dynamic_cast< EnPlayerAnimation* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLANIM, _playerAttributes._animationEntity ) ); if ( _p_playerAnimation ) { _p_playerAnimation->setPlayer( this ); log_debug << " - animation entity successfully attached" << std::endl; if ( _cameraMode == Ego ) // in ego mode we won't render our character { removeFromSceneGraph(); } else // if in spheric mode disable the mouse pointer { gameutils::GuiUtils::get()->showMousePointer( false ); } } else { log_error << " could not attach player animation entity" << std::endl; } // attach sound entity log_debug << " - searching for sound entity '" << _playerAttributes._soundEntity << "' ..." << std::endl; // find and attach sound component, tollerate missing sound for now _p_playerSound = dynamic_cast< EnPlayerSound* >( yaf3d::EntityManager::get()->findEntity( ENTITY_NAME_PLSOUND, _playerAttributes._soundEntity ) ); if ( !_p_playerSound ) log_error << " could not find sound entity '" << _playerAttributes._soundEntity << "' of type PlayerSound. player sound deactivated" << std::endl; else { _p_playerSound->setPlayer( this ); log_debug << " - sound entity successfully attached" << std::endl; } // setup camera mode setCameraMode( _cameraMode ); // create the chat manager if ( !createChatManager() ) { log_error << " - could not create chat system" << std::endl; } log_info << " player implementation successfully initialized" << std::endl; // create only the input handler when animation and physics are attached if ( _p_playerAnimation && _p_playerPhysics ) { // create a new input handler for this player _p_inputHandler = new PlayerIHCharacterCameraCtrl< PlayerImplStandalone >( this, getPlayerEntity() ); _p_inputHandler->setMenuEnabled( false ); // get configuration settings getConfiguration(); } // set initial camera transformation if ( _p_camera ) _p_camera->setCameraTransformation( getPlayerPosition(), getPlayerRotation() ); }