示例#1
0
 inline auto getFingerPosition(FingerID mX) const noexcept
 {
     return renderWindow.mapPixelToCoords(
         sf::Touch::getPosition(mX, renderWindow));
 }
示例#2
0
//Player rendering
void Player::draw(sf::RenderWindow& window, sf::View& view, Level level, string move) {

	//Player control scheme
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || move == "up") {

		//Grounded check
		if (grounded) { 

			//Jump
			velocity.y = -20;
			position.y += 0.5;
			grounded = false;
		}
	}
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || move == "left") {

		//Move player left
		velocity.x = -7;
	}
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || move == "right") {
		
		//Move player right
		velocity.x = 7;
	}

	//Add force of gravity to player velocity
	velocity.y += 0.8;
	
	//Position at player center
	int centerX = position.x - (size / 2);
	int centerY = position.y - (size / 2);

	//Dimensions
	int halfSize = size / 2;
	float skin = 2;

	//Nearest tiles for preforming collision checks
	Tile currentTile = level.getTileFromWorld(sf::Vector2f(centerX, centerY));
	Tile below = level.getTileFromWorld(sf::Vector2f(centerX, centerY + (currentTile.size / 2) + velocity.y));
	Tile right = level.getTileFromWorld(sf::Vector2f(centerX + skin + (currentTile.size / 2), centerY));
	Tile top = level.getTileFromWorld(sf::Vector2f(centerX, centerY - skin - (currentTile.size / 2)));
	Tile left = level.getTileFromWorld(sf::Vector2f(centerX - skin - (currentTile.size / 2), centerY));

	//Check bottom collision
	if (below.type != 0 && velocity.y > 0) {
		grounded = true;
		velocity.y = 0;
	}
	else {
		grounded = false;
	}

	//Check top collision
	if (top.type != 0 && velocity.y < 0) velocity.y = 0;
	 
	//Check left collision
	if (left.type != 0 && velocity.x < 0) velocity.x = 0;

	//Check right collision
	if (right.type != 0 && velocity.x > 0) velocity.x = 0;

	//Update player position
	position.y += velocity.y;
	position.x += velocity.x;

	//Update position tracking
	lastX = position.x;

	//Centered camera
	view.setCenter(position);
	
	//Reset x velocity to prevent momentum build up
	velocity.x = 0;
	
	//Render player
	shape.setPosition(position);
	window.draw(shape);
};
示例#3
0
void getEvent(sf::Event& event, sf::RenderWindow& window, Input& in)
{
	switch (event.type)
	{
	case sf::Event::Closed:
		window.close();
		break;
	case sf::Event::KeyPressed:
		switch (event.key.code)
		{
		case sf::Keyboard::W: in.W = true; break;
		case sf::Keyboard::A: in.A = true; break;
		case sf::Keyboard::S: in.S = true; break;
		case sf::Keyboard::D: in.D = true; break;

		case sf::Keyboard::Up: in.W = true; break;
		case sf::Keyboard::Left: in.A = true; break;
		case sf::Keyboard::Down: in.S = true; break;
		case sf::Keyboard::Right: in.D = true; break;

		case sf::Keyboard::I: in.record = true; break;
		case sf::Keyboard::O: in.edit = true; break;
		case sf::Keyboard::P: in.predict = true; break;
		case sf::Keyboard::Space: in.reset = true; break;

		case sf::Keyboard::Num0: in.action = 0; break;
		case sf::Keyboard::Num1: in.action = 1; break;
		case sf::Keyboard::Num2: in.action = 2; break;
		case sf::Keyboard::Num3: in.action = 3; break;
		case sf::Keyboard::Num4: in.action = 4; break;
		case sf::Keyboard::Num5: in.action = 5; break;
		case sf::Keyboard::Num6: in.action = 6; break;
		case sf::Keyboard::Num7: in.action = 7; break;
		case sf::Keyboard::Num8: in.action = 8; break;
		case sf::Keyboard::Num9: in.action = 9; break;

		case sf::Keyboard::Numpad0: in.action = 10; break;
		case sf::Keyboard::Numpad1: in.action = 11; break;
		case sf::Keyboard::Numpad2: in.action = 12; break;
		case sf::Keyboard::Numpad3: in.action = 13; break;
		case sf::Keyboard::Numpad4: in.action = 14; break;
		case sf::Keyboard::Numpad5: in.action = 15; break;
		case sf::Keyboard::Numpad6: in.action = 16; break;
		case sf::Keyboard::Numpad7: in.action = 17; break;
		case sf::Keyboard::Numpad8: in.action = 18; break;
		case sf::Keyboard::Numpad9: in.action = 19; break;

		case sf::Keyboard::X: in.zoom += 0.5f; break;
		case sf::Keyboard::Z: in.zoom -= 0.5f; break;

		case sf::Keyboard::F1: in.action = -2;

		default:
			break;
		}
		break;

	case sf::Event::KeyReleased:
		switch (event.key.code)
		{
		case sf::Keyboard::W: in.W = false; break;
		case sf::Keyboard::A: in.A = false; break;
		case sf::Keyboard::S: in.S = false; break;
		case sf::Keyboard::D: in.D = false; break;

		case sf::Keyboard::Up: in.W = false; break;
		case sf::Keyboard::Left: in.A = false; break;
		case sf::Keyboard::Down: in.S = false; break;
		case sf::Keyboard::Right: in.D = false; break;
		default:
			break;
		}
	default:
		break;
	}
}
示例#4
0
void ParentUI::Draw(sf::RenderWindow &window)
{
	window.draw(*m_arrow);
	window.draw(*m_indicator);
	window.draw(*m_parent_ball);
}
示例#5
0
void Projectile::draw(sf::RenderWindow & window, float dt)
{
	window.draw(*this->projectileBody);
}
void score::render(sf::RenderWindow &app)
    {
        app.draw(_text);
    }
