コード例 #1
0
ファイル: PhysicObject.cpp プロジェクト: Glyca/RunicOrbs
void PhysicObject::processMove(const preal f_elapsedTimeSec)
{
	// Si en dessous de nous c'est du vide, alors on applqiue le poids
	if(!this->touchesFloor()) {
		applyWeightForce();
	}
	else // Sinon on annule la vitesse verticale (collision)
	{
		v_velocity.y = 0.0;
	}

	destuck();

	applyFluidFrictionForce();

	// Calcul de l'accélération en fonction de la somme des forces appliquées que l'on supprime ensuite
	// a = F / m
	v_acceleration = v_forces / f_mass;

	// Les forces sont appliquées, donc on les supprime
	v_forces.null();

	// v += a * dt
	v_velocity += v_acceleration * f_elapsedTimeSec;

	v_totalVelocity = velocity();
	processCollisions();// corrects v_totalVelocity

	// x += v * dt
	v_position += v_totalVelocity * f_elapsedTimeSec;
}
コード例 #2
0
ファイル: sseSceneGraph.cpp プロジェクト: onepremise/Scale
void sseSceneGraph::renderLevels(sseObject *pObject)
{
	sseLog *log=sseLog::Instance();
	sseObject** nodes=pObject->getNodes();

	for (int i=0; i<pObject->getNumNodes(); i++) {
		sseObject *child=nodes[i];
		if (child->isEnabled() && child->isLocalNode()) {
			((sseConcurrentContextGuard*)child)->Update(m_paused);

			if (child->isCollisionEnabled()) {
				processCollisions(child);
			}

			glPushMatrix();

			::glMultMatrixd((*child->getLocalTransform()).GetOGLMatrix());

			((sseConcurrentContextGuard*)child)->Render(m_pRenderer);

			if (child->getNumNodes()>0)
  				renderLevels(child);

			glPopMatrix();
		}
	}
}
コード例 #3
0
void PlayerUpdater::updateEntity(const da::EntityPtr &entity) {
    Player        &player = entity->getAttribute<Player>();
    Collider      &coll   = entity->getAttribute<Collider>();
    Velocities    &vels   = entity->getAttribute<Velocities>();
    da::Transform &xform  = entity->getAttribute<da::Transform>();
    
    // Keyboard movement
    int horz = mInput.isButtonHeld(Input::Right) -
               mInput.isButtonHeld(Input::Left);
    int vert = mInput.isButtonHeld(Input::Down) -
               mInput.isButtonHeld(Input::Up);
    
    // Mouse movement
    
    // Normalize cursor position
    sf::Vector2f distance;
    distance = (mInput.getAxes() * 2.f) - sf::Vector2f(1.f, 1.f);
    
    // Move view based on cursor
    mView.setCenter(xform.getPosition() + (distance * player.viewDistance));
    
    vels.speed.x = horz * player.walkSpeed;
    vels.speed.y = vert * player.walkSpeed;
    
    // The game states are simply a collection of Behavior settings.  For example, PLAYER_CONTROL state
    // allows the PlayerUpdater to handle player movement and camera control.  SCENE_RUN state gives that
    // control to the Director.
    // Lua Script -> Game -> Behaviors.  Where does Director fit into all this?  Merged into Game?
    
    //~ std::cout << "Cursor position: " << mInput.getCursorPosition().x << ", " << mInput.getCursorPosition().y << std::endl
              //~ << "Distance From Center: " << distance.x << ", " << distance.y << std::endl;
    
    processCollisions(entity);
}
コード例 #4
0
int main(int argc, char** argv) {
    // setup basic vehicles
    initBaseVehicles();
    
    /// OpenMP may or may not immediately start execution of a task... the
    /// runtime is free to decide. Using the section construct is better.
    
    // accept connection
    #pragma omp parallel num_threads(2)
    #pragma omp sections
{
    #pragma omp section
    {
    printf("net started\n");
    startNetwork(8866);
    }

    #pragma omp section
    {
    printf("not net running\n");
    // run simulation
    while(1) {
        // handle the move phase
        updateSettings();
        updateLocations();
        processCollisions();
    }
    }
}
}
コード例 #5
0
/////////////////////////////////////////////////////////////////////
// processCollisions() - processes collision responces for given
//                       entity name or ALL
/////////////////////////////////////////////////////////////////////
void MyEntityManager::processCollisions(String name)
{
	//printf("Processing Collision for %s\n", name.c_str());
	if (name.compare("ALL") == 0)
	{
		//printf("doing all\n");
		for (uint i = 0; i < m_nEntityCount; i++)
		{
			processCollisions(i);
		}
		return;
	}
	int idx = this->GetIndex(name);
	if (idx < 0)
		return;
	processCollisions(idx);
}
コード例 #6
0
void Objects::frameObjects( ) 
{
	Input::handleTankControlKeys( );

	processCollisions( );

	frameTank( );
	frameWeapon( );
	frameMonsters( );
	framePackets( );
}
コード例 #7
0
//-----------------------------------------------------------------------------
//
// VActorPhysicsController::integrateTickUpdate( pDelta, pMove );
//
// ...
//
//-----------------------------------------------------------------------------
void VActorPhysicsController::integrateTickUpdate( const F32 &pDelta, const Move *pMove )
{
    // Update Collision Set.
    updateWorkingCollisionSet();
    // Ground Ground Status.
    updateGroundStatus();

    // Execute Physics Table.
    VActorPhysicsState *physState = dynamic_cast<VActorPhysicsState*>( mPhysicsStateTable.execute() );
    // Assert.
    AssertFatal( physState, "VActorPhysicsController::update() - Invalid Physics State in the Table." );

    // Process the State.
    physState->processTick( mObject, pDelta, pMove );

    // Process Collisions.
    processCollisions();
}
コード例 #8
0
int main(int argc, char** argv) {
    // setup basic vehicles
    initBaseVehicles();
    
    tbb::parallel_invoke( 
        [] {
            // accept connection
            startNetwork(8866);
        }, 
        [] {
            // run simulation
            while(1) {
                // handle the move phase
                updateSettings();
                updateLocations();
                processCollisions();
            }
        } 
    );
}
コード例 #9
0
ファイル: sseSceneGraph.cpp プロジェクト: onepremise/Scale
void sseSceneGraph::renderScene()
{
	sseLog *log=sseLog::Instance();
	m_pCamera->Update();

	::glLoadMatrixd(m_world.GetOGLMatrix());
	::glScaled(m_dScale,m_dScale,m_dScale);

	dMatrix copy;
	GLdouble modelMatrix[16]={0};

	::glMultMatrixd(m_pCamera->GetViewTransformation()->GetOGLMatrix());

	deque<sseObject*>::iterator itObject;
	for(itObject=m_renderingQueue.begin(); itObject!=m_renderingQueue.end(); itObject++)
	{
		sseObject* pObject=(*itObject);
		if (pObject->isEnabled())
		{
			if (pObject->isCollisionEnabled() && !m_paused)
				processCollisions(pObject);

			glPushMatrix();

			((sseConcurrentContextGuard*)pObject)->Update(m_paused);

			::glMultMatrixd(pObject->getLocalTransform()->GetOGLMatrix());

			((sseConcurrentContextGuard*)pObject)->Render(m_pRenderer);

			renderLevels(pObject);

			glPopMatrix();
		}
	}

	//glPushMatrix();
	//m_pDisplay->RenderText();
	//glPopMatrix();
}
コード例 #10
0
ファイル: animator.c プロジェクト: Subatomicpig/RandomStuff
/*
    Purpose: animate and run the game with the clock
    Input  : a char length pointer to the frame buffer and a long length pointer to the frame buffer
    Returns: nothing, but constantly runs the game and its functions
    Assume : nothing
*/
void animate_main(char *base,long *iBase)
{
    long *back,*temp;

    int musicCounter = 0;
    int enMisCount = 0;
    int plMisCount = 0;
    int x,y = 0;
    long clock;
    long newClock;
    int mouseClicked = 0;
    unsigned short mouseX,mouseY;
    int i= 0,j = 0,k = 0,l = 0;
    int randX,randY,randX2;
    int fire = 0;
    int s = 0;
    int done = 0;
	int render = 0;

    struct missile friendlyMis[NUM_MISSILES];
    struct missile enemyMis[NUM_MISSILES];
    struct explosion explosions[NUM_EXPLOSIONS];
    struct missile_Silo silo;
    struct city city1;
    struct city city2;
    struct city city3;
    struct city city4;
    struct city city5;
    struct city city6;
    int *music = get_music();
    
	
	Vector original_Vector;
	/*start the music*/
	stop_sound();
    start_music();
    
	/*init ther model*/
	initialize_model(&city1,&city2,&city3,&city4,&city5,&city6,&silo,friendlyMis,enemyMis,explosions);

	/*create the backbuffer*/
    back = (long *)(buffer + (256 -((long)&buffer)%256));
    
	init_VBL_ISR(original_Vector);
	
	
	
	while(done == 0)
    {
        /*random values for enemy missiles*/

        randX = rand() % BORDER_RIGHT + 16;
        randX2 = rand() % BORDER_RIGHT + 16;
        randY = rand() % GROUND_LEVEL - 200;

        /* needs to fire a player missile at the mouse click coordinates */
        if (mouseClicked == TRUE)
        {                     /* process on input */
            if (k > NUM_MISSILES-1)
            {
                k = 0;
            }
            if (friendlyMis[k].destroyed == TRUE)
            {
                friendlyMis[k].destroyed = FALSE;
                friendlyMis[k].currentY = GROUND_LEVEL-20;
                friendly_Missile_Fired(mouseX,mouseY, &friendlyMis[k],MISSILE_SILO_FIRING_POINT);
                missile_fired_sound();
                k++;
            }
        }

        clock = clockGet();

        if (clock != newClock)
        {                      /* process on clock change */
            fire++;
            if(fire == MISSILE_FIRED_TIME)
            {
                enemyMis[j].destroyed = FALSE;
                enemy_Missile_Fired(randX, GROUND_LEVEL, &enemyMis[j],randX2);
                j++;
                if(fire == MISSILE_FIRED_TIME)
                {
                    fire = 0;
                }
                if (j == NUM_MISSILES-1)
                {
                    j = 0;
                }
            }

            mouseClicked = get_mouse_pos(&mouseX,&mouseY);

			
			if(render == 1)
			{
				render_main(back, city1, city2, city3, city4, city5, city6, silo, enemyMis,friendlyMis, explosions,mouseX,mouseY,render);
			}
			
			
			
			
			
			/* T */
            temp = iBase;
            iBase = back;
            back = temp;

            /* wait for sync and then set the screen to the current buffer */
            set_video_base_wrap((char *)iBase);

            /* process missiles
               might need to change to be able to handle more */
            for (i = 0; i < NUM_MISSILES; i++)
            {
                if (enemyMis[i].destroyed == FALSE && explosions[i].exists == FALSE)
                {
                    processEnemyMissiles(&enemyMis[i],&explosions[i],clock,ENEMY_SPEED);
                }
                if (friendlyMis[i].destroyed == FALSE && explosions[i+NUM_MISSILES].exists == FALSE)
                {
                    processEnemyMissiles(&friendlyMis[i],&explosions[i+NUM_MISSILES],clock,FRIENDLY_SPEED);
                }
            }
            /* process explosions
               might need to change to be able to handle more */
            for (i = 0; i < NUM_EXPLOSIONS; i++)
            {
                if (explosions[i].exists == TRUE)
                {
                    processExplosions(&explosions[i]);
                }
            }
            /* process missile -> explosion collisions */
            for (i = NUM_MISSILES; i < NUM_EXPLOSIONS; i++)
            {
                if (explosions[i].exists == TRUE)
                {
                    processCollisions(friendlyMis,enemyMis,explosions[i]);
                }
            }
            /* process explosion -> city explosions */
            for (i = 0; i < NUM_MISSILES; i++)
            {
                if (explosions[i].hit_city != FALSE)
                {
                    city_collision(explosions[i].hit_city,&city1,&city2,&city3,&city4,&city5,&city6);
                }
            }
            if (musicCounter < SONG_LENGTH){
                if (fire % 4 == 0)
                {
                    play_music(music[musicCounter]);
                    musicCounter++;
                }
            }
            else
            {
                musicCounter = 0;
            }
        }
        newClock = clockGet();
        done = game_over(city1,city2,city3,city4,city5,city6);
    }
    stop_sound();
}