Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fixed  (Read 1681 times)

0 Members and 1 Guest are viewing this topic.

terrifiedobama

  • Newbie
  • *
  • Posts: 13
  • Hi, i am eager to learn SFML.
    • AOL Instant Messenger - Skype+:+live:mohasmedec
    • View Profile
    • https://www.google.bg/search?ei=fSI7XdixF6PuxgOC64iwCA&q=Chicken+fight&oq=Chicken+fight&gs_l=psy-ab.3..0l10.2406.2677..2783...0.0..0.92.181.2......0....1..gws-wiz.......0i71.bzIU-zC-Thw&ved=0ahUKEwiY5JaY-dLjAhUjt3EKHYI1AoYQ4dUDCAo&uact
    • Email
Fixed
« on: June 28, 2019, 01:39:12 pm »
So basically in the following picture there is an visual explanation for the problem which is occuring right when the action takes place.

((((The Code))))


#include "GameScreen.h"
#include "Collision.h"
#include <iostream>



GameScreen::GameScreen()
{
   
}


GameScreen::~GameScreen()
{

}

void GameScreen::LoadContent() {

   if (!font.loadFromFile("Font4.ttf"))
      std::cout << " no font found" << std::endl;

   text.setString("Press F1 To go to back");
   text.setFont(font);

   PlayerTexture.loadFromFile("player.png");
   PlayerSprite.setTexture(PlayerTexture);
   PlayerSprite.setPosition(sf::Vector2f(500, 275));
   PlayerSprite.setScale(sf::Vector2f(2, 2));


   //camera ?
   //sf::View Camera(sf::Vector2f(400.f, 300.f), sf::Vector2f(400.f, 300.f));
   //sf::Sprite* follow = &PlayerSprite;


   




   Tile001Texture.loadFromFile("tile001.png");
   //Tile001Sprite.setTextureRect(sf::IntRect(33, 30, 30, 30));
   Tile001Sprite.setTexture(Tile001Texture);
   
   //Tile001Rect.intersects
   Tile001Sprite.setPosition(sf::Vector2f(445,600));
   Tile001Sprite.setScale(sf::Vector2f(2,2));
   

   if (playpos == true) {
      PlayerSprite.setPosition(sf::Vector2f(33, 33));

   }
   
   
      
   
   


   
   
   

}



void GameScreen::UnloadContent() {

}

void GameScreen::Update() {
   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
   {
      // left key is pressed: move our character
      //std::cout << "Player right" << std::endl;

      PlayerSprite.setTextureRect(sf::IntRect(52, 0, -53, 98));
      PlayerSprite.move(3.1, 0.0);
   }
   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
   {
      // left key is pressed: move our character
      //std::cout << "Player  left" << std::endl;

      PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
      PlayerSprite.move(-3.1, 0.0);
   }

   

      if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt))
      {
         //playpos = true;
         //PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
         //if (playpos == true)

            PlayerSprite.move(sf::Vector2f(0, -10));

         

         

         //comment teleport
         //if (PlayerSprite.getPosition().y) {
         //   PlayerSprite.setPosition(0, 0);
         //   PlayerSprite.move(sf::Vector2f(0,-1));
         //  }
         //comment no out fly y+
         //else PlayerSprite.move(sf::Vector2f(0, 1));
         //if (PlayerSprite.getPosition().y) {
            //PlayerSprite.setPosition(PlayerSprite);
               //}



      }
   
      // gravity
   for (int t = 0;t <= 5;t++) {

      PlayerSprite.move(sf::Vector2f(0,0.3));
      
      
   }

   xposplayer = PlayerSprite.getPosition().x;
   yposplayer = PlayerSprite.getPosition().y;
   xpostile001 = Tile001Sprite.getPosition().x;
   ypostile001 = Tile001Sprite.getPosition().y;
   while (xsetposplayer == true) {

      PlayerSprite.setPosition(PlayerSprite.getPosition());
      
   }

   if (PlayerSprite.getGlobalBounds().intersects(Tile001Sprite.getGlobalBounds())) {
      std::cout << "good job fool" << std::endl;
      
      
      


      if (xpostile001&&xposplayer) {
      //   PlayerSprite.move() = Tile001Sprite.move();
         std::cout << "1" << std::endl;
         xsetposplayer = true;
         if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
            //xposplayer = 66;

         }
      }
      else if (!xpostile001 && xposplayer) {
         xsetposplayer = false;
         std::cout << "2" << std::endl;
         
      }
   }
   else
   {
      std::cout << "no" << std::endl;
   }


   
   
   
   


}

