bool InvestigationScene::tick(double dt) { if (inputLocked) { return true; } int tx = playerSprite->getPosition().x / collision->getTileSize().width; int ty = playerSprite->getPosition().y / collision->getTileSize().height; std::vector<Room *> rooms = mystery->getRooms(); std::vector<Room *>::iterator itRooms; for (itRooms = rooms.begin(); itRooms < rooms.end(); ++itRooms) { Room *room = (Room *) *itRooms; if (rectContainsPoint(room->bounds, pointMake(tx, ty)) && room != currentRoom) { currentRoom = room; currentRoomLabel->setText(room->name.c_str()); } } float dx = 0; float dy = 0; bool isMoving = !pointEqualsIntegral(moving, pointMake(0, 0)); if (isMoving) { dx = moving.x * 200 * dt; dy = moving.y * 200 * dt; if (dy < 0) { moveDir = 0; } else if (dy > 0) { moveDir = 18; } else if (dx < 0) { moveDir = 9; } else if (dx > 0) { moveDir = 27; } curFrame += dt * 10; if (curFrame > 8) curFrame -= 8; } else { curFrame = 0; } bool collided = false; Rect colRect = rectMake(playerSprite->getPosition().x - 16, playerSprite->getPosition().y - 16, 32, 32); Rect colRectX = rectOffset(colRect, dx, 0); Rect colRectY = rectOffset(colRect, 0, dy); int tw = collision->getTileSize().width; int th = collision->getTileSize().height; int tpx = playerSprite->getPosition().x / collision->getTileSize().width; int tpy = playerSprite->getPosition().y / collision->getTileSize().height; for (int j = tpy - 2; j <= tpy + 2; j++) { for (int i = tpx - 2; i <= tpx + 2; i++) { if (i >= 0 && i < collision->getSize().width && j >= 0 && j < collision->getSize().height) { int gid = collision->getTileAt(i, j); if (gid != 0) { Rect tileRect = rectMake(i * tw, j * th, tw, th); if (rectIntersectsRect(colRectX, tileRect)) { dx = 0; collided = true; } if (rectIntersectsRect(colRectY, tileRect)) { dy = 0; collided = true; } } } } } actionButton->setVisible(false); actionButton->setEnabled(false); activeCharacter = NULL; activePOI = NULL; std::vector<Character *> characters = mystery->getCharacters(); std::vector<Character *>::iterator it; for (it = characters.begin(); it < characters.end(); ++it) { Character *character = (Character *) *it; std::string action; if (character->dead) { action.append("Look at "); } else { action.append("Talk to "); } action.append(character->name); Drawable *sprite = getByTag(character->tag); Rect otherColRect = rectMake(sprite->getPosition().x - 16, sprite->getPosition().y - 16, 32, 32); if (rectIntersectsRect(colRect, otherColRect)) { actionButton->setLabelText(action.c_str()); actionButton->setPosition(pointMake(sprite->getPosition().x, sprite->getPosition().y - 32)); actionButton->setVisible(true); actionButton->setEnabled(true); activeCharacter = character; } } if (currentRoom != NULL) { std::vector<POI *> POIList = currentRoom->pointsOfInterest; std::vector<POI *>::iterator itPOI; for (itPOI = POIList.begin(); itPOI < POIList.end(); ++itPOI) { POI *poi = (POI *) *itPOI; Rect tileRect = collision->getTileRect(poi->position.x, poi->position.y); tileRect = rectExpand(tileRect, 4, 4); if ((poi->interest == InterestContainerVisible || poi->interest == InterestContainerConceiled) && rectIntersectsRect(colRect, tileRect)) { std::string action = "Examine "; action.append(poi->shortDescription); actionButton->setLabelText(action.c_str()); actionButton->setPosition(rectMidPoint(tileRect)); actionButton->setVisible(true); actionButton->setEnabled(true); activePOI = poi; } } } playerSprite->setFrame(moveDir + (int)curFrame + (isMoving ? 1 : 0)); playerSprite->setPosition(pointOffset(playerSprite->getPosition(), dx, dy)); camera->setCenter(playerSprite->getPosition()); return !endScene; }
/*** Will be called before the first display of the dialog *******************/ BOOL CCalendarDlg2::OnInitDialog() { m_mcMonthCal.SetHolidaysFromFile(_T("HOLIDAYS.INI")); m_mcMonthCal.pDelegates=this; CResizeableDialog::OnInitDialog(); // ֿאנסטל פאיכ CString sContent; ReadFile(sMainFile,sContent); sContent.Replace("\r\n","\n"); sContent=CString("\n")+sContent+"\n"; while(sContent!="") { CString sLine=sContent.SpanExcluding("\n"); if(sLine!="") { aItems.Add(sLine); if(sContent.GetLength()>sLine.GetLength()) { sContent=sContent.Mid(sLine.GetLength()+1); } else { sContent=""; } } sContent.TrimLeft(); } LRESULT lRes=0; NMDAYSTATE pDayState; SYSTEMTIME stMinRange, stMaxRange; memset(&pDayState,0,sizeof(pDayState)); m_mcMonthCal.GetMonthRange(&stMinRange, &stMaxRange, GMR_DAYSTATE); pDayState.cDayState=(stMaxRange.wYear - stMinRange.wYear) * 12 + stMaxRange.wMonth - stMinRange.wMonth + 1; memcpy(&pDayState.stStart,&stMinRange,sizeof(SYSTEMTIME)); OnGetdaystate((NMHDR*)&pDayState,&lRes); //pDayState.prgDayState[0]=0xffff; //memset(pDayState.prgDayState,555,5*sizeof(MONTHDAYSTATE)); m_mcMonthCal.SetDayState(pDayState.cDayState,pDayState.prgDayState); m_mcMonthCal.Invalidate(); //----------------------------------- // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon GetDlgItem(IDC_STATIC1)->SetWindowText(_l(sStatic1)); GetDlgItem(IDC_STATIC2)->SetWindowText(_l(sStatic2)); SetWindowText(_l(sTitle)); GetDlgItem(IDOK)->SetWindowText(_l(sButton)); GetDlgItem(IDCLEAR)->SetWindowText(_l("Clear field")); // Register resizable controls RegisterControl(IDC_STATIC1, ATTACH_TO_TOP_EDGE | ATTACH_TO_VERTICAL_EDGES); RegisterControl(IDC_MONTHCALENDAR1, ATTACH_TO_TOP_EDGE | ATTACH_TO_VERTICAL_EDGES); RegisterControl(IDC_STATIC2, ATTACH_TO_TOP_EDGE | ATTACH_TO_VERTICAL_EDGES); RegisterControl(IDC_EDIT_TXT, ATTACH_TO_TOP_EDGE | ATTACH_TO_VERTICAL_EDGES); RegisterControl(IDC_STATIC3, ATTACH_TO_BOTTOM_EDGE | ATTACH_TO_LEFT_EDGE); RegisterControl(IDCLEAR, ATTACH_TO_BOTTOM_EDGE | ATTACH_TO_LEFT_EDGE); RegisterControl(IDOK, ATTACH_TO_BOTTOM_EDGE | ATTACH_TO_RIGHT_EDGE); // Calculate minimum and maximum size of calendar window CRect rect; m_mcMonthCal.GetClientRect(rect); int nWidth = rect.Width(); int nHeight = rect.Height(); if (m_mcMonthCal.GetMinReqRect(rect)) { int nMinWidth = rect.Width(); int nMinHeight = rect.Height(); int nDiffWidth = nMinWidth - nWidth; int nDiffHeight = nMinHeight - nHeight; CRect rectOffset(nDiffWidth/2, nDiffHeight/2, nDiffWidth/2 + nDiffWidth%2, nDiffHeight/2 + nDiffHeight%2); GetWindowRect(rect); rect += rectOffset; MoveWindow(rect); ThisSizeIsMinSize(); int nMaxWidth = nMinWidth * 2 + 6*(3-1); int nMaxHeight = nMinHeight * 2 + 13*(4-1); nDiffWidth = nMaxWidth - nWidth; nDiffHeight = nMaxHeight - nHeight; rectOffset = CRect(nDiffWidth/2, nDiffHeight/2, nDiffWidth/2 + nDiffWidth%2, nDiffHeight/2 + nDiffHeight%2); GetWindowRect(rect); rect += rectOffset; int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); if (rect.Width() > nScreenWidth) { rect.left = 0; rect.right = nScreenWidth-1; } if (rect.Height() > nScreenHeight) { rect.top = 0; rect.bottom = nScreenHeight-1; } m_nMaxWidth = m_nMinWidth*2; m_nMaxHeight = m_nMinHeight; /* MoveWindow(rect); ThisSizeIsMaxSize(); CRect rtBegin(rect); MoveWindow(rtBegin); */ } SYSTEMTIME sysTime; GetSystemTime(&sysTime); BOOL bResult = (BOOL)::SendMessage(m_mcMonthCal, MCM_SETCURSEL, 0, (LPARAM) &sysTime); SetTextForDay(&sysTime); return TRUE; // return TRUE unless you set the focus to a control }