Example #1
1
File: OneWay.c Project: 0w/moai-dev
static void
update(int ticks)
{
	int steps = 1;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		cpSpaceStep(space, dt);
	}
}
Example #2
0
void world_step(World_t *aWorld, GameTimer_t *aTimer)
{
    if(aWorld->isPaused == true)
        return;

    float dt = 1.0/60.0;
    for(float t = 0.0f; t < aTimer->desiredInterval; t += dt)
        cpSpaceStep(aWorld->cpSpace, dt);
    llist_apply(aWorld->entities, (LinkedListApplier_t)&_callEntityUpdateCallback, aWorld);
}
Example #3
0
int lc_space_Step(lua_State *vm){
    //space, number
    cpSpace *space = (lc_GetSpace(1, vm))->space;
    if (space == NULL){
        printf("chipmunk: Object can't call :Step\n");
        return 0;
    }
    cpSpaceStep(space, lua_tonumber(vm, 2));
    return 0;
}
Example #4
0
void ChipmunkTestLayer::update(float delta)
{
    // Should use a fixed size step based on the animation interval.
    int steps = 2;
    float dt = CCDirector::sharedDirector()->getAnimationInterval()/(float)steps;

    for(int i=0; i<steps; i++){
        cpSpaceStep(m_pSpace, dt);
    }
}
static void
update(cpSpace *space, double dt)
{
	cpFloat coef = (2.0f + ChipmunkDemoKeyboard.y)/3.0f;
	cpFloat rate = ChipmunkDemoKeyboard.x*10.0f*coef;
	cpSimpleMotorSetRate(motor, rate);
	cpConstraintSetMaxForce(motor, (rate) ? 100000.0f : 0.0f);
	
	cpSpaceStep(space, dt);
}
Example #6
0
/* step the space with fixed time step */
static void _step()
{
    static Scalar remain = 0.0;

    remain += timing_dt;
    while (remain >= period)
    {
        cpSpaceStep(space, period);
        remain -= period;
    }
}
Example #7
0
static void update(int ticks)
{
	int steps = 1;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
//i51AdeOsLog ( i51_LOG_DC , "i=%d",i ) ; 
		cpSpaceStep(mmSABSpace, dt);
//		cpSpaceEachBody(space, &eachBody, NULL);
	}
}
Example #8
0
void Level::draw()
{
    cpSpaceStep(m_pSpace, 1.0/60.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glTranslatef(-(m_pPlayer->getX()), -(m_pPlayer->getY()), 0);
    for (std::vector<LevelObject*>::iterator it = m_objList.begin(); it != m_objList.end(); ++it)
    {
        (*it)->draw();
    }
    m_pPlayer->draw();
}
Example #9
0
void KRSimulator2D::step(double time)
{
    mCollisions.clear();

    cpSpaceStep((cpSpace*)mCPSpace, time);
    
    if (mHasChangedAngle) {
        cpBodySetAngle((cpBody*)mCPStaticBody, mNextAngle);
        cpSpaceRehashStatic((cpSpace*)mCPSpace);
        mHasChangedAngle = false;
    }
}
Example #10
0
/*** Step the space through time dt ***/
void Stage::updateEnvironment(double dt){

    cpSpaceStep(envSpace, dt);
    cpVect controlPos = cpBodyGetPosition(userControlObject->body);
    if(firstPerson){
        camera.update(glm::vec3(controlPos.x, controlPos.y + userControlObject->height/4.0f, 0.0f));
        Obj::matView = glm::lookAt(camera.pos, camera.origin, camera.up);
    } else
        Obj::matView = glm::lookAt(glm::vec3(controlPos.x, controlPos.y + 400.0f, 1000.0f), glm::vec3(controlPos.x, controlPos.y, 0.0f), camera.up);
    skybox->position = glm::vec3(controlPos.x, controlPos.y, 0);

}
void GameInst::Update(float a_dt)
{
	if(m_Running)
	{
		//update physworld
		/*m_tLeftPhysUpdate -= a_dt;
		if(m_tLeftPhysUpdate < 0)
		{
			m_tLeftPhysUpdate = PHYS_UPDATE_INTERVAL;
		}*/
		cpSpaceStep(m_pSpace, a_dt);

		//update player
		if(m_pCursor)
		{
			m_pPlayer->SetRedirectDir( VectorNormalise(m_pCursor->GetPosition() - m_pPlayer->GetPosition()) );
		}
		m_pPlayer->Update(a_dt);

		//update emitters (emitters update their individual laser chains)
		for (auto it = Emitters.begin(); it != Emitters.end();++it)
		{
			(*it)->Update(a_dt);
			(*it)->ParseCatchers(catcherPositions);
			
			if ((*it)->GetWon()) {
				if (!m_won) {
					m_winImage->SetPosition(sf::Vector2f(512-(float)m_winImageSource.getSize().x/2,386-(float)m_winImageSource.getSize().y/2));
					m_GUIMgr.AddWidget(m_winImage);
					//Widgets.push_back(winText);
					m_won = true;
				} else {
					m_winTimer += a_dt;
					if (m_winTimer > 3.0f) {
						m_winImage->SetPosition(sf::Vector2f(2048,2048));
						m_GUIMgr.RemoveWidget(m_winImage);
						m_won = false;
						m_winTimer = 0.0f;
						UnloadLevel();
						LoadLevel();
						return;
					}
				}
			}
		}
		
		//update blocks
		for (auto it = m_blocks.begin(); it != m_blocks.end();++it)
		{
			(*it)->Update(a_dt);
		}
	}
}
Example #12
0
//update space with the given time step, one line
void core_update_space ( cpSpace *space, cpFloat time_step ) {
    
    GameInfo *info = (GameInfo *) (space->data);
    if ( info->gameisover == 1 || info->gameisover == 2 ) {
        printf ( "GAME IS OVER\n" );
        core_explode_planet(space);
    }
    
    cpSpaceStep ( space, time_step );
    cpSpaceEachBody ( space, &core_update_body, (void *) NULL );
    cpSpaceEachBody ( space, &core_destroy_out_bodies, (void *) NULL );
}
Example #13
0
File: physics.c Project: dns/CLove
static int l_physics_updateSpace(lua_State* state)
{

    l_tools_checkUserDataPlusErrMsg(state, 1, "You must provide a space");
    l_physics_PhysicsData* physics = (l_physics_PhysicsData*)lua_touserdata(state, 1);

    float dt = luaL_optnumber(state, 2, timer_getDelta());

    cpSpaceStep(physics->physics->space, dt);

	return 0;
}
Example #14
0
void affichage(){
    
       
    cpFloat timeStep = 1.0/60.0;
      SDL_Color white={255,255,255};
          for(cpFloat time = 0; time < 25; time += timeStep){
              SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,0,0,0));
              for(int i=0;i<50;i++){
                  if(lesBoules[i].del==FALSE){
                 cpVect pos = cpBodyGetPos(lesBoules[i].body);
                 cpVect vel = cpBodyGetVel(lesBoules[i].body);
    
                 rectangleColor(ecran,10, 0, 630, 420,SDL_MapRGB(ecran->format,255,255,255));
                 circleRGBA(ecran, pos.y, pos.x, lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a); 
                 filledCircleRGBA(ecran,pos.y,pos.x,lesBoules[i].radius, lesBoules[i].r,lesBoules[i].g,lesBoules[i].b,lesBoules[i].a);
                 
                 //lettre
                 
                 SDL_Surface *lettre= TTF_RenderText_Solid(police, lesBoules[i].lettre, white);
                 SDL_Rect position;
                 position.y=pos.x;
                 position.x=pos.y;
                 lesBoules[i].x=pos.x;
                 lesBoules[i].y=pos.y;
                 SDL_BlitSurface(lettre, NULL, ecran, &position);
                  }
                 
 
               }

              SDL_Surface *pointsTexte=TTF_RenderText_Solid(police,"Score:" , white);
                 SDL_Rect position_pointsTexte;
                 position_pointsTexte.y=435;
                 position_pointsTexte.x=10;
                 SDL_BlitSurface(pointsTexte, NULL, ecran, &position_pointsTexte);
                 char scoreChar[15]={"0"};
                 snprintf(scoreChar, 15, "%d", score);
                 SDL_Surface *points=TTF_RenderText_Solid(police,scoreChar, white);
                 SDL_Rect position_points;
                 position_points.y=435;
                 position_points.x=100;
                 SDL_BlitSurface(points, NULL, ecran, &position_points);
                 
                 
              cpSpaceStep(espace, timeStep);
              SDL_Flip(ecran);
          }
                      //affichage points
                 
 SDL_Flip(ecran);
}
Example #15
0
void eol_level_update(eolLevel *level)
{
  eolLevelLayer *layer = NULL;
  if (!level)return;
  layer = g_list_nth_data(level->layers,level->active);
  if (layer == NULL)return;
  /*presync*/
  eol_entity_presync_all();

  cpSpaceStep(layer->space,_eol_level_clip_step);

  /*post sync*/
  eol_entity_postsync_all();
}
Example #16
0
static void
update(int ticks)
{
	if(ChipmunkDemoRightClick){
		QUERY_START = ChipmunkDemoMouse;
	}
	
	int steps = 1;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		cpSpaceStep(space, dt);
	}
}
Example #17
0
 void CDynamics2DEngine::Update() {
    /* Update the physics state from the entities */
    for(TDynamics2DEntityMap::iterator it = m_tPhysicsEntities.begin();
        it != m_tPhysicsEntities.end(); ++it) {
       it->second->UpdateFromEntityStatus();
    }
    /* Perform the step */
    cpSpaceStep(m_ptSpace, m_fSimulationClockTick);
    /* Update the simulated space */
    for(TDynamics2DEntityMap::iterator it = m_tPhysicsEntities.begin();
        it != m_tPhysicsEntities.end(); ++it) {
       it->second->UpdateEntityStatus();
    }
 }
