예제 #1
0
 void Physics::createEntities()
 {
     createWorkspace(TOP_LEFT.x,BOTTOM_RIGHT.x,
                     BOTTOM_RIGHT.y,TOP_LEFT.y,.5);
     createBall(b2Vec2(-5,5),2,15.f,0.5f,1,0.2);
     createBall(b2Vec2(0,-5),2,35.f,0.5f,1,0.2);
     createBall(b2Vec2(5,5),2,50.f,0.8f,2,0.2);
     createSolidWall(b2Vec2(10,-2),1.2,b2Vec2(5,2),false);
     createSolidWall(b2Vec2(-10,-2),-1.2,b2Vec2(5,2),false);
     createEffector(1);
 }
예제 #2
0
void Wallbreaker::setStatus(Status status)
{
	m_status = status;
	switch (status)
	{
	case READY:
		// Remove power-ups applied to the paddle
		m_paddle.reset();

		// Clear all and spawn a new ball
		clearEntities();
		createBall();
		m_info_text.setString("Ready?");
		Game::getInstance().getWindow().setMouseCursorVisible(false);
		break;

	case GAME_OVER:
		m_info_text.setString(m_player_lives > 0 ? "Game complete!" : "Game Over");
		Game::getInstance().getWindow().setMouseCursorVisible(true);
		break;

	case PAUSED:
		m_info_text.setString("Paused");
		Game::getInstance().getWindow().setMouseCursorVisible(true);
		break;

	case PLAYING:
		Game::getInstance().getWindow().setMouseCursorVisible(false);
		break;
	}
	// Center text
	m_info_text.setScale(2, 2);
	m_info_text.setPosition(X_OFFSET + LevelManager::BORDER_SIZE + (m_width - m_info_text.getSize().x) / 2, 80);
}
예제 #3
0
// on "init" you need to initialize your instance
bool GameScene_02::init()
{
    if ( !LayerColor::initWithColor(Color4B(255,255,255,255)) )
    {
        return false;
    }
    visibleSize = Director::getInstance()->getVisibleSize();

    auto backGround = Sprite::create("Game/Level_1/background.png");
    addChild(backGround,0);
    backGround->setAnchorPoint(Vec2::ZERO);
    Timers = Label::create();
    addChild(Timers);
    Timers->setPosition(100, visibleSize.height - 40);
    Timers->setColor(Color3B::ORANGE);
    Timers->setSystemFontSize(48);
    createMenu();
    createSlider();
    createBall();
    creatBricks();
    this->scheduleUpdate();
    slider->startTimer();

    return true;
}
예제 #4
0
bool BallApp::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) {
  if(id == OIS::MB_Left) { 
   
    createBall(-500, -300, 500,
              rand() % 120 - 60, 500, rand() % 80 - 40);

  } else if (id == OIS::MB_Right) {
    static int gravity = 1;
    btDiscreteDynamicsWorld *world = mPhysics->getDynamicsWorld();
    if (gravity == 0) {
      world->setGravity(btVector3(0,0,0));
      mDetailsPanel->setParamValue(3, "Off");
    } else if (gravity == 1) {
      world->setGravity(btVector3(0,980,0));
      mDetailsPanel->setParamValue(3, "Upward");
    } else if (gravity == 2) {
      world->setGravity(btVector3(0,-980,0));
      mDetailsPanel->setParamValue(3, "Downward");
    }

    gravity = (gravity+1)%3;
  }
  
  return BaseApplication::mouseReleased(arg, id);
}
예제 #5
0
TurnAndBank::TurnAndBank(ExtPlanePanel *panel, ExtPlaneConnection *conn) :
    PanelItem(panel, PanelItemTypeGauge, PanelItemShapeCircular),
    _client(this, typeName(), conn)
{
    _rollValue = 10;
    _slipValue = -20;
    
    //    _rollRef = QString("sim/cockpit2/gauges/indicators/turn_rate_roll_deg_pilot");
    _rollRef = QString("sim/cockpit2/gauges/indicators/roll_electric_deg_pilot");   // Matches XP's C172
    //_rollRef = QString("sim/cockpit2/gauges/indicators/turn_rate_heading_deg_pilot");
    _slipRef = QString("sim/cockpit2/gauges/indicators/slip_deg");
    
    //    _card = QPixmap(QString("junk"));//../images/engine_FUELP.png"));

    createCard();
    //createGlass();
    createFrame();
    createBall();
    //_bezel = QPixmap::fromImage(QImage(QString("../images/bezel_square_.png")), Qt::AutoColor);
    
    connect(&_client, SIGNAL(refChanged(QString,double)), this, SLOT(refChanged(QString,double)));
    _client.subscribeDataRef(_slipRef,0.02);
    _client.subscribeDataRef(_rollRef,0.1);
    
}
예제 #6
0
std::unique_ptr<Court> AvatarsFactory::createCourt() const
{
    auto playerMap = createPlayerMap();
    auto ball = createBall();
    auto courtSettings = mSettingsParser->retrieveCourtSettings();

    return std::unique_ptr<Court>(new Court(courtSettings, std::move(playerMap), std::move(ball)));
}
예제 #7
0
void PivotJointScene::onEnter()
{
    BaseDemo::onEnter();
    auto visibleSize = VisibleRect::getVisibleRect().size;
    
    float pierPosY = 100.0f;
    Sprite* bridgePierL = createBox(Point(visibleSize.width/2 - 400, pierPosY), Size(40, 40));
    Sprite* bridgePierR = createBox(Point(visibleSize.width/2 + 400, pierPosY), Size(40, 40));
    bridgePierL->setRotation(0);
    bridgePierR->setRotation(0);
    bridgePierL->getPhysicsBody()->setDynamic(false);
    bridgePierR->getPhysicsBody()->setDynamic(false);
    bridgePierL->getPhysicsBody()->setTag(0);
    bridgePierR->getPhysicsBody()->setTag(0);
    this->addChild(bridgePierL);
    this->addChild(bridgePierR);
    
    float ballRadius = 40.0f;
    Sprite* fallingBall = createBall(Point(visibleSize.width/2, visibleSize.height-ballRadius), ballRadius);
    this->addChild(fallingBall);
    
    Vector<Sprite*> bamboos;
    for (int i = 0; i < BAMBOO_SEGMENTS_NUM; i++)
    {
        auto box = createBox(Point(bridgePierL->getPositionX() + BAMBOO_SEGMENT_SIZE.width * i, pierPosY), BAMBOO_SEGMENT_SIZE);
        box->setRotation(0);
        this->addChild(box);
        
        bamboos.pushBack(box);
    }
    
    PhysicsJointPin* pinJointL = PhysicsJointPin::construct(bridgePierL->getPhysicsBody(), bamboos.front()->getPhysicsBody(),bridgePierL->getPosition());
    PhysicsJointPin* pinJointR = PhysicsJointPin::construct(bridgePierR->getPhysicsBody(), bamboos.back()->getPhysicsBody(),bridgePierR->getPosition());
    pinJointL->setCollisionEnable(false);
    pinJointR->setCollisionEnable(false);
    _world->addJoint(pinJointL);
    _world->addJoint(pinJointR);

    
    for (int i = 0; i < BAMBOO_SEGMENTS_NUM - 1; i++)
    {
        auto body1 = bamboos.at(i)->getPhysicsBody();
        auto body2 = bamboos.at(i+1)->getPhysicsBody();
        
        PhysicsJointPin* pivotJointUp = PhysicsJointPin::construct(body1, body2, bamboos.at(i+1)->getPosition() + Point(-BAMBOO_SEGMENT_SIZE.width/2, BAMBOO_SEGMENT_SIZE.height/2));
        
        PhysicsJointPin* pivotJointDown = PhysicsJointPin::construct(body1, body2, bamboos.at(i+1)->getPosition() + Point(-BAMBOO_SEGMENT_SIZE.width/2, -BAMBOO_SEGMENT_SIZE.height/2));
        
        PhysicsJointRotarySpring* springJoint = PhysicsJointRotarySpring::construct(body1, body2, 2000, 0.8f);
        
        pivotJointUp->setCollisionEnable(false);
        pivotJointDown->setCollisionEnable(false);
        springJoint->setCollisionEnable(false);
        _world->addJoint(pivotJointUp);
        _world->addJoint(pivotJointDown);
        _world->addJoint(springJoint);
    }
}
예제 #8
0
void BallApp::createBall(int x, int y, int z, int vx, int vy, int vz) {
  static int ballID;
  
  std::stringstream ss;
  ss << "myBall" << ballID;
  std::string ent = ss.str();
  ss << "node";
  ballID++;
  
  createBall(ent, ss.str(), x, y, z, vx, vy, vz);
}
예제 #9
0
void PlatformDemoState::addItems()
{
    std::function<void(const sf::Vector2f&)> createBox = 
        [this](const sf::Vector2f& position)
    {
        auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic);
        xy::Physics::CollisionRectangleShape cs({ 100.f, 100.f }, { -50.f, -50.f });
        cs.setDensity(11.f);
        cs.setFriction(0.7f);
        body->addCollisionShape(cs);

        auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus);
        model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Demo));

        auto ent = xy::Entity::create(m_messageBus);
        ent->setPosition(position);
        ent->addComponent(body);
        ent->addComponent(model);

        m_scene.addEntity(ent, xy::Scene::BackFront);
    };


    std::function<void(const sf::Vector2f&)> createBall = 
        [this](const sf::Vector2f& position)
    {
        auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic);
        xy::Physics::CollisionCircleShape cs(34.f);
        cs.setDensity(4.f);
        cs.setFriction(0.2f);
        cs.setRestitution(0.8f);
        body->addCollisionShape(cs);

        auto model = m_meshRenderer.createModel(MeshID::Sphere, m_messageBus);
        model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::SphereTest));

        auto ent = xy::Entity::create(m_messageBus);
        ent->setPosition(position);
        ent->addComponent(body);
        ent->addComponent(model);

        m_scene.addEntity(ent, xy::Scene::BackFront);
    };

    for (auto i = 0u; i < 5u; ++i)
    {
        createBox({ xy::Util::Random::value(20.f, 2500.f), 20.f });
        createBall({ xy::Util::Random::value(20.f, 2500.f), 20.f });
    }

}
예제 #10
0
bool GameLayer::init() {
  if (!BaseLayer::init()) {
    return false;
  }

  createWall();
  createBall();
  createPaddles();
  createGoals();
  createScores();

  start();

  return true;
}
예제 #11
0
void GameScreen::restartLevel()
{
    delete gameWonLbl;
    delete saveAndQuitBtn;
    delete restartBtn;
    delete mainMenuBtn;
    delete nextLvlBtn;
    delete ball;
    delete paddle;

    spacePressed = false;

    createBlocks();
    createPaddle();
    createBall();
}
예제 #12
0
///*
void PointQueryScene::onTouchEnded(Touch *touch, Event *event)
{
    auto location = touch->getLocation();
    auto p = CCRANDOM_0_1();
    if (p < 1.0f / 3.0f)
    {
        addChild(createBall(location, CCRANDOM_0_1() * 10 + 30));
    }
    else if (p < 2.0f / 3.0f)
    {
        addChild(createBox(location, Size(CCRANDOM_0_1() * 20 + 30, CCRANDOM_0_1() * 20 + 30)));
    }
    else
    {
        addChild(createTriangle(location, Size(CCRANDOM_0_1() * 20 + 30, CCRANDOM_0_1() * 20 + 30)));
    }
}
예제 #13
0
/* Creates a number of balls and starts the game loop
 *
*/
int main() {
  // Set up objects
  createBall(.5, .5, -.00045, 0, .1);
  createBall(-.25, .5, .00045, 0, .2);
  createBall(-.75, .45, .0001, .0002, .1);
  createBall(0, 0, .0007, -.00005, .15);
  createBall(.6, -.45, .0003, -.0002, .05);
  createBall(-.35, -.45, .0003, -.0002, .05);

  // Run loop
  ODLGameLoop_initOpenGL();
}
예제 #14
0
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();
    }
}
Graph fillVertices(Graph g){	//reads from input and fills in the graph
	FILE *fp;
	int i,r,nodes;
	char c;
	Ball ball;
	fp=fopen("nodes.txt","r");
	fscanf(fp,"%d\n",&nodes);
	listsize=nodes;
	g=(Graph)malloc(nodes*sizeof(Vertex));
	for(i=0;i<nodes;i++){
		fscanf(fp,"%c %d\n",&c,&r);
		ball=createBall(c,r,i);	//creates ball using input data
		g[i].ball=ball;	//fills other details fort he vertices
		g[i].head=NULL;
	}
	fclose(fp);
	return g;
}
예제 #16
0
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;
    }
}
Graph fillVertices(Graph g){
	FILE *fp;
	int i,r,nodes;
	char c;
	Ball ball;
	fp=fopen("nodes.txt","r");
	fscanf(fp,"%d\n",&nodes);
	listsize=nodes;
	g=(Graph)malloc(nodes*sizeof(Vertex));
	for(i=0;i<nodes;i++){
		fscanf(fp,"%c %d\n",&c,&r);
		ball=createBall(c,r,i);
		g[i].visit=0;
		g[i].ball=ball;
		g[i].head=NULL;
	}
	fclose(fp);
	return g;
}
예제 #18
0
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);
}
예제 #19
0
파일: Scene.cpp 프로젝트: novichiv/osgode
/* ....................................................................... */
osgODE::World*
createWorld(void)
{
    PS_DBG("%s", "createWorld()") ;


    osgODE::Space*  space = new osgODE::Space() ;
    PS_ASSERT1(space) ;




    space->setERP(0.2) ;
    space->setCFM(1.0e-5) ;



    osgODE::NearCallback*   near_callback = createNearCallback() ;
    PS_ASSERT1(near_callback) ;

    space->setNearCallback( near_callback ) ;



    osgODE::ODEObject*  ball = createBall() ;
    PS_ASSERT1(ball) ;

    osgODE::ODEObject*  ground = createGround() ;
    PS_ASSERT1(ground) ;


    space->addObject(ball) ;
    space->addObject(ground) ;



    return space ;
}
예제 #20
0
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;
}
예제 #21
0
/**   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;
}
예제 #22
0
void Wallbreaker::onEvent(const sf::Event& event)
{
	switch (m_status)
	{
		case PLAYING:
			switch (event.type)
			{
				case sf::Event::KeyPressed:
					switch (event.key.code)
					{
						case sf::Keyboard::F2:
							Game::getInstance().takeScreenshot();
							break;
						case sf::Keyboard::Escape:
							setStatus(PAUSED);
							break;
						case sf::Keyboard::Space:
							if (m_paddle.isSticky())
								applyOnEachBall(&Ball::unstick);
							else if (m_paddle.hasLaser())
								addEntity(m_paddle.shoot());
							break;
#ifdef WALLBREAKER_DEBUG
						case sf::Keyboard::R: // Reload level
							m_remaining_bricks = m_level.reload();
							m_hud.setBrickCount(m_remaining_bricks);
							break;
						case sf::Keyboard::N: // Go to next level
							loadNextLevel();
							break;
						case sf::Keyboard::G: // Simulate LARGE_PADDLE
							m_paddle.grow();
							break;
						case sf::Keyboard::S: // Simulate SMALL_PADDLE
							m_paddle.shrink();
							break;
						case sf::Keyboard::Y: // Simulate STICKY_PADDLE
							m_paddle.activeSticky();
							break;
						case sf::Keyboard::L: // Simulate LASER_PADDLE
							m_paddle.activeLaser();
							break;
						case sf::Keyboard::T: // Simulate TRIPLE_BALL
							createBall();
							createBall();
							break;
						case sf::Keyboard::P: // Simulate POWER_BALL
							applyOnEachBall(&Ball::enablePowerBall);
							break;
						case sf::Keyboard::E: // Simulate SPEED_RESET
							applyOnEachBall(&Ball::resetSpeed);
							break;
#endif
						default:
							break;
					}
					break;

				case sf::Event::MouseButtonPressed:
					if (m_paddle.isSticky())
						applyOnEachBall(&Ball::unstick);
					else if (m_paddle.hasLaser())
						addEntity(m_paddle.shoot());
					break;

				case sf::Event::LostFocus:
					setStatus(PAUSED);
					break;

				default:
					break;
			}
			break;

		case PAUSED:
			switch (m_pause_menu.onEvent(event))
			{
				case 1: // Resume
					setStatus(PLAYING);
					break;
				case 2: // Go to options menu
					Game::getInstance().setCurrentScreen("OptionsMenu");
					break;
				case 3: // Clear game and back to main menu
					resetGame();
					Game::getInstance().restorePreviousScreen();
					break;
				default:
					// Resume
					if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
						setStatus(PLAYING);
					break;
			}
			break;

		case READY:
			if (event.type == sf::Event::MouseButtonPressed)
				setStatus(PLAYING);
			break;

		case GAME_OVER:
			switch (m_game_over_menu.onEvent(event))
			{
				case 1: // Continue (reload current level)
					resetGame(m_level.getCurrentLevel());
					break;
				case 2: // Clear game and back to main menu
					resetGame();
					Game::getInstance().restorePreviousScreen();
					break;
			}
			break;
	}
}
    vd::Time init(const vd::Time&)
    {
        createWall(0, 0, 0, 40);
        createWall(0, 40, 100, 40);
        createWall(100, 0, 100, 40);
        createWall(0, 0, 100, 0);
        createBall(1, 1,-1.0,-1.0, 0.25); //runtime error (corner problem)
        createBall(30, 30, 0, 0.5, 1);
        createBall(5, 5, -0.5, -0.5, 0.5);
        createBall(66,35, 0.5, -0.5, 1);
        createBall(20, 1, 0.5, 0.5, 1);
        createBall(3, 3, 0.5, 0.5, 1);
        createBall(24, 24, 0, 0.5, 1);
        createBall(30, 5, -1, -1, 0.5);
        createBall(10, 2, 0.5, -0.5, 1);
        createBall(15, 9, 0.5, 1, 1);
        createBall(90, 24, 0, 0.5, 2);
        createBall(38, 5, -0.5, -0.5, 0.5);
        createBall(75, 2, 0.5, -0.5, 2);
        createBall(60, 9, 0.5, 0.5, 3);

        //~ createBall(10, 10, -1, -1, sqrt(2)/2.0);
        //~ createBall(8, 10, 1, -1, sqrt(2)/2.0);
        //~ createBall(9, 9, 0, 1, sqrt(2)/2.0);
        return vd::infinity;
    }
예제 #24
0
//-------------------------------------------------------------------------------------
void BallApp::createScene(void)
{
  mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.05f, 0));
  mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

  // Boxed Environment
  Ogre::Plane planes[] = {
    Ogre::Plane(Ogre::Vector3::UNIT_X, 0),
    Ogre::Plane(Ogre::Vector3::NEGATIVE_UNIT_X, 0),
    Ogre::Plane(Ogre::Vector3::UNIT_Y, 0),
    Ogre::Plane(Ogre::Vector3::NEGATIVE_UNIT_Y, 0),
    Ogre::Plane(Ogre::Vector3::UNIT_Z, 0),
    Ogre::Plane(Ogre::Vector3::NEGATIVE_UNIT_Z, 0)
  };

  std::string pNames[] = {
    "leftWall", "rightWall", "ground", "ceiling", "farWall", "nearWall"
  };

  Ogre::Vector3 up[] = {
    Ogre::Vector3::UNIT_Y, Ogre::Vector3::UNIT_Y, 
    Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_Z, 
    Ogre::Vector3::UNIT_X, Ogre::Vector3::UNIT_X
  };
  
  int l,w,h;
  l = w = h = 3000;
  
  btVector3 pos[] = {
    btVector3(-w/2,0,0),
    btVector3(w/2,0,0),
    btVector3(0,-h/2,0),
    btVector3(0,h/2,0),
    btVector3(0,0,-l/2),
    btVector3(0,0,l/2),
  };
    

  for (int i = 0; i < 6; i++) {
    Ogre::MeshManager::getSingleton().createPlane(pNames[i],
                                                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                  planes[i], l, w, 20, 20, true, 1, 5, 5, up[i]);

    Ogre::Entity* entity = mSceneMgr->createEntity(pNames[i], pNames[i]);
    if (pNames[i] == "ground") {
      entity->setMaterialName("Examples/Rockwall");
    }
    entity->setCastShadows(false);
    
    Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(pNames[i]);
    node->attachObject(entity);

    mPhysics->addRigidBox(entity, node, 0.0f, 0.95f, btVector3(0,0,0), pos[i]);  
  }
  
  // Lights
  Ogre::Light* pLight = mSceneMgr->createLight( "PointLight" );
  pLight->setType(Ogre::Light::LT_POINT);
  pLight->setPosition(-150,300,250);
  pLight->setDiffuseColour(1,0,0);
  pLight->setSpecularColour(1,0,0);

  Ogre::Light* dLight = mSceneMgr->createLight( "DirectionalLight" );
  dLight->setType(Ogre::Light::LT_DIRECTIONAL);
  dLight->setDiffuseColour(Ogre::ColourValue(.25,.25,0));
  dLight->setSpecularColour(Ogre::ColourValue(.25,.25,0));
  dLight->setDirection(Ogre::Vector3(0,-1,1));

  Ogre::Light* sLight = mSceneMgr->createLight("SpotLight");
  sLight->setType(Ogre::Light::LT_SPOTLIGHT);
  sLight->setDiffuseColour(0, 0, 1);
  sLight->setSpecularColour(0, 0, 1);

  sLight->setDirection(-1, -1, 0);
  sLight->setPosition(Ogre::Vector3(0, 400, 200));

  sLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));

  for (int i = 0; i < 4; i++)
    createBall(-500, -300, 500,
               rand() % 800 - 400, rand() % 800 - 400, rand() % 800 - 400);
}
예제 #25
0
void main() {

	int	ballColumn, ballRow, paddleColumn, paddleRow;

	ball_t myBall, paddle;
	myBall = createBall(1,5,1,-1,1);
	ballColumn = getX(myBall);
	ballRow = getY(myBall);

	paddle = createBall(1,5,0,0,1);
	paddleColumn = getX(paddle);
	paddleRow = getY(paddle);
	// === Initialize system ================================================
	IFG1=0; /* clear interrupt flag1 */
	WDTCTL=WDTPW+WDTHOLD; /* stop WD */

	init();
	initNokia();
	clearDisplay();
	drawBall(ballRow,ballColumn);
	while(1) {

			if (ballColumn == 0){ //Hit the left side
				clearDisplay();
				while(AUX_BUTTON){
					// Keeps the screen cleared until the aux button is pressed
				}

				myBall = createBall(1,5,1,-1,1);
			}

			if (UP_BUTTON == 0) {
				//while(UP_BUTTON == 0);
				paddleRow--;
				paddle.position.y = paddleRow;
			}

			  else if (DOWN_BUTTON == 0) {
				//while(DOWN_BUTTON == 0);
				paddleRow++;
				paddle.position.y = paddleRow;
			}
//			} else if (LEFT_BUTTON == 0) {
//				while(LEFT_BUTTON == 0);
//				if (x>=1) x=x-1;
//				button_press = TRUE;
//			} else if (RIGHT_BUTTON == 0) {
//				while(RIGHT_BUTTON == 0);
//				if (x<=10) x=x+1;
//				button_press = TRUE;
//			} else if (AUX_BUTTON == 0) {
//				while(AUX_BUTTON == 0);
//				color ^= 1; // toggles the block color flag
//			}

			myBall = moveBall(myBall);
			ballColumn = getX(myBall);
			ballRow = getY(myBall);

			paddleColumn = getX(paddle);
			paddleRow = getY(paddle);

			drawBall(ballRow,ballColumn);
			drawBlock(paddleRow,paddleColumn,0);

			Sleep(100);
			clearDisplay();
			Sleep(20);

			if(hitBall(myBall,paddle)){
				myBall.velocity.x *= -1;
			}

		}
}
예제 #26
0
void Physics::createBall(b2Vec2 position, float radius)
{
    createBall(position,radius,stiffness,damping,density,0.2);
}