Example #1
0
	bool SnakeLayer::init()
	{
		maximumLength = 100;
		itemsPicked = 0;
		score = 0;
		bonus = 0;
		direction = Point::ZERO;
		speed = 180;

		LayerColor* lc = LayerColor::create(Color4B(0, 0, 0, 210), PX(1.0f), PY(0.8f));
		lc->setPosition(CP(0.5f, 0.5f));
		lc->setAnchorPoint(Point(0.5f, 0.5f));
		lc->ignoreAnchorPointForPosition(false);
		addChild(lc);
		bounds = lc->getBoundingBox();

		LayerColor* scorebg = LayerColor::create(Color4B::BLACK, PX(1.0f), PY(0.1f));
		scorebg->setPosition(Point::ZERO);
		addChild(scorebg);

		addChild(lineGroup = Node::create());
		addChild(bonusGroup = Node::create());
		addChild(itemGroup = Node::create());

		LineNode* line = LineNode::create(CP(0.5f, 0.5f), CP(0.5f, 0.5f));
		lineGroup->addChild(line);

		schedule(schedule_selector(SnakeLayer::considerSpawningBonus), 5.0f);
		scheduleUpdate();

		lblScore = Label::createWithTTF(LS("ScoreColon") + " 0", NORMAL_TTF, 42.0f);
		lblScore->setColor(Color3B::WHITE);
		lblScore->setPosition(CP(0.5f, 0.05f));
		//lblScore->enableGlow(Color4B::BLACK);
		//lblScore->enableShadow(Color4B::BLACK, Size::ZERO, 4);
		addChild(lblScore);

		string instruction = LS("SNAKE_INSTRUCTIONS");
		lblInstruction = Label::createWithTTF(instruction, NORMAL_TTF, 48.0f);
		lblInstruction->setPosition(CP(0.5f, 0.5f));
		lblInstruction->setHorizontalAlignment(TextHAlignment::CENTER);
		lblInstruction->setColor(Color3B::WHITE);
		lblInstruction->enableGlow(Color4B::RED);
		lblInstruction->runAction(RepeatForever::create(
			Sequence::createWithTwoActions(ScaleTo::create(1.0f, 1.1f),
			ScaleTo::create(1.0f, 1.0f))));
		addChild(lblInstruction);
		instructionVisible = true;

		return true;
	}
Example #2
0
void HelpScene::onTouchMoved(Touch* t, Event*)
{
    if (touched && t->getID() == touchId)
    {
        Point position = t->getLocationInView();
        position = Director::getInstance()->convertToGL(position);
        Size winSize = Director::getInstance()->getWinSize();
        float newY = (t->getLocation() - t->getStartLocation()).y + initY;
        if (newY < 0) newY = 0;
        if (newY > (PY(bounds)+PY(1.0f))) newY = (PY(bounds)+PY(1.0f));
        getChildByTag(1)->setPositionY(newY);
        touchY = t->getLocation().y;
    }
}
Example #3
0
void HelpScene::onTouchEnded(Touch* t, Event*)
{
    unschedule(schedule_selector(HelpScene::updateLastY));
    touched = false;
    float targetY = getChildByTag(1)->getPositionY() + 2.0f * (t->getLocation().y - lastY);
    if (targetY < 0) targetY = 0;
    if (targetY > (PY(bounds)+PY(1.0f))) targetY = (PY(bounds)+PY(1.0f));
    if (targetY != getChildByTag(1)->getPositionY())
    {
        getChildByTag(1)->runAction(
            EaseIn::create(MoveTo::create(1.0f, Point(0, targetY)), 0.2f));
    }

    log(nToString(targetY / PY(1.0f)));
    //btnBackPressed(this);
}
Example #4
0
	void ScoreText::initWithScore(int score, Point pos, Color3B col)
	{
		setPosition(pos);

		Label* label = Label::createWithBMFont(MATH_FNT, "+" + nToString(score));//, NORMAL_TTF, 46.0f);
		//label->setScale(1.1f);
		label->setHorizontalAlignment(TextHAlignment::CENTER);
		addChild(label);
		
		label->setOpacity(0);
		label->runAction(Sequence::create(
			FadeIn::create(0.3f),
			DelayTime::create(0.8f),
			FadeOut::create(0.3f),
			NULL));
/*
		col.r *= 0.5;
		col.g *= 0.5;
		col.b *= 0.5;*/

		label->setColor(Color3B::WHITE);
		label->disableEffect();

		label->runAction(TintTo::create(1.0f, col.r, col.g, col.b));
		label->runAction(MoveBy::create(1.0f, Point(0, PY(0.05f))));
		
		//label->enableGlow(Color4B(col));
		//label->enableShadow();

		scheduleOnce(schedule_selector(ScoreText::collect), 3.0f);
	}