示例#7
0
文件: Block.cpp 项目: minhasg/Brick
void Block::render(sf::RenderWindow& window){
	window.draw(_block);	
}
示例#8
0
void entity_draw(const Entity& entity, sf::RenderWindow& renderWindow)
{
	renderWindow.draw(entity.sprite);
}
示例#9
0
文件: button.cpp 项目: MarDom92/Last
void Button::wyswietl(sf::RenderWindow &okno)
{
    okno.draw(przycisk);
    okno.draw(sprajt);
    okno.draw(napis);
}
示例#10
0
void Map::renderBackground(sf::RenderWindow& window) const
{
	window.Draw(*mBackground);
}
示例#11
0
void Map::renderForeground(sf::RenderWindow& window) const
{
	window.Draw(*mForeground);
}
示例#12
0
void SplashScreen::render(const sf::Time & /*dt*/, sf::RenderWindow &window)
{
    window.draw(text);
}
示例#13
0
void game::render(sf::RenderWindow &window)
{
    window.display();
}
示例#14
0
文件: UnlockPew.cpp 项目: nebula2/Pew
void UnlockPew::Render(sf::RenderWindow &window){
	if (m_active)
		window.draw(pewDropSprite);
}
示例#15
0
void Window::BeginDraw() {
	_window.clear(sf::Color::Black);
}
示例#16
0
void Game::manageEvents(sf::RenderWindow &window, Character &player, TileMap map)
{

    sf::Event event;
    while (window.pollEvent(event))
    {

    // Close window : exit
    if (event.type == Event::Closed)
    {
        window.close();
        deleteAllMobs();
    }
    
    // Escape pressed : exit
    else if (Keyboard::isKeyPressed(Keyboard::Escape))
    {
        window.close();
        deleteAllMobs();
    }
    //Right arrow : move player right
    else if (Keyboard::isKeyPressed(Keyboard::Right))
    {
        player.getAnimatedWalk().y=48*2;
        player.collisionWithTileManager(map);
        player.moveRight();
        player.canMove();
    }
    //Left arrow : move player left
    else if (Keyboard::isKeyPressed(Keyboard::Left))
    {
        player.getAnimatedWalk().y=48;
        player.collisionWithTileManager(map);
        player.moveLeft();
        player.canMove();
    }
    //Up arrow : move player up
    else if (Keyboard::isKeyPressed(Keyboard::Up))
    {
        player.getAnimatedWalk().y=48*3;
        player.collisionWithTileManager(map);
        player.moveUp();
        player.canMove();
        
    }
    //Down arrow : move player down
    else if (Keyboard::isKeyPressed(Keyboard::Down))
    {
        player.getAnimatedWalk().y=0;
        player.collisionWithTileManager(map);
        player.moveDown();
        player.canMove();
        
    }
    if(Keyboard::isKeyPressed(Keyboard::Right)||Keyboard::isKeyPressed(Keyboard::Left) || //So walk animation only occur
           Keyboard::isKeyPressed(Keyboard::Up)   ||Keyboard::isKeyPressed(Keyboard::Down))  //when pler moved
    {
        //Animates the plaer's movements
        player.getAnimatedWalk().x += 47;
        if(player.getAnimatedWalk().x>=47*2)
        player.getAnimatedWalk().x=0;
            
        player.getSprite().setTextureRect(IntRect(player.getAnimatedWalk().x,player.getAnimatedWalk().y,47,47));
        }
    }

}
示例#17
0
void Window::EndDraw() {
	_window.display();
}
示例#18
0
void SnakeNode::render(sf::RenderWindow& window)
{
	window.draw(shape_);
}
示例#19
0
文件: Player.cpp 项目: 8102/R-Type
void Player::getDrawn(sf::RenderWindow & win)
{
	win.draw(*this);
	if (isShielded() == true)
		win.draw(_shield);
}
示例#20
0
	int render(Phys* phys)
	{
        window->clear(sf::Color::Black);
		
		sf::Vector2f viewmove(0, 0);
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) viewmove.x -= base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) viewmove.x += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) viewmove.y += base_camera_move;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) viewmove.y -= base_camera_move;
		viewmove *= (phys->dt * view->getSize().x / scrw);
		viewmove = sv2rotate(viewmove, -view->getRotation());
		view->move(viewmove);
		
		view->zoom(pow(1.2, -mouse_wheel));
		mouse_wheel = 0;

		float viewrotate = 0;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::LBracket)) viewrotate += base_camera_rotate;
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::RBracket)) viewrotate -= base_camera_rotate;
		viewrotate *= phys->dt;
		view->rotate(viewrotate);
		
		window->setView(*view);
		
		
		
		for (std::vector<Ship*>::iterator its = phys->ship_list.begin(); its != phys->ship_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}		
		for (std::vector<Shell*>::iterator its = phys->shell_list.begin(); its != phys->shell_list.end(); ++its)
		{
			sf::ConvexShape& shape = (*its)->shape;
			cpVect pos = cpBodyGetPosition((*its)->body);
			cpFloat angle = cpBodyGetAngle((*its)->body);
			shape.setPosition(pos.x, pos.y);
			shape.setRotation(180 / PI * angle);
			window->draw(shape);
		}
		
		char* str = new char[30];
		float acc = 0;
		for (int i = 0; i < frame_time_count; i++) acc += phys->last_frame_deltas[i];
		acc /= frame_time_count;
		sprintf(str, "%.1f", 1./acc);
		drawtext(str, 0.02, 0.98, 10);	
		
		int sc = (*phys->ship_list.begin())->score;
		sprintf(str, "%d", sc);
		drawtext(str, 0.98, 0.98, 10);
		
		delete str;
		
		
        window->display();
		
		return 0;
	}
