Пример #1
0
void ProcessAllCollisions()
{
    ProcessCollisions(&playerProjectileCollection, &enemyCollection, SquareSquareCollision);
    ProcessCollisions(&playerProjectileCollection, &breakablesCollection, SquareSquareCollision);
    ProcessCollisionsAgainstPlayer(&enemyCollection, SquareSquareCollision);
    ProcessCollisionsAgainstPlayer(&enemyProjectileCollection, SquareSquareCollision);
    ProcessCollisionsAgainstPlayer(&pickupCollection, SquareSquareCollision);
}
Пример #2
0
void AdvanceFrame()
{
  RebuildGrid();
  ComputeForces();
  ProcessCollisions();
  AdvanceParticles();
#if defined(USE_ImpeneratableWall)
  // N.B. The integration of the position can place the particle
  // outside the domain. We now make a pass on the perimiter cells
  // to account for particle migration beyond domain.
  ProcessCollisions2();
#endif
#ifdef ENABLE_STATISTICS
  float mean, stddev;
  int i;

  mean = (float)numParticles/(float)numCells;
  stddev = 0.0;
  for(i=0; i<numCells; i++) {
    stddev += (mean-cnumPars[i])*(mean-cnumPars[i]);
  }
  stddev = sqrtf(stddev);
  std::cout << "Cell statistics: mean=" << mean << " particles, stddev=" << stddev << " particles." << std::endl;
#endif
}
Пример #3
0
void Game::Go(){
	//pWnd->ShowMouseCursor(false);

	//objeto para recibir eventos
	Event evt;

	//Inicializa los objetos del juego
	Init();
	
	if(pWnd->IsOpened())
	{
		Intro();
		ShowMenu();		
	}
	while(pWnd->IsOpened()){
		//procesar eventos
		while (pWnd->GetEvent(evt))
			ProcessEvent(evt);

		//procesar colisiones
		ProcessCollisions();
		
		//actualizar estados de objetos
		UpdateGame();
		
		pWnd->Clear();
		
		DrawGame();
		
		pWnd->Display();
	}
	StopMusic();	
}
Пример #4
0
void CEntity::OnPrepare()
{
	/*
	   Frame#  Action
	   ----------------
	   0-39    idle
	   40-46   running
	   47-60   getting shot but not falling (back bending)
	   61-66   getting shot in shoulder
	   67-73   jumping
	   74-95   idle
	   96-112  getting shot and falling down
	   113-122 idle
	   123-135 idle
	   136-154 crouch
	   155-161 crouch crawl
	   162-169 crouch adjust weapon (idle)
	   170-177 kneeling dying
	   178-185 falling back dying
	   186-190 falling forward dying
	   191-198 falling back slow dying
	*/

	switch (modelState)
	{
	case MODEL_IDLE:
		stateStart = 0;
		stateEnd = 39;
		break;
	case MODEL_CROUCH:
		break;
	/****************Faith Satterthwaite 12/1/2012***********************/
	case MODEL_WALK:
		stateStart = 42;
		stateEnd = 44;
		velocity = CVector(-15.0, -15.0, -15.0);
		break;
	/*******************************************************************/
	case MODEL_RUN:
		stateStart = 40;
		stateEnd = 46;
		velocity = CVector(0.0, 0.0, 15.0);
		break;
	case MODEL_JUMP:
		stateStart = 67;
		stateEnd = 73;
		break;
	case MODEL_DIE:
		stateStart = 178;
		stateEnd = 184;
		break;
	default:
		stateStart = 0;
		stateEnd = 1;
		break;
	}

	// perform collision detection from this entity with all other objects in world
	ProcessCollisions(FindRoot());
}
Пример #5
0
void CRocket::OnPrepare()
{
	// perform collision detection from this entity with all other objects in world
	if (!isExplosion)
		ProcessCollisions(FindRoot());

	if (isExplosion)
	{
		// Phase 16 - Take out for now
		// Phase 19 - Uncomment the following
		if (explosion->IsDead())
		{
			explosion->KillSystem();
			delete explosion;
			explosion = NULL;
			isExplosion = false;

			isDead = true;

			///// -- Adam
			
			///// -- Adam
		}
	}
}
Пример #6
0
void Ball::Update(unordered_map<string, Game_Object*> objects)
{
	Matrix4::UpdatePositionMatrix(translationMatrix, velocity->x, velocity->y, 0);
	*velocity += *accel;

	// "Friction"
	//if(accel > 0)
	//	*(accel) += Vector4(-0.01f, 0.0f, 0.0f, 0);
	//else if(accel < 0)
	//	*(accel) += Vector4(0.01f, 0.0f, 0.0f, 0);

	//PollUserInput();
	ProcessCollisions(objects);
}
Пример #7
0
void GameStart() {
	RenderWindow window(VideoMode(MapWidth * SpriteSize, MapHeight * SpriteSize), "Snake");
	Clock clock;
	Game* game;
	NewGame(game);
	Text text = game->game_text->text;

	while (window.isOpen()) //разбить на 3 метода
	{
		float time = clock.getElapsedTime().asSeconds();
		clock.restart();
		game->consts->time_counter += time;

		ProcessEvents(window, game);

		if (game->state == STARTGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Snake!\n\nPress 'U' to start!");
			text.setPosition(250, 50);
			window.draw(text);
		}
		else if (game->state == RESTART) {
			DestroyGame(game);
			NewGame(game);
			text = game->game_text->text;
			game->state = PLAY;
		}
		else if (game->state == PAUSE) {
			window.clear();
			Render(window, game);
			text.setCharacterSize(150);
			text.setString("Pause");
			text.setPosition(455, 160);
			window.draw(text);
		}
		else if (game->state == PLAY) {
			while (game->consts->time_counter > game->consts->speed) {
				game->consts->time_counter = 0;

				//Snake movement

				Step(game->snake);

				int snake_draw_counter = SnakeLength(game->snake);

				ProcessCollisions(snake_draw_counter, game);
			}
			Render(window, game);
		}
		else if (game->state == ENDGAME) {
			window.clear();
			text.setCharacterSize(120);
			text.setString("       Score: " + ToString(game->consts->score) + "\n Press 'Esc' to exit\n Press 'R' to restart");
			text.setPosition(170, 28);
			window.draw(text);
		}

		window.display();
	}
	DestroyGame(game);
}
Пример #8
0
	void ManagerModel::OnUpdate(const float dt) {
		//Exit if score is over rhs.
		if (GetScore() >= maxScore) {
			mWonRound = true;
		}

		//Add health package if time delta is right
		timerHealthPackage -= dt;
		if (timerHealthPackage <= 0) {
			timerHealthPackage = timePeriodSpawnHealtPackage;
			AddHealthPackage();
		}

		//Collision
		ColissionWall();
		auto collisions = CollisionEntities();
		if (collisions.size() > 0) {
			ProcessCollisions(collisions);
		}

		for (Entity *e : mEntities) {
			e->OnUpdate();
			if (e->Type() == ENTITY_PLAYER) {
				for (auto view : mViews) {
					bool btnIsPressed = view->OnPlayerUpdatedAnimation((Player*)e);
					((Player*)e)->OnUpdateAnimation(btnIsPressed, dt);

					((Player*)e)->OnUpdatePhysics(dt);
					view->OnPlayerUpdatedPhysics((Player*)e);

					SetHealth(((Player*)e)->mHealth);
				}
			} else if (e->Type() == ENTITY_BULLET) {
				for (auto view : mViews) {
					((Shot*)e)->OnUpdatedPhysics(dt);
					view->OnShotUpdatePhysics((Shot*)e);
				}
			} else if (e->Type() == ENTITY_ASTEROID) {
				for (auto view : mViews) {
					((Asteroid*)e)->OnUpdateAnimation(dt);
					view->OnAsteroidUpdatedAnimation(((Asteroid*)e));

					((Asteroid*)e)->OnUpdatePhysics(dt);
					view->OnAsteroidUpdatedPhysics((Asteroid*)e);
				}
			} else if (e->Type() == ENTITY_EXPLOSION) {
				for (auto view : mViews) {
					((Explosion*)e)->OnUpdateAnimation(dt);
					view->OnExplosionUpdateAnimation((Explosion*)e);
				}
			} else if (e->Type() == ENTITY_HEALTHPACKAGE) {
				for (auto view : mViews) {
					((HealthPackage*)e)->OnUpdatePhysics(dt);
					view->OnHealthPackageUpdatedPhysics((HealthPackage*)e);
				}
			} else if (e->Type() == ENTITY_ENEMIEBOSS) {
				for (auto *view : mViews) {
					((EnemieBoss*)e)->OnUpdateAnimation(dt, DelayEnemieBossMove(((EnemieBoss*)e), dt));
					view->OnEnemieBossUpdatedAnimation((EnemieBoss*)e);

					((EnemieBoss*)e)->OnUpdatePhysics(dt);
					view->OnEnemieBossUpdatedPhysics((EnemieBoss*)e);
				}
			} else if (e->Type() == ENTITY_BULLETENEMIEBOSS) {
				for (auto view : mViews) {
					((EnemieBossShot*)e)->OnUpdatedPhysics(dt);
					view->OnEnemieBossShotUpdatePhysics((EnemieBossShot*)e);
				}
			}
		}

		EvalRequestNewBullet(dt);
		RemoveDeadExplosion();
	}