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

Pages: [1]
1
Graphics / Ray casting
« on: August 23, 2011, 01:43:07 pm »
http://lodev.org/cgtutor/
http://www.permadi.com/tutorial/raycast/index.html
These sites have such tutorials.  I've already ported the first 2 tutorials from Lode's site into SFML and they work flawlessly.  I've been extremely busy and haven't gotten to the third one yet.

2
Graphics / Re: Line and Rectangle does not show up
« on: August 22, 2011, 12:33:30 pm »
Hello:
I think it ought to work if you change the lines to:

Code: [Select]

line = sf::Shape::Line(0, 0, App.GetWidth(), App.GetHeight(), 5, red);

rectangle = sf::Shape::Rectangle(100, 100, App.GetWidth() - 200, App.GetHeight() - 200, red);

3
General / Pac man game
« on: August 13, 2011, 11:33:24 pm »
The code ought to be:
Code: [Select]
PacPosX = pac.TransformToGlobal(pac.GetCenter()).x/BLOCKSIZE;
PacPosY = pac.TransformToGlobal(pac.GetCenter()).y/BLOCKSIZE;

4
General / Pac man game
« on: August 13, 2011, 08:11:20 pm »
The code would be pac.TransformToGlobal(pac.GetCenter()).x or y.  And you should do pac.SetCenter(halfOfPacMan'sWidth, halfOfPacMan'sHeight).  It should also be possible to just offset PacMan.GetPosition().x and y by adding the values here as well.

5
General / Pac man game
« on: August 13, 2011, 04:42:39 pm »
Casting to int ought to merely truncate the number, not round it up or down.  But I think my mistake is that pac.GetPosition gets the top-left x/y coordinate of the sprite by default, when you really need the sprite's center.  You would have to use pac.GetCenter().x/y (which you would first need to transform to global coordinates).

6
General / Pac man game
« on: August 13, 2011, 12:47:20 am »
Quote from: "gl0w"
Quote from: "Vit"
Pac-Man is tile-based; your array should be the size of your tile grid. For example, if each of your tiles was 20x20 pixels, and your screen size was 640x480, your tile grid would be 32x24 tiles. Each element in your array would then represent a 20x20 square on the screen.
When you want to move Pac-Man on the screen, you'll need to find out which tile he'll be moving to first. For example, assuming your tile array starts from the top-left, to move right you'll need to check board[pacman.x + 1][pacman.y]. If the element is passable, you can start moving him into the tile; otherwise, do nothing (as he's trying to move into a wall).


Hello,

Could you please tell me what do you mean by "board[pacman.x + 1][pacman.y]" is the position X and Y on the screen? if yes, how can i compare a float number with a integer on the board? I'm not understanding.

Could you kindly explain?
thank you.


Hello:
You would do something like this:
Code: [Select]
if (board[int(PacMan.GetPosition().x/tileWidth) + 1][int(PacMan.GetPosition().y/tileHeight)] == 0)  // Where 0 denotes a passable tile
       // Code for moving PacMan to the right;

As you can see, by wrapping the PacMan.GetPostion().x/y values with int( ), you can cast the floats as int.  The formula will allow you to get the square Pac-Man is on.  For example, on a 640x480 screen with a grid of 32x24 tiles and PacMan's x/y at 100,78, PacMan is at square board[3][3].  The code will check if board[4][3] is a passable square, and if it is, allow PacMan to move there.  I hope that helps!

7
General / Ghost pathfinding for Pacman help please.
« on: August 09, 2011, 07:51:14 pm »
There is a detailed and informative article here on Pac-Man ghost behavior:
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
You can create a grid like the one in the article by making a two-dimensional integer array of 1s and 0s, where 1s are tiles that the actors cannot move to.  So, for example to get the tile Pac-Man is currently at, you get the integer value of Pac-Man's center x in global coordinates divided by how many pixels wide one grid square is, and the integer value of Pac-Man's center y in global coordinates divided by how many pixels tall one grid square is (so if Pac-Man is at 65, 73 on a grid of 8x8 squares means Pac-Man is at square 8,9).  Then you pass this coordinate to the ghost's pathfinding function.
But, why not use A* pathfinding?
Dijikstra's algorithm is unnecessarily complex for a Pac-Man type of game, in my opinion.  Just look at this comparison:
http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html#S3

8
General / Rotation Formula
« on: August 08, 2011, 12:02:07 am »
Hi,
The line:
Code: [Select]
float BodyAngle = Rect.GetRotation() * PI / 180;
converts the angle of the body from degrees to radians.  We will need the radian values to work with the sin and cos trigonometric functions.  Once we have the angle in radians, we can set the x position of the satellite by first getting the x value of the center of the main body rectangle (which we need to convert to global coordinates in this case), and add the sine of the angle in radians multiplied by the distance we want the satellite to be positioned from the body.  We do the same for the y position of the satellite, this time getting the cosine (if we switched the sine and cosine, the satellite will orbit in the opposite direction when we change the angle, so this is really a matter of how you intend to implement it).  That's all there is to it!  For some additional reading, here's a couple good articles:
http://www.helixsoft.nl/articles.php
 :)