Example #5
0
	void BlobLayer::updatePhysics(float dt)
	{
		const int velocityIterations = 1;
		const int positionIterations = 1;

		ambientForce.y -= dt * 6.0f;
		
		// Instruct the world to perform a single step of simulation. It is
		// generally best to keep the time step and iterations fixed.
		if (state == GameStates::Playing)
			world->Step(dt, velocityIterations, positionIterations);

		for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
		{
			if (b->GetUserData() != NULL) {
				//Synchronize the AtlasSprites position and rotation with the corresponding body
				Node* myActor = (Node*) b->GetUserData();
				auto aabb = myActor->getBoundingBox();
				myActor->setPosition(Point(
					b->GetPosition().x * PTM_RATIO,
					b->GetPosition().y * PTM_RATIO));
				myActor->setRotation(-1 * CC_RADIANS_TO_DEGREES(b->GetAngle()));

				Entity* e = dynamic_cast<Entity*>(myActor);
				if (e)
				{
					auto af = ambientForce;
					if (e->controllable) af *= 2.0f;
					b->ApplyForceToCenter(b2Vec2(af.x * 1400.0f * dt, af.y * dt), true);

					for (auto r : ring)
					{
						b2Vec2 rv = b2Vec2(r.second->getPositionX() / PTM_RATIO, r.second->getPositionY() / PTM_RATIO);
						const float maxPower = 1300.0f;
						b2Vec2 v = rv - b->GetPosition();
						float ir2 = 1.0f / v.LengthSquared();
						v.Normalize();
						float power = min(maxPower, maxPower * ir2);
						if (e->happy) power *= 1.2f;
						if (e->controllable) power *= 1.2f;
						v.x *= power;
						v.y *= power;
						b->ApplyForceToCenter(v, true);
					}

					if (e->getPositionY() > PY(1.0f) - getPositionY() && !e->controllable && !e->active)
					{
						gameOver();
					}
				}
			}
		}
	}