void GameScreen::Draw(sf::RenderWindow& Window) {
   Window.draw(text);
   Window.draw(PlayerSprite);
   Window.draw(Tile001Sprite);
   Window.setFramerateLimit(60);

   
   
   
}

---------------------------------------------------------------------------------------------------------------------------


The point of this code is that im trying to get my playersprite to collide with the tilesprite
and move jump go to all following directions.
but i cant even continue because it crashes.


i know its a stupid way to make this happen but im trying hard to do it alone & my way u know what i mean.

im new to coding forgive me for the dumb coding mechanism.
« Last Edit: June 28, 2019, 11:07:13 pm by terrifiedobama »
Guys my name's Boris. I'm 22 year old and I want to tell you that I'm happy to join your community. I hope we can learn together , or learn each other.
If you want to get to know me or help me or help you contact me, the following below is the INFORMATION..
@@@@@@@@
Skype : live:mohasmedec
@@@@@@@@

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: my window crash
« Reply #1 on: June 28, 2019, 02:07:55 pm »
Quote
   while (xsetposplayer == true) {

      PlayerSprite.setPosition(PlayerSprite.getPosition());
     
   }
Infinite loop...   :-\
« Last Edit: June 28, 2019, 02:12:51 pm by Laurent »

terrifiedobama

  • Newbie
  • *
  • Posts: 13
  • Hi, i am eager to learn SFML.
    • AOL Instant Messenger - Skype+:+live:mohasmedec
    • View Profile
    • https://www.google.bg/search?ei=fSI7XdixF6PuxgOC64iwCA&q=Chicken+fight&oq=Chicken+fight&gs_l=psy-ab.3..0l10.2406.2677..2783...0.0..0.92.181.2......0....1..gws-wiz.......0i71.bzIU-zC-Thw&ved=0ahUKEwiY5JaY-dLjAhUjt3EKHYI1AoYQ4dUDCAo&uact
    • Email
Re: My window crash
« Reply #2 on: June 28, 2019, 06:07:58 pm »
yep changed it with for
but still i couldnt manage to collide this position thingy
Guys my name's Boris. I'm 22 year old and I want to tell you that I'm happy to join your community. I hope we can learn together , or learn each other.
If you want to get to know me or help me or help you contact me, the following below is the INFORMATION..
@@@@@@@@
Skype : live:mohasmedec
@@@@@@@@

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: my window crash
« Reply #3 on: June 28, 2019, 10:25:50 pm »
Quote
   while (xsetposplayer == true) {

      PlayerSprite.setPosition(PlayerSprite.getPosition());
     
   }
Infinite loop...   :-\

Even without the loop, the position setting seems pointless - setting it to the position to which it is already set!
Is this intentional?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

terrifiedobama

  • Newbie
  • *
  • Posts: 13
  • Hi, i am eager to learn SFML.
    • AOL Instant Messenger - Skype+:+live:mohasmedec
    • View Profile
    • https://www.google.bg/search?ei=fSI7XdixF6PuxgOC64iwCA&q=Chicken+fight&oq=Chicken+fight&gs_l=psy-ab.3..0l10.2406.2677..2783...0.0..0.92.181.2......0....1..gws-wiz.......0i71.bzIU-zC-Thw&ved=0ahUKEwiY5JaY-dLjAhUjt3EKHYI1AoYQ4dUDCAo&uact
    • Email
Re: My window crash
« Reply #4 on: June 28, 2019, 11:06:09 pm »
finally managed to create a crazy collision lol.

#include "GameScreen.h"
#include "Collision.h"
#include <iostream>



GameScreen::GameScreen()
{
   
}


GameScreen::~GameScreen()
{

}

