Exemplo n.º 1
0
void Player::Tick()
{
    if (GlobalInput->IsKeyDown(sf::Key::Left))
    {
        //Velocity.x = -4;
        Acceleration.x = -Accel;
        if (Physic != PHYS_Landed && fabs(Velocity.x)>=4)
            Acceleration.x*=AirControl;
        Direction=-1;
    }
    else if (GlobalInput->IsKeyDown(sf::Key::Right))
    {
        //Velocity.x = 4;
        Acceleration.x = Accel;
        if (Physic != PHYS_Landed && fabs(Velocity.x)>=4 )
            Acceleration.x*=AirControl;
        Direction=1;
    }
    else
    {
        if (fabs(Velocity.x)>0.5)
        {
            Acceleration.x = -sign(Velocity.x)*.25;

            if (Physic != PHYS_Landed )
                Acceleration.x*=AirControl;

        }
        else
        {
            Velocity.x = 0;
            Acceleration.x=0;
        }
    }


    if (GlobalInput->IsKeyDown(sf::Key::Space) && Physic == PHYS_Landed && !Level->GetBlockAt(GridLocationExt + vec2i(0,-1)).bSolid)
    {
        Physic = PHYS_Jumping;
    	Velocity.y = -8;
        PlayAnimation("jump");
        MaxJumpHeight = Location.y - 60;
        SM.PlaySound(*JumpSound);

    }

    if (Physic == PHYS_Jumping && (!GlobalInput->IsKeyDown(sf::Key::Space) || (Location.y+Velocity.y < MaxJumpHeight)))
        Physic = PHYS_Falling;

    if (Physic == PHYS_Landed)
    {
        if (Velocity.x ==0)
            PlayAnimation("idle");
        else
        {
            if (Direction == sign(Velocity.x))
                PlayAnimation("walk");
            else
                PlayAnimation("turn");
        }
    }

    vec2f & C = Level->GetCameraLocation();

    int S = Velocity.x==0 ? Direction : sign(Velocity.x);
    if ( (S<0 && Location.x+Velocity.x < C.x ) ||  (S>0 && Location.x+Velocity.x+16 > C.x + 320))
    {
        Velocity.x = 0;
        Acceleration.x=0;
    }


    C.x = Location.x-160;
    C.y = Location.y-224;

    EntityBase::Tick();

}
Exemplo n.º 2
0
int main ()
{
  printf ("Results of test 'test':\n");

  try
  {
    Timer timer (bind (&Application::Exit, 0), TEST_WORK_TIME);

    srand ((unsigned int)time (NULL));

    SoundManager manager ("OpenAL", "*");
    Listener     listener;
    Emitter      emitter;

    emitter.SetSource ("declaration1");
    emitter.SetSampleIndex (rand ());

/*
   Testing basic manager properties
*/

    printf ("Initial volume = %f,", manager.Volume ());
    manager.SetVolume (0.7f);
    printf (" new volume = %f.\n", manager.Volume ());

    printf ("Initial mute: "); print (manager.IsMuted ());
    manager.SetMute (true);
    printf ("Mute: "); print (manager.IsMuted ());
    manager.SetMute (false);
    printf ("Mute: "); print (manager.IsMuted ());

    printf ("Initial listener status: "); print (manager.Listener ());
    listener.position  = vec3f (0.f, 1.f, 0.f);
    listener.direction = vec3f (0.f, 0.f, 1.f);
    listener.up        = vec3f (0.f, -1.f, 0.f);
    listener.velocity  = vec3f (1.f, 0.f, 0.f);
    manager.SetListener (listener);
    printf ("New listener status: "); print (manager.Listener ());

    manager.LoadSoundLibrary (library_file);
/*
   Testing basic emitter properties
*/

    printf ("Emitter source - %s\n", emitter.Source ());
    printf ("Initial emitter volume = %f,", emitter.Volume ());
    emitter.SetVolume (0.9f);
    printf (" new emitter volume = %f.\n", emitter.Volume ());

    printf ("Initial position: ");  print (emitter.Position ());
    printf ("\nInitial direction: "); print (emitter.Direction ());
    printf ("\nInitial velocity: ");  print (emitter.Velocity ());
    emitter.SetPosition  (vec3f (-50.f, 2.f, 4.f));
    emitter.SetDirection (vec3f (-2.f, -2.f, -4.f));
    emitter.SetVelocity  (vec3f (0.f, 0.f, 0.1f));
    printf ("\nNew position: ");  print (emitter.Position ());
    printf ("\nNew direction: "); print (emitter.Direction ());
    printf ("\nNew velocity: ");  print (emitter.Velocity ());  printf ("\n");

/*
   Testing manager work
*/
    manager.PlaySound (emitter, 0.3f);

    printf ("Current offset in seconds = %f\n", manager.Tell (emitter));
    printf ("Duration in seconds = %f\n", manager.Duration (emitter));
    printf ("Looping = %c\n", manager.IsLooping (emitter) ? 'y' : 'n');
    printf ("Is Playing = %c\n", manager.IsPlaying (emitter) ? 'y' : 'n');

    Timer timer2 (bind (&TimerHandler, ref (emitter)), ACTION_TIME);

    Application::Run ();
  }
  catch (std::exception& exception)
  {
    printf ("exception: %s\n",exception.what ());
  }
  catch (...)
  {
    printf ("unknown exception\n");
  }

  printf ("exit\n");

  return Application::GetExitCode ();
}
Exemplo n.º 3
0
 void Player::Land()
{
    SM.PlaySound(*LandSound);
}