コード例 #1
0
ファイル: mw.cpp プロジェクト: colortheskyjade/game_ruyanche
void MainWindow::newLevel(int l){
	attack += 1;
	// clear the beam deque, intialize variables
	if(attack == 1){
		  QBrush back1(*bg1);
 			gameScene->setBackgroundBrush(back1);
 			maxcount = 15;
	}
	else if(attack == 2){
		  QBrush back2(*bg2);
 			gameScene->setBackgroundBrush(back2);
 			maxcount = 20;
	}
	else if(attack == 3){
		  QBrush back3(*bg3);
 			gameScene->setBackgroundBrush(back3);
 			maxcount = 25;
	
	}
	beampellets.clear();
	hasRed = false;
	ecount = 0;
	// make the game faster
	gameSpeed = gameSpeed * 3 / 5 + 1;
	maxhp += 5;
	if(l == 1){gameSpeed = 15; maxhp = 10; attack = 1;}
	timer->setInterval(gameSpeed);
	// reset player HP
	human->setHP(std::min(maxhp, human->getHP() + 5));
	// make temporarily invincible
	human->setInvincible();
	// start the game
	timer->start();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: bloopton/TestAnimation
int main()
{
    // setup window
    sf::Vector2i screenDimensions(576,272);
    sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Rainsford");
    window.setFramerateLimit(60);
    
    sf::Vector2f scaler(screenDimensions.x/72, screenDimensions.y/34);
    
    /*background setup
    There are 3 copies of each background layer (z-score), one is drawn in left and one is drawn right of
     the default background that is automatically drawn. After the any of the 3 copies moves its entire width left
     (position.x is negative width) it is assigned position.x = positive width. This "shuffles" the copies
     and gives an illusion of continuity.
     
     */
    sf::RectangleShape titlescreen (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture title;
    if (!title.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Rainsford Titlescreen.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    titlescreen.setTexture(&title); // texture is a sf::Texture
    titlescreen.setTextureRect(sf::IntRect(0, 0, 576,272));

    
    
    sf::RectangleShape titleback (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture titlebackTex;
    if (!titlebackTex.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Titleback.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    titleback.setTexture(&titlebackTex); // texture is a sf::Texture
    titleback.setTextureRect(sf::IntRect(0, 0, 576,272));
    
    
    
    sf::RectangleShape moon (sf::Vector2f(screenDimensions.x, screenDimensions.y));
    sf::Texture moonT;
    if (!moonT.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moon.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    moon.setTexture(&moonT); // texture is a sf::Texture
    moon.setTextureRect(sf::IntRect(0, 0, 576,272));

    
    

    //back1
    sf::RectangleShape back1(sf::Vector2f(72,34));
    sf::Texture textureBack1;
    if (!textureBack1.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background1.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back1.setTexture(&textureBack1); // texture is a sf::Texture
    back1.setTextureRect(sf::IntRect(0, 0, 72,34));
    
    //back2
    sf::RectangleShape back2(sf::Vector2f(128,32));
    sf::Texture textureBack2;
    if (!textureBack2.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background2.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back2.setTexture(&textureBack2); // texture is a sf::Texture
    back2.setTextureRect(sf::IntRect(0, 0, 128,32));

    sf::RectangleShape back2a(sf::Vector2f(128,32));
    back2a.setTexture(&textureBack2); // texture is a sf::Texture
    back2a.setTextureRect(sf::IntRect(0, 0, 128,32));
    back2a.setPosition(-128*8, 0);
    
    sf::RectangleShape back2b(sf::Vector2f(128,32));
    back2b.setTexture(&textureBack2); // texture is a sf::Texture
    back2b.setTextureRect(sf::IntRect(0, 0, 128,32));
    back2b.setPosition(128*8, 0);
    
    //back3
    sf::RectangleShape back3(sf::Vector2f(128,32));
    sf::Texture textureBack3;
    if (!textureBack3.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background3.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back3.setTexture(&textureBack3); // texture is a sf::Texture
    back3.setTextureRect(sf::IntRect(0, 0, 128,32));

    sf::RectangleShape back3a(sf::Vector2f(128,32));
    back3a.setTexture(&textureBack3); // texture is a sf::Texture
    back3a.setTextureRect(sf::IntRect(0, 0, 128,32));
    back3a.setPosition(-128*8, 0);
    
    sf::RectangleShape back3b(sf::Vector2f(128,32));
    back3b.setTexture(&textureBack3); // texture is a sf::Texture
    back3b.setTextureRect(sf::IntRect(0, 0, 128,32));
    back3b.setPosition(128*8, 0);
    
    //back4
    sf::RectangleShape back4(sf::Vector2f(112,32));
    sf::Texture textureBack4;
    if (!textureBack4.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background4.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back4.setTexture(&textureBack4); // texture is a sf::Texture
    back4.setTextureRect(sf::IntRect(0, 0, 112,32));

    sf::RectangleShape back4a(sf::Vector2f(112,32));
    back4a.setTexture(&textureBack4); // texture is a sf::Texture
    back4a.setTextureRect(sf::IntRect(0, 0, 112,32));
    back4a.setPosition(-112*8, 0);
    
    sf::RectangleShape back4b(sf::Vector2f(112,32));
    back4b.setTexture(&textureBack4); // texture is a sf::Texture
    back4b.setTextureRect(sf::IntRect(0, 0, 112,32));
    back4b.setPosition(112*8, 0);
    
    //back5
    sf::RectangleShape back5(sf::Vector2f(96,32));
    sf::Texture textureBack5;
    if (!textureBack5.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background5.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back5.setTexture(&textureBack5); // texture is a sf::Texture
    back5.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape back5a(sf::Vector2f(96,32));
    back5a.setTexture(&textureBack5); // texture is a sf::Texture
    back5a.setTextureRect(sf::IntRect(0, 0, 96,32));
    back5a.setPosition(-96*8, 0);
    
    sf::RectangleShape back5b(sf::Vector2f(96,32));
    back5b.setTexture(&textureBack5); // texture is a sf::Texture
    back5b.setTextureRect(sf::IntRect(0, 0, 96,32));
    back5b.setPosition(96*8, 0);
    
    //back6
    sf::RectangleShape back6(sf::Vector2f(72,32));
    sf::Texture textureBack6;
    if (!textureBack6.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background6.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    back6.setTexture(&textureBack6); // texture is a sf::Texture
    back6.setTextureRect(sf::IntRect(0, 0, 72,32));

    sf::RectangleShape back6a(sf::Vector2f(72,32));
    back6a.setTexture(&textureBack6); // texture is a sf::Texture
    back6a.setTextureRect(sf::IntRect(0, 0, 72,32));
    back6a.setPosition(-72*8, 0);
    
    sf::RectangleShape back6b(sf::Vector2f(72,32));
    back6b.setTexture(&textureBack6); // texture is a sf::Texture
    back6b.setTextureRect(sf::IntRect(0, 0, 72,32));
    back6b.setPosition(72*8, 0);
    
    //moonlight
    sf::RectangleShape moonlight(sf::Vector2f(96,32));
    sf::Texture textureMoon;
    if (!textureMoon.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moonlight.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    moonlight.setTexture(&textureMoon); // texture is a sf::Texture
    moonlight.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape moonlighta(sf::Vector2f(96,32));
    moonlighta.setTexture(&textureBack6); // texture is a sf::Texture
    moonlighta.setTextureRect(sf::IntRect(0, 0, 96,32));
    moonlighta.setPosition(-96*8, 0);
    
    sf::RectangleShape moonlightb(sf::Vector2f(96,32));
    moonlightb.setTexture(&textureMoon); // texture is a sf::Texture
    moonlightb.setTextureRect(sf::IntRect(0, 0, 96,32));
    moonlightb.setPosition(96*8, 0);

    
    //vines
    sf::RectangleShape vines(sf::Vector2f(96,32));
    sf::Texture textureVines;
    if (!textureVines.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Vines.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    vines.setTexture(&textureVines); // texture is a sf::Texture
    vines.setTextureRect(sf::IntRect(0, 0, 96,32));
    
    sf::RectangleShape vinesa(sf::Vector2f(96,32));
    vinesa.setTexture(&textureVines); // texture is a sf::Texture
    vinesa.setTextureRect(sf::IntRect(0, 0, 96,32));
    vinesa.setPosition(-96*8, 0);
    
    sf::RectangleShape vinesb(sf::Vector2f(96,32));
    vinesb.setTexture(&textureVines); // texture is a sf::Texture
    vinesb.setTextureRect(sf::IntRect(0, 0, 96,32));
    vinesb.setPosition(96*8, 0);

    
    //end of backgrounds ***********************************************************
    
    back1.scale(scaler);
    back2.scale(scaler);
    back3.scale(scaler);
    back4.scale(scaler);
    back5.scale(scaler);
    back6.scale(scaler);
    vines.scale(scaler);
    back2a.scale(scaler);
    back3a.scale(scaler);
    back4a.scale(scaler);
    back5a.scale(scaler);
    back6a.scale(scaler);
    vinesa.scale(scaler);
    back2b.scale(scaler);
    back3b.scale(scaler);
    back4b.scale(scaler);
    back5b.scale(scaler);
    back6b.scale(scaler);
    vinesb.scale(scaler);
    moonlight.scale(scaler);
    moonlighta.scale(scaler);
    moonlightb.scale(scaler);
    
    //flickering stormlamp spritesheet
    sf::Texture stormLamp;
    
    if (!stormLamp.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/RainsfordStormLamp_Spritesheet.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    Animation flicker;
    flicker.setSpriteSheet(stormLamp);
    flicker.addFrame(sf::IntRect (0, 0, 160, 90));
    flicker.addFrame(sf::IntRect (0, 90, 160, 90));
    flicker.addFrame(sf::IntRect (0, 180, 160, 90));
    flicker.addFrame(sf::IntRect (0, 90, 160, 90));


    AnimatedSprite flickerSprite(sf::seconds(.3), true, false);
    flickerSprite.scale(scaler);
    flickerSprite.setPosition(((-160/scaler.x)*18), -120*scaler.y/4);
    
    //IVAN STUFF
    // load texture (spritesheet)
    sf::Texture textureIvan;
    if (!textureIvan.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Ivan.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    // set up the animations for all four directions (set spritesheet and push frames)
    
    Animation ivan_standingRight;
    ivan_standingRight.setSpriteSheet(textureIvan);
    ivan_standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect(32, 0, 8, 8));
    ivan_standingRight.addFrame(sf::IntRect( 40, 0, 8, 8));
    
    Animation ivan_standingLeft;
    ivan_standingLeft.setSpriteSheet(textureIvan);
    ivan_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(32, 8, 8, 8));
    ivan_standingLeft.addFrame(sf::IntRect(40, 8, 8, 8));
    
    Animation ivan_walkingRight;
    ivan_walkingRight.setSpriteSheet(textureIvan);
    ivan_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect(32, 16, 8, 8));
    ivan_walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8));
    
    Animation ivan_walkingLeft;
    ivan_walkingLeft.setSpriteSheet(textureIvan);
    ivan_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8));
    ivan_walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8));

    Animation* currentIvanAnimation = &ivan_standingRight;
    
    AnimatedSprite ivan(sf::seconds(.07), true, false);
    ivan.setPosition(sf::Vector2f(screenDimensions.x / 2 - 264, 192));
    ivan.scale(scaler);
    
    
    // DOG load texture (spritesheet)
    sf::Texture textureDog;
    if (!textureDog.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Dog.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    

    //dog spritesheet animation setup
    Animation dog_standingRight;
    dog_standingRight.setSpriteSheet(textureDog);
    dog_standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    dog_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
    
    Animation dog_standingLeft;
    dog_standingLeft.setSpriteSheet(textureDog);
    dog_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    dog_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));

    Animation dog_walkingRight;
    dog_walkingRight.setSpriteSheet(textureDog);
    dog_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    dog_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    
    Animation dog_walkingLeft;
    dog_walkingLeft.setSpriteSheet(textureDog);
    dog_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    dog_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));

    Animation dog_walkingRightHostile;
    dog_walkingRightHostile.setSpriteSheet(textureDog);
    dog_walkingRightHostile.addFrame(sf::IntRect(0, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect(8, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect(16, 32, 8, 8));
    dog_walkingRightHostile.addFrame(sf::IntRect( 24, 32, 8, 8));
    
    Animation dog_walkingLeftHostile;
    dog_walkingLeftHostile.setSpriteSheet(textureDog);
    dog_walkingLeftHostile.addFrame(sf::IntRect(0, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect(8, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect(16, 40, 8, 8));
    dog_walkingLeftHostile.addFrame(sf::IntRect( 24, 40, 8, 8));

    Animation* currentDogAnimation = &dog_standingRight;
    
    AnimatedSprite dog(sf::seconds(.07), true, false);
    dog.setPosition(sf::Vector2f(screenDimensions.x / 2 - 200, 192));
    dog.scale(scaler);
    
    
    // load texture (spritesheet)
    sf::Texture texture;
    if (!texture.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Rainsford.png"))
    {
        std::cout << "Failed to load player spritesheet!" << std::endl;
        return 1;
    }
    
    // set up the animations for all directions (set spritesheet and push frames)
    
    Animation standingRight;
    standingRight.setSpriteSheet(texture);
    standingRight.addFrame(sf::IntRect(0, 0, 8, 8));
    standingRight.addFrame(sf::IntRect(8, 0, 8, 8));
    standingRight.addFrame(sf::IntRect(16, 0, 8, 8));
    standingRight.addFrame(sf::IntRect( 24, 0, 8, 8));
   // standingRight.addFrame(sf::IntRect(32, 0, 8, 8));
   // standingRight.addFrame(sf::IntRect( 40, 0, 8, 8));
    
    Animation standingLeft;
    standingLeft.setSpriteSheet(texture);
    standingLeft.addFrame(sf::IntRect(0, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect(8, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect(16, 8, 8, 8));
    standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8));
   // standingLeft.addFrame(sf::IntRect(32, 8, 8, 8));
   // standingLeft.addFrame(sf::IntRect(40, 8, 8, 8));

    Animation walkingRight;
    walkingRight.setSpriteSheet(texture);
    walkingRight.addFrame(sf::IntRect(0, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect(8, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect(16, 16, 8, 8));
    walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8));
    //walkingRight.addFrame(sf::IntRect(32, 16, 8, 8));
    //walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8));
    
    Animation walkingLeft;
    walkingLeft.setSpriteSheet(texture);
    walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8));
    walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8));
    //walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8));
    //walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8));
  
    Animation jumpingRight;
    jumpingRight.setSpriteSheet(texture);
    jumpingRight.addFrame(sf::IntRect(0, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect(8, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect(16, 32, 8, 8));
    jumpingRight.addFrame(sf::IntRect( 24, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8));

    
    Animation jumpingLeft;
    jumpingLeft.setSpriteSheet(texture);
    jumpingLeft.addFrame(sf::IntRect(0, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect(8, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect(16, 40, 8, 8));
    jumpingLeft.addFrame(sf::IntRect( 24, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8));

    
    Animation crawlingRight;
    crawlingRight.setSpriteSheet(texture);
    crawlingRight.addFrame(sf::IntRect(0, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect(8, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect(16, 64, 8, 8));
    crawlingRight.addFrame(sf::IntRect( 24, 64, 8, 8));
    //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8));
    //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8));
    
    
    Animation crawlingLeft;
    crawlingLeft.setSpriteSheet(texture);
    crawlingLeft.addFrame(sf::IntRect(0, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect(8, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect(16, 72, 8, 8));
    crawlingLeft.addFrame(sf::IntRect( 24, 72, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8));
    //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8));

    
    Animation disguise1;
    disguise1.setSpriteSheet(texture);
    disguise1.addFrame(sf::IntRect(0, 48, 8, 8));
    Animation disguise2;
    disguise2.setSpriteSheet(texture);
    disguise2.addFrame(sf::IntRect(8, 48, 8, 8));
    Animation disguise3;
    disguise3.setSpriteSheet(texture);
    disguise3.addFrame(sf::IntRect(16, 48, 8, 8));
    Animation disguise4;
    disguise4.setSpriteSheet(texture);
    disguise4.addFrame(sf::IntRect(24, 48, 8, 8));
    
    Animation crouchedRight;
    crouchedRight.setSpriteSheet(texture);
    crouchedRight.addFrame(sf::IntRect(0, 56, 8, 8));
    
    Animation crouchedLeft;
    crouchedLeft.setSpriteSheet(texture);
    crouchedLeft.addFrame(sf::IntRect(8, 56, 8, 8));


    Animation* currentAnimation = &standingRight;
    
    
    
    float rainsfordAnimationSpeed = .07;
    
    
    // set up AnimatedSprite
    AnimatedSprite animatedSprite(sf::seconds(rainsfordAnimationSpeed), true, false);
    animatedSprite.setPosition(sf::Vector2f(screenDimensions.x / 2 - 64, 192));
    animatedSprite.scale(scaler);
    sf::Clock frameClock;
    
    float speed = 650.f;
    bool noKeyWasPressed = true;
    
    
    enum direction { left, right};
    direction currentDir = right;
    
    
       while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                window.close();
        }
        
        sf::Time frameTime = frameClock.restart();
        
        
        // if a key was pressed set the correct animation and move correctly
        sf::Vector2f movement(0.f, 0.f);
        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            if(currentDir == left)
            {
                currentAnimation = &jumpingLeft;
                noKeyWasPressed = false;
            }
            if(currentDir == right)
            {
                currentAnimation = &jumpingRight;
                noKeyWasPressed = false;
            }
 
        }
        
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                currentAnimation = &crawlingLeft;
                currentDogAnimation = &dog_walkingLeft; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION

                movement.x += .2*speed;
                noKeyWasPressed = false;
                currentDir = left;
            }
            else
            {
                currentAnimation = &walkingLeft;
                currentDogAnimation = &dog_walkingLeftHostile; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION

                movement.x += speed;
                noKeyWasPressed = false;
                currentDir = left;

            }
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
           

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                currentAnimation = &crawlingRight;
                currentDogAnimation = &dog_walkingRight; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION

                movement.x -= .2*speed;
                noKeyWasPressed = false;
                currentDir = right;
            }
            else
            {
                currentAnimation = &walkingRight;
                currentDogAnimation = &dog_walkingRightHostile; //DOG ANIMATION
                currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION

                movement.x -= speed;
                noKeyWasPressed = false;
                currentDir = right;
            }
        }
        
    }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            if(currentDir == left)
            {
                currentAnimation = &crouchedLeft;
                noKeyWasPressed = false;
            }
            if(currentDir == right)
            {
                currentAnimation = &crouchedRight;
                noKeyWasPressed = false;
            }
            
        }
        

        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
        {
            currentAnimation = &disguise1;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
        {
            currentAnimation = &disguise2;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::T))
        {
            currentAnimation = &disguise3;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y))
        {
            currentAnimation = &disguise4;
            noKeyWasPressed = false;
            movement.x = 0;
        }
        
        

        
        // if no key was pressed
        if (noKeyWasPressed)
        {
            sf::Time slowerFrameTime = sf::seconds(.3);
            
            animatedSprite.setFrameTime(slowerFrameTime);
            dog.setFrameTime(slowerFrameTime); //DOG WUZ HERE
            ivan.setFrameTime(slowerFrameTime); //IVAn

            if (currentDir == left)
            {
                currentAnimation = &standingLeft;
                currentDogAnimation = &dog_standingLeft;// DAWG HERE TOO DOG
                currentIvanAnimation = &ivan_standingLeft;// IVAN

            }
            if (currentDir == right)
            {
                currentAnimation = &standingRight;
                currentDogAnimation = &dog_standingRight; // DAWG HERE TOO 2 DOG
                currentIvanAnimation = &ivan_standingRight;// IVAN

            }
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            animatedSprite.setFrameTime(sf::seconds(.15));
            dog.setFrameTime(sf::seconds(.15));//DOOOOOOOGGGGEEE DOG
            ivan.setFrameTime(sf::seconds(.15));//IVAN

        }
        else
        {
            animatedSprite.setFrameTime(sf::seconds(.07));
            dog.setFrameTime(sf::seconds(.07));//DOOOOOOOGGGGEEEDOOOOOOOGGGGEEEDOOOOOOOGGGGEEE DOG
            ivan.setFrameTime(sf::seconds(.07));//IVAN
        }
        
        
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
               //EDGE EFFECT HERE
        if (back2.getPosition().x <= back2.getSize().x*-8)
        {
            back2.setPosition(back2.getSize().x*8, 0);
        }
        if (back2a.getPosition().x <= back2a.getSize().x*-8)
        {
            back2a.setPosition(back2a.getSize().x*8, 0);
        }
 
        if (back2b.getPosition().x <= back2b.getSize().x*-8)
        {
            back2b.setPosition(back2b.getSize().x*8, 0);
        }
        
        if (back3.getPosition().x <= back3.getSize().x*-8)
        {
            back3.setPosition(back3.getSize().x*8, 0);
        }
        if (back3a.getPosition().x <= back3a.getSize().x*-8)
        {
            back3a.setPosition(back3a.getSize().x*8, 0);
        }
        
        if (back3b.getPosition().x <= back3b.getSize().x*-8)
        {
            back3b.setPosition(back3b.getSize().x*8, 0);
        }

        
        if (back4.getPosition().x <= back4.getSize().x*-8)
        {
            back4.setPosition(back4.getSize().x*8, 0);
        }
        if (back4a.getPosition().x <= back4a.getSize().x*-8)
        {
            back4a.setPosition(back4a.getSize().x*8, 0);
        }
        
        if (back4b.getPosition().x <= back4b.getSize().x*-8)
        {
            back4b.setPosition(back4b.getSize().x*8, 0);
        }

        
        if (back5.getPosition().x <= back5.getSize().x*-8)
        {
            back5.setPosition(back5.getSize().x*8, 0);
        }
        if (back5a.getPosition().x <= back5a.getSize().x*-8)
        {
            back5a.setPosition(back5a.getSize().x*8, 0);
        }
        
        if (back5b.getPosition().x <= back5b.getSize().x*-8)
        {
            back5b.setPosition(back5b.getSize().x*8, 0);
        }

        
        if (back6.getPosition().x <= back6.getSize().x*-8)
        {
            back6.setPosition(back6.getSize().x*8, 0);
        }
        if (back6a.getPosition().x <= back6a.getSize().x*-8)
        {
            back6a.setPosition(back6a.getSize().x*8, 0);
        }
        
        if (back6b.getPosition().x <= back6b.getSize().x*-8)
        {
            back6b.setPosition(back6b.getSize().x*8, 0);
        }
        
        
            //vines
        if (vines.getPosition().x <= vines.getSize().x*-8)
        {
            vines.setPosition(vines.getSize().x*8, 0);
        }
        if (vinesa.getPosition().x <= vinesa.getSize().x*-8)
        {
            vinesa.setPosition(vinesa.getSize().x*8, 0);
        }
        
        if (vinesb.getPosition().x <= vinesb.getSize().x*-8)
        {
            vinesb.setPosition(vinesb.getSize().x*8, 0);
        }

            //moonlight
        if (moonlight.getPosition().x <= moonlight.getSize().x*-8)
        {
            moonlight.setPosition(moonlight.getSize().x*8, 0);
        }
        if (moonlighta.getPosition().x <= moonlighta.getSize().x*-8)
        {
            moonlighta.setPosition(moonlighta.getSize().x*8, 0);
        }
        
        if (moonlightb.getPosition().x <= moonlightb.getSize().x*-8)
        {
            moonlightb.setPosition(moonlightb.getSize().x*8, 0);
        }

        
    }
        
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
    {
        
        //positive
        /*
        if (back2.getPosition().x >= back2.getSize().x*8)
        {
            back2.setPosition(back2.getSize().x*-8, 0);
        }
        if (back2a.getPosition().x >= back2a.getSize().x*8)
        {
            back2a.setPosition(back2a.getSize().x*-8, 0);
        }
        
        if (back2b.getPosition().x >= back2b.getSize().x*8)
        {
            back2b.setPosition(back2b.getSize().x*-8, 0);
        }
        
        if (back3.getPosition().x >= back3.getSize().x*8)
        {
            back3.setPosition(back3.getSize().x*-8, 0);
        }
        if (back3a.getPosition().x >= back3a.getSize().x*8)
        {
            back3a.setPosition(back3a.getSize().x*-8, 0);
        }
        
        if (back3b.getPosition().x >= back3b.getSize().x*8)
        {
            back3b.setPosition(back3b.getSize().x*-8, 0);
        }
        */
        
        if (back4.getPosition().x >= back4.getSize().x*8)
        {
            back4.setPosition(back4.getSize().x*-8, 0);
        }
        if (back4a.getPosition().x >= back4a.getSize().x*8)
        {
            back4a.setPosition(back4a.getSize().x*-8, 0);
        }
        
        if (back4b.getPosition().x >= back4b.getSize().x*8)
        {
            back4b.setPosition(back4b.getSize().x*-8, 0);
        }
        
        
        if (back5.getPosition().x >= back5.getSize().x*8)
        {
            back5.setPosition(back5.getSize().x*-8, 0);
        }
        if (back5a.getPosition().x >= back5a.getSize().x*8)
        {
            back5a.setPosition(back5a.getSize().x*-8, 0);
        }
        
        if (back5b.getPosition().x >= back5b.getSize().x*8)
        {
            back5b.setPosition(back5b.getSize().x*-8, 0);
        }
        
        
        if (back6.getPosition().x >= back6.getSize().x*8)
        {
            back6.setPosition(back6.getSize().x*-8, 0);
        }
        if (back6a.getPosition().x >= back6a.getSize().x*8)
        {
            back6a.setPosition(back6a.getSize().x*-8, 0);
        }
        
        if (back6b.getPosition().x >= back6b.getSize().x*8)
        {
            back6b.setPosition(back6b.getSize().x*-8, 0);
        }
            //vines
         if (vines.getPosition().x >= vines.getSize().x*8)
         {
         vines.setPosition(vines.getSize().x*-8, 0);
         }
         if (vinesa.getPosition().x >= vinesa.getSize().x*8)
         {
         vinesa.setPosition(vinesa.getSize().x*-8, 0);
         }
         
         if (vinesb.getPosition().x >= vinesb.getSize().x*8)
         {
         vinesb.setPosition(vinesb.getSize().x*-8, 0);
         }
        
        //moonlight
        if (moonlight.getPosition().x >= moonlight.getSize().x*8)
        {
            moonlight.setPosition(moonlight.getSize().x*-8, 0);
        }
        if (moonlighta.getPosition().x >= moonlighta.getSize().x*8)
        {
            moonlighta.setPosition(moonlighta.getSize().x*-8, 0);
        }
        
        if (moonlightb.getPosition().x >= moonlightb.getSize().x*8)
        {
            moonlightb.setPosition(moonlightb.getSize().x*-8, 0);
        }

        
    }
        
        
        float timeMov = 1;
        timeMov = frameTime.asSeconds();
        
        ivan.play(*currentIvanAnimation);
        dog.play(*currentDogAnimation);//dog animation here
        animatedSprite.play(*currentAnimation);
        flickerSprite.play(flicker);
        animatedSprite.move(0,0);
        back2.move(-16 * timeMov, 0);
        back3.move(-32 * timeMov, 0);
        back4.move(.3*movement.x * timeMov, 0);
        moonlight.move(.45*movement.x * timeMov, 0);
        back5.move(.55*movement.x * timeMov, 0);
        vines.move(.65*movement.x * timeMov, 0);
        back6.move(.8*movement.x * timeMov, 0);
        back2a.move(-16 * timeMov, 0);
        back3a.move(-32 * timeMov, 0);
        back4a.move(.3*movement.x * timeMov, 0);
        moonlighta.move(.45*movement.x * timeMov, 0);
        back5a.move(.55*movement.x * timeMov, 0);
        vinesa.move(.65*movement.x * timeMov, 0);
        back6a.move(.8*movement.x * timeMov, 0);
        back2b.move(-16 * timeMov, 0);
        back3b.move(-32 * timeMov, 0);
        back4b.move(.3*movement.x * timeMov, 0);
        moonlightb.move(.45*movement.x * timeMov, 0);
        back5b.move(.55*movement.x * timeMov, 0);
        vinesb.move(.65*movement.x * timeMov, 0);
        back6b.move(.8*movement.x * timeMov, 0);
        noKeyWasPressed = true;

        
        // update AnimatedSprite
        dog.update(frameTime);//dog
        ivan.update(frameTime);//ivan
        animatedSprite.update(frameTime);
        flickerSprite.update(sf::seconds(.03f));
        
        
        // draw
        window.clear();
        window.draw(titleback);
        window.draw(moon);
        //window.draw(back1);
        window.draw(back2);
        window.draw(back2a);
        window.draw(back2b);
        window.draw(back3);
        window.draw(back3a);
        window.draw(back3b);
        /*window.draw(back4);
        window.draw(back4a);
        window.draw(back4b);
        window.draw(back5);
        window.draw(back5a);
        window.draw(back5b);
        window.draw(back6);
        window.draw(back6a);
        window.draw(back6b);
        window.draw(animatedSprite);
        window.draw(dog);//dog
        window.draw(ivan);//ivan
         */
        
        window.draw(titlescreen);
        
        
        int flickerCounter = 0;
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::F))
        {
            if(flickerCounter==0) flickerCounter++;
            else flickerCounter--;
        }
        if(flickerCounter!=0)
        window.draw(flickerSprite);
        
        window.display();
    }
    
    return 0;
}
コード例 #3
0
// 
// メインプログラム
// 
int main() {
	// アプリウインドウの準備
	AppEnv app_env(Window::WIDTH, Window::HEIGHT);

	// ハイスコア
	int hi_score = 0;
	{
		std::ifstream fstr("score.txt");
		if (fstr){
			fstr >> hi_score;
		}
	}
	// 結果画面からタイトル画面に戻るループ
	while (1){
		// 背景を動かす変数
		float scroll_back = 0;
		// 飛距離
		int jump_distance = 0;

		// タイトル画面
		{
			// タイトル画像
			Texture title_image("res/title_back.png");
			Texture title_rogo("res/title.png");
			Texture GAMESTART("res/GAME START.png");

			// 「Run and Jump」演出用変数を用意
			float title_angle = 0.0;
			int blink = 0;
			// メインループ
			while (1) {
				// ウィンドウが閉じられたらアプリを終了
				if (!app_env.isOpen()) return 0;

				// 描画準備
				app_env.setupDraw();

				// 入力による操作(break本編へ,returnアプリ終了)
				if (app_env.isPushButton(Mouse::RIGHT)) break;
				if (app_env.isPushButton(Mouse::LEFT))  break;
				if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

				// タイトル画像
				drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
					0, 0, 2048, 1024,
					title_image,
					Color(1, 1, 1));

				// タイトルロゴの色にサイン,コサインを利用
				title_angle += 0.05;
				float title_sin = std::abs(std::sin(title_angle));
				float title_cos = std::abs(std::cos(title_angle));

				// タイトルロゴを表示
				drawTextureBox(0 - 1024 / 2, 512 / 2, 565, 80,
					0, 512, 565, 80,
					title_rogo,
					Color(0, title_sin, title_cos),
					0,
					Vec2f(2, 2),
					Vec2f(0, 0));

				// 「GAME START」を表示
				blink += 1;
				int value = (blink / 30) % 2;

				if (value){
					drawTextureBox(0 - 360, 0 - 480, 512, 256,
						0, 0, 512, 256,
						GAMESTART,
						Color(1, 0, 0),
						0,
						Vec2f(1.8, 1.8),
						Vec2f(0, 0));
				}
				// 画面を更新
				app_env.update();
			}
			// 入力のフラッシュ
			app_env.flushInput();
		}
		// 操作説明画面
		{
		// 操作説明画像
		Texture tutorial("res/tuto.png");
		Texture back("res/field.png");

		// メインループ
		while (1) {
			// ウィンドウが閉じられたらアプリを終了
			if (!app_env.isOpen()) return 0;

			// 描画準備
			app_env.setupDraw();

			// 入力による操作(break本編へ,returnアプリ終了)
			if (app_env.isPushButton(Mouse::RIGHT)) break;
			if (app_env.isPushButton(Mouse::LEFT))  break;
			if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
			if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

			// 操作説明画面
			drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
				0, 0, 2048, 1024,
				back,
				Color(1, 1, 1));

			drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
				0, 0, 2048, 1024,
				tutorial,
				Color(1, 1, 1));

			// 画面を更新
			app_env.update();

			// 入力のフラッシュ
			app_env.flushInput();
		}

		// 本編
		{
			// 本編の画像
			Texture back("res/field.png");
			Texture run("res/run.png");
			Texture jump("res/jump.png");
			Texture back2("res/field2.png");
			Texture back3("res/field3.png");
			Texture dispnumber("res/number.png");

			int blink = 0;
			// キャラの表示位置
			float x = 0 - 1024 / 1.5;
			float y = 0 - 380;
			// キャラの加速度
			float a = 0;
			// 重力加速度
			float g = -0.2;
			// キャラの速度
			float v = 0;
			// キャラのジャンプ回数
			int jump_count = 3;
			// キャラのジャンプスイッチ
			int jump_switch = 0;

			// メインループ
			while (1){
				// ウインドウが閉じられたら終了
				if (!app_env.isOpen()) return 0;
				if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

				// 描画準備
				app_env.setupDraw();

				// キャラクターのモーション情報
				struct Texture {
					// 画像からの切り抜き情報
					float texture_x, texture_y;
					float texture_width, texture_height;
				};

				// キャラクターの情報を配列で用意
				Texture move_info[] = {
					{ 0 * 100, 0, 100, 150 },
					{ 1 * 100, 0, 100, 150 },
					{ 2 * 100, 0, 100, 150 },
					{ 3 * 100, 0, 100, 150 },
					{ 4 * 100, 0, 100, 150 },
					{ 5 * 100, 0, 100, 150 },
					{ 6 * 100, 0, 100, 150 },
				};

				// 数字の情報を配列で用意
				Texture number_info[] = {
					{ 0 * 50, 0, 29, 55 },
					{ 1 * 50, 0, 48, 54 },
					{ 2 * 50, 0, 44, 55 },
					{ 3 * 50, 0, 45, 54 },
					{ 4 * 50, 0, 47, 54 },
					{ 5 * 50, 0, 43, 55 },
					{ 6 * 50, 0, 43, 54 },
					{ 7 * 50, 0, 45, 55 },
					{ 8 * 50, 0, 43, 55 },
					{ 9 * 50, 0, 38, 57 },
				};

				// キャラクターの情報を配列から取り出す
				Texture move_chara1 = move_info[0];
				Texture move_chara2 = move_info[1];
				Texture move_chara3 = move_info[2];
				Texture move_chara4 = move_info[3];
				Texture move_chara5 = move_info[4];
				Texture move_chara6 = move_info[5];
				Texture move_chara7 = move_info[6];

				Texture disp_num1 = number_info[0];
				Texture disp_num2 = number_info[1];
				Texture disp_num3 = number_info[2];
				Texture disp_num4 = number_info[3];
				Texture disp_num5 = number_info[4];
				Texture disp_num6 = number_info[5];
				Texture disp_num7 = number_info[6];
				Texture disp_num8 = number_info[7];
				Texture disp_num9 = number_info[8];
				Texture disp_num0 = number_info[9];

				// ゲーム本編
				{
					
					// キャラクター処理
					{
						// 本編背景を連ねて表示に必要な変数
						int draw_back = 0;
						float num_x = -Window::WIDTH / 2 + 50;
						float num_y = -Window::HEIGHT / 2 + 25;

						// 本編画像を表示					
						draw_back += 2000;

						if (app_env.isPressKey(GLFW_KEY_RIGHT)){
							scroll_back += 20;
						}

						drawTextureBox(0 - 2048 / 2 - scroll_back, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 2000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 4000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back2,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 6000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 8000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						drawTextureBox(0 - 2048 / 2 - scroll_back + 10000, 0 - 1024 / 2,
							2048, 1024,
							0, 0,
							2048, 1024,
							back3,
							Color(1, 1, 1));

						// キャラをジャンプさせる
						if (app_env.isPushKey(GLFW_KEY_SPACE) && jump_count > 0){
							a = 10 + g;
							jump_count--;
							jump_switch = 1;
						}
						else{
							a = g;
						}
						v = v + a;
						y = y + ((1 / 2) * a) + v;

						if (y < (0 - 380)) {
							v = 0;
							y = 0 - 380;
							// キャラが飛んでから地面に足をついたら結果画面へ
							if (jump_switch == 1 && y <= 0 - 380){
								break;
							}
						}

						// キャラが画面上端を超えたら止める
						if (y >= 512 - 200){
							y = 512 - 200;
							v = 0;
						}

						// キャラを表示
						if (app_env.isPressKey(GLFW_KEY_RIGHT)){
							blink += 1;
						}
						int value = (blink / 3) % 7;

						drawTextureBox(x, y, move_info[value].texture_width, move_info[value].texture_height,
							move_info[value].texture_x, move_info[value].texture_y,
							move_info[value].texture_width, move_info[value].texture_height,
							run,
							Color(0, 0, 0),
							0,
							Vec2f(1.5, 1.5),
							Vec2f(0, 0));
						

						// 飛距離を表示する
						if (scroll_back >= 3250 - x && jump_count >= 0){
							jump_distance = (scroll_back - 4100) / 20;
						}
						// 線を越えても飛んでなかったらファウル
						if (scroll_back >= 3300 - x && jump_count == 3){
							jump_distance = 0;
							break;
						}

						// 100の位
						if (jump_distance >= 100){
							int hundred_distance = jump_distance / 100;
							if (hundred_distance != 0){
								drawTextureBox(num_x, num_y, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
									number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
									number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (hundred_distance == 0){
								drawTextureBox(num_x, num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
						// 10の位
						if (jump_distance >= 10){
							int ten_distance = jump_distance % 100 / 10;
							if (ten_distance != 0){
								drawTextureBox(num_x + 120, num_y, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
									number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
									number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (ten_distance == 0){
								drawTextureBox(num_x + 120 , num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
						// 1の位
						if (jump_distance >= 1){
							int one_distance = jump_distance % 10;
							if (one_distance != 0){
								drawTextureBox(num_x + 240, num_y, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
									number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
									number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
							if (one_distance == 0){
								drawTextureBox(num_x + 240, num_y, number_info[9].texture_width, number_info[9].texture_height,
									number_info[9].texture_x, number_info[9].texture_y,
									number_info[9].texture_width, number_info[9].texture_height,
									dispnumber,
									Color(1, 1, 1),
									0,
									Vec2f(3, 3),
									Vec2f(0, 0));
							}
						}
					}
					// ハイスコア更新チェック
					if (jump_distance > hi_score){
						std::ofstream fstr("score.txt");
						if (fstr){
							fstr << jump_distance << std::endl;
							hi_score = jump_distance;
						}
					}

					// 画面を更新
					app_env.update();
				}
				// 入力のフラッシュ
				app_env.flushInput();
			}

			// 結果画面
			{
				Texture result("res/result.png");
				Texture back("res/field.png");
				Texture dispnumber("res/number.png");
				Texture Return("res/Return to Title");

				// メインループ
				while (1) {
					// ウィンドウが閉じられたらアプリを終了
					if (!app_env.isOpen()) return 0;

					float num_x = 0 - 25 / 2;
					float num_y_now = 0 - 30 / 2;
					float num_y_hi = 0 - 30 / 2 - 270;

					// 描画準備
					app_env.setupDraw();

					// 入力による操作(break本編へ,returnアプリ終了)
					if (app_env.isPushButton(Mouse::RIGHT)) break;
					if (app_env.isPushButton(Mouse::LEFT))  break;
					if (app_env.isPushKey(GLFW_KEY_ENTER))  break;
					if (app_env.isPushKey(GLFW_KEY_ESCAPE)) return 0;

					// 結果画面表示
					drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
						0, 0, 2048, 1024,
						back,
						Color(1, 1, 1));

					drawTextureBox(0 - 2048 / 2, 0 - 1024 / 2, 2048, 1024,
						0, 0, 2048, 1024,
						result,
						Color(1, 1, 1));

					// 「Return to Title」を表示
					drawTextureBox(0 - 360, 0 - 480, 512, 256,
							0, 0, 512, 256,
							Return,
							Color(1, 0, 0),
							0,
							Vec2f(1.8, 1.8),
							Vec2f(0, 0));

					// 100の位
					if (jump_distance >= 100){
						int hundred_distance = jump_distance / 100;
						if (hundred_distance != 0){
							drawTextureBox(num_x, num_y_now, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
								number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (hundred_distance == 0){
							drawTextureBox(num_x, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 10の位
					if (jump_distance >= 10){
						int ten_distance = jump_distance % 100 / 10;
						if (ten_distance != 0){
							drawTextureBox(num_x + 120, num_y_now, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
								number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (ten_distance == 0){
							drawTextureBox(num_x + 120, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 1の位
					if (jump_distance >= 1){
						int one_distance = jump_distance % 10;
						if (one_distance != 0){
							drawTextureBox(num_x + 240, num_y_now, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
								number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (one_distance == 0){
							drawTextureBox(num_x + 240, num_y_now, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// ハイスコア
					// 100の位
					if (jump_distance >= 100){
						int hundred_distance = jump_distance / 100;
						if (hundred_distance != 0){
							drawTextureBox(num_x, num_y_hi, number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								number_info[hundred_distance - 1].texture_x, number_info[hundred_distance - 1].texture_y,
								number_info[hundred_distance - 1].texture_width, number_info[hundred_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (hundred_distance == 0){
							drawTextureBox(num_x, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 10の位
					if (jump_distance >= 10){
						int ten_distance = jump_distance % 100 / 10;
						if (ten_distance != 0){
							drawTextureBox(num_x + 120, num_y_hi, number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								number_info[ten_distance - 1].texture_x, number_info[ten_distance - 1].texture_y,
								number_info[ten_distance - 1].texture_width, number_info[ten_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (ten_distance == 0){
							drawTextureBox(num_x + 120, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}
					// 1の位
					if (jump_distance >= 1){
						int one_distance = jump_distance % 10;
						if (one_distance != 0){
							drawTextureBox(num_x + 240, num_y_hi, number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								number_info[one_distance - 1].texture_x, number_info[one_distance - 1].texture_y,
								number_info[one_distance - 1].texture_width, number_info[one_distance - 1].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
						if (one_distance == 0){
							drawTextureBox(num_x + 240, num_y_hi, number_info[9].texture_width, number_info[9].texture_height,
								number_info[9].texture_x, number_info[9].texture_y,
								number_info[9].texture_width, number_info[9].texture_height,
								dispnumber,
								Color(1, 1, 1),
								0,
								Vec2f(3, 3),
								Vec2f(0, 0));
						}
					}

					// 画面を更新
					app_env.update();
				}
				// 入力のフラッシュ
				app_env.flushInput();
			}
		}
	}
		// アプリ終了
	}
}
コード例 #4
0
ファイル: player.cpp プロジェクト: noodlehair/ParticleSystem
void player::draw(float x, float y, float z){
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	float ambient=1;
	float diffuse=1;
	float specular=1;
	float emission=0;
	float shininess=50;
	GLfloat mat_ambient[]  = {ambient, ambient, ambient, 1.0f};         
        GLfloat mat_diffuse[]  = {diffuse, diffuse, diffuse, 1.0f};         
        GLfloat mat_specular[] = {specular, specular, specular, 1.0f};         
        GLfloat mat_emission[] = {emission, emission, emission, 1.0f};         
        GLfloat mat_shininess  = shininess;           
        glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);         
        glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);         
        glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);         
        glMaterialfv(GL_FRONT, GL_EMISSION,  mat_emission);         
        glMaterialf (GL_FRONT, GL_SHININESS, mat_shininess);

	glPushMatrix();
	glTranslatef(x, 0, 0);
	glTranslatef(0, y-1, 0);
	glTranslatef(0, 0, z-5);
	glRotatef(45,1,0,0);
	glEnable(GL_TEXTURE_2D);
	
  
    node back1(-0.25, 0.15, 0.25); 
    node back2(-.5, -.35, .25); 
    node back3(.5, -.35, .25); 
    node back4(.25, .15, .25); 
      
    node front1(-.25,.25,-.25); 
    node front2(.25, .25, -.25); 
    node front3(.25,-.25,-.25); 
    node front4(-.25, -.25, -.25); 
  
    node hexA1(0.05, .087, -0.25); 
    node hexA2(0.1, 0, -0.25); 
    node hexA3(0.05, -0.087, -0.25); 
    node hexA4(-0.05, -0.087, -0.25); 
    node hexA5(-0.1, 0, -0.25); 
    node hexA6(-0.05, 0.087, -0.25); 
  
    node hexB1(0.05, .087, -0.75); 
    node hexB2(0.1, 0, -0.75); 
    node hexB3(0.05, -0.087, -0.75); 
    node hexB4(-0.05, -0.087, -0.75); 
    node hexB5(-0.1, 0, -0.75); 
    node hexB6(-0.05, 0.087, -0.75); 
  
    node fa1(0.25, 0.087, -0.25); 
    node fa2(0.25, 0, -0.25); 
    node fa3(0.25, -0.087, -0.25); 
  
    node fb1(-0.25, 0.087, -0.25); 
    node fb2(-0.25, 0, -0.25); 
    node fb3(-0.25, -0.087, -0.25); 
  
    //backside 
	glBindTexture(GL_TEXTURE_2D, p_tex);
	glColor3f(.25, .30, 0.3);
	glBegin(GL_QUADS);
	
	glTexCoord2d(1, 1);
	glVertex3f(back1.x, back1.y, back1.z);
	glTexCoord2d(0, 1);
	glVertex3f(back2.x, back2.y, back2.z);
	glTexCoord2d(1, 0);
	glVertex3f(back3.x, back3.y, back3.z);
	glTexCoord2d(0, 0);
	glVertex3f(back4.x, back4.y, back4.z);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	//frontside 
	glBegin(GL_QUADS);
	
	glColor3f(0.6, 0.1, 0); glVertex3f(front1.x, front1.y, front1.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(front2.x, front2.y, front2.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fa1.x, fa1.y, fa1.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb1.x, fb1.y, fb1.z);

	glColor3f(0.6, 0.1, 0); glVertex3f(fa1.x, fa1.y, fa1.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fa2.x, fa2.y, fa2.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA2.x, hexA2.y, hexA2.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA1.x, hexA1.y, hexA1.z);

	glColor3f(0.6, 0.1, 0); glVertex3f(fa2.x, fa2.y, fa2.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fa3.x, fa3.y, fa3.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA3.x, hexA3.y, hexA3.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA2.x, hexA2.y, hexA2.z);

	glColor3f(0.6, 0.1, 0); glVertex3f(fa3.x, fa3.y, fa3.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(front3.x, front3.y, front3.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(front4.x, front4.y, front4.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb3.x, fb3.y, fb3.z);

	glColor3f(0.6, 0.1, 0); glVertex3f(hexA5.x, hexA5.y, hexA5.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA4.x, hexA4.y, hexA4.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb3.x, fb3.y, fb3.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb2.x, fb2.y, fb2.z);

	glColor3f(0.6, 0.1, 0); glVertex3f(hexA5.x, hexA5.y, hexA5.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb2.x, fb2.y, fb2.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(fb1.x, fb1.y, fb1.z);
	glColor3f(0.6, 0.1, 0); glVertex3f(hexA6.x, hexA6.y, hexA6.z);
	glEnd();
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, p_tex1);
	//upside 
	glColor3f(.25, .30, 0.3);
	glBegin(GL_QUADS);
	//
	glTexCoord2d(1, 1);
	glVertex3f(back1.x, back1.y, back1.z);
	glTexCoord2d(0, 1);
	glVertex3f(back4.x, back4.y, back4.z);
	glTexCoord2d(1, 0);
	glVertex3f(front2.x, front2.y, front2.z);
	glTexCoord2d(0, 0);
	glVertex3f(front1.x, front1.y, front1.z);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, p_tex);
	//leftside 
	glColor3f(.25, .30, 0.3);
	glBegin(GL_QUADS);
	//
	glTexCoord2d(1, 1);
	glVertex3f(back1.x, back1.y, back1.z);
	glTexCoord2d(0, 1);
	glVertex3f(front1.x, front1.y, front1.z);
	glTexCoord2d(1, 0);
	glVertex3f(front4.x, front4.y, front4.z);
	glTexCoord2d(0, 0);
	glVertex3f(back2.x, back2.y, back2.z);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, p_tex);
	//rightside 
	glColor3f(.25, .30, 0.3);
	glBegin(GL_QUADS);
	//
	glTexCoord2d(1, 1);
	glVertex3f(back4.x, back4.y, back4.z);
	glTexCoord2d(0, 1);
	glVertex3f(back3.x, back3.y, back3.z);
	glTexCoord2d(1, 0);
	glVertex3f(front3.x, front3.y, front3.z);
	glTexCoord2d(0, 0);
	glVertex3f(front2.x, front2.y, front2.z);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	//downside 
	glBegin(GL_QUADS);
	
	glColor3f(.25, .30, 0.3); glVertex3f(back3.x, back3.y, back3.z);
	glColor3f(.25, .30, 0.3); glVertex3f(back2.x, back2.y, back2.z);
	glColor3f(.25, .30, 0.3); glVertex3f(front4.x, front4.y, front4.z);
	glColor3f(.25, .30, 0.3); glVertex3f(front3.x, front3.y, front3.z);
	glEnd();
	//pipe 
	glBegin(GL_QUADS);
	
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA1.x, hexA1.y, hexA1.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA2.x, hexA2.y, hexA2.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB2.x, hexB2.y, hexB2.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB1.x, hexB1.y, hexB1.z);

	
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB2.x, hexB2.y, hexB2.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA2.x, hexA2.y, hexA2.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA3.x, hexA3.y, hexA3.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB3.x, hexB3.y, hexB3.z);

	
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA3.x, hexA3.y, hexA3.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA4.x, hexA4.y, hexA4.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB4.x, hexB4.y, hexB4.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB3.x, hexB3.y, hexB3.z);

	
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA4.x, hexA4.y, hexA4.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA5.x, hexA5.y, hexA5.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB5.x, hexB5.y, hexB5.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB4.x, hexB4.y, hexB4.z);

	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA5.x, hexA5.y, hexA5.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA6.x, hexA6.y, hexA6.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB6.x, hexB6.y, hexB6.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB5.x, hexB5.y, hexB5.z);

	
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA6.x, hexA6.y, hexA6.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexA1.x, hexA1.y, hexA1.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB1.x, hexB1.y, hexB1.z);
	glColor3f(0.2, 0.0, 0.0); glVertex3f(hexB6.x, hexB6.y, hexB6.z);

	glEnd();
	glTranslatef(0, 0.4, 0);
	glTranslatef(0, 0, -1);
	glBegin(GL_LINES);

	glColor3f(1, 0, 0); 
	glVertex3f(-0.25, 0, 0);
	glColor3f(1, 0, 0);
	glVertex3f(0.25, 0, 0);
	glColor3f(1, 0, 0);
	glVertex3f(0, 0.25, 0);
	glColor3f(1, 0, 0);
	glVertex3f(0, -0.25, 0);
	glEnd();
	
/*
	//glTranslatef(x, 0, 0);
	glTranslatef(0, 1, 0);
	glTranslatef(0, 0, 0);

	glBegin(GL_LINES);

	glColor3f(1, 0, 0); 
	glVertex3f(-0.5, 0, 0);
	glVertex3f(0.5, 0, 0);

	glVertex3f(0, 0.5, 0);
	glVertex3f(0, -0.5, 0);

	/*glEnable(GL_LINE_STIPPLE);  
    glLineStipple(1,0xAAAA);  
    glBegin(GL_LINES);  
         
    glVertex2f(0.0,0.0);  
    glVertex2f(0.0,0.5);  
    //glDisable(GL_LINE_STIPPLE);  
    glEnd();  
    glDisable(GL_LINE_STIPPLE);  
    glBegin(GL_LINE_LOOP);  
    //draw a circle with specific points.  
    int circle_points = 100;  
    float angle = 0;  
    int i = 0;  
      
    for(i = 0;i<circle_points;i++) {  
        // draw with yellow and black in turn.  
        if(i%2==0){  
          glColor3f(1.0,1.0,0.0);         
        }else{  
          glColor3f(0.0,0.0,0.0);  
        }  
        angle = 2*i*PI/circle_points;  
        //the cos and sin will occupy hole screen.  
        glVertex2f(0.5*cos(angle),0.5*sin(angle));      
    }  */
    //glEnd(); 
	


    glPopMatrix(); 
	glPopAttrib();
	 
	}