bool MiniGolf::Update(){ ball.position = ball.position->add(ball.velocity); camManager->setCamTarg(ball.position->getX(), ball.position->getZ(), ball.position->getY()); //golfball.setVelocity(0, 0, 0); ball.aim = arrowAngle; //Find the current tile we are on Tile* currTile = getTile(ball.position, physMan, currLevel - 1); ball.position->setY(physMan->getHeightOfBall(currTile, &ball)); //std::cout <<"Height of ball is " << height <<std::endl; //Check to see if we need to bounce off a wall physMan->checkForCollision(currTile, &ball); //Check to see if we're in the cup if(checkWinCondition()){ playNextLevel(); return false; } //Apply physicsManager forces Vector3* normal = currTile->tileNorm; ball.velocity = physMan->applyForces(ball.velocity, currTile->slope, currTile->downVec); //std::cout << "Down vector is (" << curr.down->getX() << ", " << curr.down->getY() << ", " <<curr.down->getZ() << ")" <<std::endl; modelViews[0] = glm::translate(defaultView, glm::vec3(ball.position->getX(), ball.position->getZ(), ball.position->getY())); modelViews[1] = modelViews[0]; modelViews[1] = glm::rotate(modelViews[1], 0 - 90.0f, glm::vec3(0.0f, 0.0f, 1.0f)); if ((ball.velocity->getLength() < MIN_BALL_SPEED) && currTile->slope == 0) { ballMoving = false; ball.velocity = new Vector3(0.0, 0.0, 0.0); } else ballMoving = true; //draw_string(0.0, 0.0, 0.0, "scojfadofj"); //If the ball is not moving, we need to aim the ball //Calculate the angle between the mouse point and the ball position if(!ballMoving){ isVisible[1] = true; modelViews[1] = modelViews[0]; modelViews[1] = glm::rotate(modelViews[1], arrowAngle - 90.0f, glm::vec3(0.0f, 0.0f, 1.0f)); } else { isVisible[1] = false; } return true; }
void PacanariDamaman::keyboard(unsigned char key, int x, int y){ switch (key) { case 27: exit(0); break; case 97: camManager->moveCam(Camera::dirLeft); break; case 98: modelViews[3] = glm::rotate(modelViews[3], arrowAngle, glm::vec3(0.0f, 0.0f, 1.0f)); break; case 99: if (camManager->getCamSetting() == Camera::FREE){ camManager->setCamSetting(Camera::TOP_DOWN); } else camManager->setCamSetting(Camera::FREE); break; case 100: camManager->moveCam(Camera::dirRight); break; case 101: arrowAngle-=ARROW_TURN_SPEED; break; case 102: playNextLevel(); nextLevelCheat = true; break; case 113: arrowAngle+=ARROW_TURN_SPEED; break; case 114: buildGameLevel(currLevel - 1); break; case 115: camManager->moveCam(Camera::dirBack); break; case 119: camManager->moveCam(Camera::dirForward); break; default: break; } }
Game::Game(QObject *parent) : QObject(parent) { spoony_message = new SpoonyMessage(this); global_timer = new QTimer(this); global_speed = DEFAULT_SPEED; global_timer->start(1000 / global_speed); main_scene = new QGraphicsScene(0, 0, WIDTH, HEIGHT); main_view = new QGraphicsView(main_scene); main_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); main_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); main_view->setRenderHint(QPainter::Antialiasing); main_view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); main_view->setCacheMode(QGraphicsView::CacheBackground); current_level = 0; connect(spoony_message, SIGNAL(finish()), this, SLOT(playNextLevel())); connect(spoony_message, SIGNAL(reset()), this, SLOT(onDie())); qml_engine = new QDeclarativeEngine(this); qml_engine->rootContext()->setContextProperty("Game", this); qml_startscreen = new QDeclarativeComponent(qml_engine, QUrl("qrc:///startscreen.qml")); qml_startscreen->setObjectName("Startup"); sound_handler = new SoundHandler(this); global_lives = LIVES; emit ready(); }