void Player::playerUpdate( KB_BUTTON jump, KB_BUTTON left, KB_BUTTON right, Pulse & pPulse, int collEdg ) { collEdgee = collEdg; //Check for key presses then move player handleInput( jump, left, right, pPulse ); //Handle jumping if needed handleJump(pPulse); //Update the player drawBox if(this->facingLeft) { drawBox = Rect(this->x+2*this->pixelX/RES_Y, this->y, this->x, this->y+2*this->pixelY/RES_Y); } else { drawBox = Rect(this->x, this->y,this->x+2*this->pixelX/RES_Y, this->y+2*this->pixelY/RES_Y); } collBox = Rect(this->x+(collBox.max.x - collBox.min.x) / 5.0f, this->y,this->x+2*this->pixelX/RES_Y - (collBox.max.x - collBox.min.x) / 5.0f, this->y+2*this->pixelY/RES_Y); //Update animation frame this->currentFrame = &this->frame[(int) this->frameCounter]; if(this->y < (-1.0f)) gameOver = true; }
bool Script::executeCommand(int index, MasterTimer* timer, QList<Universe *> universes) { if (index < 0 || index >= m_lines.size()) { qWarning() << "Invalid command index:" << index; return false; } QList <QStringList> tokens = m_lines[index]; if (tokens.isEmpty() == true) return true; // Empty line bool continueLoop = true; QString error; if (tokens[0].size() < 2) { error = QString("Syntax error"); } else if (tokens[0][0] == Script::startFunctionCmd) { error = handleStartFunction(tokens, timer); } else if (tokens[0][0] == Script::stopFunctionCmd) { error = handleStopFunction(tokens); } else if (tokens[0][0] == Script::waitCmd) { // Waiting should break out of the execution loop to prevent skipping // straight to the next command. If there is no error in wait parsing, // we must wait at least one cycle. error = handleWait(tokens); if (error.isEmpty() == true) continueLoop = false; } else if (tokens[0][0] == Script::waitKeyCmd) { // Waiting for a key should break out of the execution loop to prevent // skipping straight to the next command. If there is no error in waitkey // parsing,we must wait at least one cycle. error = handleWaitKey(tokens); if (error.isEmpty() == true) continueLoop = false; } else if (tokens[0][0] == Script::setFixtureCmd) { error = handleSetFixture(tokens, universes); } else if (tokens[0][0] == Script::labelCmd) { error = handleLabel(tokens); } else if (tokens[0][0] == Script::jumpCmd) { // Jumping can cause an infinite non-waiting loop, causing starvation // among other functions. Therefore, the script must relinquish its // time slot after each jump. If there is no error in jumping, the jump // must have happened. error = handleJump(tokens); if (error.isEmpty() == true) continueLoop = false; } else { error = QString("Unknown command: %1").arg(tokens[0][0]); } if (error.isEmpty() == false) qWarning() << QString("Script:%1, line:%2, error:%3").arg(name()).arg(index).arg(error); return continueLoop; }