Example #18
0
/* Updating each frame
 * -------------------
 *
 * Updating and drawing a frame takes stepping the Chipmunk2D
 * simulation by the 1/1000s fration of a second passed and
 * then drawing any active tile using its up-to-date
 * position.
 * We then delegate any mouse actions to apply_mouse_motion().
 */
static void update_sample(void* data, float elapsed_ms)
{
    struct state* state = data;
    cpFloat timeStep = elapsed_ms / 1000.0;
    cpSpaceStep(state->space, timeStep);
    screen_color(color_from_RGB(244, 244, 244));
    for (size_t i = 0; i < MAX_TILES; i++) {
        if (state->tiles[i].is_active) {
            cpVect pos = cpBodyGetPosition(state->tiles[i].body);
            draw_image(state->tile_img, pos.x - state->tile_img->width / 2,
                       pos.y - state->tile_img->height / 2, NULL, 0);
        }
    }
    apply_mouse_motion(state);
}
Example #19
0
void ws::game::Scene::update(float deltaTime) {
	
	cpSpaceStep(space, 1.0f/60.0f);//deltaTime);
	
	// PhysicalBody
	for( auto object : objects )
	{
		auto physics = object->getComponent<ws::components::PhysicalBody>("physics");
		if( physics != nullptr )
		{
			physics->update(deltaTime);
		}
	}
	sf::sleep(sf::seconds(0.01f));
}
Example #20
0
void PhysicsWorld::update(float delta)
{
    cpSpaceStep(_info->space, delta);
    
    if (_drawNode)
    {
        _drawNode->removeFromParent();
        _drawNode = nullptr;
    }
    
    if (_debugDraw)
    {
        debugDraw();
    }
}
Example #21
0
static void
update(int ticks)
{
	int steps = 3;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		cpSpaceStep(space, dt);
		
		// Manually update the position of the box body so that the box rotates.
		// Normally Chipmunk calls this and cpBodyUpdateVelocity() for you,
		// but we wanted to control the angular velocity explicitly.
		cpBodyUpdatePosition(rogueBoxBody, dt);
	}
}
Example #22
0
static void
update(int ticks)
{
	cpFloat coef = (2.0f + ChipmunkDemoKeyboard.y)/3.0f;
	cpFloat rate = ChipmunkDemoKeyboard.x*10.0f*coef;
	cpSimpleMotorSetRate(motor, rate);
	cpConstraintSetMaxForce(motor, (rate) ? 100000.0f : 0.0f);
	
	int steps = 3;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		cpSpaceStep(space, dt);
	}
}
static void
update(cpSpace *space, double dt)
{
    cpSpaceStep(space, dt);

    ChipmunkDemoPrintString("Place objects on the scale to weigh them. The ball marks the shapes it's sitting on.\n");

    // Sum the total impulse applied to the scale from all collision pairs in the contact graph.
    // If your compiler supports blocks, your life is a little easier.
    // You can use the "Block" versions of the functions without needing the callbacks above.
#if USE_BLOCKS
    __block cpVect impulseSum = cpvzero;
    cpBodyEachArbiter_b(scaleStaticBody, ^(cpArbiter *arb) {
        impulseSum = cpvadd(impulseSum, cpArbiterTotalImpulse(arb));
    });
void DynamicTimeLineManager::stepSpace()
{
	float timeStep = ( 1.0 / 30.0 ) / 12.0;
	cpSpaceStep( m_Space, timeStep );
	cpSpaceStep( m_Space, timeStep );
	cpSpaceStep( m_Space, timeStep );
	cpSpaceStep( m_Space, timeStep );
	cpSpaceStep( m_Space, timeStep );
	cpSpaceStep( m_Space, timeStep );
}
Example #25
0
	void PhysicsManager::Update( float iTimeElapsed )
	{
		mSpaces.erase(std::remove(mSpaces.begin(), mSpaces.end(), static_cast<cpSpace*>(0)), mSpaces.end());

		mBufferedTime += iTimeElapsed;

		while(mBufferedTime >= mStepTime)
		{
			mBufferedTime -= mStepTime;

			for(SpaceVecIter iter = mSpaces.begin(); iter != mSpaces.end(); ++iter)
			{
				cpSpaceStep(*iter, mStepTime);
			}
		}
	}
Example #26
0
 void CDynamics2DEngine::Update() {
    /* Update the physics state from the entities */
    for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
        it != m_tPhysicsModels.end(); ++it) {
       it->second->UpdateFromEntityStatus();
    }
    /* Perform the step */
    for(size_t i = 0; i < GetIterations(); ++i) {
       cpSpaceStep(m_ptSpace, GetPhysicsClockTick());
    }
    /* Update the simulated space */
    for(CDynamics2DModel::TMap::iterator it = m_tPhysicsModels.begin();
        it != m_tPhysicsModels.end(); ++it) {
       it->second->UpdateEntityStatus();
    }
 }
