#include "Plankton.h"
#include "LD.h"



Plankton::Plankton() :
GameObject( LD::GO_PLANKTON )
{
  m_Texture = LD::TEX_PLANKTON;
  Width = 8;
  Height = 8;
  AnimDelay = 0.0f;
  AnimState = false;

  Angle = (float)( rand() % 360 );
}



void Plankton::Display()
{
  //GameObject::Display();

  theApp.RenderTextureSectionRotated2d( X, Y, theApp.m_TexSec[m_Texture], Angle, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, Width, Height );
  //theApp.RenderTextureSection2d( X, Y, theApp.m_TexSec[m_Texture], 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, Width, Height );
}



void Plankton::Update( Level& Level, float ElapsedTime )
{
  AnimDelay += ElapsedTime;
  if ( fmodf( AnimDelay, 0.5f ) >= 0.25f )
  {
    if ( !AnimState )
    {
      AnimState = true;
      --X;
      --Y;
      Width = 8;
      Height = 8;
    }
  }
  else
  {
    if ( AnimState )
    {
      AnimState = false;
      ++X;
      ++Y;
      Width = 6;
      Height = 6;
    }
  }

  while ( XFract >= 1.0f )
  {
    XFract -= 1.0f;
    ++X;
  }
  while ( XFract < 0.0f )
  {
    XFract += 1.0f;
    --X;
  }
  while ( YFract >= 1.0f )
  {
    YFract -= 1.0f;
    ++Y;
  }
  while ( YFract < 0.0f )
  {
    YFract += 1.0f;
    --Y;
  }
}



RECT Plankton::Bounds()
{
  RECT    rc;

  SetRect( &rc, X - 4, Y - 4, X - 4 + 8, Y - 4 + 8 );

  return rc;
}