9
General / Rotation Formula
« on: August 07, 2011, 08:11:01 pm »
Hello:
I believe the formula you are looking for goes something like this:
Code: [Select]
satellite.x = body.x + (body.width/2) + Math.cos(angleofBodyInDegrees) * DistanceFromBodyCenter;
satellite.y = body.y + (body.height/2) + Math.sin(angleofBodyInDegrees) * DistanceFromBodyCenter;

It's from an old formula I was using in Flixel, I hope it's still relevant.  I believe what I was trying to do with the body.x + (body.width/2), body.y + (body.height/2) parts of the code was get the center of the body?  I forget.  I hope this helps!

Edit:  Whoops, I think the angle of the body ought to be in radians, not degrees.

Edit 2: Okay, it's sloppy, but here's a simple program that should demonstrate everything:

Code: [Select]
#include <SFML/Graphics.hpp>
#include <cmath>

const double PI = 3.14159265;

int main()
{
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(400, 300, 32), "SFML Events");

    sf::Shape Rect = sf::Shape::Rectangle(0, 0, 50, 50, sf::Color::Green);
    Rect.SetCenter(25, 25);
    Rect.SetX(200);
    Rect.SetY(150);

    sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 24, 24, sf::Color::Blue);
    Rect2.SetCenter(12, 12);

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

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        if (App.GetInput().IsKeyDown(sf::Key::Up))    Rect.Move(0, -80 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  Rect.Move(0,  80 * ElapsedTime);

        if (App.GetInput().IsKeyDown(sf::Key::Left))
        {
            Rect.SetRotation(Rect.GetRotation() - 1 * ElapsedTime * 100);
        }
        if (App.GetInput().IsKeyDown(sf::Key::Right))
        {
            Rect.SetRotation(Rect.GetRotation() + 1 * ElapsedTime * 100);
        }
        float BodyAngle = Rect.GetRotation() * PI / 180;
        Rect2.SetX(Rect.TransformToGlobal(Rect.GetCenter()).x + (sin(BodyAngle) * 80));
        Rect2.SetY(Rect.TransformToGlobal(Rect.GetCenter()).y + (cos(BodyAngle) * 80));

        // Clear the screen (fill it with white color)
        App.Clear(sf::Color(255, 255, 255));

        // Draw player
        App.Draw(Rect);
        App.Draw(Rect2);

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

    return EXIT_SUCCESS;
}

10
Graphics / All sprites shifted down and right when resizing the window
« on: August 07, 2011, 04:07:22 pm »
Hello:

For the images, they need to be set to the file itself, not the link:
This:
http://www.freeimagehosting.net/newuploads/0f786.png
Not:
http://www.freeimagehosting.net/0f786

TL;DR - Solution: For now, use RenderWindow's Create function to change the resolution and Views to change the "zoom" of the screen.

I have been able to replicate this SetSize problem.  I created a 1 x 1 render window, set up a sprite, and then before calling the main loop I re-sized the window to 1280 x 1024.  The image was proportionally offset by the window border and title bar's sizes.  On my Windows XP, the left of the sprite was 11 pixels away from the border, which is 4 pixels wide, and the top of the sprite was 376 pixels away from the bottom of the title bar, which is 30 pixels tall.  The greater the proportional difference between the original window and the re-sized window, the greater the offset will be (as far as I can tell, this only occurs when going from a smaller size to larger).  Not only that, the window's contents will be similarly stretched out.  Consider the following code:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(500, 500, 32), "SFML Events");

    sf::Shape Rect = sf::Shape::Rectangle(1, 1, 20, 20, sf::Color::Green);

    App.SetSize (800, 800);

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

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the shape
        if (App.GetInput().IsKeyDown(sf::Key::Left))  Rect.Move(-80 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) Rect.Move( 80 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    Rect.Move(0, -80 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  Rect.Move(0,  80 * ElapsedTime);

        // Clear the screen (fill it with white color)
        App.Clear(sf::Color(255, 255, 255));

        // Draw shape
        App.Draw(Rect);

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

    return EXIT_SUCCESS;
}


Which produces a small square that you can move around.  But only change the initial width and height of the RenderWindow to 50, 50 and the square will then be stretched out along the y axis.

Since I've only been using SFML for about a week, and I don't have much programming experience since it's only a hobby for me, I don't know what the culprit is, or of any other solution than to use RenderWindow's Create function to change the resolution, and setting a View to change the "zoom" of the Window content.  Sorry I couldn't be of more help!

11
Window / OpenGL not rendering
« on: August 04, 2011, 09:34:26 pm »
Quote from: "drummerp"
It still displays no more than a blank screen, and I cannot determine why. Please, any explanation is greatly appreciated, let alone help. I just want to get this working.


Hello:
In your code at the end of your setup function, you need to setup a perspective projection like so:
Code: [Select]
   glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);


And in your render function you need to add glMatrixMode(GL_MODELVIEW); like so:

Code: [Select]
void render() {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);

I hope that helps!

Pages: [1]