Example #27
0
void TitleScreenDoLogic(bool* Continue, bool* Error, Uint32 Milliseconds)
{
	(void)Continue;
	(void)Error;
	cpSpaceStep(space.Space, Milliseconds * 0.001);
	for (int i = 0; i < MAX_PLAYERS; i++)
	{
		PlayerUpdate(&players[i], Milliseconds);

		// Check which players have fallen below their start pads
		cpVect pos = cpBodyGetPosition(players[i].Body);
		if (pos.y < BLOCK_Y)
		{
			if (!playersEnabled[i])
			{
				// New player entered
				countdownMs = COUNTDOWN_START_MS;
				SoundPlay(SoundStart, 1.0);
			}
			playersEnabled[i] = true;
		}
	}

	if (countdownMs >= 0)
	{
		const int countdownMsNext = countdownMs - Milliseconds;
		// Play a beep every second
		if ((countdownMs / 1000) > (countdownMsNext / 1000))
		{
			SoundPlay(SoundBeep, 1.0);
		}
		// Start game if counted down to zero
		if (countdownMsNext <= 0)
		{
			TitleScreenEnd();
			ToGame();
			return;
		}
		countdownMs = countdownMsNext;
	}

	Animation *a = Start ? &TitleAnim : &GameOverAnim;
	AnimationUpdate(a, Milliseconds);

	HighScoreDisplayUpdate(&HSD, Milliseconds);
}
Example #28
0
void GameScene::update(float delta)
{
	// Step physics
	accumulator += delta;
	while (accumulator > physicsStep)
	{
		cpSpaceStep(space, physicsStep);
		accumulator -= physicsStep;
	}
	
	// Move ball sprite with body
	if (ball)
	{
		auto v = static_cast<cpBody*>(ball->getUserData())->p;
		ball->setPosition(v.x, v.y);
	}
}
Example #29
0
void PlayLayer::step(float delta) {
    
	int steps = 2;
	double dt = delta/(double)steps;
	
	if (dt > MAX_DELTA_FRAME) 
		dt = MAX_DELTA_FRAME;
	
    cpSpace * space = DoodleTruck::sharedDoodleTruck()->getSpace();
	for(int i = 0; i < steps; i++){
		cpSpaceStep(space, dt);
	}
    
	cpSpaceEachShape(space, (cpSpaceShapeIteratorFunc)&eachShape, NULL);
   	//cpSpaceHashEach(space->staticShapes, &eachShape, NULL);

}
Example #30
0
static void
update(cpSpace *space, double dt)
{
	// Set the first anchor point (the one attached to the static body) of the dolly servo to the mouse's x position.
	cpPivotJointSetAnchorA(dollyServo, cpv(ChipmunkDemoMouse.x, 100));
	
	// Set the max length of the winch servo to match the mouse's height.
	cpSlideJointSetMax(winchServo, cpfmax(100 - ChipmunkDemoMouse.y, 50));
	
	if(hookJoint && ChipmunkDemoRightClick){
		cpSpaceRemoveConstraint(space, hookJoint);
		cpConstraintFree(hookJoint);
		hookJoint = NULL;
	}
	
	cpSpaceStep(space, dt);
}