예제 #1
0
EntityPtr EntityFactory::createDefault() {
	EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(0, 0, 16, 16));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));
	physicsComponent->setCollider(GCC_NEW Collider(0, 0, 16, 16));

	GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS));
	DrawablePtr blockDrawable(GCC_NEW BlockDrawable(16, 16, 255, 0, 0, 255));
	graphicsSystem->registerDrawable(entity->id, blockDrawable);
	DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, blockDrawable));

	InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT));
	InputListenerPtr inputListener(GCC_NEW InputListener(entity->id));
	inputSystem->registerEventListener(inputListener);
	InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener));

	entity->addComponent(ComponentPtr(physicsComponent));
	entity->addComponent(ComponentPtr(drawableComponent));
	entity->addComponent(ComponentPtr(inputComponent));

	return entity;
}
예제 #2
0
EntityPtr EntityFactory::createPhysicsEntity(float x, float y, float width, float height) {
	EntitySystemPtr entitySystem(makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)));
	EntityPtr entity(GCC_NEW Entity());
	entitySystem->addEntity(entity);

	PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS));
	BodyPtr blockBody(GCC_NEW Body(x, y, width, height));
	physicsSystem->registerBody(entity->id, blockBody);
	PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody));
	physicsComponent->setCollider(GCC_NEW Collider(x, y, width, height));

	entity->addComponent(ComponentPtr(physicsComponent));

	return entity;
}
예제 #3
0
BatMan::BatMan(Vector2 pos, int& handle, int& deadHandle, Player& player, Camera& camera)
:_playerRef(player), _cameraRef(camera), _fragDrawer(deadHandle)//この時点でFragmentDrawerの引数なしコンストラクタ呼ばれてる
{
	_isAvailable = true;
	_prevRejectY = false;
	_collider = Collider(this, ct_batman, col_default);
	_collider.ToEnable();
	_pos = pos;
	_collider.SetRect(Rect(_pos, 29, 128));
	_collider.SetCenter(_pos + Vector2(_cameraRef.OffsetX(), 0));
	_velocity = Vector2(0, 0);
	_acceleration = Vector2(0, 0.3f);
	_pFunc = &BatMan::ArialUpdate;
	_handle = handle;
	_deadhandle = deadHandle;
	_walkFrame = 0;
	_state = state_arial;

	_hpMax = 10;
	_hp = _hpMax;

	_pfuncMap[BatMan::state_far] = &BatMan::FarUpdate;
	_pfuncMap[BatMan::state_near] = &BatMan::NearUpdate;
	_pfuncMap[BatMan::state_dead] = &BatMan::DeadUpdate;
	_pfuncMap[BatMan::state_underThrow] = &BatMan::UnderThrowUpdate;
	_pfuncMap[BatMan::state_overThrow] = &BatMan::OverThrowUpdate;
	_pfuncMap[BatMan::state_preUnderThrow] = &BatMan::PreUnderThrowUpdate;
	_pfuncMap[BatMan::state_preOverThrow] = &BatMan::PreOverThrowUpdate;
	_pfuncMap[BatMan::state_arial] = &BatMan::ArialUpdate;
	_pfuncMap[BatMan::state_wait] = &BatMan::WaitUpdate;


	_drawFuncMap[BatMan::state_far] = &BatMan::DrawFar;
	_drawFuncMap[BatMan::state_near] = &BatMan::DrawNear;
	_drawFuncMap[BatMan::state_dead] = &BatMan::DrawDead;
	_drawFuncMap[BatMan::state_arial] = &BatMan::DrawArial;
	_drawFuncMap[BatMan::state_underThrow] = &BatMan::DrawUnderThrow;
	_drawFuncMap[BatMan::state_overThrow] = &BatMan::DrawOverThrow;
	_drawFuncMap[BatMan::state_preUnderThrow] = &BatMan::DrawPreUnderThrow;
	_drawFuncMap[BatMan::state_preOverThrow] = &BatMan::DrawPreOverThrow;
	_drawFuncMap[BatMan::state_wait] = &BatMan::DrawWait;


	_stateFrame[BatMan::state_far] = 0;
	_stateFrame[BatMan::state_near] = 0;
	_stateFrame[BatMan::state_dead] = 0;
	_stateFrame[BatMan::state_arial] = 0;
	_stateFrame[BatMan::state_underThrow] = 0;
	_stateFrame[BatMan::state_overThrow] = 0;
	_stateFrame[BatMan::state_preUnderThrow] = 0;
	_stateFrame[BatMan::state_preOverThrow] = 0;
	_stateFrame[BatMan::state_wait] = 0;



	_isGrabbing = false;
	_isNear = false;
	_isDead = false;
	_isLeft = false;

	_overThrowOffset = Vector2(0, -32);
	_underThrowOffset = Vector2(0, 32);

	_attackCol = Collider(this, ct_batman, col_attack);
	_attackCol.width = 40;
	_attackCol.height = 32;
	_attackOffset = _isLeft ? Vector2(-40, -32) : Vector2(40, 32);
	_attackOffset_under = _isLeft ? Vector2(-50, 0) : Vector2(50, 0);
	_attackRange = 40;
	_attackCol.ToDisable();

	//_fragDrawer = new FragmentDrawer(_deadhandle);
}
예제 #4
0
int launchSnow(Scene& scene) {
  std::cerr << "Custom Scene created!" << std::endl;
  srand(time(NULL));

  scene.grid =
      make_shared<Grid>(GRID_DIM_X, GRID_DIM_Y, GRID_DIM_Z, GRID_SPACING,
                        GRID_POS_X, GRID_POS_Y, GRID_POS_Z);
  shared_ptr<Mesh> halfplane = make_shared<Mesh>();
  halfplane->setPosition(
      GRID_POS_X + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Y + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Z + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(1.0f, 0.0f, 0.0f)));

  shared_ptr<Mesh> halfplane2 = make_shared<Mesh>();
  halfplane2->setPosition(
      GRID_POS_X + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Y + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Z + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane2, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(0.0f, 1.0f, 0.0f)));

  shared_ptr<Mesh> halfplane3 = make_shared<Mesh>();
  halfplane3->setPosition(
      GRID_POS_X + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Y + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING,
      GRID_POS_Z + GRID_COLLISION_PLANE_OFFSET * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane3, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(0.0f, 0.0f, 1.0f)));

  shared_ptr<Mesh> halfplane4 = make_shared<Mesh>();
  halfplane4->setPosition(
      GRID_POS_X + (GRID_DIM_X - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Y + (GRID_DIM_Y - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Z + (GRID_DIM_Z - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane4, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(-1.0f, 0.0f, 0.0f)));

  shared_ptr<Mesh> halfplane5 = make_shared<Mesh>();
  halfplane5->setPosition(
      GRID_POS_X + (GRID_DIM_X - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Y + (GRID_DIM_Y - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Z + (GRID_DIM_Z - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane5, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(0.0f, -1.0f, 0.0f)));

  shared_ptr<Mesh> halfplane6 = make_shared<Mesh>();
  halfplane6->setPosition(
      GRID_POS_X + (GRID_DIM_X - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Y + (GRID_DIM_Y - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING,
      GRID_POS_Z + (GRID_DIM_Z - GRID_COLLISION_PLANE_OFFSET) * GRID_SPACING);

  scene.colliderSys->colliders.push_back(Collider(halfplane6, 0.0f, 0,
                                                  Vector3f(0.0f, 0.0f, 0.0f),
                                                  Vector3f(0.0, 0.0f, -1.0f)));

  /*
        Mesh halfplane;
halfplane.setPosition(0.7125f,0.7125f,0.7125f);
pCo->colliders->push_back(Collider(halfplane));
*/

  /*
Mesh quad;
quad.LoadMesh("model/box.obj");
quad.setPosition(5.0f,-3.0f,5.0f);
quad.setScale(10.0f,1.0f,10.0f);
quad.setRotation(0,0,0);
meshes->push_back(std::move(quad));

*/
  GLFWWindow();

  auto renderer = ParticleRenderer(scene.get_renderable_scene());
  auto simulationMethod =
      std::make_unique<ExplicitTimeUpdate>(scene.get_physical_scene());
  auto simulation = MPMPhysicEngine(std::move(simulationMethod));
  renderer.init();
  simulation.init();

  double currentTime = glfwGetTime();  // gafferongames.com
  double accumulator = 0.0;
  while (GLFWWindow::shouldClose()) {
    double newTime = glfwGetTime();
    double frameTime = newTime - currentTime;
    currentTime = newTime;
    accumulator += frameTime;
    while (accumulator >= STEP_DT) {
      simulation.update(PHYSIC_DT);
      accumulator -= STEP_DT;
    }
    GLFWWindow::clear();
    renderer.render();
    GLFWWindow::swapBuffers();
#ifdef BENCHMARK
    BenchmarkerGPU::getInstance().collect_times_last_frame();
#endif
  }
#ifdef BENCHMARK
  BenchmarkerGPU::getInstance().write_to_file();
#endif
  GLFWWindow::stop();
  return 0;
}
예제 #5
0
KnifeMan::KnifeMan(Vector2 pos, int& handle, int& deadHandle, Player& player, Camera& camera,EnemyBulletFactory& ebulletFac)
:_playerRef(player), _cameraRef(camera), _fragDrawer(deadHandle),_ebulletFac(ebulletFac)//この時点でFragmentDrawerの引数なしコンストラクタ呼ばれてる
{
	_isAvailable = true;
	_prevRejectY = false;
	_collider = Collider(this, ct_knifeMan, col_default);
	_collider.ToEnable();
	_pos = pos;
	_collider.SetRect(Rect(_pos, 29, 128));
	_collider.SetCenter(_pos + Vector2(_cameraRef.OffsetX(), 0));
	_velocity = Vector2(0, 0);
	_acceleration = Vector2(0, 0.3f);
	_pFunc = &KnifeMan::ArialUpdate;
	_handle = handle;
	_deadhandle = deadHandle;
	_walkFrame = 0;
	_state = state_arial;

	_hpMax = 5;
	_hp = _hpMax;

	_pfuncMap[KnifeMan::state_far] = &KnifeMan::FarUpdate;
	_pfuncMap[KnifeMan::state_near] = &KnifeMan::NearUpdate;
	_pfuncMap[KnifeMan::state_dead] = &KnifeMan::DeadUpdate;
	_pfuncMap[KnifeMan::state_underThrow] = &KnifeMan::UnderThrowUpdate;
	_pfuncMap[KnifeMan::state_overThrow] = &KnifeMan::OverThrowUpdate;
	_pfuncMap[KnifeMan::state_preUnderThrow] = &KnifeMan::PreUnderThrowUpdate;
	_pfuncMap[KnifeMan::state_preOverThrow] = &KnifeMan::PreOverThrowUpdate;
	_pfuncMap[KnifeMan::state_arial] = &KnifeMan::ArialUpdate;
	_pfuncMap[KnifeMan::state_wait] = &KnifeMan::WaitUpdate;


	_drawFuncMap[KnifeMan::state_far] = &KnifeMan::DrawFar;
	_drawFuncMap[KnifeMan::state_near] = &KnifeMan::DrawNear;
	_drawFuncMap[KnifeMan::state_dead] = &KnifeMan::DrawDead;
	_drawFuncMap[KnifeMan::state_arial] = &KnifeMan::DrawArial;
	_drawFuncMap[KnifeMan::state_underThrow] = &KnifeMan::DrawUnderThrow;
	_drawFuncMap[KnifeMan::state_overThrow] = &KnifeMan::DrawOverThrow;
	_drawFuncMap[KnifeMan::state_preUnderThrow] = &KnifeMan::DrawPreUnderThrow;
	_drawFuncMap[KnifeMan::state_preOverThrow] = &KnifeMan::DrawPreOverThrow;
	_drawFuncMap[KnifeMan::state_wait] = &KnifeMan::DrawWait;


	_stateFrame[KnifeMan::state_far] = 0;
	_stateFrame[KnifeMan::state_near] = 0;
	_stateFrame[KnifeMan::state_dead] = 0;
	_stateFrame[KnifeMan::state_arial] = 0;
	_stateFrame[KnifeMan::state_underThrow] = 0;
	_stateFrame[KnifeMan::state_overThrow] = 0;
	_stateFrame[KnifeMan::state_preUnderThrow] = 0;
	_stateFrame[KnifeMan::state_preOverThrow] = 0;
	_stateFrame[KnifeMan::state_wait] = 0;



	_isGrabbing = false;
	_isNear = false;
	_isDead = false;
	_isLeft = false;

	_overThrowOffset = Vector2(0, -32);
	_underThrowOffset = Vector2(0, 32);

	//_fragDrawer = new FragmentDrawer(_deadhandle);
}