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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Made Y

Pages: [1]
1
Graphics / Re: Checking 2 shapes Position
« on: May 25, 2017, 01:20:23 pm »
Oh, that's right,
It would be better to use> = or <= instead of ==
Heheh. Thank you sir; D
I just found how to find the intersects

If (sFigures.getGlobalBounds (). Intersects (Triangle.getGlobalBounds ())) {
Break;
}

And it works,

I apologize,
I really should search for it first before asking it.
Sorry for my bad english; D

2
Graphics / Checking 2 shapes Position
« on: May 25, 2017, 08:39:49 am »
I want to check if two shapes are in the same position.

if(sFigures.getPosition() == Triangle.getPosition()){
         break;
      }

I want to check if two shapes are in the same position.


here is the main

int main(){
   srand(time(NULL));

   RenderWindow window(VideoMode(800, 600), "ROBOT !");
   Texture figures;

   float dx = 0.5, dy = 0.5;

   if(!figures.loadFromFile("figures2.png")){
      cout << "FAILED" << endl;
      return -1;
   }

   CircleShape Triangle(32, 3);
   Triangle.setFillColor(Color::Black);
   int x1 = rand() % 768, y1 = rand() % 568;
   Triangle.setPosition(x1, y1);

   Sprite sFigures;
   sFigures.setTexture(figures);
   sFigures.setTextureRect(IntRect(0, 0, 32, 35));
   float x = 400;
   float y = 300;
   sFigures.setPosition(x, y);

   while(window.isOpen()){
      Event e;
      while(window.pollEvent(e)){
         if(e.type == Event::Closed){
            window.close();
         }if(e.type == Event::LostFocus){
            
         }
         
      }

      /////// MOVE CHARACTER ///////
      if(Keyboard::isKeyPressed(Keyboard::Down) && sFigures.getPosition().y < 568){
         sFigures.move(0,0.5);
         sFigures.setTextureRect(IntRect(0, 0, 32, 35));
      }else if(Keyboard::isKeyPressed(Keyboard::Up) && sFigures.getPosition().y > 0 ){
         sFigures.move(0,-0.5);
         sFigures.setTextureRect(IntRect(64, 71, 32, 35));
      }else if(Keyboard::isKeyPressed(Keyboard::Left) && sFigures.getPosition().x > 0 ){
         sFigures.move(-0.5,0);
         sFigures.setTextureRect(IntRect(96, 106, 32, 35));
      }else if(Keyboard::isKeyPressed(Keyboard::Right) && sFigures.getPosition().x < 768 ){
         sFigures.move(0.5,0);
         sFigures.setTextureRect(IntRect(32, 36, 32, 35));
      }
      
      ///// ENEMY MOVE /////
      if(Triangle.getPosition().x == 0){
         dx = 0.5;
      }else if(Triangle.getPosition().x == 768){
         dx = -0.5;
      }
      if(Triangle.getPosition().y == 0){
         dy = 0.5;
      }else if (Triangle.getPosition().y == 568){
         dy = -0.5;
      }
      Triangle.move(dx, dy);
      
      ///// CHECK //////
      if(sFigures.getPosition() == Triangle.getPosition()){
         break;
         
      }

      window.clear(Color(255, 0, 255));
      window.draw(Triangle);
      window.draw(sFigures);
      window.display();

   }

   return 0;   

}

Is there a better way to do this?
somethings like, checking with the player/enemy radius
sFigures = Player
Triangle = Enemy

ThankYou  :)

3
oh. okay, thankyou for the advice sir  ;)

4
i want to create my own application to count key per second. so when i played some rhythm games. i can get to know how many keys that i type and how fast can i type. and i need the window to get every keys that i type even when the window is lost focus.

I hv tried using this outside pollEvent loop

window.setKeyRepeatEnabled(false);
          .
          .
          .
if(Keyboard::isKeyPressed(Keyboard::Z)){
   count.addkey1(); //key++
}

But it count repeatedly.
Is there anyway to do it ? Please help :(

5
i have installed sfml2.3.2 and tried using !window.hasFocus().
but its still didnt count when the window is lost focus.

and heres the main: 

int main(){
   kps count;
   RenderWindow kps_wind(VideoMode(275,75),"KeyPerSecond");
   while(kps_wind.isOpen()){
      kps_wind.setKeyRepeatEnabled(false);
      Event e;
      while(kps_wind.pollEvent(e)){
         if(e.type == Event::Closed)
            kps_wind.close();
         
         if ((e.type == Event::KeyPressed && e.key.code == Keyboard::Z) && !kps_wind.hasFocus()){
            count.addkey1();
         }else if((e.type == Event::KeyPressed && e.key.code == Keyboard::Z) && kps_wind.hasFocus()){
            count.addkey1();
         }
      }

      //////DRAW//////
      Font font;
      if (!font.loadFromFile("Arial.ttf")){}
      //Text text(count.getkey1(), font, 24);
      Text text;
         text.setString(count.getkey1());
         text.setFont(font);
         text.setCharacterSize(24);
         text.setColor(Color::Red);
         text.setPosition(0,0);

      kps_wind.clear(Color::Black);
      kps_wind.draw(text);
      kps_wind.display();

   }
   return 0;   
}

please help  :(

6
i have tried this insde the pollEvent loop

window.setKeyRepeatEnabled(false);
          .
          .
          .
 if (e.type == Event::KeyPressed && e.key.code == Keyboard::Z && e.type == Event::LostFocus){
   count.addkey1(); //key++
}

but that didnt count the pressed keys when the window is lost focus,
and i tried ths outside the pollEvent loop

window.setKeyRepeatEnabled(false);
          .
          .
          .
if(Keyboard::isKeyPressed(Keyboard::Z)){
   count.addkey1(); //key++
}
and it works, can still countin when the window is lost focus. but it count repeatedly when it is pressed.

i want 1 pressed key = 1count, even though the window is lost focus.
im using sfml 2.0.
sorry for my bad english. please help and thankyou.

Pages: [1]
anything