Exemple #1
0
void DefaultMap::create(World* world) {
  addFloor(world, Vector(0, -10, 0), Vector(20, 1, 20));
  addFloor(world, Vector(500, -10, 0), Vector(5, 5, 5), Vector(100, 100, 100));
  addFloor(world, Vector(0, 240, 0), Vector(5, 1, 5));
  addFloor(world, Vector(0, -10, 250), Vector(5, 9, 5));

  world->setBoundary(AABB(
    Vector(-20, -500, -30), 
    Vector(1900, 800, 1900)
  ));

  createSpawns(world, Vector(1800, 0, 1800), Vector(0, 10, 0));
}
Exemple #2
0
void MazeParser::loadFloorPlan()
{
   int count = 0;
   char line_buffer[MAX_LINE_SIZE];
   fprintf(stderr,"Loading floor plan\n");
   fflush(stderr);

   /* compute the size of the scene */
   scene_width = cells_wide * cell_size;
   scene_height = cells_high * cell_size;

   fprintf(stderr,"size of scene: %d x %d\n", scene_width, scene_height);
   fflush(stderr);

   while((count < cells_high * 2) && fgets(line_buffer, MAX_LINE_SIZE, fp))
   {
      /* only do something if it's not a comment and the line is not blank */
      if (!lineCanBeIgnored(line_buffer))
      {
         parseFloorPlan(count, line_buffer);
         count++;
      }
   }

   /* after i have added all the walls, let us add the floor */
   float x = -(((float)scene_width) / (float)2);
   float y = (((float)scene_height) / (float)2);
   addFloor(x, y, x + scene_width, y - scene_height, scene->textures[num_tex-1], scene_width, scene_height);

   return;
}
Exemple #3
0
void House::addFloorBottom(Scene* scene) {
    floorIndex = 0;
    middleIndex++;
    addFloor(scene, floors.size() ? floors.front() : NULL);
    floors.insert(floors.begin(), floorTiles);
    rooms.insert(rooms.begin(), list<Room*>());
}
Exemple #4
0
static void initLevel(bool isStart) {
    if (isStart) {
        state = STATE_START;
        gameFrames = 0;
        score = 0;
        level = 0;
        arduboy.playScore2(soundStart, 0);
    } else {
        level++;
        arduboy.tunes.stopScore();
    }
    dprint("Init Level ");
    dprintln(level);

    flrTypesNum = 0;
    if (level < 6) flrTypes[flrTypesNum++] = FLRTYPE_NORMAL;
    if (level ==1) flrTypes[flrTypesNum++] = FLRTYPE_NORMAL;
    if (level & 1) flrTypes[flrTypesNum++] = FLRTYPE_MOVE;
    if (level & 2) flrTypes[flrTypesNum++] = FLRTYPE_VANISH;
    if (level & 4 || level == 8) flrTypes[flrTypesNum++] = FLRTYPE_SMALL;

    for (int i = 0; i < FLOORS_MANAGE; i++) {
        floorAry[i].type = FLRTYPE_NONE;
    }
    floorIdxFirst = 0;
    floorIdxLast = 0;
    addFloor(FLRTYPE_NORMAL, 0, playerX, playerY, FLOOR_Z_MAX);
}
Exemple #5
0
static void moveFloors(int scrollX, int scrollY, int scrollZ)
{
    FLOOR *pFloor;
    for (int i = 0; i < FLOORS_MANAGE; i++) {
        pFloor = &floorAry[i];
        if (pFloor->type != FLRTYPE_NONE) {
            pFloor->x += scrollX + pFloor->vx;
            pFloor->y += scrollY + pFloor->vy;
            pFloor->z += scrollZ;
            int z = pFloor->z;
            if (pFloor->type == FLRTYPE_VANISH) {
                if (z < 0) {
                    pFloor->size = pFloor->sizeBack;
                } else if (pFloor->size != pFloor->sizeBack && pFloor->size > 0) {
                    pFloor->size--;
                }
            }
            if (scrollZ <= 0 && z >= 0 && z + scrollZ - 1 < 0) {
                int diff = max(abs(pFloor->x - playerX), abs(pFloor->y - playerY));
                if (diff < pFloor->size * 128) {
                    springPlayer(pFloor, diff);
                    dprint("Spring floor ");
                    dprintln(i);
                }
            }
        }
    }

    pFloor = &floorAry[floorIdxFirst];
    if (pFloor->z > FLOOR_Z_MAX) {
        pFloor->type = FLRTYPE_NONE;
        floorIdxFirst = nextFloorIdx(floorIdxFirst);
        dprint("floorIdxFirst=");
        dprintln(floorIdxFirst);
    }

    pFloor = &floorAry[floorIdxLast];
    int z = pFloor->z;
    if (state == STATE_GAME && z >= 0 && pFloor->type != FLRTYPE_GOAL) {
        uint8_t pos = pFloor->pos + 1;
        uint8_t type = (pos == FLOORS_LEVEL) ? FLRTYPE_GOAL : flrTypes[random(flrTypesNum)];
        floorIdxLast = nextFloorIdx(floorIdxLast);
        addFloor(type, pos, rand() * 2, rand() * 2, z - (512 + level * 32));
        dprint("floorIdxLast=");
        dprintln(floorIdxLast);
    }

#ifdef DEBUG
    if (dbgRecvChar == 'z') {
        pFloor->type = FLRTYPE_GOAL;
        springPlayer(pFloor, 0);
    }
#endif
}
void editLevelStateClass::returnPressed()
{
    if(currentMode == ADD_FLOOR)
    {
        addFloor();
    }
    else if(currentMode == ADD_WALL)
    {
        addWallToCurrentFloor();
    }
    else if(currentMode == PLACE_PLAYER)
    {
        setNoMode();
    }
}
void Physics::registBodies(){
    addFloor();

    addBall(2.5,btVector3(SIZE_WIDTH/1.5,0,SIZE_DEPTH/1.5),0.08);

    btVector3 posTeam1[] = {btVector3(15,4,SIZE_DEPTH- 55),btVector3(35,4,30),btVector3(55,4,45)};
    btVector3 posTeam2[] = {btVector3(SIZE_WIDTH-15,4,55),btVector3(SIZE_WIDTH-25,4,SIZE_DEPTH - SIZE_DEPTH/2.5 + 20),btVector3(SIZE_WIDTH-55,4,85)};
    //Create robots here
    //Team 1
    for(int i = 0;i < numRobotsTeam;i++){
        if(numTeams >= 1){
            addRobot(Color(0.3,0.3,0.3),posTeam1[i],btVector3(0,90,0),8,0.25,clrPlayers[i],clrTeams[0]);
        }
    }

    for(int i = 0;i < numRobotsTeam;i++){
        if(numTeams == 2){
            addRobot(Color(0.3,0.3,0.3),posTeam2[i],btVector3(0,-100,0),8,0.25,clrPlayers[i],clrTeams[1]);
        }
    }

    addWall(Color(0,0,0),btVector3(SIZE_WIDTH/2+1,7.5,-2.5),SIZE_WIDTH,15,5,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH/2+1,7.5,SIZE_DEPTH+2.5),SIZE_WIDTH,15,5,0);

    addWall(Color(0,0,0),btVector3(-1.6,7.5,SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-1.6,7.5,SIZE_DEPTH-SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-12.5,7.5, SIZE_DEPTH/2),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-7,7.5,SIZE_DEPTH/3),15,15,5,0);
    addWall(Color(0,0,0),btVector3(-7,7.5,2*SIZE_DEPTH/3+2.5),15,15,5,0);

    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+3.5,7.5,SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+3.5,7.5,SIZE_DEPTH-SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+13.5,7.5, SIZE_DEPTH/2),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+8.5,7.5,SIZE_DEPTH/3),15,15,5,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+8.5,7.5,2*SIZE_DEPTH/3+2.5),15,15,5,0);

    addCorner(Color(0,0,0),btVector3(10,7.5,10),30,15,btVector3(0,45,0));
    addCorner(Color(0,0,0),btVector3(SIZE_WIDTH-9,7.5,10),30,15,btVector3(0,-45,0));
    addCorner(Color(0,0,0),btVector3(SIZE_WIDTH-9,7.5,SIZE_DEPTH-10),30,15,btVector3(0,45,0));
    addCorner(Color(0,0,0),btVector3(10,7.5,SIZE_DEPTH-10),30,15,btVector3(0,-45,0));
}
Exemple #8
0
void Test::init()
{
	m_world = new World(vec3(0.0f, -10.0f, 0.0f));
	//m_world = new World(vec3(0.0f, 0.0f, 0.0f));


	gBox = ShapePtr();
	gCapsule = ShapePtr();
	gFloor = ShapePtr();
	gSlope = ShapePtr();
	gSphere = ShapePtr();

	Material m;
	m.density = 10.0f;
	m.friction = 1.0f;
	m.restitution = 0.0f;

	Material* material = m_world->createMaterial(m);

	BodyDescription descr;
	descr.type = BodyType::Dynamic;
	descr.transform = Transform(vec3(0.0f, 5.0f, -4.0f), QuatFromAxisAngle(vec3(1.0f, 2.0f, 3.0f), 1.0f));
	descr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
	descr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);

	m_entities.push_back(addBox(m_world, descr, material));

	ShapeDescription shapeDescr;
	shapeDescr.shapeType = ShapeType::CAPSULE;
	shapeDescr.capsule.r = 0.5f;
	shapeDescr.capsule.c1 = vec3(0.0f, 0.5f, 0.0f);
	shapeDescr.capsule.c2 = vec3(0.0f, -0.5f, 0.0f);

	gCapsule = m_world->createShape(shapeDescr);

	ColliderDescription colliderDescr;
	colliderDescr.material = material;
	colliderDescr.transform = Transform(vec3(0, 0, 0), QuatFromAxisAngle(vec3(1, 0, 0), 0));
	colliderDescr.shape = gCapsule;
	colliderDescr.isSensor = false;

	descr.transform.p.x += 3.0f;

	Collider* c = m_world->createCollider(colliderDescr);
	Body* b = m_world->createBody(descr);
	b->addCollider(c);
	m_entities.push_back(new Entity(b, vec3(0, 0, 1)));



	// spherestack
	{

		shapeDescr.shapeType = ShapeType::SPHERE;
		shapeDescr.sphere.r = 1.0f;
		shapeDescr.sphere.c = vec3(0, 0, 0);
		gSphere = m_world->createShape(shapeDescr);

		colliderDescr.shape = gSphere;

		descr.transform.p.x += 3.0f;
		Collider* c = m_world->createCollider(colliderDescr);
		Body* b = m_world->createBody(descr);
		b->addCollider(c);
		m_entities.push_back(new Entity(b, vec3(0, 0, 1)));




		descr.transform = Transform(vec3(-10.0f, 3.0f, -10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));

		for (int i = 0; i < 4; ++i)
		{
			Collider* c = m_world->createCollider(colliderDescr);

			Body* b = m_world->createBody(descr);
			b->addCollider(c);
			m_entities.push_back(new Entity(b, vec3(0, 0, 1)));

			descr.transform.p.y += 3.0f;
		}
	}

	colliderDescr.shape = gCapsule;
	descr.transform = Transform(vec3(-10.0f, 3.0f, 10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));

	for (int i = 0; i < 4; ++i)
	{
		Collider* c = m_world->createCollider(colliderDescr);

		Body* b = m_world->createBody(descr);
		b->addCollider(c);
		m_entities.push_back(new Entity(b, vec3(0, 0, 1)));

		descr.transform.p.y += 3.0f;
	}

	
	//pyramid
	descr.transform = Transform(vec3(10.0f, 0.0f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 0.0f, -2.5f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 0.0f, +2.5f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));

	descr.transform = Transform(vec3(10.0f, 2.125f, -1.25f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 2.125f, +1.25f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));

	descr.transform = Transform(vec3(10.0f, 4.25f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));






	descr.transform = Transform(vec3(-10.0f, 3.0f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));

	
	for (int i = -1; i <= 1; ++i)
	{
		for (int j = -1; j <= 1; ++j)
		{
			m_entities.push_back(addFloor(m_world, material, vec3(i *60, 0, j*60)));

		}
	}
	m_entities.push_back(addSlope(m_world, Transform(vec3(0, 0, -4), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f)), material));
	m_entities.push_back(addSlope(m_world, Transform(vec3(0, 0, 4), QuatFromAxisAngle(vec3(0.0f, 1.0f, 0.0f), ong_PI)), material));
	
	descr.transform = Transform(vec3(-3.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	descr.transform = Transform(vec3(0.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(3.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	m_entities.push_back(addBox(m_world, descr, material));

	
	//player
	Transform t = Transform(vec3(0.0f, 8.0f, -10.0f), QuatFromAxisAngle(vec3(1, 0, 0), 0));
	m_player = addPlayer(m_world, t);
	m_entities.push_back(m_player);



	static int gNumSteps = 0;
	int numSteps = 0;
	for (int i = 0; i < numSteps; ++i)
	{
		printf("%d\n", gNumSteps);
		m_world->step(1.0f / 60.0f);
		++gNumSteps;
	}


}
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
//    cur_global_init()
    // 定义重力加速
    b2Vec2 gravity;
    
    // 设定垂直方向的加速度,这里采用真实的物理数据
    gravity.Set(0.0f, -9.8f);
    
    // 使用刚刚定义好的加速度生成物理世界对象,这样世界中的所有对象都会受到重力加速度的影响
    phyWorld = new b2World(gravity);
    
    // 物理世界的对象都参与碰撞检测,无休眠对象
    //phyWorld->SetAllowSleeping(false);
    
    //连续碰撞检测,避免发生物体穿过另一个物体的事件
    //phyWorld->SetContinuousPhysics(true);
    
    // 设置碰撞监听器
    listener = new ContactListener();
    phyWorld->SetContactListener(listener);
    
    addFloor();
    addRect(5, 3, b2_dynamicBody);
    scheduleUpdate();
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width*2 ,
                                60));
    
    closeItem->setScale(2);
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    
    this->addChild(menu, 1);
    
    auto left = MenuItemImage::create(
                                           "b1.png",
                                           "b1.png",
                                           CC_CALLBACK_1(HelloWorld::menuLeftCallback, this));
    left->setPosition(Vec2(50,60));
    left->setScale(2);
    auto leftMenu = Menu::create(left, NULL);
    leftMenu->setPosition(Vec2::ZERO);
    
    this->addChild(leftMenu, 1);
    
    auto right = MenuItemImage::create(
                                      "f1.png",
                                      "f1.png",
                                      CC_CALLBACK_1(HelloWorld::menuRightCallback, this));
    
    right->setPosition(Vec2(100,60));
    
    auto rightMenu = Menu::create(right, NULL);
    rightMenu->setPosition(Vec2::ZERO);
    right->setScale(2);
    
    this->addChild(rightMenu, 1);
    inum = 1;
    auto changeShield = MenuItemImage::create(
                                       "changeShield.png",
                                       "changeShield.png",
                                       CC_CALLBACK_1(HelloWorld::menuChangeShieldCallback, this));
    
    changeShield->setPosition(Vec2(100,200));
    
    auto changeShieldMenu = Menu::create(changeShield, NULL);
    changeShieldMenu->setPosition(Vec2::ZERO);
    //changeShield->setScale(2);
    
    this->addChild(changeShieldMenu, 1);
    
    auto changeWeapon = MenuItemImage::create(
                                       "changeWeapon.png",
                                       "changeWeapon.png",
                                       CC_CALLBACK_1(HelloWorld::menuChangeWeaponCallback, this));
    
    changeWeapon->setPosition(Vec2(200,200));
    
    auto changeWeaponMenu = Menu::create(changeWeapon, NULL);
    changeWeaponMenu->setPosition(Vec2::ZERO);
    //changeWeapon->setScale(2);
    
    this->addChild(changeWeaponMenu, 1);
    
    spineNode = SpineNode::createWithFile("res/spineboy.json", "res/spineboy.atlas");
    
    spineNode->setScale(0.2);
    spineNode->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/4 + origin.y));
    this->addChild(spineNode);
    

    spineSheildNode = SpineNode::createWithFile("res/shield.json", "res/shield.atlas");
    spineSheildNode->setScale(0.2);
    spineSheildNode->setPosition(Vec2(visibleSize.width/2 + origin.x, 0));
    this->addChild(spineSheildNode);
    
    return true;
}
Exemple #10
0
void House::addFloorTop(Scene* scene) {
    floorIndex = floors.size();
    addFloor(scene, floors.size() ? floors.back() : NULL);
    floors.push_back(floorTiles);
    rooms.push_back(list<Room*>());
}