Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mybowlcut

Member Since 30 Nov 2006
Offline Last Active Jul 15 2014 08:49 AM
-----

Topics I've Started

2D Pathfinding

19 December 2011 - 06:56 AM

I'm making a 2D game where the I want the world to be freely navigable by AI - specifically, the game is based on an island and there will be animals running around, following (preferably) random paths. I've implemented A* for grid-based 2D games, but am not sure what the best approach would be in this scenario. From what I've read, navigation meshes would be my best bet. I think Recast would do the trick, but am not sure... are nagivation meshes what I want? How can I create a mesh for a 2D world to pass into a tool like Recast? What do I do for collidable objects that are dynamically placed in the world (like a hut built by the player)?

Oh, and some additional info: the game is being developed in Java. I thought I'd mention this in case any suggestions require an API in some other language to be used instead of some tool that you'd use outside of the game's execution. Edit: This looks promising.

Cheers.

Expecting calculation to be 0

06 November 2011 - 01:31 AM

If I pass in amount=25 rotation=90 to the method below, the result is a weird -1.5308086E-15 instead of (what I thought) should be 0. Why is this?

/**
  * @param amount The distance to move. Will always be positive.
  * @param rotation
  * @return The distance resulting from moving <code>amount</code> in the direction of <code>rotation</code>.
  */
  public static float getYDistanceMovedBy(float amount, float rotation) {
 	return Math.abs(amount) * (float) -Math.cos(Math.toRadians(rotation));
}

public void testGetYDistanceMovedBy2() {
  float amount = 25.0f;
  float rotation = 90.0f;
  float distance = Geometry.getYDistanceMovedBy(amount, rotation);
  assertEquals(0.0f, distance);
}


The same code for the x axis works as expected, with the result being 0:
/**
  * @param amount The distance to move. Will always be positive.
  * @param rotation
  * @return The distance resulting from moving <code>amount</code> in the direction of <code>rotation</code>.
  */
  public static float getXDistanceMovedBy(float amount, float rotation) {
      return Math.abs(amount) * (float) Math.sin(Math.toRadians(rotation));
}

public void testGetXDistanceMovedBy2() {
    float amount = 25.0f;
    float rotation = 0.0f;
    float distance = Geometry.getXDistanceMovedBy(amount, rotation);
    assertEquals(0.0f, distance);
}

Cheers.

[C++] What's better?

08 June 2011 - 02:36 AM

GameDev source tags are crappy, so I have to use pastebin: http://pastebin.com/GZkbihzY

Which is more efficient if the input is a string?

Separating event updates from time updates

03 June 2011 - 06:08 PM

In my previous games I've used separate update functions for input events and time-based "delta" updates. E.g. event updates would set the direction an object was moving:
void Human_Controller::Event_Update(const SDL_Event* event_)
{
    using namespace Direction;
    using namespace SDL_Tools;

    unit_ptr commander((*map->Get_Players())[PLAYER]->Get_Commander());

    if(responsive && commander && commander->Is_Alive())
    {
        if(event_->type == SDL_KEYDOWN || event_->type == SDL_KEYUP)
        {
            // Using GetKeyState works much better for multiple keys being held down.
            unsigned char* keys = SDL_GetKeyState(NULL);

            if(keys[SDLK_LEFT] || keys[SDLK_a])
            {
                commander->Set_Direction(PointF(-1.0f, commander->Get_Direction().y));
            }
            else if(keys[SDLK_RIGHT] || keys[SDLK_d])
            {
                commander->Set_Direction(PointF(1.0f, commander->Get_Direction().y));
            }
            else
            {
                commander->Set_Direction(PointF(0, commander->Get_Direction().y));
            }

            if(keys[SDLK_UP] || keys[SDLK_w])
            {
                commander->Set_Direction(PointF(commander->Get_Direction().x, -1.0f));
            }
            else if(keys[SDLK_DOWN] || keys[SDLK_s])
            {
                commander->Set_Direction(PointF(commander->Get_Direction().x, 1.0f));
            }
            else
            {
                commander->Set_Direction(PointF(commander->Get_Direction().x, 0));
            }
        }
    }
}


and time-based updates would move it in that direction, decreasing its velocity slightly each frame:
void Human_Controller::Time_Update(float delta)
{
    player->Update(delta);

    player->Get_Totals().Set_Seconds_Elapsed(player->Get_Totals().Get_Seconds_Elapsed() + delta);

    const Unit_Data* unit_data = NULL;
    unit_it begin = player->Get_Units().begin(), end = player->Get_Units().end();

    unit_ptr commander(player->Get_Commander());
    if(commander)
    {        
        PointF old_pos = commander->Get_Position();

        commander->Update(delta);
        
        if(!commander->Is_Alive())
        {
            float speed = GET_UNIT_DATA(commander->Get_Type_ID()).Get_Movement_Speed();
            GET_UNIT_DATA(commander->Get_Type_ID()).Set_Movement_Speed(speed *= 0.99f);
        }

        commander->Set_Position(commander->Get_Position() +
            commander->Get_Direction() * GET_UNIT_DATA(*commander).Get_Movement_Speed() * delta);

        if(commander->Is_Alive() && commander->Get_Position() != old_pos)
        {
            Refocus_Turrets(*commander);
        }
    }
}


Now I'm working with a different library (SFML) that has a function GetFrameTime in the window class, and I'm wondering if it's still worth separating these update functions. I think it is, because this way you have nicely separated functions, and it's easy to control the game speed if necessary. What are others' opinions on this?

Using specific libraries of Boost

28 May 2011 - 06:55 PM

How can I use only certain Boost libraries in my project? I only want to use a few libraries and not use the rest, but am not sure if they have dependencies on each other. I've got Boost.Build set up, but am kinda unsure of what to do next...

PARTNERS