void hlct::Game::startGame(){ helmets.clear(); winHelmets.clear(); addRandomHelmet(); gameTimer.setDuration(endTime); gameTimer.animateFromTo(0, endTime); state = GAME_STATE_GAME; currentTime = 0; currentTimeStr = "0"; score = 0; livesLeft = HLCT_LIVES; bPaused = false; ofRectangle stageRect(stagePos.get(), stageWidth.get(), stageHeight.get()); hero.setup(ofVec2f(stageRect.getWidth()/2, stageRect.getBottom()), imgPack.hero->getPixels()); }
void TCueSheetWindow::Init() { // Init Undo Engine fUndoEngine = new TUndoEngine(); // Member file used for saves fFile = NULL; // Dialog box state fPanelOpen = false; // Create the stage window BRect stageRect(0,0,420,340); fStageWindow = new TStageWindow(stageRect, this); CenterWindow(fStageWindow); // Set up menu bar BRect mbarRect = Bounds(); mbarRect.bottom = mbarRect.top+kMenuHeight; BMenuBar* mbar = new BMenuBar(mbarRect, "MuseumMenu"); // Set up application menus. // Create a new TMuseumMenu object and pass the BMenuBar object in to the constructor. // Then add the individual menu items with the TMuseumMenu object fAppMenu = new TMuseumMenus(mbar); AddChild(mbar); // Set the channel length to an hour duration in milliseconds float channelLength = TimeToPixels( 60 * 60 * 1000L, B_TIMECODE_24, 3); // Create Toolbar. It is always at the top of the window, below the menu. BRect toolRect = Bounds(); toolRect.Set(toolRect.left, kMenuHeight, toolRect.right, kMenuHeight+kToolbarHeight); fToolbar = new TToolbar(toolRect, this); AddChild(fToolbar); fToolbar->Show(); // Create ExportTimeView. It is always located below the toolbar and to the // very left of the cue sheet. It is as wide as the cue sheet headers. BRect exportTimeRect; exportTimeRect.left = fToolbar->Frame().left; exportTimeRect.top = fToolbar->Frame().bottom+1; exportTimeRect.right = exportTimeRect.left + kHeaderWidth; exportTimeRect.bottom = exportTimeRect.top + kExportZoneHeight + 11; fExportTimeView = new TExportTimeView(this, exportTimeRect); AddChild(fExportTimeView); fExportTimeView->Show(); // Create CueSheet Time Zone. It is always located below the toolbar and to the // very left of the cue sheet. It is as wide as the cue sheet headers. BRect zoneRect; zoneRect.left = exportTimeRect.left; zoneRect.top = exportTimeRect.bottom+1; zoneRect.right = zoneRect.left+kHeaderWidth; zoneRect.bottom = zoneRect.top + kTimelineHeight - 11; fTimeZone = new TCueSheetTimeView(this, zoneRect); AddChild(fTimeZone); fTimeZone->Show(); // Create ExportZone. It is always located below the toolbar and to the right // of the TimeZone. This is where the user determines the span of the cue sheet // to preview or export BRect exportRect; exportRect.left = zoneRect.right + 1; exportRect.top = fToolbar->Frame().bottom+1; exportRect.right = Bounds().right; exportRect.bottom = exportRect.top + kExportZoneHeight; fExportZone = new TExportZone(exportRect, this); AddChild(fExportZone); fExportZone->Show(); // Create Timeline. It is always located below the toolbar and to the right // of the TimeZone. This is where the time is indicated and the playback head resides BRect timeRect; timeRect.left = exportRect.left; timeRect.top = exportRect.bottom + 1; timeRect.right = Bounds().right; timeRect.bottom = timeRect.top + kTimelineHeight; fTimeline = new TTimelineView(timeRect, this); AddChild(fTimeline); fTimeline->Show(); // Create Header Container View BRect containerRect = Bounds(); containerRect.top = fTimeline->Frame().bottom; containerRect.right = containerRect.left + kHeaderWidth; containerRect.bottom -= kScrollHeight+1; fHeaderContainer = new THeaderContainerView(containerRect); AddChild(fHeaderContainer); fHeaderContainer->SetViewColor(kMediumGrey); // Create cue sheet view. Add one pixel to left to fix drawing bug with header... BRect bounds = fTimeline->Frame(); bounds.Set(bounds.left, bounds.bottom+1, Bounds().right-(kScrollWidth+1), Bounds().bottom - (kScrollHeight+1)); fCueSheetView = new TCueSheetView(bounds, this); fCueSheetView->SetViewColor(kGrey); // // Create scroll bars // // Horizontal BRect scrollRect = Bounds(); scrollRect.Set(scrollRect.left+kTimeScalerWidth, scrollRect.bottom-kScrollHeight, scrollRect.right-kScrollWidth, scrollRect.bottom); fHScroll = new TCueSheetScrollBarH(this, scrollRect, NULL, 0, channelLength); AddChild(fHScroll); fHScroll->SetSteps(kTickSpacing, kTickSpacing*4); // Vertical scrollRect = Bounds(); scrollRect.Set(scrollRect.right-kScrollWidth, scrollRect.top + (fTimeline->Frame().bottom+1), scrollRect.right, scrollRect.bottom-kScrollHeight); fVScroll = new TCueSheetScrollBarV(this, scrollRect, fCueSheetView, 0, channelLength); AddChild(fVScroll); fVScroll->SetSteps(kTickSpacing, kTickSpacing*4); // Create TimeScaler BRect scalerRect(0, Bounds().bottom-14,kTimeScalerWidth, Bounds().bottom); fTimeScaler = new TTimeScalerView(scalerRect, fCueSheetView); AddChild(fTimeScaler); // Limit the window size SetSizeLimits( 280, 1500, 280, 1500); // Add CueSheetView to frame AddChild(fCueSheetView); // Adjust the scroll bars AdjustScrollBars(); // Add ourself to cue sheet list static_cast<MuseumApp*>(be_app)->GetCueSheetList()->AddItem(this); // Create the video engine fVideoEngine = new TVideoEngine(fCueSheetView); ASSERT(fVideoEngine); // Create audio engine fAudioEngine = new TAudioEngine(); // Set Pulse rate for views that need it SetPulseRate(5000); }
void hlct::Game::draw(){ ofRectangle stageRect(stagePos.get(), stageWidth.get(), stageHeight.get()); background.draw(stageRect); switch (state){ case GAME_STATE_TITLE: screens["title"].draw(); break; case GAME_STATE_POSING: { screens["posing"].draw(); if (bUserExists && bUserPosing){ ofSetColor(ofColor::white); drawLoadingBar(loadingBarRect, gameStartTimer.getCurrentValue()); if (gameStartTimer.getCurrentValue() == 1.f && !gameStartTimer.isAnimating()){ startGame(); } } break; } case GAME_STATE_GAME: { ofSetColor(ofColor::white); hero.draw(bDebug); for (auto h : winHelmets){ h->draw(bDebug); } for (auto h : helmets){ h->draw(bDebug); } if (bDebug){ ofPushStyle(); ofNoFill(); ofSetColor(ofColor::purple); ofDrawRectangle(stagePos.get().x + dropX, stagePos.get().y, dropWidth, stageHeight); ofPopStyle(); } livesDisplay.draw(stageRect, livesLeft, scaleLive); break; } case GAME_STATE_END_LOOSE: screens["loose"].draw(); break; case GAME_STATE_END_WIN: screens["win"].draw(); break; default: break; } // Draw end timer bar if (state == GAME_STATE_END_LOOSE || state == GAME_STATE_END_WIN){ ofSetColor(ofColor::white, 100); drawLoadingBar(loadingBarRect, gameEndTimer.getCurrentValue()); ofSetColor(ofColor::white); } if (bDebug) { ofPushStyle(); ofSetColor(ofColor::greenYellow); ofNoFill(); ofDrawRectangle(stageRect); ofPopStyle(); } }
void hlct::Game::setup(const ofRectangle& rect){ this->resize(rect); setupInfoScreens(rect); background.setup(rect, imgPack.background->getPixels()); helmets.clear(); state = GAME_STATE_TITLE; ofRectangle stageRect(rect.getTopLeft(), rect.getWidth(), rect.getHeight()); gameStartTimer.setDuration(HLCT_USER_POSE_DURATION); gameStartTimer.setCurve(LINEAR); gameTimer.setRepeatType(PLAY_ONCE); gameTimer.setRepeatTimes(0); gameTimer.setCurve(LINEAR); gameEndTimer.setDuration(HLCT_GAME_END_TO_TITLE_DURATION); gameEndTimer.setCurve(LINEAR); livesDisplay.setup(imgPack, HLCT_LIVES); params.setName("Game"); ofParameterGroup stageParams; stageParams.setName("Stage"); stageParams.add(bDebug.set("Debug Mode", false)); stageParams.add(stagePos.set("Top Left", ofVec2f(HLCT_CLAMP_STAGE, 40), ofVec2f::zero(), ofGetWindowRect().getBottomRight())); stageParams.add(stageWidth.set("Width", ofGetWidth() - HLCT_CLAMP_STAGE * 2, ofGetWidth()/2, ofGetWidth()*2)); stageParams.add(stageHeight.set("Height", ofGetHeight() - 200, ofGetHeight()/2, ofGetHeight()*2)); stageParams.add(dropX.set("Drop Left", 0, 0, ofGetWidth()/2)); stageParams.add(dropWidth.set("Drop Width", 0, 0, ofGetWidth())); stageParams.add(loadingBarOffsetBottom.set("Loadingbar Offset", 120, -500, 500)); ofParameterGroup alignParams; alignParams.setName("Scaling and Alignment"); alignParams.add(scaleHero.set("Hero Scale", .5f, HLCT_HERO_SCALE_MIN, HLCT_HERO_SCALE_MAX)); alignParams.add(scaleBait.set("Dropping Scale", .3f, HLCT_BAIT_SCALE_MIN, HLCT_BAIT_SCALE_MAX)); alignParams.add(scaleBaitWin.set("Win Scale", .3f, HLCT_BAIT_SCALE_MIN, HLCT_BAIT_SCALE_MAX)); alignParams.add(offsetBaitWin.set("Win Offset", 70, HLCT_BAIT_WIN_OFFSET_MIN, HLCT_BAIT_WIN_OFFSET_MAX)); alignParams.add(diffBaitWin.set("Win Diff", .05f, HLCT_BAIT_WIN_DIFF_MIN, HLCT_BAIT_WIN_DIFF_MAX)); alignParams.add(scaleLive.set("Live Scale", .75f, HLCT_LIVE_SCALE_MIN, HLCT_LIVE_SCALE_MAX)); ofParameterGroup gameParams; gameParams.setName("Game Settings"); gameParams.add(bStart.set("New", false)); gameParams.add(endTime.set("Duration", 50, HLCT_MIN_DURATION, HLCT_MAX_DURATION)); gameParams.add(currentTimeStr.set("Curent Time", "0")); gameParams.add(bPaused.set("Paused", false)); params.add(stageParams); params.add(alignParams); params.add(gameParams); params.add(score.set("Score", 0, 0, HLCT_MAX_CATCH)); params.add(bUserExists.set("User Exists", false)); params.add(bUserPosing.set("User Posing", false)); useOsc.set("Use Osc", true); bAddHelmet.set("Add Helmet", false); helmetSection.set("Helmet Section", 0, 0, HLCT_HELMET_SECTION_COUNT); scaleHero.addListener(this, &Game::handleScaleHero); scaleBait.addListener(this, &Game::handleScaleBait); scaleBaitWin.addListener(this, &Game::handleScaleBaitWin); bUserExists.addListener(this, &Game::handleUserExists); bUserPosing.addListener(this, &Game::handlePosing); bStart.addListener(this, &Game::handleGameStart); bAddHelmet.addListener(this, &Game::handleAddHelmet); receiver.setup(HLCT_OSC_PORT); }
void hlct::Game::update(){ ofRectangle stageRect(stagePos.get(), stageWidth.get(), stageHeight.get()); background.setStageRectangle(stageRect); if (useOsc){ while (receiver.hasWaitingMessages()){ ofxOscMessage m; receiver.getNextMessage(m); // Set game duration if (m.getAddress() == HLCT_OSC_ENDPOINT_DURATION){ endTime = m.getArgAsFloat(0); } if (m.getAddress() == HLCT_OSC_ENDPOINT_USER){ bUserExists = m.getArgAsBool(0); } if (m.getAddress() == HLCT_OSC_ENDPOINT_POSING && bUserExists){ bUserPosing = m.getArgAsBool(0); } if (m.getAddress() == HLCT_OSC_ENDPOINT_POSITION){ float x = ofMap(m.getArgAsFloat(0), 0, 1, stageRect.getX(), stageRect.getX() + stageRect.getWidth()); hero.moveTo(x); } if (m.getAddress() == HLCT_OSC_ENDPOINT_NEW){ bStart = m.getArgAsBool(0); } if (m.getAddress() == HLCT_OSC_ENDPOINT_PAUSE){ bPaused = m.getArgAsBool(0); } } } switch (state){ case GAME_STATE_TITLE: { screens["title"].update(stageRect); break; } case GAME_STATE_POSING: { screens["posing"].update(stageRect); gameStartTimer.update(HLCT_ANIM_UPDATE_CYCLE); resizeLoadingBar(stageRect); break; } case GAME_STATE_GAME: { if (!bPaused){ gameTimer.update(HLCT_ANIM_UPDATE_CYCLE); } currentTime.set(gameTimer.getCurrentValue()); currentTimeStr = ofToString(currentTime); bool gameEnded = gameTimer.getCurrentValue() >= endTime || score == HLCT_MAX_CATCH || livesLeft == 0; if (!bDebug){ if (gameEnded) { endGame(); } } if (!gameEnded || bDebug) { hero.update(stageRect, scaleHero); if (helmets.size() == 0) { addRandomHelmet(); } updateHelmets(stageRect); if (!bDebug) { score = winHelmets.size(); } } break; } case GAME_STATE_END_LOOSE: case GAME_STATE_END_WIN: { resizeLoadingBar(stageRect); if (state == GAME_STATE_END_LOOSE){ screens["loose"].update(stageRect); } else if (state == GAME_STATE_END_WIN){ screens["win"].update(stageRect); } gameEndTimer.update(HLCT_ANIM_UPDATE_CYCLE); if (!gameEndTimer.isAnimating()){ state = GAME_STATE_TITLE; bUserExists = bUserExists; bUserPosing = bUserPosing; } } break; default: break; } }