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

Pages: [1]
1
General / Re: String to movement help
« on: August 01, 2014, 08:28:35 am »
Sorry I must not have made my original post clear enough.

I understand how movement works, I've successfully made player movement work with mouse click and arrow keys, but I'm not sure how to go about making the player move by checking route.

I can't do a...

while(rect.pos != targetPos)
{
    rect.move(0.01*deltaTime.asMilliseconds(), 0);
}

... within the switch loop within the for loop, as my program will freeze.

I am wondering how I would go about writing and calling a function to make my player move with the specific route in mind.

2
General / String to movement help
« on: August 01, 2014, 06:24:07 am »
Hey everyone,

Currently I'm having a problem trying to implement movement into my game that works with path-finding.

Right now what I have is A* code that will create a string, "0000100223331100", that shows which direction the player needs to walk. '0' is right, '1' is down, '2' is left, and '3' is up. I have also tried to change the string into a vector of sf::Vector2f's, but I've taken it out as I think it's unnecessary.

The problem I'm having is converting this string into player movement. I have tried a for-loop, but it doesn't work very well. The best I have so far is...

for(int i = 0; i < route.size(); i++)
{
        switch(route[i])
        {
        case '0':
                rect.move(32, 0);
                break;
        case '1':
                rect.move(0, 32);
                break;
        case '2':
                rect.move(-32, 0);
                break;
        case '3':
                rect.move(0, -32);
                break;
        }
}

... while this follows the path, it instantly teleports my play straight to the end. Instead I would like the player to slowly walk along the path.

I would love it if someone could post some code or explain to me how to structurally go about writing the code.

Thanks,
Nswift

Pages: [1]
anything