cGameStateObject* cGameStateIntro::update(double timeDifference, Camera &cam, CGameData &data, CGraphics &con){
  m_event = EVENT_GO_NO_WHERE;
  
  //initialize data first time this state is called
  static bool bFirstTime = true;
  if(bFirstTime == true){
 
    CAudioManager *pAudio = CAudioManager::Instance();
    if(pAudio->IsPlaying(0) == false)    //nature sounds
      pAudio->PlaySoundClip(0, 1);
    if(pAudio->IsPlaying(13) == false)    //birds
      pAudio->PlaySoundClip(13, 1);

    bFirstTime = false;
  }

  //keystrokes
  if(::GetActiveWindow() == data.m_hWnd && keyDown(VK_SPACE))
    m_event = EVENT_GO_MAIN;

  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
cGameStateObject* cGameStateFireControl::update(double timeDifference){
  m_event = EVENT_GO_NO_WHERE;

  //loads mouse position into global variable.
  POINT pt;
  POINT *ppt = &pt;
  ::GetCursorPos(ppt);
  RECT rct;
  ::GetWindowRect(g_hWnd, &rct);
  g_Global.g_mouse.x = pt.x - rct.left;
  g_Global.g_mouse.y = pt.y - rct.top;
  
  CGameData *pData = CGameData::Instance();
  pData->Update(timeDifference);
  CAudioManager *pAudio = CAudioManager::Instance();

  static double timeDiffTotal = 0;
  timeDiffTotal += timeDifference;
  if(timeDiffTotal > .1){
    timeDiffTotal = 0;

    if(keyDown(VK_SPACE) && ::GetActiveWindow() == g_hWnd){
      CTorpedo torpedo(pData->m_Player.m_heading, pData->m_Player.m_heading, pData->m_Player.m_posX, pData->m_Player.m_posY);
      pData->m_torpedos.push_back(torpedo);
      //there are 2 torpedo sounds...play 1..if busy play 2
      if(pAudio->IsPlaying(SOUND_TORPEDO1) == false)
        pAudio->PlaySoundClip(SOUND_TORPEDO1, 0);
      else{
        if(pAudio->IsPlaying(SOUND_TORPEDO2) == false)
          pAudio->PlaySoundClip(SOUND_TORPEDO2, 0);
      }
    }
  
    //process short cut buttons
    if(g_Global.g_mouse.y > 10 && g_Global.g_mouse.y < 130 
      && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
      if(g_Global.g_mouse.x > 10 && g_Global.g_mouse.x < 110)
        m_event = EVENT_GO_SONAR;
      else if(g_Global.g_mouse.x > 120 && g_Global.g_mouse.x < 220)
        m_event = EVENT_GO_RADAR;
      else if(g_Global.g_mouse.x > 230 && g_Global.g_mouse.x < 330)
        m_event = EVENT_GO_CONTROL;
      else if(g_Global.g_mouse.x > 804 && g_Global.g_mouse.x < 904)
        m_event = EVENT_GO_STATUS;
      else if(g_Global.g_mouse.x > 914 && g_Global.g_mouse.x < 1014)
        m_event = EVENT_GO_CHART;
    }      
  }

  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
Esempio n. 3
0
CGameState* CStateIntro::Update(double timeDifference){
  m_event = GO_NO_WHERE;

  if(g_audio.IsPlaying(2) == false)
    g_audio.PlaySoundClip(2, 1);


  //process this code for the very first Update(...) call
  static bool bFirstTime = false;
  if(bFirstTime == false){
    bFirstTime = true;
  }

  //check user interface
  INPUT_RECORD InRec = GetConsoleInputInfo();

  //key press events
  if(InRec.EventType == KEY_EVENT){
    m_event = GO_MENU;//press any key
  }

  //mouse events
  else if(InRec.EventType == MOUSE_EVENT){
    //left mouse 
    if(InRec.Event.MouseEvent.dwButtonState == 0x01){
    }
    //right mouse
    else if(InRec.Event.MouseEvent.dwButtonState == 0x02){
    }
    //mouse move
    else if(InRec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED){
      m_mouseX = InRec.Event.MouseEvent.dwMousePosition.X;
      m_mouseY = InRec.Event.MouseEvent.dwMousePosition.Y;
    }
  }
  
  //animated border
  if(m_timerBorder.GetTimer(.05)== true){
    m_borderCount++;
    if(m_borderCount > 205)
      m_borderCount = 0;
  }

  //game state transition code...very important
  for(unsigned int i=0; i< m_TE.size(); ++i){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }

  return 0;
}
Esempio n. 4
0
/*************************************  U P D A T E *****************************************/
cGameStateObject* CGameStatePlay::update(double timeDifference){
  m_event = EVENT_GO_NO_WHERE;
  static double timeDiffTotal = 0;
  static double thingTimeDiff = 0;
  //GRAPHIC_IMAGE gi;
  int spriteID;
  int frameMax  = 0;
  int frameCount  = 0;

  //start ambient sound loop
  CAudioManager *pAudio = CAudioManager::Instance();
  if(pAudio->IsPlaying(SOUND_ANCHORS) == false)
    pAudio->PlaySoundClip(SOUND_ANCHORS, 0);

  //loads mouse position into global variable.
  POINT pt;
  POINT *ppt = &pt;
  ::GetCursorPos(ppt);
  RECT rct;
  ::GetWindowRect(g_hWnd, &rct);
  g_Global.g_mouse.x = pt.x - rct.left;
  g_Global.g_mouse.y = pt.y - rct.top;

  //accept...go to control
  if(g_Global.g_mouse.x > 289 && g_Global.g_mouse.x < 407
    && g_Global.g_mouse.y > 683 && g_Global.g_mouse.y < 718
    && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
    m_event = EVENT_GO_CONTROL;
  }

  //reject..return to menu  
  if(g_Global.g_mouse.x > 626 && g_Global.g_mouse.x < 743
    && g_Global.g_mouse.y > 683 && g_Global.g_mouse.y < 718
    && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
    m_event = EVENT_GO_SELECT;
  }

  //game state transition code...very important
  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }

  return 0;
}
Esempio n. 5
0
cGameStateObject* cGameStateIntro::update(double timeDifference){
  m_event = EVENT_GO_NO_WHERE;

  
 // if(keyDown(VK_SPACE) && ::GetActiveWindow() == g_hWnd){
 //   m_event = EVENT_GO_MAIN;
 //   ::ShowCursor(true);
 // }

  //loads mouse position into global variable.
  //loads mouse position into global variable.
  POINT pt;
  POINT *ppt = &pt;
  ::GetCursorPos(ppt);
  RECT rct;
  ::GetWindowRect(g_hWnd, &rct);
  g_Global.g_mouse.x = pt.x - rct.left;
  g_Global.g_mouse.y = pt.y - rct.top;

  if(m_motionTimer.getTimer(0.005) == true){
    m_motionCount += m_motionStep;
  }

  if(g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd) 
      m_event = EVENT_GO_MAIN;

  //play music
  CAudioManager *pAudio = CAudioManager::Instance();
  if(pAudio->IsPlaying(SOUND_REMEMBER) == false)
    pAudio->PlaySoundClip(SOUND_REMEMBER, 0);


  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
Esempio n. 6
0
cGameStateObject* cGameStateChart::update(double timeDifference){
  m_event = EVENT_GO_NO_WHERE;
  //loads mouse position into global variable.
  
  POINT pt;
  POINT *ppt = &pt;
  ::GetCursorPos(ppt);
  RECT rct;
  ::GetWindowRect(g_hWnd, &rct);
  g_Global.g_mouse.x = pt.x - rct.left;
  g_Global.g_mouse.y = pt.y - rct.top;
  
  CGameData *pData = CGameData::Instance();
  //start ambient sound loop
  CAudioManager *pAudio = CAudioManager::Instance();
  if(pAudio->IsPlaying(SOUND_AMBIENCE1) == false)
    pAudio->PlaySoundClip(SOUND_AMBIENCE1, 1);

  if(pData->m_bAttack == true){
    if(pAudio->IsPlaying(SOUND_PING) == false)
      pAudio->PlaySoundClip(SOUND_PING,0);
  }

  if(pData->m_bDropped == true && pAudio->IsPlaying(SOUND_DEPTH_CHARGE2) == false)
        pAudio->PlaySoundClip(SOUND_DEPTH_CHARGE2, 0);

  //update all targets, sub, torpedos, and depth charges
  pData->Update(timeDifference);

  static double timeDiffTotal = 0;
  timeDiffTotal += timeDifference;
  if(timeDiffTotal > .11){
    timeDiffTotal = 0;

    if(keyDown(VK_SPACE) == true && ::GetActiveWindow() == g_hWnd){
      CLog *pLog = CLog::Instance();
      pLog->Log("Tautog ...............");
      pLog->Log("subX", (long)pData->m_Player.m_posX);
      pLog->Log("subY", (long)pData->m_Player.m_posY);
      pLog->Log("subH", pData->m_Player.m_heading);
      pLog->Log("subS", pData->m_Player.m_speed);
      pLog->Log("..............");

      for(int i = 0; i < pData->m_targets.size(); ++i){
        pLog->Log("target", i);
        pLog->Log("targetX", (long)pData->m_targets[i].m_posX);
        pLog->Log("targetY", (long)pData->m_targets[i].m_posY);
        pLog->Log("targetH", pData->m_targets[i].m_heading);
        pLog->Log("targetS", pData->m_targets[i].m_speed);
        pLog->Log("targetTB", pData->m_targets[i].m_trueBearing);
        pLog->Log("targetRB", pData->m_targets[i].m_relativeBearing);
        pLog->Log("targetAOB",(int)pData->m_targets[i].m_AOB);
        pLog->Log("targetAOBindex", pData->m_targets[i].m_AOBindex);
        pLog->Log(".......................");
      }
    }

    //process short cut buttons
    if(g_Global.g_mouse.y > 10 && g_Global.g_mouse.y < 130 
      && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
      //if(g_Global.g_mouse.x > 10 && g_Global.g_mouse.x < 110)
      //  m_event = EVENT_GO_SONAR;
      //else if(g_Global.g_mouse.x > 120 && g_Global.g_mouse.x < 220)
      //  m_event = EVENT_GO_RADAR;
      if(g_Global.g_mouse.x > 230 && g_Global.g_mouse.x < 330)
        m_event = EVENT_GO_CONTROL;
      //else if(g_Global.g_mouse.x > 694 && g_Global.g_mouse.x < 794)
      //  m_event = EVENT_GO_FIRECONTROL;
      //else if(g_Global.g_mouse.x > 804 && g_Global.g_mouse.x < 904)
      //  m_event = EVENT_GO_STATUS;
    } 
    else if(g_Global.g_mouse.x > 806 && g_Global.g_mouse.x < 1006 
      && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){
        if(g_Global.g_mouse.y > 134 && g_Global.g_mouse.y < 249){//zoom in
          m_chartScaleIndex++;
          if(m_chartScaleIndex > 4)
            m_chartScaleIndex = 4;
        }
        else if(g_Global.g_mouse.y > 269 && g_Global.g_mouse.y < 384){//zoom out
          m_chartScaleIndex--;
          if(m_chartScaleIndex < 0)
            m_chartScaleIndex = 0;
        }
    }
  }
  
  //this controls game states
  if(pData->m_missionOver == MISSION_OVER_WIN  )
    m_event = EVENT_GO_WIN;
  else if(pData->m_missionOver == MISSION_OVER_DEAD || pData->m_missionOver == MISSION_OVER_TIMEOVER || pData->m_missionOver == MISSION_OVER_COLLISION )
    m_event = EVENT_GO_LOSE;

  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
Esempio n. 7
0
CGameStateObject* CGameStateHelp::Update(double timeDifference,  CGameData &data, CConfigData &cfg, CGraphics &con){
  m_event = EVENT_GO_NO_WHERE;

  CAudioManager *pAudio = CAudioManager::Instance();

  //play background music
  if(cfg.PlayMusic == true && pAudio->IsPlaying(4) == false)
    pAudio->PlaySoundClip(4, 1);

  //first time
  static bool bFirstTime = true;
  if(bFirstTime == true){
    bFirstTime = false;
    m_screenNumber = 0;
    m_arrowX = 150;
    m_arrowY = 150;
  }


  //CAudioManager *pAudio = CAudioManager::Instance();
  m_mouse.SetHandle(data.m_hWnd);


  static double screenTime = 0;
  screenTime += timeDifference;
  
  if(::GetActiveWindow() == data.m_hWnd && screenTime > 0.4 && data.m_bLeftMouseDown == true){
    
    //previous button
    if(m_mouse.MouseX() > 212 && m_mouse.MouseX() < 312 && 
      m_mouse.MouseY() > 650 && m_mouse.MouseY() < 700){
        m_screenNumber--;
        if(m_screenNumber < 0)
          m_screenNumber = 0;
    }
    //next button
    else if(m_mouse.MouseX() > 712 && m_mouse.MouseX() < 812 && 
      m_mouse.MouseY() > 650 && m_mouse.MouseY() < 700){
        m_screenNumber++;
        if(m_screenNumber > 9)
          m_screenNumber = 9;
    }
    
    screenTime = 0;
  }
  
  //animate arrow
  static double arrowTime = 0;
  arrowTime += timeDifference;
  if(arrowTime > 0.05 && m_screenNumber == 1){
    m_arrowX += 10;
    m_arrowY += 5;

    if(m_arrowX > 750){
      m_arrowX = 150;
      m_arrowY = 150;
    }    
    arrowTime = 0;
  }

  if(::GetActiveWindow() == data.m_hWnd && data.m_bLeftMouseDown == true){
    //main menu
    if(m_mouse.MouseX() > 812 && m_mouse.MouseX() < 1012 && 
      m_mouse.MouseY() > 50 && m_mouse.MouseY() < 100){
      m_event = EVENT_GO_MAIN;    
    }
  }


  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
//***************************************************************
//                         U P D A T E
//***************************************************************
cGameStateObject* cGameStateEditor::update(double timeDifference, Camera &cam, CGameData &data, CGraphics &con){
  m_event = EVENT_GO_NO_WHERE;
  static bool bStop = false;
  D3DXVECTOR3 position;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;
  std::ostringstream oss;

  CLog *pLog = CLog::Instance(); 

  //play audio file at start of game state
  CAudioManager *pAudio = CAudioManager::Instance();
  if(pAudio->IsPlaying(0) == false)    
    pAudio->PlaySoundClip(0, 1);

  //configure mouse
  m_mouse.SetHandle(data.m_hWnd);

  //set aircraft camera to 1000 feet
  static bool bFirstTime = true;
  if(bFirstTime == true){
    position.x = 0.0f; position.y = 3.0f; position.z = 0.0f;
    cam.setPosition(&position); 
    cam.roll(0.0f);

    //define position of editor control panel
    gi = con.GetSprite(42);
    m_panelX = con.GetScreenWidth() - 50 - gi.width;
    m_panelY = 50;
    gi = con.GetSprite(47);
    m_fileBarY = con.GetScreenHeight() - 50 - gi.height;
    bFirstTime = false;
    m_viewChoice = 4;
    m_editLevel = 0;
    //data.LoadGameLevel("data//level1.dat", con);
  }

  //escape state by pressing ESC key
  if(::GetActiveWindow() == data.m_hWnd && keyDown(VK_ESCAPE))
    m_event = EVENT_GO_MAIN;

  cam.getPosition(&position);
  static double timeDiff = 0;
  timeDiff = timeDifference;

  for(int i = 0; i < data.m_pObject.size(); ++i){
    data.m_pObject[i]->Update(timeDiff);
  }

  //slows down key press for PageUp and PageDown
  static double timeSprite = 0;
  timeSprite += timeDiff;

  //only process keys if this window has focus
  if(::GetActiveWindow() == data.m_hWnd){// && gTimerKey.getTimer(0.03) == true){
    cam.yaw(0.0f);

    //rotate sprite
    if(keyDown('X') == true   && timeSprite > 0.05){
      cam.yaw(-2.0f * timeDiff);
      m_angle += 0.05f;
      if(m_angle > 6.28)
        m_angle = 0.0f;
      timeSprite = 0;
    }
    if(keyDown('Z') == true   && timeSprite > 0.05){
      cam.yaw(2.0f * timeDiff);
      m_angle -= 0.05f;
      if(m_angle < 0.0f)
        m_angle = 6.28f;
      timeSprite = 0;
    }
    
    //walk
    if(keyDown('W') == true){
      cam.walk(1.0f * timeDiff);
      data.m_playerY -= 200.0f * timeDiff;
      if(data.m_playerY < data.m_world_top)
        data.m_playerY = data.m_world_top;
    }
    if(keyDown('S') == true){
      cam.walk(-1.0f * timeDiff);
      data.m_playerY += 200.0f * timeDiff;
      if(data.m_playerY > data.m_world_bottom)
        data.m_playerY = data.m_world_bottom;
    }

    //strafe
    if(keyDown('A') == true){
      cam.strafe(-1.0f * timeDiff);
      data.m_playerX -= 200.0f * timeDiff;
      if(data.m_playerX < data.m_world_left)
        data.m_playerX = data.m_world_left;
    }
    if(keyDown('D') == true){
      cam.strafe(1.0f * timeDiff);
      data.m_playerX += 200.0f * timeDiff;
      if(data.m_playerX > data.m_world_right)
        data.m_playerX = data.m_world_right;
    }

    //walk
    if(keyDown(VK_UP) == true){
      cam.walk(1.0f * timeDiff);
      data.m_playerY -= 1000.0f * timeDiff;
      if(data.m_playerY < data.m_world_top)
        data.m_playerY = data.m_world_top;
    }
    if(keyDown(VK_DOWN) == true){
      cam.walk(-1.0f * timeDiff);
      data.m_playerY += 1000.0f * timeDiff;
      if(data.m_playerY > data.m_world_bottom)
        data.m_playerY = data.m_world_bottom;
    }

    //strafe
    if(keyDown(VK_LEFT) == true){
      cam.strafe(-1.0f * timeDiff);
      data.m_playerX -= 1000.0f * timeDiff;
      if(data.m_playerX < data.m_world_left)
        data.m_playerX = data.m_world_left;
    }
    if(keyDown(VK_RIGHT) == true){
      cam.strafe(1.0f * timeDiff);
      data.m_playerX += 1000.0f * timeDiff;
      if(data.m_playerX > data.m_world_right)
        data.m_playerX = data.m_world_right;
    }

    //editor
    if(keyDown(VK_NEXT) == true  && timeSprite > 0.2){//page up
      m_currentObjectID++;
      if(m_currentObjectID > data.m_objectType.size() - 1)
        m_currentObjectID = 0;
        timeSprite = 0.0;
    }
    if(keyDown(VK_PRIOR) == true && timeSprite > 0.2){//page down
      m_currentObjectID--;
      if(m_currentObjectID < 0)
        m_currentObjectID = data.m_objectType.size() - 1;
        timeSprite = 0.0;
    }

    //UNDO
    if(keyDown('U') == true && timeSprite > 0.15){
      if(data.m_pObject.size() > 0)
        data.m_pObject.pop_back();
      timeSprite = 0.0;
    }

    //fill ground with grass
    if(keyDown('G') == true && m_bFillGround == false && timeSprite > 0.15){
      go = data.GetObjectInfo(3);
      gi = con.GetSprite(go.spriteID);
      go.alive = true;
      go.alpha = gi.alpha;
      go.angle = gi.angle;
      go.maxFrames = gi.maxFrames;
      go.updateInterval = gi.updateInterval;
      go.frameCount = 0;
      go.width = gi.width;
      go.height = gi.height;

      for(int i = 0; i < 20; ++i){
        for(int j = 0; j < 20; ++j){
          go.pos.x = i * 128;
          go.pos.y = j * 128;
          data.AddGameObject(go);        
        }
      }
      timeSprite = 0.0;
      m_bFillGround = true;
    }
  }

  //mouse moves the game world
    //strafe
    if(::GetActiveWindow() == data.m_hWnd && m_mouse.MouseX() < 50){
      cam.strafe(-1.0f * timeDiff);
      data.m_playerX -= 1000.0f * timeDiff;
      if(data.m_playerX < data.m_world_left)
        data.m_playerX = data.m_world_left;
    }
    if(::GetActiveWindow() == data.m_hWnd && m_mouse.MouseX() > con.GetScreenWidth() - 50){
      cam.strafe(1.0f * timeDiff);
      data.m_playerX += 1000.0f * timeDiff;
      if(data.m_playerX > data.m_world_right)
        data.m_playerX = data.m_world_right;
    }
    if(::GetActiveWindow() == data.m_hWnd && m_mouse.MouseY() < 50) {
      cam.walk(1.0f * timeDiff);
      data.m_playerY -= 1000.0f * timeDiff;
      if(data.m_playerY < data.m_world_top)
        data.m_playerY = data.m_world_top;
    }
    if(::GetActiveWindow() == data.m_hWnd && m_mouse.MouseY() > con.GetScreenHeight() - 50){
      cam.walk(-1.0f * timeDiff);
      data.m_playerY += 1000.0f * timeDiff;
      if(data.m_playerY > data.m_world_bottom)
        data.m_playerY = data.m_world_bottom;
    }

  //editor
  //mouse affects editor control panel
  gi = con.GetSprite(42);
  bool bPanel = false;

  if(m_mouse.MouseX() > m_panelX && m_mouse.MouseX() < m_panelX + gi.width && m_mouse.MouseY() > m_panelY && m_mouse.MouseY() < m_panelY + gi.height){
    bPanel = true;
  }

  //is mouse on file bar
  gi = con.GetSprite(47);
  bool bFileBar = false;
  if(m_mouse.MouseX() > m_fileBarX && m_mouse.MouseX() < m_fileBarX + gi.width && m_mouse.MouseY() > m_fileBarY && m_mouse.MouseY() < m_fileBarY + gi.height){
    bFileBar = true;
  }

  //mouse click on editor panel
  if(data.m_bLeftMouseDown == true && bPanel == true){
    
    //turn grid on
    if(m_mouse.MouseX() > m_panelX + 99 && m_mouse.MouseX() < m_panelX + 157 &&
       m_mouse.MouseY() > m_panelY + 554 && m_mouse.MouseY()< m_panelY + 592)
      m_gridOn = true;

    //turn grid off
    if(m_mouse.MouseX() > m_panelX + 158 && m_mouse.MouseX() < m_panelX + 224 &&
       m_mouse.MouseY() > m_panelY + 554 && m_mouse.MouseY()< m_panelY + 592)
      m_gridOn = false;

    //turn snap on
    if(m_mouse.MouseX() > m_panelX + 99 && m_mouse.MouseX() < m_panelX + 157 &&
      m_mouse.MouseY() > m_panelY + 593 && m_mouse.MouseY()< m_panelY + 641 && m_snapOn == false){
      m_snapOn = true;
      }

    //turn snap off
    if(m_mouse.MouseX() > m_panelX + 158 && m_mouse.MouseX() < m_panelX + 224 &&
      m_mouse.MouseY() > m_panelY + 593 && m_mouse.MouseY()< m_panelY + 641 && m_snapOn == true){
      m_snapOn = false;
      }

    //32 pixel grid spacing
    if(m_mouse.MouseX() > m_panelX + 28 && m_mouse.MouseX() < m_panelX + 84 &&
      m_mouse.MouseY() > m_panelY + 642 && m_mouse.MouseY()< m_panelY + 686 ){
       m_gridSpace = 32;
      }

    //64 pixel grid spacing
    if(m_mouse.MouseX() > m_panelX + 85 && m_mouse.MouseX() < m_panelX + 145 &&
      m_mouse.MouseY() > m_panelY + 642 && m_mouse.MouseY()< m_panelY + 686){
       m_gridSpace = 64;
      }

    //128 pixel grid spacing
    if(m_mouse.MouseX() > m_panelX + 146 && m_mouse.MouseX() < m_panelX + 217 &&
      m_mouse.MouseY() > m_panelY + 642 && m_mouse.MouseY()< m_panelY + 686){
       m_gridSpace = 128;
      }

    //uses mouse to select new object type
    if(m_mouse.MouseX() > m_panelX + 28 && m_mouse.MouseX() < m_panelX + 242){
      for(int i = 0; i < data.m_objectType.size(); ++i){
        if(m_mouse.MouseY() > m_panelY + 67 + (i * 16) && m_mouse.MouseY() < m_panelY + 81 + (i * 16)){
          m_currentObjectID = i;
        }
      }
    }
  }

  //look for mouse click on file bar
  if(data.m_bLeftMouseDown == true && bFileBar == true && timeSprite > 0.25){
    //clear game world
    if(m_mouse.MouseX() > m_fileBarX + 18 && m_mouse.MouseX() < m_fileBarX + 103 &&
      m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55 && m_bClear == false ){
      //m_bClear = true;
      data.m_pObject.clear();
      m_bFillGround = false;
    }

    //open level file 1
    if(m_mouse.MouseX() > m_fileBarX + 195 && m_mouse.MouseX() < m_fileBarX + 217 &&
      m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55 && m_bOpen == false ){
        m_editLevel = 1;
        data.m_pObject.clear();
        data.LoadGameLevel("data//level1.dat", con);
    }

    //open level file 2
    if(m_mouse.MouseX() > m_fileBarX + 223 && m_mouse.MouseX() < m_fileBarX + 245 &&
      m_mouse.MouseY() > m_fileBarY + 21 && m_mouse.MouseY() < m_fileBarY + 51 && m_bOpen == false ){
        m_editLevel = 2;
        data.m_pObject.clear();
        data.LoadGameLevel("data//level2.dat", con);
    }

    //open level file 3
    if(m_mouse.MouseX() > m_fileBarX + 251 && m_mouse.MouseX() < m_fileBarX + 273 &&
      m_mouse.MouseY() > m_fileBarY + 21 && m_mouse.MouseY() < m_fileBarY + 51 && m_bOpen == false ){
        m_editLevel = 3;
        data.m_pObject.clear();
        data.LoadGameLevel("data//level3.dat", con);
    }

    //save level file
    if(m_mouse.MouseX() > m_fileBarX + 439 && m_mouse.MouseX() < m_fileBarX + 524 &&
      m_mouse.MouseY() > m_fileBarY + 21 && m_mouse.MouseY() < m_fileBarY + 51 && m_bSave == false ){
      if(m_editLevel == 1)
        data.SaveGameLevel(data.GetLevelFilename(1));
      else if(m_editLevel == 2)
        data.SaveGameLevel(data.GetLevelFilename(2));
      else if(m_editLevel == 3)
        data.SaveGameLevel(data.GetLevelFilename(3));
    }

    //undo last game object
    if(m_mouse.MouseX() > m_fileBarX + 515 && m_mouse.MouseX() < m_fileBarX + 590 &&
      m_mouse.MouseY() > m_fileBarY + 15 && m_mouse.MouseY() < m_fileBarY + 55 && m_bUndo == false ){
      if(data.m_pObject.size() > 0)
        data.m_pObject.pop_back();
      //m_bUndo = true;
    }

    timeSprite = 0;
  }

  //allow user to move around the game world quickly
  static bool bMap = false;
  gi = con.GetSprite(45);
  m_mapX = m_editorX + gi.width + 20;
  m_mapY = m_editorY + 30;
  if(m_mouse.MouseX() > m_mapX && m_mouse.MouseX() < m_mapX + 80 && m_mouse.MouseY() > m_mapY && m_mouse.MouseY() < m_mapY + 80){
    bMap = true;
  }
  else
    bMap = false;

  if(data.m_bLeftMouseDown == true && bMap == true){
    if((m_mouse.MouseX() - m_mapX) * 32 > 0 && (m_mouse.MouseY() - m_mapY) * 32 > 0){
      data.m_playerX = (m_mouse.MouseX() - m_mapX) * 32;
      data.m_playerY = (m_mouse.MouseY() - m_mapY) * 32;      
    }
  }

  //add game objects to level
  static double addTime = 0.0;
  addTime += timeDiff;
  int posX = 0;
  int posY = 0;
  if(m_snapOn == true){
    posX = (int)(data.m_playerX - con.GetScreenCenterX() + m_mouse.MouseX()) / m_gridSpace;
    posY = (int)(data.m_playerY - con.GetScreenCenterY() + m_mouse.MouseY()) / m_gridSpace;
  }
  else{
    posX = (int)(data.m_playerX - con.GetScreenCenterX() + m_mouse.MouseX());// / m_gridSpace;
    posY = (int)(data.m_playerY - con.GetScreenCenterY() + m_mouse.MouseY());// / m_gridSpace;
  }
  static int lastPosX = -100;
  static int lastPosY = -100;

  //mouse click NOT on editor panel
  if(data.m_bLeftMouseDown == true && bPanel == false && bFileBar == false && bMap == false){
    go = data.GetObjectInfo(m_currentObjectID);
    if( posX == lastPosX && posY == lastPosY){
      //do nothing if mouse cursor has not moved since last mouse click
    }
    else if(go.spriteID > -1){// && (posX < lastPosX || posX > lastPosX) && (posY < lastPosY || posY > lastPosY)){ //don't place tiles on top of last tile
      gi = con.GetSprite(go.spriteID);
      go.alive = true;
      go.alpha = gi.alpha;
      go.angle = gi.angle;
      go.maxFrames = gi.maxFrames;
      go.updateInterval = gi.updateInterval;
      go.frameCount = 0;
      go.width = gi.width;
      go.height = gi.height;
      if(m_snapOn == true){
        go.pos.x = posX  * m_gridSpace;
        go.pos.y = posY  * m_gridSpace;
      }
      else{
        go.pos.x = posX;//  * m_gridSpace;
        go.pos.y = posY;//  * m_gridSpace;
      }
      if(gi.spriteID == 90)//elf
        go.speed = 10 + rand() % 35;
      else if(gi.spriteID == 91)//fairy
        go.speed = 35 + rand() % 50;
      else if(gi.spriteID = 92) //witch
        go.speed = 60 + rand() % 70;
      
      //add only if mouse position is within world limits
      if(go.pos.x < data.m_world_right && go.pos.x >= data.m_world_left && go.pos.y >= data.m_world_top && go.pos.y < data.m_world_bottom){
        lastPosX = posX;
        lastPosY = posY;
        //pLog->Log("Pos",go.pos.x, go.pos.y);
        go.totalTime = 0;
        data.AddGameObject(go);
      }
    }
    addTime = 0.0;
  }

  //delete item in game level
  int nDelete;
  int nStore;
  bool bDeleted = false;
  if(data.m_bRightMouseDown == true && addTime > 0.06 && bPanel == false && bFileBar == false && bMap == false){// && addTime > 0.25){
    posX = (int)(data.m_playerX - con.GetScreenCenterX() + m_mouse.MouseX());
    posY = (int)(data.m_playerY - con.GetScreenCenterY() + m_mouse.MouseY());
    
    nStore = -1;
    for(int i = 0; i < data.m_screen.size(); ++i){
      nDelete = data.m_screen[i];

      if(posX > data.m_pObject[nDelete]->go.pos.x && posX < data.m_pObject[nDelete]->go.pos.x + data.m_pObject[nDelete]->go.width &&
       posY > data.m_pObject[nDelete]->go.pos.y && posY < data.m_pObject[nDelete]->go.pos.y + data.m_pObject[nDelete]->go.height)
      {
         if(data.m_pObject[nDelete]->go.layer < 4){
           nStore = nDelete; //continue on
         }
         else{
           //data.m_pObject.erase(data.m_pObject.begin() + nDelete, data.m_pObject.begin() + nDelete + 1); 
           data.m_pObject[nDelete]->go.alive = false;
           bDeleted = true;
           break;
         }
      }    
     // if(bDeleted == true)
     //   break;
    }

    if(bDeleted == false && nStore > -1){
      //data.m_pObject.erase(data.m_pObject.begin() + nStore, data.m_pObject.begin() + nStore + 1);     
      data.m_pObject[nDelete]->go.alive = false;
    }
    addTime = 0.0;
  }


  //events manager
  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}
void CGameData::AddProjectile(float x, float y, float vx, float vy, int type, float dir){
  WEAPON_OBJECT temp;
  temp.pos.x = x;
  temp.pos.y = y;
  temp.vel.x = vx;
  temp.vel.y = vy;
  temp.weaponType = type;
  temp.alive = true;
  temp.distance = 0;
  temp.dir = dir;
  GAME_OBJECT go;
  go.pos.x = x;
  go.pos.y = y;
  go.frameCount = 0;
  go.angle = dir;
  go.alive = true;

  CAudioManager *pAudio = CAudioManager::Instance();
  if(type == WEAPON_PISTOL)// && pAudio->IsPlaying(5) == false)
    pAudio->PlaySoundClip(5, 0);
  if(type == WEAPON_SHOTGUN)// && pAudio->IsPlaying(4) == false)
    pAudio->PlaySoundClip(4, 0);
  if(type == WEAPON_MACHINEGUN && pAudio->IsPlaying(2) == false)
    pAudio->PlaySoundClip(2, 0);
  if(type == WEAPON_ROCKET)// && pAudio->IsPlaying(6) == false)
    pAudio->PlaySoundClip(6, 0);
  if(type == WEAPON_FLAMETHROWER)// && pAudio->IsPlaying(3) == false)
    pAudio->PlaySoundClip(3, 0);


  switch(type){
    case 0:  //bat      
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 87;   
      go.maxFrames = 8;
      go.updateInterval =0.2;
      go.totalTime = 0;      
      go.height = 32;
      go.width = 32;
      break;
    case 1: //pistol
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 84;      
      go.maxFrames = 12;
      go.updateInterval =0.1;
      go.totalTime = 0;      
      go.height = 32;
      go.width = 32;
      break;
    case 2: //shotgun
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 85;  
      go.maxFrames = 12;
      go.updateInterval =0.1;
      go.totalTime = 0;      
      go.height = 32;
      go.width = 32;
      break;
    case 3: //machinegun
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 86;  
      go.maxFrames = 4;
      go.updateInterval =0.1;
      go.totalTime = 0;      
      go.height = 32;
      go.width = 32;
      break;
    case 4: //rocket
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 88;  
      go.maxFrames = 12;
      go.updateInterval =0.1;
      go.totalTime = 0;      
      go.height = 32;
      go.width = 32;
      break;
    case 5: //flamethrower
      temp.damage = 1;
      temp.radius = 1;
      temp.range = 10;
      temp.spriteID = 89;      
      go.maxFrames = 16;
      go.updateInterval =0.1;
      go.totalTime = 0;    
      go.height = 124;
      go.width = 32;
      break;
  }
  CProjectile cp;
  cp.m_WO = temp;
  go.spriteID = temp.spriteID;
  cp.go = go;  
  m_projectiles.push_back(cp);
}
//***************************************************************
//                         U P D A T E
//***************************************************************
cGameStateObject* cGameStatePlay2::update(double timeDifference, Camera &cam, CGameData &data, CGraphics &con){
  m_event = EVENT_GO_NO_WHERE;
  static bool bStop = false;

  D3DXVECTOR3 position;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;

  CLog *pLog = CLog::Instance(); 

  //play audio file at start of game state
  CAudioManager *pAudio = CAudioManager::Instance();
  //if(pAudio->IsPlaying(0) == false)    
  //  pAudio->PlaySoundClip(0, 1);

  //configure mouse
  m_mouse.SetHandle(data.m_hWnd);

  //first time code
  //**********************************************************
  static bool bFirstTime = true;
  if(bFirstTime == true){
    position.x = 0.0f; position.y = 3.0f; position.z = 0.0f;
    cam.setPosition(&position); 
    cam.roll(0.0f);
    
    m_inventoryX = con.GetScreenWidth()  - 163; //293;
    m_inventoryY = 10;
    m_statusX = 150;   //10;
    m_statusY = con.GetScreenHeight() - 95;

    bFirstTime = false;
    m_viewChoice = 4;
    data.m_player.SetupPlayer(con); //updates player data
    data.LoadGameLevel("data//level2.dat", con);

    //data.m_gameOver = false;
    m_bInventory = true;
    m_bPause = false;
    m_bHelp = false;
    //data.m_score = 0;
    //data.m_levelComplete = false;
  }

  //this is the code to allow for pause
  //***********************************
  static double pauseTime = 0;
  pauseTime += timeDifference;  
  if(::GetActiveWindow() == data.m_hWnd && keyDown('P') == true && pauseTime > 0.25){
    m_bPause = !m_bPause;
    pauseTime = 0;
  }
  if(m_bPause == true)
    return 0;

  //manages help
  //**********************************
  static double helpTime = 0;
  helpTime += timeDifference;
  if(::GetActiveWindow() == data.m_hWnd && keyDown('H') == true && helpTime > 0.25){
    m_bHelp = !m_bHelp;
    helpTime = 0;
  }

  //manages kindness accumulation next to grandma
  //*********************************************
  static double kindnessTime = 0;
  kindnessTime += timeDifference;


  //game over if not enough time
  //*********************************
  if(m_secondTimer.getTimer(1) == true){
    data.m_player.m_time--;
    if(data.m_player.m_time <= 0){
      data.m_gameOver = true;
      data.m_timeOut = true;
    }
  }

  //level is complete
  //***************************************
  if(data.m_levelComplete == true){
    m_event = EVENT_GO_CONTROL;
    //return 0;
  }

  //game over
  if(data.m_gameOver == true){
    m_event = EVENT_GO_CONTROL;
    //return 0;
  }

  //update projectiles
  for(int i = 0; i < data.m_projectiles.size(); ++i){
    data.m_projectiles[i].Update(timeDifference);
  }

  //escape state by pressing ESC key
  if(::GetActiveWindow() == data.m_hWnd && keyDown(VK_ESCAPE)){
    data.m_playerQuit = true;
    m_event = EVENT_GO_CONTROL;
  }
  //if(::GetActiveWindow() == data.m_hWnd && keyDown('2'))
  //  m_event = EVENT_GO_PLAY2;

  cam.getPosition(&position);
  static double timeDiff = 0;
  static double timeFire = 0;
  static double timeKey = 0;
  timeDiff = timeDifference;
  timeFire += timeDifference;
  timeKey += timeDifference;

  //update all objects
  for(int i = 0; i < data.m_pObject.size(); ++i){
    data.m_pObject[i]->Update(timeDiff);
    data.m_pObject[i]->UpdatePlayerPosition(data.m_player.go.pos.x, data.m_player.go.pos.y);

  }

  bool bRet = false;

  //delete obsolete projectiles
  for(int i = data.m_projectiles.size() - 1; i > -1; --i){
    if(data.m_projectiles[i].go.alive == false)
      data.m_projectiles.erase(data.m_projectiles.begin() + i, data.m_projectiles.begin() + i + 1);
  }

  //delete objects
  for(int i = data.m_pObject.size() - 1; i > -1; --i){
    if(data.m_pObject[i]->go.alive == false)
      data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
  }

  //slows down key press for PageUp and PageDown
  static double timeSprite = 0;
  timeSprite += timeDiff;

  //**********************************************
  // Move player
  //**********************************************
  //only process keys if this window has focus
  if(::GetActiveWindow() == data.m_hWnd){// && gTimerKey.getTimer(0.03) == true){
    cam.yaw(0.0f);

    //walk
    if(keyDown('W') == true){
      //cam.walk(0.5f * timeDiff);
      data.m_player.MoveUp(timeDiff);
      if(data.m_player.go.pos.y < data.m_world_top)
        data.m_player.go.pos.y = data.m_world_top;
    }
    else if(keyDown('S') == true){
      //cam.walk(-0.5f * timeDiff);
      data.m_player.MoveDown(timeDiff);
      if(data.m_player.go.pos.y > data.m_world_bottom - 32)
        data.m_player.go.pos.y = data.m_world_bottom - 32;
    }

    //strafe
    else if(keyDown('A') == true){
      //cam.strafe(-0.5f * timeDiff);
      data.m_player.MoveLeft(timeDiff);
      if(data.m_player.go.pos.x < data.m_world_left)
        data.m_player.go.pos.x = data.m_world_left;
    }
    else if(keyDown('D') == true){
      //cam.strafe(0.5f * timeDiff);
      data.m_player.MoveRight(timeDiff);
      if(data.m_player.go.pos.x > data.m_world_right - 32)
        data.m_player.go.pos.x = data.m_world_right - 32;
    }
    else
      data.m_player.Stand();
  }
   
  //select weapon type from keyboard
  //****************************************
  if(::GetActiveWindow() == data.m_hWnd && timeKey > 0.25){
    if(keyDown('1'))
      data.m_weaponType = 1;//pistol
    else if(keyDown('2'))
      data.m_weaponType = 2;//shotgun
    else if(keyDown('3'))
      data.m_weaponType = 3;//machine gun
    else if(keyDown('4'))
      data.m_weaponType = 4;//rockets
    else if(keyDown('5'))
      data.m_weaponType = 5;//flame thrower

    //toggle inventory
    if(keyDown('I') && m_bInventory == true)
      m_bInventory = false;
    else if(keyDown('I') && m_bInventory == false)
      m_bInventory = true;

    timeKey = 0;
  }

  //fire weapon with spacebar
  if(::GetActiveWindow() == data.m_hWnd && timeFire > 0.25){

    //walk
    if((keyDown(VK_SPACE) == true || data.m_bLeftMouseDown == true) && data.m_weapons[data.m_weaponType].exists == true && data.m_weapons[data.m_weaponType].rounds > 0){
      data.AddProjectile(data.m_player.go.pos.x, data.m_player.go.pos.y, 0, 0, data.m_weaponType, data.m_player.GetPlayerDir());
      data.m_weapons[data.m_weaponType].rounds--;
/*   
      if(data.m_weaponType == WEAPON_PISTOL)// && pAudio->IsPlaying(5) == false)
        pAudio->PlaySoundClip(5, 0);
      if(data.m_weaponType == WEAPON_SHOTGUN)// && pAudio->IsPlaying(4) == false)
        pAudio->PlaySoundClip(4, 0);
      if(data.m_weaponType == WEAPON_MACHINEGUN && pAudio->IsPlaying(2) == false)
        pAudio->PlaySoundClip(2, 0);
      if(data.m_weaponType == WEAPON_ROCKET)// && pAudio->IsPlaying(6) == false)
        pAudio->PlaySoundClip(6, 0);
      if(data.m_weaponType == WEAPON_FLAMETHROWER)// && pAudio->IsPlaying(3) == false)
        pAudio->PlaySoundClip(3, 0);
*/
      //pLog->Log("Projectile added", data.m_player.go.pos.x, data.m_player.go.pos.y);
      timeFire = 0;
    }
  }
  
  //combined direction and shooting
  //*******************************************************************************************************************
  if(::GetActiveWindow() == data.m_hWnd  && timeFire > 0.25){// && gTimerKey.getTimer(0.03) == true){
    cam.yaw(0.0f);

    //walk
    if(keyDown(VK_UP) == true  && data.m_weapons[data.m_weaponType].exists == true && data.m_weapons[data.m_weaponType].rounds > 0){
      //cam.walk(0.5f * timeDiff);
      data.m_player.MoveUp(timeDiff);
      if(data.m_player.go.pos.y < data.m_world_top)
        data.m_player.go.pos.y = data.m_world_top;
      data.AddProjectile(data.m_player.go.pos.x, data.m_player.go.pos.y, 0, 0, data.m_weaponType, data.m_player.GetPlayerDir());
      data.m_weapons[data.m_weaponType].rounds--;

    }
    else if(keyDown(VK_DOWN) == true   && data.m_weapons[data.m_weaponType].exists == true && data.m_weapons[data.m_weaponType].rounds > 0){
      //cam.walk(-0.5f * timeDiff);
      data.m_player.MoveDown(timeDiff);
      if(data.m_player.go.pos.y > data.m_world_bottom - 32)
        data.m_player.go.pos.y = data.m_world_bottom - 32;
      data.AddProjectile(data.m_player.go.pos.x, data.m_player.go.pos.y, 0, 0, data.m_weaponType, data.m_player.GetPlayerDir());
      data.m_weapons[data.m_weaponType].rounds--;
    }
    //strafe
    else if(keyDown(VK_LEFT) == true   && data.m_weapons[data.m_weaponType].exists == true && data.m_weapons[data.m_weaponType].rounds > 0){
      //cam.strafe(-0.5f * timeDiff);
      data.m_player.MoveLeft(timeDiff);
      if(data.m_player.go.pos.x < data.m_world_left)
        data.m_player.go.pos.x = data.m_world_left;
      data.AddProjectile(data.m_player.go.pos.x, data.m_player.go.pos.y, 0, 0, data.m_weaponType, data.m_player.GetPlayerDir());
      data.m_weapons[data.m_weaponType].rounds--;

    }
    else if(keyDown(VK_RIGHT) == true   && data.m_weapons[data.m_weaponType].exists == true && data.m_weapons[data.m_weaponType].rounds > 0){
      //cam.strafe(0.5f * timeDiff);
      data.m_player.MoveRight(timeDiff);
      if(data.m_player.go.pos.x > data.m_world_right - 32)
        data.m_player.go.pos.x = data.m_world_right - 32;
      data.AddProjectile(data.m_player.go.pos.x, data.m_player.go.pos.y, 0, 0, data.m_weaponType, data.m_player.GetPlayerDir());
      data.m_weapons[data.m_weaponType].rounds--;

    }
    else
      data.m_player.Stand();

    timeFire = 0;
  }

  //select weapon from inventory
  if(::GetActiveWindow() == data.m_hWnd && data.m_bLeftMouseDown == true){
    if(m_mouse.MouseX() > m_inventoryX && m_mouse.MouseX() < m_inventoryX + 140 &&
       m_mouse.MouseY() > m_inventoryY && m_mouse.MouseY() < m_inventoryY + 730){
      
        if(m_mouse.MouseY() > m_inventoryY + 68 && m_mouse.MouseY() < m_inventoryY + 196)
          data.m_weaponType = 1;
        else if(m_mouse.MouseY() > m_inventoryY + 196 && m_mouse.MouseY() < m_inventoryY + 328)
          data.m_weaponType = 2;
        else if(m_mouse.MouseY() > m_inventoryY + 328 && m_mouse.MouseY() < m_inventoryY + 460)
          data.m_weaponType = 3;
        else if(m_mouse.MouseY() > m_inventoryY + 460 && m_mouse.MouseY() < m_inventoryY + 590)
          data.m_weaponType = 4;
        else if(m_mouse.MouseY() > m_inventoryY + 590 && m_mouse.MouseY() < m_inventoryY + 710)
          data.m_weaponType = 5;
        if(pAudio->IsPlaying(1) == false)    
          pAudio->PlaySoundClip(1, 0);
      
    }
  }

  //update player information
  data.m_player.Update(timeDiff);

  //update grandma information
  data.m_player.m_rechargeKindness = false;
  if(kindnessTime > 0.1){
    for(int i = 0; i < data.m_grandma.size(); ++i){
      data.m_grandma[i].Update(timeDiff);
      if(sqrt((data.m_player.go.pos.x - data.m_grandma[i].go.pos.x) * (data.m_player.go.pos.x - data.m_grandma[i].go.pos.x) +
        (data.m_player.go.pos.y - data.m_grandma[i].go.pos.y) * (data.m_player.go.pos.y - data.m_grandma[i].go.pos.y)) < 100){
          data.m_player.m_kindness += 3;
          data.m_player.m_rechargeKindness = true;
          if(pAudio->IsPlaying(16) == false)    
            pAudio->PlaySoundClip(16, 0);
      }    
    }
    kindnessTime = 0;
  }

    // C O L L I S I O N    D E T E C T I O N player
  for(int i = 0; i < data.m_pObject.size(); ++i){

    //collision with block
    if(data.m_pObject[i]->go.layer == 6 && data.m_pObject[i]->go.objectID != 27){
      bRet = data.IsPlayerCollision(i);        
    }

    //collision with elf...oops!!!
    else if(data.m_pObject[i]->go.layer == 8 && data.m_pObject[i]->go.objectID == 27){
      if(data.IsPlayerCollision(i) == true){
        data.m_player.m_health -= 1;
        if(pAudio->IsPlaying(8) == false)    
          pAudio->PlaySoundClip(8, 0);
        break;
      }
    }
    //collision with fairy
    else if(data.m_pObject[i]->go.layer == 8 && data.m_pObject[i]->go.objectID == 28){
      if(data.IsPlayerCollision(i) == true){
        data.m_player.m_health -= 1;
        if(pAudio->IsPlaying(7) == false)    
          pAudio->PlaySoundClip(7, 0);
        break;
      }
    }
    //collision with witch
    else if(data.m_pObject[i]->go.layer == 8 && data.m_pObject[i]->go.objectID == 29){
      if(data.IsPlayerCollision(i) == true){
        data.m_player.m_health -= 1;
        if(pAudio->IsPlaying(9) == false)    
          pAudio->PlaySoundClip(9, 0);
        break;
      }
    }

    //weapon pickup
    else if(data.m_pObject[i]->go.layer == 7 && data.m_pObject[i]->go.radius == -1){
      if(data.IsPlayerCollision(i) == true){
        data.m_pObject[i]->go.alive = false;

        //pistol
        if(data.m_pObject[i]->go.objectID == 12){ // && data.m_weapons[1].exists == false){
          data.m_weapons[1].exists = true;
          data.m_weapons[1].rounds += data.m_weapons[1].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //shotgun
        else if(data.m_pObject[i]->go.objectID == 13){// && data.m_weapons[2].exists == false){
          data.m_weapons[2].exists = true;
          data.m_weapons[2].rounds += data.m_weapons[2].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //machine gun
        else if(data.m_pObject[i]->go.objectID == 14){// && data.m_weapons[3].exists == false){
          data.m_weapons[3].exists = true;
          data.m_weapons[3].rounds += data.m_weapons[3].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //rocket launcher
        else if(data.m_pObject[i]->go.objectID == 15){// && data.m_weapons[4].exists == false){
          data.m_weapons[4].exists = true;
          data.m_weapons[4].rounds += data.m_weapons[4].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //flame thrower
        else if(data.m_pObject[i]->go.objectID == 16){// && data.m_weapons[5].exists == false){
          data.m_weapons[5].exists = true;
          data.m_weapons[5].rounds += data.m_weapons[5].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //ammo_pistol
        else if(data.m_pObject[i]->go.objectID == 17){// && data.m_weapons[1].exists == true){
          data.m_weapons[1].rounds += data.m_weapons[1].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);
          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //ammo shotgun
        else if(data.m_pObject[i]->go.objectID == 18){// && data.m_weapons[2].exists == true){
          data.m_weapons[2].rounds += data.m_weapons[2].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);
          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //ammo machine gun
        else if(data.m_pObject[i]->go.objectID == 19 ){//&& data.m_weapons[3].exists == true){
          data.m_weapons[3].rounds += data.m_weapons[3].maxRounds;
          if(pAudio->IsPlaying(12) == false)    
            pAudio->PlaySoundClip(12, 0);
          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //pickup first aid health
        else if(data.m_pObject[i]->go.objectID == 9 ){//&& data.m_weapons[3].exists == true){
          data.m_pObject[i]->go.alive = false;
          data.m_player.m_health += 200;
          if(data.m_player.m_health > 1000)
              data.m_player.m_health = 1000;
          if(pAudio->IsPlaying(10) == false)    
            pAudio->PlaySoundClip(10, 0);

          data.m_pObject.erase(data.m_pObject.begin() + i, data.m_pObject.begin() + i + 1);
        }

        //exit through the door
        else if(data.m_pObject[i]->go.objectID == 20 ){//&& data.m_weapons[3].exists == true){
          data.m_pObject[i]->go.alive = false;
          data.m_levelComplete = true;
          
        }
      }
    }
  }

  /*
  //ensure all elves don't collide
  //*****************************************************
  for(int i = 0; i < data.m_pObject.size(); ++i){

    //only process for elves
    if(data.m_pObject[i]->go.objectID == 27){
      
      //iterate through all objects except witches, and fairies
      for(int j = 0; j < data.m_pObject.size(); ++j){

        //check for collision
        if(data.m_pObject[j]->go.layer == 6){
          if(data.m_pObject[i]->go.pos.x > data.m_pObject[j]->go.pos.x - 50 && data.m_pObject[i]->go.pos.x < data.m_pObject[j]->go.pos.x + 50){
            if(data.m_pObject[i]->go.pos.y > data.m_pObject[j]->go.pos.y - 50 && data.m_pObject[i]->go.pos.y < data.m_pObject[j]->go.pos.y + 50){
              bRet = data.IsElfCollision(i, j);
            }
          }
        }

      }
    }
  }
*/
  //check game over stuff
  if(data.m_player.m_health < 1){
    data.m_gameOver = true;
    data.m_healthOut = true;
    data.m_player.m_health = 0;
  }
  if(data.m_player.m_kindness < 1){
    data.m_gameOver = true;
    data.m_player.m_kindness = 0;
    data.m_kindnessOut = true;
  }

  //process projectile collision with elf, fairy, and witch
  //*******************************************************
  data.UpdateProjectiles(timeDifference);

  //data.m_pObject.erase(data.m_pObject.begin() + nDelete, data.m_pObject.begin() + nDelete + 1); 
  //events manager
  for(unsigned int i=0; i< m_TE.size(); i++){
    if (m_TE[i].event == m_event){
      return m_TE[i].p_gso;
    }
  }
  return 0;
}