示例#1
0
bool Fireball::update(int deltaMS)
{
	position_ += velocity_ * (deltaMS / 1000.0f);

	bool movedOffScreen = was_on_screen_ && !onScreen();
	was_on_screen_ = onScreen();
	return movedOffScreen;
}
示例#2
0
long Light::update (void) {

	if (!getFlag(OBJECT_FLAG_DONE)) {
		//----------------------------------
		//-- Always force position altitude 'cause set every frame.
		position.z += ((LightTypePtr)getObjectType())->altitudeOffset;
		setPosition(position);
	
		if (getFlag(OBJECT_FLAG_JUSTCREATED)) {
			setFlag(OBJECT_FLAG_JUSTCREATED, false);
			setFlag(OBJECT_FLAG_TANGIBLE, false);
		}
	
#ifdef USE_LIGHT_APPEARANCE
		//-----------------------------------------
		// Light is NEVER Done.  Unless its done!
		bool inView = onScreen();
		lightAppearance->setInView(inView);
		long result = lightAppearance->update();
		if (!result && ((LightTypePtr)getObjectType())->oneShotFlag)
			setFlag(OBJECT_FLAG_DONE, true);
#endif
	}

	return (true);
}
示例#3
0
void GameSession::onFrame(float elapsedTime)
{
    // update units
    mat4 vpMatrix = Root::shared().getScene()->getCamera()->getVPMatrix();
    for(unsigned int i = 0; i < factions.size(); ++i)
    {
        for(list<Unit*>::iterator it = factions[i]->getUnits().begin();
                it != factions[i]->getUnits().end(); )
        {
            if((*it)->obsolete() && (*it)->readyToDelete()) {
                delete *it;
                it = factions[i]->getUnits().erase(it);
            }
            else {
                vec4 onScreen((*it)->getObject()->getPosition(), 1.0);
                onScreen = vpMatrix * onScreen;
                onScreen.x /= onScreen.w;
                onScreen.y /= onScreen.w;
                (*it)->setScreenPosition(vec2(onScreen.x, onScreen.y));

                (*it)->update(elapsedTime);
                ++it;
            }
        }
    }
}
示例#4
0
void drawAllFeatures()
{
    //features drawn here
    for (unsigned i = 0; i < allFeatures.size(); i++) {
       if(!onScreen(allFeatures[i].getboundary())) continue;
       if(!(allFeatures[i].getboundary().area()/trueScreen.area() > drawFeatureThreshold)) continue;
        drawFeature(i,0);
    }
}
示例#5
0
void Light::render (void) {

	if (g_gamePaused)
		onScreen();

	if (!getFlag(OBJECT_FLAG_JUSTCREATED) && (windowsVisible == turn) && !getFlag(OBJECT_FLAG_DONE)) {
#ifdef USE_LIGHT_APPEARANCE
		lightAppearance->render(LIGHT_DEPTH_FIXUP);
#endif
	}
}
示例#6
0
void BigEnemy::move(GameLevel& context) {
  // moving
  if(grazed() && x > SCREEN_WIDTH - 5) {
    x += -3; // submarine found
  }
  else if(timer % 5 == 0) { // -0.2
    --x;
  }

  // frame out
  if(x + bitmapCruEnemy0[0] < 0) {
    inactivate();
  }

  // setting sonar reaction
  context.echo.add(x, y, y+H);

  // firing bullet
  if(x < SCREEN_WIDTH - W / 2) {
    if(!onScreen()) {
      timer = 0;  // in order to sync fire cycle
      state |= ON_SCREEN_MASK;
    }
    const byte d = context.difficulty();
    if(timer == 0 || (d >= 60 && timer == 40)) {  // freq up when 60 and over
      const char bulletY     = y + bitmapCruEnemy0[1] / 2;
      const char bulletSpeed = (d >= 80) ? BULLET_TYPE2_SPD : BULLET_TYPE0_SPD;
      const char bulletType  = (d >= 80) ? 2 : 0;
      context.fireBullet(x, bulletY, context.getFutureSubmarineAngle(x, bulletY, bulletSpeed), bulletType);
    }
  }

  // updating timer
  static const byte PERIOD = 150;
  timer = (timer + 1) % PERIOD;
}
示例#7
0
bool HelloWorld::onScreen(Vec2 pos, Vec2 margin)
{
    return onScreen(pos, Vec4(margin.x, margin.y, margin.x, margin.y));
}
示例#8
0
bool HelloWorld::onScreen(Vec2 pos)
{
    return onScreen(pos, Vec4::ZERO);
}
示例#9
0
///all screen move functions should use this
void HelloWorld::lookAt(Vec2 pos)
{
    Vec2 visible = Director::getInstance()->getVisibleSize();
    this->setPosition(-1*(pos - visible/2));
    protractor->setPosition(lookingAt());
    notifier->setPosition(lookingAt());

    //draw grid
    Vec2 botleft = screenspaceToWorldspace(Vec2::ZERO);
    Vec2 topright = screenspaceToWorldspace(visible);
    Vec2 drawSpaceBotLeft = botleft - GRID_LABEL_SPACING;
    Vec2 drawSpaceTopRight = topright + GRID_LABEL_SPACING;
	DrawNode* gridSprite = (DrawNode*)getChildByName("gridSprite");
    if (gridSprite)
    {
        gridSprite->clear();
        std::vector<std::string> toRemove;
        for (auto child : gridSprite->getChildren())
        {
            if (!onScreen(child->getPosition(), Vec2(GRID_LABEL_SPACING)))
                toRemove.push_back(child->getName());
        }
        for (auto name : toRemove)
        {
            gridSprite->removeChildByName(name);
        }
    }
    else
    {
        gridSprite = DrawNode::create();
        gridSprite->setName("gridSprite");
        addChild(gridSprite, 0);
    }
    //vertical lines
    for (int i= drawSpaceBotLeft.x; i<drawSpaceTopRight.x; i++)
    {
        if(i % (int)GRID_SPACING.x)
            continue;
        gridSprite->drawSegment(Vec2(i, drawSpaceBotLeft.y), Vec2(i, drawSpaceBotLeft.y+visible.y+2*GRID_LABEL_SPACING.y),
                                GRID_LINE_THICKNESS, Color4F(1,1,1,0.1));
        if(!(i % (int)GRID_LABEL_SPACING.x))
        {
            std::string txt = std::to_string(i);
            auto label = gridSprite->getChildByName("v" + txt);
            if (!label)
            {
                label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE);
                label->setName("v" + txt);
                gridSprite->addChild(label);
            }
            label->setPosition(Vec2(i, topright.y - GRID_LABEL_SIZE * 2));
        }
    }
    //horizontal lines
    for (int i= drawSpaceBotLeft.y; i<drawSpaceTopRight.y; i++)
    {
        if(i % (int)GRID_SPACING.y)
            continue;
        gridSprite->drawSegment(Vec2(drawSpaceBotLeft.x, i), Vec2(drawSpaceBotLeft.x+visible.x + 2 * GRID_LABEL_SPACING.x, i),
                                GRID_LINE_THICKNESS, Color4F(1,1,1,0.1));   
        if(!(i % (int)GRID_LABEL_SPACING.y))
        {
            std::string txt = std::to_string(i);
            auto label = gridSprite->getChildByName("h" + txt);
            if (!label)
            {
                label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE);
                label->setName("h" + txt);
                gridSprite->addChild(label);
            }
            label->setPosition(Vec2(botleft.x + GRID_LABEL_SIZE * 2, i));
        }
    }
    repaintCursor();
    Commorose* c = (Commorose*)commorose;
    c->setPosition(screenspaceToWorldspace(c->getPositionOnScreen()));
}