// 12.63 % of time - this can improve
static void
_calc_spans(RGBA_Map_Point *p, Line *spans, int ystart, int yend, int cx, int cy, int cw, int ch)
{
   int i, y, yp;
   int py[4];
   int edge[4][4], edge_num, swapped, order[4];
   FPc uv[4][2], u, v, x, h, t;
   DATA32 col[4];
   
#if 1 // maybe faster on x86?
   for (i = 0; i < 4; i++) py[i] = p[i].y >> FP;
# define PY(x) (py[x])   
#else
# define PY(x) (p[x].y >> FP) 
#endif
   
   if ((PY(0) == PY(1)) && (PY(0) == PY(2)) && (PY(0) == PY(3)))
     {
        int leftp, rightp;
        int nocol = 1;
        
        leftp = rightp = 0;
        for (i = 1; i < 4; i++)
          {
             if (p[i].x < p[leftp].x) leftp = i;
             if (p[i].x > p[rightp].x) rightp = i;
             if (p[i].col != 0xffffffff) nocol = 0;
          }
        for (y = ystart; y <= yend; y++)
          {
             yp = y - ystart;
             if (y == PY(0))
               {
                  i = 0;
                  spans[yp].span[i].x1 = p[leftp].x >> FP;
                  spans[yp].span[i].o1 = p[leftp].x;
                  spans[yp].span[i].u[0] = p[leftp].u;
                  spans[yp].span[i].v[0] = p[leftp].v;
                  spans[yp].span[i].col[0] = p[leftp].col;
                  spans[yp].span[i].x2 = p[rightp].x >> FP;
                  spans[yp].span[i].o2 = p[rightp].x;
                  spans[yp].span[i].u[1] = p[rightp].u;
                  spans[yp].span[i].v[1] = p[rightp].v;
                  spans[yp].span[i].col[1] = p[rightp].col;
                  if ((spans[yp].span[i].x1 >= (cx + cw)) ||
                      (spans[yp].span[i].x2 < cx))
                    spans[yp].span[i].x1 = -1;
                  else
                    {
                       _limit(&(spans[yp].span[i]), cx, cx + cw, nocol);
                       i++;
                       spans[yp].span[i].x1 = -1;
                    }
               }
             else
Example #7
0
bool HelpScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    touched = false;
    Size visibleSize = Director::getInstance()->getVisibleSize();

    //setKeyboardEnabled(true);
    auto keyboard = EventListenerKeyboard::create();
    keyboard->onKeyReleased = CC_CALLBACK_2(HelpScene::onKeyReleased, this);
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyboard, this);

    //setTouchEnabled(true);
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(HelpScene::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(HelpScene::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(HelpScene::onTouchEnded, this);
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);

    addChild(BackgroundWidget::create("bg", Color3B(20, 20, 80)));

    addChild(Vignette::create());

    auto layer = Layer::create();
    layer->setTag(1);
    addChild(layer);

    auto bg = LayerColor::create(C4Fto4B(0.12f, 0.02f, 0.15f, 1.0f), visibleSize.width, visibleSize.height);
    bg->setPositionY(PY(0.82f));
    addChild(bg);

    auto hooker = TopAnchor::create();
    addChild(hooker, 1);
    auto pMenu = Menu::create();
    pMenu->setPosition(Point::ZERO);
    //hooker->addChild(bg);
    hooker->addChild(pMenu);

    auto txt1 = Label::createWithTTF(LS("HowToPlay"), NORMAL_TTF, 48.0f);
    txt1->setPosition(VCP(0.22f, 0.935f));
    txt1->setAnchorPoint(Point(0, 0.5f));
    txt1->setHorizontalAlignment(TextHAlignment::LEFT);
    txt1->setColor(Color3B::WHITE);

    hooker->addChild(txt1);
    //addChild(txt1, 5);

    auto btnBack = MAKEBUTTON("btnBackBlackUp", "btnBackBlackDn", HelpScene::btnBackPressed);
    pMenu->addChild(btnBack, 2);
    btnBack->setPosition(VCP(0.03f, 0.935f));
    btnBack->setAnchorPoint(Point(0, 0.5f));

    auto playerLayer = makeItem("manRt1", LS("HelpPlayer"), '@');
    playerLayer->setPosition(CP(0.2f, 0.80f));
    layer->addChild(playerLayer);

    auto robotLayer = makeItem("robot", LS("HelpRobot"), 'R');
    robotLayer->setPosition(CP(0.2f, 0.50f));
    robotLayer->SPRITEREF->runAction(
        RepeatForever::create(Sequence::createWithTwoActions(
                                  ScaleTo::create(1.0f, 1.0f), ScaleTo::create(1.0f, 0.9f)
                              )));
    layer->addChild(robotLayer);

    auto holeLayer = makeItem("hazard", LS("HelpBlackhole"), '!');
    holeLayer->setPosition(CP(0.2f, 0.10f));
    holeLayer->SPRITEREF->runAction(RepeatForever::create(RotateBy::create(2.0f, 365.0f)));
    holeLayer->SPRITEREF->runAction(RepeatForever::create(Sequence::createWithTwoActions(
                                        TintTo::create(0.5f, 210, 255, 255), TintTo::create(0.5f, 255, 0, 0)
                                    )));
    layer->addChild(holeLayer);

    auto starLayer = makeItem("dronesGoal", LS("HelpStar"), 'X');
    starLayer->setPosition(CP(0.2f, -0.10f));
    starLayer->SPRITEREF->runAction(RepeatForever::create(Sequence::createWithTwoActions(
                                        TintTo::create(1.0f, 255, 255, 255), TintTo::create(1.0f, 255, 255, 0)
                                    )));
    starLayer->SPRITEREF->runAction(RepeatForever::create(Sequence::createWithTwoActions(
                                        DelayTime::create(10.0f), RotateBy::create(1.0, -360)
                                    )));
    layer->addChild(starLayer);

    auto gemLayer = makeItem("gem", LS("HelpGem"), 'g');
    gemLayer->setPosition(CP(0.2f, -0.30f));
    layer->addChild(gemLayer);

    auto creditsY = -0.20f;

    auto creditsLayer3 = makeText(LS("HelpConclusion"), 38.0f);
    creditsLayer3->setPosition(CP(0.5f, creditsY-0.3f));
    creditsLayer3->setHorizontalAlignment(TextHAlignment::CENTER);
    creditsLayer3->setAnchorPoint(Point(0.5f, 1.0f));
    layer->addChild(creditsLayer3);

    auto facebook = MAKESPRITE("facebook");
    facebook->setPosition(CP(0.5f, creditsY - 0.6f));
    layer->addChild(facebook);
    return true;
}
Example #8
0
void lw_object_show(const lwObject *lw_object)
{
  int i,j;
  int prev_index_cnt = -1;
  int prev_material  = -1;
  GLfloat prev_nx = 0;
  GLfloat prev_ny = 0;
  GLfloat prev_nz = 0;

  for (i=0; i<lw_object->face_cnt; i++) {
    GLfloat ax,ay,az,bx,by,bz,nx,ny,nz,r;
    const lwFace *face = lw_object->face+i;

    /* ignore faces with less than 3 points */
    if (face->index_cnt < 3)
      continue;

    /* calculate normal */
    ax = PX(1) - PX(0);
    ay = PY(1) - PY(0);
    az = PZ(1) - PZ(0);

    bx = PX(face->index_cnt-1) - PX(0);
    by = PY(face->index_cnt-1) - PY(0);
    bz = PZ(face->index_cnt-1) - PZ(0);

    nx = ay * bz - az * by;
    ny = az * bx - ax * bz;
    nz = ax * by - ay * bx;

    r = sqrt(nx*nx + ny*ny + nz*nz);
    if (r < 0.000001) /* avoid division by zero */
      continue;
    nx /= r;
    ny /= r;
    nz /= r;

    /* glBegin/glEnd */
    if (prev_index_cnt != face->index_cnt || prev_index_cnt > 4) {
      if (prev_index_cnt > 0) glEnd();
      prev_index_cnt = face->index_cnt;
      switch (face->index_cnt) {
      case 3:
    glBegin(GL_TRIANGLES);
    break;
      case 4:
    glBegin(GL_QUADS);
    break;
      default:
    glBegin(GL_POLYGON);
      }
    }

    /* update material if necessary */
    if (prev_material != face->material) {
      prev_material = face->material;
      glColor3f(lw_object->material[face->material].r,
        lw_object->material[face->material].g,
        lw_object->material[face->material].b);
    }

    /* update normal if necessary */
    if (nx != prev_nx || ny != prev_ny || nz != prev_nz) {
      prev_nx = nx;
      prev_ny = ny;
      prev_nz = nz;
      glNormal3f(nx,ny,nz);
    }

    /* draw polygon/triangle/quad */
    for (j=0; j<face->index_cnt; j++)
      glVertex3f(PX(j),PY(j),PZ(j));

  }

  /* if glBegin was called call glEnd */
  if (prev_index_cnt > 0)
    glEnd();
}