void FirstLevelState::Update(float dt)
{
    map.Update(dt);
    InputManager input = InputManager::GetInstance();
    quitRequested = (input.IsKeyDown(ESCAPE_KEY) || input.IsQuitRequested());
    UpdateArray(dt);
    CheckMovementCollisions();
}
Example #2
0
/******************************************************************************
  AdjustWindow - Resize the window according to maxwidth by number of buttons
******************************************************************************/
void AdjustWindow()
{
  int new_width=0,new_height=0,tw,i,total;
  char *temp;

  total = ItemCountD(&windows );
  if (!total)
  {
    if (WindowIsUp==1)
    {
      XUnmapWindow(dpy,win);
      WindowIsUp=2;
    }
    return;
  }
  for(i=0;i<total;i++)
  {
    temp=ItemName(&windows,i);
    if(temp != NULL)
    {
	tw=10+XTextWidth(ButtonFont,temp,strlen(temp));
	tw+=XTextWidth(ButtonFont,"()",2);

	tw+=14; /* for title icon */ /* Magic Number ? */

	new_width=max(new_width,tw);
    }
  }
  new_width=max(new_width, MinWidth);
  new_width=min(new_width, MaxWidth);
  new_height=(total*(fontheight+6+1)-1);
  if (WindowIsUp && (new_height!=win_height  || new_width!=win_width))
  {
    if (Anchor)
    {
      if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
        win_x-=(new_width-win_width);

      if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
        win_y-=(new_height-win_height);

      if(RESIZE_BUG_HACK)
      {
        if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
		win_x+= win_border - 2;
	else
		win_x-=win_border;

	if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
		win_y+=win_border - 2;
	else	
		win_y-=win_border;
      }

      XMoveResizeWindow(dpy,win,win_x+win_border,win_y+win_title+win_border,
        new_width,new_height);

    }
    else
      XResizeWindow(dpy, win, new_width,new_height);

    XSync(dpy,False);
  }
  UpdateArray(&buttons,-1,-1,new_width,-1);
  if (new_height>0) win_height = new_height;
  if (new_width>0) win_width = new_width;
  if (WindowIsUp==2)
  {
    XMapWindow(dpy,win);
    WindowIsUp=1;
    WaitForExpose();
  }
}
Example #3
0
/******************************************************************************
  AdjustWindow - Resize the window according to maxwidth by number of buttons
******************************************************************************/
void AdjustWindow(void)
{
    int new_width=0,new_height=0,tw,i,total,off_x,off_y;
    char *temp;
    Window frame;
    XWindowAttributes win_attr, frame_attr;

    total = ItemCountD(&windows );
    if (!total)
    {
        if (WindowIsUp==1)
        {
            XUnmapWindow(dpy,win);
            WindowIsUp=2;
        }
        return;
    }
    for(i=0; i<total; i++)
    {
        temp=ItemName(&windows,i);
        if(temp != NULL)
        {
            tw=10+XTextWidth(ButtonFont,temp,strlen(temp));
            tw+=XTextWidth(ButtonFont,"()",2);

#ifdef MINI_ICONS
            tw+=14; /* for title icon */ /* Magic Number ? */
#endif

            new_width=max(new_width,tw);
        }
    }
    new_width=max(new_width, MinWidth);
    new_width=min(new_width, MaxWidth);
    new_height=(total*(fontheight+6+1));
    if (WindowIsUp && (new_height!=win_height  || new_width!=win_width))
    {
        if (Anchor)
        {
            off_x = off_y = 0;
            MyXGrabServer(dpy);
            frame = find_frame_window(win, &off_x, &off_y);
            XGetWindowAttributes(dpy, frame, &frame_attr);
            XGetWindowAttributes(dpy, win, &win_attr);
            win_x = frame_attr.x + frame_attr.border_width + off_x;
            win_y = frame_attr.y + frame_attr.border_width + off_y;

            if (win_grav == SouthEastGravity || win_grav == NorthEastGravity)
                win_x += win_attr.width - new_width;
            if (win_grav == SouthEastGravity || win_grav == SouthWestGravity)
                win_y += win_attr.height - new_height;

            XMoveResizeWindow(dpy, win, win_x, win_y, new_width, new_height);
            MyXUngrabServer(dpy);
        }
        else
            XResizeWindow(dpy, win, new_width, new_height);

    }
    UpdateArray(&buttons,-1,-1,new_width,-1);
    if (new_height>0) win_height = new_height;
    if (new_width>0) win_width = new_width;
    if (WindowIsUp==2)
    {
        XMapWindow(dpy,win);
        WindowIsUp=1;
        WaitForExpose();
    }
}
void StageState::Update(float dt) {
	if (music.isOverInd){
		cMusic++;
		if (cMusic == musicNames.size()){
			cMusic = 0;
		}
		music.Open(musicNames[cMusic]);
		music.Play(1);
	}
	
	int size = 0;
	int cost = 0;
	Input();
	creationTimer.Update(dt);
	switch (action)	{
	case NONE:
		break;
	case TILE_SELECT:
		p = tileMap.GetTile(InputManager::GetInstance().GetMouseX()-Camera::pos.x,InputManager::GetInstance().GetMouseY()-Camera::pos.y);
        selectionBox.SetBegin(p);
		selectionBox.Update(&tileMap);
        p = tileMap.GetTileCenter(p);
		break;
	case GUI_ROOM:
		roomSheet.UpdateObjectSheet();
		break;
	case CONSTRUCT_ROOM:
		selectionBox.Update(&tileMap);
		size = (abs(selectionBox.end.x - selectionBox.begin.x) + 1)*(abs(selectionBox.end.y - selectionBox.begin.y) + 1);
		cost = size * 5;
		break;
	case DESTROY_ROOM:
		break;
	case AREA_SELECT:
		break;
	case BUY:
		buySheet.UpdateObjectSheet();
		break;
	case EDIT_OBJECT:{
		Point tiles = Point(InputManager::GetInstance().GetMouseX() - Camera::pos.x, InputManager::GetInstance().GetMouseY() - Camera::pos.y);
		tiles = tileMap.GetTileCenterFromScreen(tiles);
		objectArray[selectedObject]->MoveTo(tiles.x, tiles.y);
	}
		break;
	default:
		break;
	}
	

	for (unsigned int i = 0; i < objectArray.size(); i++) {
		if (objectArray[i]->IsDead()) {
			DestroyCharacter(i);
			for (unsigned int j = 0; j < objectArray.size(); j++) {
				if (objectArray[j]->IsCharacter()) {
					objectArray[j]->ChangeSelection(i);
				}
			}
			i--;
		}
	}

	UpdateArray(dt, &tileMap);
	
	for (int i = 0; i < objectArray.size(); i++){

		if (objectArray[i]->IsCharacter()){
			if (objectArray[i]->GetAction() == DECIDING_ROOM){
				charChoice = objectArray[i]->GetChoice();
				charRoom = charChoice;

				if (!roomArray.empty()){
					for (int j = 0; j < roomArray.size(); j++){
						if ((roomArray[j]->GetState() == charRoom) && (roomArray[j]->roomState != Room::EDITING)){
							int x, y;
							Point t;
							x = objectArray[i]->box.x + objectArray[i]->box.w / 2;
							y = objectArray[i]->box.y + objectArray[i]->box.h;
							t = tileMap.GetTile(x, y);
							vector<int> path = PathAStar(t.x, t.y, roomArray[j]->GetDoor(), heuristicsArray[roomArray[j]->GetID()]);
							if (!path.empty())
								objectArray[i]->AddObjective(path);
							else
								cout << "No path!!!!" << endl;
						}
					}
				}
			}
			else{
				if (objectArray[i]->GetAction() == DECIDING_OBJECT){
					int objectIndex = objectArray[i]->GetObjectIndex();
					if (objectIndex != -1){
						Point objective = Point(objectArray[objectIndex]->GetTile().x, objectArray[objectIndex]->GetTile().y - 1);
						Point t = objectArray[i]->GetTile();
						cout << endl << "Debug action DO" << endl << endl;
						cout << "X,Y : " << t.x << "," << t.y << endl;
						cout << "Object index : " << objectIndex << endl;
						cout << objectArray[objectIndex]->GetHeuristic(0).size() << endl;
						vector<int> path = PathAStar(t.x, t.y, objective, objectArray[objectIndex]->GetHeuristic(0));
						if (!path.empty())
							objectArray[i]->AddObjective(path);
						else
							cout << "No path!!!!" << endl;
					}
				}
				else{
					if (objectArray[i]->GetAction() == EXITING){
						cout << "Entrou exitting!!!!!!!!!!" << endl;
						int objectIndex = objectArray[i]->GetObjectIndex();
						if (objectIndex != -1){
							Point objective = Point(objectArray[objectIndex]->GetTile().x, objectArray[objectIndex]->GetTile().y - 1);
							Point t = objectArray[i]->GetTile();
							vector<int> path = PathAStar(t.x, t.y, objective, objectArray[objectIndex]->GetHeuristic(0));
							if (!path.empty())
								objectArray[i]->AddObjective(path);
							else
								cout << "No path!!!!" << endl;
						}
					}

				}
			}
		}
	}
	if (creationTimer.Get() > 10){
		CreateCharacter(5, 5);
		creationTimer.Restart();
	}
	if (cost > 0)
		costText.SetText(to_string(-cost));
	else
		costText.SetText(" ");
	costText.SetPos(InputManager::GetInstance().GetMouseX() + 10, InputManager::GetInstance().GetMouseY() + 5, false, false);
	
}