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 - BlitzCoder

Pages: [1]
1
General / Code Hints in Code::Blocks?(mostly solved)
« 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.

2
General / Code Hints in Code::Blocks?(mostly solved)
« 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..

3
General / Code Hints in Code::Blocks?(mostly solved)
« 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.

4
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 03:34:48 am »
Quote from: "Ashenwraith"
type: bluePaddle.

Make sure the caret is after the .

Then press ctrl+space


works with bluePaddle fine, but not with bluePaddleSprite.

Also, that formula you gave me.. now I can move the paddle at all because it keeps resetting...
Code: [Select]

      if(bluePaddleSprite.GetPosition().x<App.GetHeight()-(800+20))
      {
        bluePaddleSprite.SetY(100);
      }


I know that is wrong, but no matter what values I change it seems to not work. (I mean, the paddle moves, but snaps back immediately). Maybe I read the code wrong...

Edit: sorry, I misunderstood your code, thank you for clarifying. Sorry for all the trouble I have caused :(

5
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 03:27:32 am »
Quote from: "Ashenwraith"
Well what is the problem?

I thought we finally figured it out.


Nah, still now giving me options when I use bluePaddleSprite. but it seems if I know what to put its ok.. w/e, close enough, I was just confused as to why it suddenly stopped giving me fill options.

6
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 03:22:08 am »
Quote from: "Ashenwraith"
The origin of x,y coordinates is 0,0. Width and Height begins at 1,1.

You need to subtract the height/width of your object to the screen size.

BTW, for archiving purposes plz change the name of your thread to [solved]Code Hints in Code::Blocks?


Changed title to [solved]Code Hints in Code::Blocks? as requested, but it really isn't solved since the original issue is still present, but w/e.

Edit: Thank you for the code snippet.

Edit 2: Is the "w" supposed to be a variable for width I need to make. or is it w/e the width of my screen is (IE 800)

7
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 03:13:47 am »
Quote from: "Ashenwraith"

If you have a problem with the IDE you need to explain what IDE you are using and what you are doing, not posting code.


Um.. I did say I was using code::blocks in my OP... I was not sure if the error was IDE or SFML related, and nothing on the C::B forums helped.

Anyways, moving past that, I used the App.GetHeight() to try to fix it but


Code: [Select]


      if (bluePaddleSprite.GetPosition().y == App.GetHeight())
      {
        bluePaddleSprite.SetY(100);
      }


Does not seem to work. I get the feeling I am making a simple error but I am not sure what that is. What I am trying to do is say "If the paddle hits the top (and after that version for the bottom), reset it". No go so far.

8
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 03:00:31 am »
Quote from: "Ashenwraith"
What are talking about?

The code runs and moves as it's supposed to.

BTW you need App.SetFramerateLimit(60);

Also App.GetWidth()/App.GetHeight() will get what you need.


Maybe I did not word it right.. the code itself works fine, I was saying that when I was editing it bluePaddleSprite was not giving me any options when I used the . operator. I was confused (still am) because it was working before.

Edit: Thank you for the code though. I am new to SFML (2D in general)

9
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 02:47:59 am »
Well, although it does not seem to be working 100% it seems as long as I know the command it will work. On a slightly side topic:

Do you know, or know how to find, the x/y values for the sides of my window? I wanted to have it so
Code: [Select]

      if (bluePaddleSprite.GetPosition().y == -50)
      {
        bluePaddleSprite.SetY(100);
      }


would work (-50 can be any number, but is supposed to be the border of the window so the paddle can't go past it...)

10
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 02:25:56 am »
what does control + space do? Nothing happened for me. As I mentioned, stuff like App. and such work, just my sprite won't... I'll keep looking into it though, its currently holding everything up..

11
General / Code Hints in Code::Blocks?(mostly solved)
« on: April 24, 2010, 01:57:04 am »
I was not sure where this post belonged, since I don't know if it is a graphics error.

Currently I am writing a small version of Pong. My code works great so far, with one little issue. In the code editor itself (I am using code::blocks if it matters), using the . operator on my sprite is doing nothing. Other things like sf:: or App. work fine in the sense they show a list of usable options or at least let me type them myself. However, for some reason this is not working for my bluePaddleSprite when I try bluePaddleSprite.

Currently I am trying to add collision of sorts so it does not go out of bounds, and I was going to do this by checking if the bluePaddleSprite's y was in bounds of my 800x600 window, and if so set it back a few or something. Code follow:

 
Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    // Create the main rendering window
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Pong");
   sf::Image bluePaddle;

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

sf::Sprite bluePaddleSprite(bluePaddle);
bluePaddleSprite.SetY(100);
bluePaddleSprite.SetScaleY(1.5);


    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // A key has been pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                // Escape key : exit
                if (Event.Key.Code == sf::Key::Escape)
                    App.Close();
            }
        }
        // Clear the screen
        App.Clear(sf::Color(0, 0, 0));

      if (App.GetInput().IsKeyDown(sf::Key::W))  {
         bluePaddleSprite.Move(0, 150 * App.GetFrameTime() * -1);
      } else if (App.GetInput().IsKeyDown(sf::Key::S)) {
        bluePaddleSprite.Move(0, 150 * App.GetFrameTime() * 1);
      }

      App.Draw(bluePaddleSprite);

        // Display window contents on screen
        App.Display();
    }


    return EXIT_SUCCESS;
}


It compiles and runs, but when I try to use the . with my sprite nothing happens. Any help would be very welcome.

Thank you.

Pages: [1]
anything