void GameScreen::restartLevel() { delete gameWonLbl; delete saveAndQuitBtn; delete restartBtn; delete mainMenuBtn; delete nextLvlBtn; delete ball; delete paddle; spacePressed = false; createBlocks(); createPaddle(); createBall(); }
void GameScreen::restartLevel(int i) { if (i == 1) { } else { delete gameWonLbl; delete saveAndQuitBtn; delete restartBtn; delete mainMenuBtn; delete nextLvlBtn; delete ball; delete paddle; createBlocks(); createPaddle(); createBall(); } }
void GameScreen::decrementLives() { QString t = ui->livesLbl->text(); int livesLeft = t.remove(0, t.length() - 2).toInt(); ui->livesLbl->setText("Lives Left: " + QString::number(--livesLeft)); time->stop(); decScore(500); if(livesLeft == 0) { emit(gameEnded()); } else { createPaddle(); createBall(); spacePressed = false; } }
GameScreen::GameScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::GameScreen) { ui->setupUi(this); tmp = new QMainWindow(this); paddleIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/paddle.png"); ballIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/white_ball.png"); gameOverIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/gameover.png"); gameOverlay = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/background.jpg"); gameWonIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/youwin.jpg"); overlayLbl = new QLabel(this); overlayLbl->setPixmap(*gameOverlay); overlayLbl->setGeometry(0, ui->menuBar->height(), this->width() - (this->width() - ui->rightLine->pos().x()), this->height() - (this->height() - ui->bottomLine->pos().y())); connect(this, SIGNAL(eventTriggered(QString)), this, SLOT(writeEvent(QString))); connect(this, SIGNAL(gameEnded()), this, SLOT(gameOver())); diff = EASY; level = 1; newLevel(level); createActions(); createMenus(); createPaddle(); createBall(); numLives = 3; time = new Timer(this, "time"); connect(time, SIGNAL(timeout()), this, SLOT(decrementTimer())); cheatModeActive = false; spacePressed = false; score = 0; createBlocks(); eventLogFullSizePos = new QPoint(310, 10); eventLogHalfSizePos = new QPoint(310, 200); hideCheatMode(); setLivesText(numLives); setTimeText(timeLeft); setLevelText(level); setScoreText(score); }
bool BreakoutMainScene::init() { if(!Layer::init()) { return false; } score = 0; checkLoseFlag = false; checkMissBall = false; createBound(); createBall(); createPaddle(); createBlock(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(BreakoutMainScene::onTouchBegan , this); listener->onTouchMoved = CC_CALLBACK_2(BreakoutMainScene::onTouchMoved , this); listener->onTouchEnded = CC_CALLBACK_2(BreakoutMainScene::onTouchEnded , this); listener->onTouchCancelled = CC_CALLBACK_2(BreakoutMainScene::onTouchCancelled , this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener , this); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto contactListener = EventListenerPhysicsContact::create(); contactListener->onContactBegin = CC_CALLBACK_1(BreakoutMainScene::onContactBegin , this); dispatcher->addEventListenerWithSceneGraphPriority(contactListener , this); this->schedule(schedule_selector(BreakoutMainScene::updateGame) , 3.0f); return true; }
Paddle::Paddle(sf::Vector2f ps, sf::Color pc, sf::Vector2f pp){ createPaddle(ps, pc, pp); }
/** after we define and instantiate our programs components **/ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { UNREFERENCED(lpszArgument); UNREFERENCED(hPrevInstance); /** here messages to the application are saved **/ MSG messages; /********************************************** * * * create the main window - width, height * * * **********************************************/ HWND hwnd = createMainWin(hThisInstance, 400, 600); /** if main window handle is invalid alert and quit **/ if(!hwnd){ // using wide string for the Unicode crowd MessageBox(NULL, _T(" can not create main window "), _T(" WinBreakoutC++ "), MB_OK); /** this in itself will end the program **/ PostQuitMessage(0); } /** make the window visible on the screen **/ ShowWindow(hwnd, nCmdShow); /** some debugging code **/ /** with the following statements a Debug build target allows us to use printf and cout/printf to display data **/ #ifdef _DEBUG if(!AllocConsole()){ MessageBox(NULL, _T(" can not create console window "), _T(" WinBreakoutC++ "), MB_OK); } freopen("CONOUT$","wb",stdout); // reopen stout handle as console window output #endif /** get our windows rectangle so we can size things **/ GetClientRect(hwnd, &mwinRect); createBall(20, mwinRect.right / 2, mwinRect.bottom / 2); // TODO: this needs to be from top with a re-sizable window createPaddle(mwinRect.bottom - 60, 40, 10); createWall(50); /** run the message loop **/ /** It will run until GetMessage() returns 0. **/ /** argument two is null we are listening to **/ /** the thread not the window. we get all **/ /** messages. this loop is the heart of our **/ /** program pumping messages not blood **/ /** messages is MSG structure that windows passes **/ /** messages to our program defined in top of WinMain **/ while(GetMessage(&messages, NULL, 0, 0)) { /** Translate virtual-key messages into character messages **/ TranslateMessage(&messages); /** Send message to WindowProcedure **/ DispatchMessage(&messages); } /** The program return-value is 0 **/ /** - The value that PostQuitMessage() gave was 0 **/ /** that's all folks **/ return messages.wParam; }