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

Author Topic: Code Hints in Code::Blocks?(mostly solved)  (Read 7817 times)

0 Members and 2 Guests are viewing this topic.

BlitzCoder

  • Newbie
  • *
  • Posts: 11
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #15 on: April 24, 2010, 03:41:47 am »
Quote from: "Ashenwraith"
Check my updated code.

You need to pay attention as I was just grabbing stuff from my own code.

x is for width, y is for height.


Ah, my bad. I tend to copy code without thinking at times.. bad habit.

Code: [Select]

      if(bluePaddleSprite.GetPosition().y > App.GetHeight()-bluePaddle.GetHeight())
      {
        bluePaddleSprite.SetY(100);
      }


Its a start, though paddle still goes abit further then I would like. Now its just about tweaking it. Many thanks for all the help.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #16 on: April 24, 2010, 03:44:11 am »
Hmm.. you should take off the solved since this is not solved.

If you want you can get code hints you can construct with:

sf::Sprite bluePaddleSprite = new sf::Sprite();


Okay I found the problem.

If you replace
Code: [Select]

if (!bluePaddle.LoadFromFile("bluePaddle.png"))
    {
    std::cout << "Error, bluePaddle.png failed to load";
    }


Code: [Select]

bluePaddle.LoadFromFile("bluePaddle.png");


It will work.

Apparently the IDE cannot look in advance to see this check.

BlitzCoder

  • Newbie
  • *
  • Posts: 11
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #17 on: April 24, 2010, 03:50:41 am »
Quote from: "Ashenwraith"
Hmm.. you should take off the solved since this is not solved.

If you want you can get code hints you can construct with:

sf::Sprite bluePaddleSprite = new sf::Sprite();


Err.. I see a new... that means heap memory and such, which I am kind of shaky with. But just so I understand, would that create a pointer to bluePaddleSprite called Sprite and then through that let me use code hints.. or am I way off?

Also, and I know the questions are probably becoming annoying but:

I got the formula to work with the paddle for when it goes "down", but when I tried making a version for up, it does not work.

I though simply taking the same one as before and changing the > to a < would work but when I do it goes back the problem of not letting me move at all...

Edit: That change to bluePaddle.LoadFromFile("bluePaddle.png");  did not fix the problem sadly.. I don't know whats going on..

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #18 on: April 24, 2010, 04:00:32 am »
The reverse is much easier since 0,0 is the corner. You just want to check if it is less than 0.

Btw check my updated post for your answer.

BlitzCoder

  • Newbie
  • *
  • Posts: 11
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #19 on: April 24, 2010, 04:07:05 am »
Quote from: "Ashenwraith"
The reverse is much easier since 0,0 is the corner. You just want to check if it is less than 0.

Btw check my updated post for your answer.


I feel dumb.. I have felt dumb a few times today... works now.. so, I suppose the opposite corners are 600,600 or something. The . issue is still there, but I can live. Through this thread I figured out some of the hard stuff. Now I just need to add the ball, the other paddle, AI, collision, scoring rules... ya. But thank you.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Code Hints in Code::Blocks?(mostly solved)
« Reply #20 on: April 24, 2010, 04:20:36 am »
The . issue is from the if(!Load part as I showed in my updated code above.

The reason it goes farther is you are scaling the paddle 1.5y

You should scale your graphics beforehand, but otherwise you need to do math to compensate for image size vs sprite size.

 

anything