void GameScreen::LoadContent() {

   if (!font.loadFromFile("Font4.ttf"))
      std::cout << " no font found" << std::endl;

   text.setString("Press F1 To go to back");
   text.setFont(font);

   PlayerTexture.loadFromFile("player.png");
   PlayerSprite.setTexture(PlayerTexture);
   PlayerSprite.setPosition(sf::Vector2f(500, 275));
   PlayerSprite.setScale(sf::Vector2f(2, 2));


   //camera ?
   //sf::View Camera(sf::Vector2f(400.f, 300.f), sf::Vector2f(400.f, 300.f));
   //sf::Sprite* follow = &PlayerSprite;

   




   Tile001Texture.loadFromFile("tile001.png");
   //Tile001Sprite.setTextureRect(sf::IntRect(33, 30, 30, 30));
   Tile001Sprite.setTexture(Tile001Texture);
   
   //Tile001Rect.intersects
   Tile001Sprite.setPosition(sf::Vector2f(445,600));
   Tile001Sprite.setScale(sf::Vector2f(2,2));
   

   if (playpos == true) {
      PlayerSprite.setPosition(sf::Vector2f(33, 33));

   }
   
   
      
   
   


   
   
   

}



void GameScreen::UnloadContent() {

}

void GameScreen::Update() {
   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
   {
      // left key is pressed: move our character
      //std::cout << "Player right" << std::endl;
      PlayerSprite.setTextureRect(sf::IntRect(52, 0, -53, 98));
      PlayerSprite.move(3.1, 0.0);
   }
   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
   {
      // left key is pressed: move our character
      //std::cout << "Player  left" << std::endl;
      PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
      PlayerSprite.move(-3.1, 0.0);
   }

   

      if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt))
      {
         //playpos = true;
         //PlayerSprite.setTextureRect(sf::IntRect(0, 0, 53, 98));
         //if (playpos == true)
            PlayerSprite.move(sf::Vector2f(0, -10));

         

         

         //comment teleport
         //if (PlayerSprite.getPosition().y) {
         //   PlayerSprite.setPosition(0, 0);
         //   PlayerSprite.move(sf::Vector2f(0,-1));
         //  }
         //comment no out fly y+
         //else PlayerSprite.move(sf::Vector2f(0, 1));
         //if (PlayerSprite.getPosition().y) {
            //PlayerSprite.setPosition(PlayerSprite);
               //}



      }
   
      // gravity
      if (gravity == true) {


         for (int t = 0;t <= 5;t++) {

            PlayerSprite.move(sf::Vector2f(0, 0.3));


         }

      }

      else
         PlayerSprite.move(sf::Vector2f(0, 0));

   xposplayer = PlayerSprite.getPosition().x;
   yposplayer = PlayerSprite.getPosition().y;
   xpostile001 = Tile001Sprite.getPosition().x;
   ypostile001 = Tile001Sprite.getPosition().y;
   xvel = 0;
   yvel = 0;
   //if (xsetposplayer == true) {

   //   PlayerSprite.setPosition(PlayerSprite.getPosition());
      
   //}
   

   if (PlayerSprite.getGlobalBounds().intersects(Tile001Sprite.getGlobalBounds())) {
      std::cout << "good job fool" << std::endl;
      
      
      PlayerSprite.move(sf::Vector2f(0,0));
      gravity = false;

      //if (xpostile001&&xposplayer) {
      //   PlayerSprite.move() = Tile001Sprite.move();
      //   std::cout << "1" << std::endl;
      //   xsetposplayer = true;
      //   if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
            //xposplayer = 66;
            
      //   }
      //}
      //else if (!xpostile001 && xposplayer) {
      //   xsetposplayer = false;
      //   std::cout << "2" << std::endl;
         
      //}
   }
   else
   {
      
      gravity = true;
      std::cout << "no" << std::endl;
   }

   
   
   
   // coll 2 with bug
   //if (Collision::PixelPerfectTest(PlayerSprite,Tile001Sprite)) {
   //   std::cout << "im idiot" << std::endl;
   //}
   //else
   //{
   //   std::cout << "no col" << std::endl;
   //}
   


}

void GameScreen::Draw(sf::RenderWindow& Window) {
   Window.draw(text);
   Window.draw(PlayerSprite);
   Window.draw(Tile001Sprite);
   Window.setFramerateLimit(60);

   
   
   
}

Guys my name's Boris. I'm 22 year old and I want to tell you that I'm happy to join your community. I hope we can learn together , or learn each other.
If you want to get to know me or help me or help you contact me, the following below is the INFORMATION..
@@@@@@@@
Skype : live:mohasmedec
@@@@@@@@