void InvestigationScene::onKeyUp(int keycode, ALLEGRO_EVENT ev) {
    
    if (inputLocked) {
        return;
    }
    
    switch (keycode) {
        case ALLEGRO_KEY_UP:
        case ALLEGRO_KEY_W:
            moving = pointOffset(moving, 0, 1);
            break;
        case ALLEGRO_KEY_DOWN:
        case ALLEGRO_KEY_S:
            moving = pointOffset(moving, 0, -1);
            break;
        case ALLEGRO_KEY_LEFT:
        case ALLEGRO_KEY_A:
            moving = pointOffset(moving, 1, 0);
            break;
        case ALLEGRO_KEY_RIGHT:
        case ALLEGRO_KEY_D:
            moving = pointOffset(moving, -1, 0);
            break;
        case ALLEGRO_KEY_ESCAPE:
            
            inputLocked = true;
            quitToMenu();
            
            break;
        default:
            break;
    }
}
Beispiel #2
0
void CRulerBar::DoPaint(CDC* pDC)
{
    CControlBar::DoPaint(pDC); // CControlBar::DoPaint -- draws border
    if (m_unit.m_nTPU != 0)
    {
        pDC->SaveDC();
        // offset coordinate system
        CPoint pointOffset(0,0);
        RulerToClient(pointOffset);
        pDC->SetViewportOrg(pointOffset);

        DrawFace(*pDC);
        DrawTickMarks(*pDC);

        DrawTabs(*pDC);
        m_leftmargin.Draw(*pDC);
        m_indent.Draw(*pDC);
        m_rightmargin.Draw(*pDC);

        pDC->RestoreDC(-1);
    }
    // Do not call CControlBar::OnPaint() for painting messages
}
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;
}
void InvestigationScene::dialogueStart() {
    
    inDialogue = true;
    
    questionsAsked++;
    
    speechLines.clear();
    
    std::vector<std::string> memories = activeCharacter->getFormattedMemories(currentFilter);
    
    if (memories.size() > 0) {
        
        speechLines.insert(speechLines.end(), memories.begin(), memories.end());
        
    } else {
        
        if (currentFilter.who == NULL) {
            
            if (currentFilter.strange) {
                speechLines.push_back(std::string("I don't remember anything strange happening there around that time."));
            } else {
                speechLines.push_back(std::string("I don't remember seeing anyone there around that time."));
            }
            
        } else if (currentFilter.where == NULL) {
            
            std::string res = "I don't remember seeing ";
            
            if (currentFilter.who->male) {
                res.append("him ");
            } else {
                res.append("her ");
            }
            
            res.append("around that time.");
            
            speechLines.push_back(res);
        }
    }
    
    speechIdx = 0;
    
    Drawable *sprite = getByTag(activeCharacter->tag);
    
    bkgSpeech->setVisible(true);
    bkgSpeech->setPosition(pointMake(sprite->getPosition().x, sprite->getPosition().y - 20));
    
    speechLabel->setText(speechLines[speechIdx].c_str());
    speechLabel->setVisible(true);
    speechLabel->setPosition(pointOffset(bkgSpeech->getPosition(), 54, -175));
    
    char buff[10];
    sprintf(buff, "%d/%lu", speechIdx + 1, speechLines.size());
    speechCountLabel->setText(buff);
    speechCountLabel->setVisible(true);
    speechCountLabel->setPosition(pointOffset(bkgSpeech->getPosition(), 188, -68));
    
    speechButton->setEnabled(true);
    speechButton->setPosition(bkgSpeech->getPosition());
    
    speechIdx++;
}