示例#21
0
int main(){

    logger.logNoEndl("Setting up window...");
    window.create(sf::VideoMode(430,430), "GL");
    logger.continueln(" done!");

    logger.logNoEndl("Setting up variables...");

    rect1.setFillColor(sf::Color(200,200,200));
    rect1.setOutlineColor(sf::Color(0,0,0));
    rect1.setOutlineThickness(-2);
    rect1.setPosition(10,10);

    rect2.setFillColor(sf::Color(200,200,200));
    rect2.setOutlineColor(sf::Color(0,0,0));
    rect2.setOutlineThickness(-2);
    rect2.setPosition(220,10);

    rect3.setFillColor(sf::Color(200,200,200));
    rect3.setOutlineColor(sf::Color(0,0,0));
    rect3.setOutlineThickness(-2);
    rect3.setPosition(10,220);

    rect4.setFillColor(sf::Color(200,200,200));
    rect4.setOutlineColor(sf::Color(0,0,0));
    rect4.setOutlineThickness(-2);
    rect4.setPosition(220,220);

    sf::Font font;
    if (!font.loadFromFile("arial.ttf")){
        logger.log(Logger::LogType::Error, "Arial font not found. Cannot continue...");
        return 1;
    }

    sf::Text label1("Solid White", font);
    label1.setColor(sf::Color::Black);
    label1.setPosition(rect1.getPosition().x + rect1.getSize().x / 2 - label1.getLocalBounds().width / 2, rect1.getPosition().y + rect1.getSize().y / 2 - label1.getLocalBounds().height / 2 - 10);

    sf::Text label2("Marquee", font);
    label2.setColor(sf::Color::Black);
    label2.setPosition(rect2.getPosition().x + rect2.getSize().x / 2 - label2.getLocalBounds().width / 2, rect2.getPosition().y + rect2.getSize().y / 2 - label2.getLocalBounds().height / 2 - 10);

    sf::Text label3("Color Cycle", font);
    label3.setColor(sf::Color::Black);
    label3.setPosition(rect3.getPosition().x + rect3.getSize().x / 2 - label3.getLocalBounds().width / 2, rect3.getPosition().y + rect3.getSize().y / 2 - label3.getLocalBounds().height / 2 - 10);

    sf::Text label4("Pew", font);
    label4.setColor(sf::Color::Black);
    label4.setPosition(rect4.getPosition().x + rect4.getSize().x / 2 - label4.getLocalBounds().width / 2, rect4.getPosition().y + rect4.getSize().y / 2 - label4.getLocalBounds().height / 2 - 10);


    unsigned short r = 0,
                   g = 0,
                   b = 0;

    logger.continueln(" done!");

    logger.log("Running until told to stop.");
    bool running = true;
    while(running){
        sf::Event event;
        while (window.pollEvent(event)){
            if (event.type == sf::Event::Closed){
                running = false;
            } else if (event.type == sf::Event::MouseMoved){
                doMouseMove();
            } else if (event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased){
                doMouseButton(event.mouseButton.button);
            }
        }
        window.clear(sf::Color::White);
        window.draw(rect1);
        window.draw(rect2);
        window.draw(rect3);
        window.draw(rect4);
        window.draw(label1);
        window.draw(label2);
        window.draw(label3);
        window.draw(label4);
        window.display();
    }

    logger.log("Closing...");
}
示例#22
0
void Player::Gravity(sf::RenderWindow &app){
        m_vely+=GameConfig::g_config["gravity"]/1000.f*app.GetFrameTime();
}
示例#23
0
void Effect::draw(sf::RenderWindow& window) {
    if(activated){
        window.draw((*this));
    }
}
示例#24
0
void Window::Create() {
	auto style = _isFullscreen ? sf::Style::Fullscreen : sf::Style::Default;
	_window.create({ _windowSize.x, _windowSize.y, 32 }, _windowTitle, style);
}
// рисует заданную птицу в нужном месте в переданном окне
void draw_bird(const dtts::BirdState &_bird_state, sf::Sprite &_sprite, sf::RenderWindow &_window) {
	_sprite.setPosition(_bird_state.x - bird_radius, height - (_bird_state.y + bird_radius));
	_sprite.setTextureRect(sf::IntRect(_bird_state.right_direction ? 0 : 2 * bird_radius, 0, bird_radius * 2, bird_radius * 2));
	_window.draw(_sprite);
}
示例#26
0
void Window::Draw(sf::Drawable& drawable) {
	_window.draw(drawable);
}
示例#27
0
Screen::Status GameMenu::drawMenu(sf::RenderWindow &window)
{
  int choice = 0; //scelta del menu.

  while(window.isOpen())
  {

    while(window.pollEvent(this->event))
    {
      if(event.type == sf::Event::Closed || ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
      {
        return Screen::EXIT;
      }

      else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Down)
      {
        if(choice == 3)
          choice = -1; // forse troverò un modo migliore un giorno
        this->scelta[++choice].setColor(sf::Color::Magenta);
        if(choice != 0)
          this->scelta[choice-1].setColor(sf::Color::White);
        else
          this->scelta[3].setColor(sf::Color::White);
      }

      else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Up)
      {
        if(choice == 0)
          choice = 4;
        this->scelta[--choice].setColor(sf::Color::Magenta);
        if(choice != 3)
          this->scelta[choice+1].setColor(sf::Color::White);
        else
          this->scelta[0].setColor(sf::Color::White);
      }

      else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
      {
        switch(choice)
        {
        case 0:
          return Screen::NEWGAME;
        case 1:
          return Screen::SCOREBOARD;
        case 2:
          return Screen::SETTINGS;
        case 3:
          return Screen::EXIT;
        }
      }
    }

    //inizia la parte del ciclo in cui la schermata viene disegnata e aggiornata
    
    window.clear();

    window.draw(this->background);

	  for (int i = 0; i < 4; i++)
	  {
		  window.draw(this->scelta[i]);
	  }

    window.display();
  }
  
}
示例#28
0
void Window::Destroy() {
	_window.close();
}
/**
Affiche le monstre la ou il doit etre sur la case, avec le bon angle et la bonne position
affiche également les points de vie du moob
*/
void afficheMonstre        (sf::RenderWindow &App, sf::Sprite  &SpriteMoob ,Monstre* monMoob,int cote, int offSetX, int offSetY ,  std::list<Tour*> &listTour)
{
   using namespace std;

    Case* caseMoob = monMoob->CaseCourante();

    drawHexagoneIJ ( caseMoob->getI() , caseMoob->getJ(), SpriteMoob, cote, offSetX,  offSetY);
    //sf::Shape pv   = sf::RectangleShape (0,0, 0+monMoob->getPV()/2 ,0,5,sf::Color::Black);

    sf::RectangleShape pv (sf::Vector2f(5,monMoob->getPV()/2));
    pv.setFillColor(sf::Color::Black);
    /// Moche

    drawHexagoneIJ ( caseMoob->getI() , caseMoob->getJ(), pv, cote, offSetX,  offSetY);
    // on centre le moob

    int etape;
    Direction dtion = monMoob->quelleDirection(etape);
    // on bouge en fonction de la direction
    double moobOffSetX=0,moobOffSetY=0,moobAvancement;
    if ( etape == 0)
    {
        moobAvancement = ((1000-monMoob->getAvancement())/1000)*cote*(sqrt(3));
    }
    else
    {
        moobAvancement = ((500-monMoob->getAvancement())/1000)*cote*(sqrt(3));
    }

    double angle = 0;
    switch (dtion)
    {
        case Est  : {
            moobOffSetX = moobAvancement;
            moobOffSetY =0;
            angle = -90;
            if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote;

            }

            break;}
        case NordEst : {
            moobOffSetX = moobAvancement / 2 ;
            moobOffSetY = -moobAvancement * (sqrt(3)/2) ;

            if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote /2;
                moobOffSetY += (sqrt(3)/2) *cote *(sqrt(3)/2);

            }
            angle = -30;
            break;}
        case NordOuest : {
            moobOffSetX = -moobAvancement / 2 ;
            moobOffSetY = -moobAvancement * (sqrt(3)/2) ;
            if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote /2;
                moobOffSetY += (sqrt(3)/2) *cote *(sqrt(3)/2);

            }
            angle = 30;
            break;}
        case Ouest : {
            moobOffSetX = - moobAvancement;
            moobOffSetY = 0;
            if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote;


            }
            angle = 90;
            break;}
        case SudOuest : {
             angle = 160;
            moobOffSetX = -moobAvancement / 2 ;
            moobOffSetY = moobAvancement * (sqrt(3)/2) ;
             if ( etape == 0)
            {
                moobOffSetX += (sqrt(3)/2) *cote /2;
                moobOffSetY -= (sqrt(3)/2) *cote *(sqrt(3)/2);

            }

            break;}
        case SudEst: {
             angle = -160;
             moobOffSetX = moobAvancement / 2 ;
            moobOffSetY = moobAvancement * (sqrt(3)/2) ;
              if ( etape == 0)
            {
                moobOffSetX -= (sqrt(3)/2) *cote /2;
                moobOffSetY -= (sqrt(3)/2) *cote *(sqrt(3)/2);

            }

            break;}
    }

    SpriteMoob.move(moobOffSetX,moobOffSetY);
   //double centreX = SpriteMoob.getSize().x/2;

   // double centreY = SpriteMoob.getSize().y/2 ;


    double centreX = SpriteMoob.getTextureRect().width /2  ;//  SpriteTower.getTexture().getSize().x/2;
    double centreY = SpriteMoob.getTextureRect().height/2 ;
    SpriteMoob.setPosition(centreX,centreY);
    SpriteMoob.rotate(angle);

    pv.  move(moobOffSetX-centreX,moobOffSetY-centreY);
    App.draw(pv);
    App.draw(SpriteMoob);

    //la gestion de l'attaque n'est pas encore definie
    if ( monMoob != NULL )
    {

        using namespace std;

        Case* laCase = monMoob->CaseCourante();

        if (laCase != NULL )
        {


            std::list<Tour*>::iterator itt = listTour.begin();

            for ( itt; itt != listTour.end() ; ++itt)
            {
                if ( (*itt)->getCible() == monMoob)
                {

                    sf::Vector2<int> ij;
                    sf::Vector2<double>xy;
                    ij.x = (*itt)->getPosition()->getI();
                    ij.y = (*itt)->getPosition()->getJ();
                    xy = IJtoXY (ij, cote, offSetX,  offSetY);
                   // sf::Shape Line   = sf::Shape::Line(SpriteMoob.GetPosition().x,SpriteMoob.GetPosition().y,xy.x,xy.y, 2, sf::Color::Red);
                   // App.Draw(Line);

                }
            }
        }
    }

}
示例#30
0
 inline auto getMousePosition() const noexcept
 {
     return renderWindow.mapPixelToCoords(
         sf::Mouse::getPosition(renderWindow));
 }