bool BreakBlocksScene::init()
{
    if (!CCLayer::init())
    {
        return false;
    }
    
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
    
    auto size = CCDirector::sharedDirector()->getWinSize();
    auto center = ccp(size.width * 0.5f, size.height * 0.5f);
    
    this->presenter = new BreakBlocksPresenter();
    this->presenter->initialize(0.0f, 0.0f, size.width, size.height);
    
    auto ball = this->presenter->getBall();
    ball->addListener(this->ballChangedHandler);
    
    this->ball = CCSprite::create("ball.png");
    this->ball->setPosition(ball->getCenterX(), ball->getCenterY());
    this->addChild(this->ball);
    
    auto bar = this->presenter->getBar();
    bar->addListener(this->barChangedHandler);
    
    this->bar = CCSprite::create("bar.png");
    this->bar->setPosition(bar->getCenterX(), bar->getCenterY());
    this->addChild(this->bar);
    
    auto blockTexture = CCTextureCache::sharedTextureCache()->addImage("block.png");
    for (int i = 0; i < this->presenter->getBlockCount(); i++)
    {
        auto b = this->presenter->getBlock(i);
        b->addListener(this->blockChangedHandler);
        
        auto block = CCSprite::createWithTexture(blockTexture);
        block->setPositionX(b->getCenterX());
        block->setPositionY(b->getCenterY());
        block->setTag(b->getId());
        this->blocks.push_back(block);
        this->addChild(block);
    }
    
    this->label = CCLabelTTF::create("", "Thonburi", 50.0f);
    this->label->setPosition(center);
    this->addChild(this->label, 100);
    
    this->schedule(schedule_selector(BreakBlocksScene::update));
    
    return true;
}
Ejemplo n.º 2
0
//==========================================================
// Box collision
// Called by collides()
// Returns: Returns the side that it collided with
// Left = 1;
// Right = 2;
// Top = 3;
// Bottom = 4;
//==========================================================
bool Entity::collideBox(Entity &ent, VECTOR2 &collision)
{
	if (!active || !ent.getActive())
		return false;

	if ((getCenterX() + edge.right*getScale() >= ent.getCenterX() + ent.getEdge().left*ent.getScale()) &&
		(getCenterX() + edge.left*getScale() <= ent.getCenterX() + ent.getEdge().right*ent.getScale()) &&
		(getCenterY() + edge.bottom*getScale() >= ent.getCenterY() + ent.getEdge().top*ent.getScale()) &&
		(getCenterY() + edge.top*getScale() <= ent.getCenterY() + ent.getEdge().bottom*ent.getScale()))
	{
		// collision = *ent.getCenter() - *getCenter();
		return 1;
	}
	return 0;
}
Ejemplo n.º 3
0
	void FractalTexture::create() {
		if(glIsTexture(texture.id)) glDeleteTextures(1, &texture.id); //cleaning gl memory up
		m_iMaxIterations = (long)((double)m_iStdMaxIterations * 1.0); //todo?
		m_dInvMaxIterations = 1.0 / (m_iMaxIterations+0.0001);
		const double winv = 1.0/(texture.width -1);
		const double hinv = 1.0/(texture.height-1);
		util::timeDiff();
		for (int x = 0; x < texture.width; ++x) {
			for (int y = 0; y < texture.height; ++y) {
#ifdef ROE_FRACTAL_GMP_USE_C
				mpf_set_d(m_xPos, x*winv);
				mpf_set_d(m_yPos, y*hinv);
				mpf_mul(m_xPos, m_xPos, m_width);
				mpf_mul(m_yPos, m_yPos, m_height);
				mpf_add(m_xPos, m_xUpLt, m_xPos);
				mpf_sub(m_yPos, m_yUpLt, m_yPos);
#else
				m_xPos = m_xUpLt + (x*winv)*m_width;
				m_yPos = m_yUpLt - (y*hinv)*m_height;
#endif
				computeColor(&(texture.data[((texture.height-1-y)*texture.width+x)*texture.bpp]));
			}
		}
		cout << "dt: " << util::timeDiff() << endl;
		cout << getCenterX() << endl;
		cout << getCenterY() << endl;
		cout << getZoomW() << endl;
		updateMipmaps();
		Texture::loadTextureIntoGL(&texture);
	}
Ejemplo n.º 4
0
bool MapDraw::isVisible(short x, short y)
{
  int distFromCenter = 
    getGrid()->distanceBetween(x, y, getCenterX(), getCenterY());

  if (distFromCenter < (GRID_SIZE - 2 ))
    return true;
  else
    return false;
/*
// Come on Owen, you have their X / Y.

  // out of array bounds.
  if ((x<0) || (y < 0) || (y>=DEPTH) || (x>=WIDTH))
    return false;

  float pos = positionY( y );
  if (fabs(pos) > (GRID_SIZE-2))
    return false;

  pos = positionX( x );
  if (fabs(pos) > (GRID_SIZE-2))
    return false;
  return true;
*/
}
Ejemplo n.º 5
0
void BossEntity::draw(Rectangle* view, Graphics* g)
{
    if(active)
    {
        if(image != NULL)
            image->draw(getCenterX() - getWidth()/2 - view->getX(), getCenterY() - getHeight()/2 - view->getY(), g);
    }
}
Ejemplo n.º 6
0
/**************************************
Debug Function.
***************************************/
void Camera::debug(){
    system("clear");
    cout << " Eye:    " << getEyeX() << "  " << getEyeY() << "  " << getEyeZ() << endl;
    cout << " Center: " << getCenterX() << "  " << getCenterY() << "  " << getCenterZ() << endl;
    cout << " Up:     " << getUpX() << "  " << getUpY() << "  " << getUpZ() << endl;
    cout << endl;
    cout << " Perspective: " << getFovy() << "  " << getAspect() << "  " << getZNear() << "  " << getZFar() << endl;
}
Ejemplo n.º 7
0
void Vehicle::moveUp(float coeff,int h,int l) {
    float deca=(int)	(speed * coeff);
    angle=270;
    if((int)(getCenterY() - deca - longueur/2)>0) {
        y= y - deca;

    }

}
Ejemplo n.º 8
0
//=============================================================================
// Axis aligned bounding box collision detection method
// Called by collision()
// Post: returns true if collision, false otherwise
//       sets collisionVector if collision
//=============================================================================
bool Entity::collideBox(Entity &ent, VECTOR2 &collisionVector)
{
    // if either entity is not active then no collision may occcur
    if (!active || !ent.getActive())
        return false;

    // Check for collision using Axis Aligned Bounding Box.
    if( (getCenterX() + edge.right*getScale() >= ent.getCenterX() + ent.getEdge().left*ent.getScale()) && 
        (getCenterX() + edge.left*getScale() <= ent.getCenterX() + ent.getEdge().right*ent.getScale()) &&
        (getCenterY() + edge.bottom*getScale() >= ent.getCenterY() + ent.getEdge().top*ent.getScale()) && 
        (getCenterY() + edge.top*getScale() <= ent.getCenterY() + ent.getEdge().bottom*ent.getScale()) )
    {
        // set collision vector
        collisionVector = *ent.getCenter() - *getCenter();
        return true;
    }
    return false;
}
Ejemplo n.º 9
0
float MapDraw::positionY(short y)
{
  // normal bounds.
  if ( ( y < (getCenterY()+GRID_SIZE)) && ( y > (getCenterY()-GRID_SIZE)))
    return ((getCenterY() - y));
  // over bounds.
  else if ( ((DEPTH-1) < (getCenterY() + GRID_SIZE)) && ( y < ((getCenterY() + GRID_SIZE)%DEPTH)))
    return ((getCenterY() - (y+DEPTH)));
  // below bounds.
  else if (  ((getCenterY()-GRID_SIZE) < 0) && (y > (getCenterY()-GRID_SIZE+DEPTH)))
    return (getCenterY() - (y-DEPTH));

  //TODO: throw exception?
  return 1215;
}
Ejemplo n.º 10
0
void Vehicle::moveBack(float coeff,int h,int l) {
    int deca=(int)(speed * coeff);
    angle=90;
    int temp = getCenterY()+deca+longueur/2;
    if(temp+5 < l) {
        y=y + deca;
    }


}
Ejemplo n.º 11
0
Projectile* Vehicle::fire(int _dx,int _dy) {
    int _x=getCenterX();
    int _y=getCenterY();
    if(used) {
        Obus* bul=new Obus(_x,_y,_dx,_dy);
        return bul;
    } else {
        return NULL;
    }

}
Ejemplo n.º 12
0
void Boss::vectorTrack()//We're going to want to change this so that it takes an argument that is what we want to track
{
	VECTOR2 vel = getCenterPoint()-targetEntity.getCenterPoint();
	if(vel.x == 0 && vel.y==0)
		return;
	VECTOR2* foo = D3DXVec2Normalize(&vel, &vel);
	setVelocity(-vel);
	setRadians((atan((targetEntity.getCenterY()-getCenterY())/(targetEntity.getCenterX()-getCenterX())))-PI/2);
	if(targetEntity.getCenterX()>getCenterX())
		setRadians(getRadians()+PI);
}
Ejemplo n.º 13
0
//=============================================================================
// Force of gravity on this entity from other entity
// Adds the gravitational force to the velocity vector of this entity
// force = GRAVITY * m1 * m2 / r*r
//                    2              2
//  r*r  =   (Ax - Bx)   +  (Ay - By)
//=============================================================================
void Entity::gravityForce(Entity *ent, float frameTime)
{
    // if either entity is not active then no gravity effect
    if (!active || !ent->getActive())
        return ;

    rr = pow((ent->getCenterX() - getCenterX()),2) + 
            pow((ent->getCenterY() - getCenterY()),2);
    force = gravity * ent->getMass() * mass/rr;

    // --- Using vector math to create gravity vector ---
    // Create vector between entities
    VECTOR2 gravityV(ent->getCenterX() - getCenterX(),
                        ent->getCenterY() - getCenterY());
    // Normalize the vector
    Graphics::Vector2Normalize(&gravityV);
    // Multipy by force of gravity to create gravity vector
    gravityV *= force * frameTime;
    // Add gravity vector to moving velocity vector to change direction
    velocity += gravityV;
}
Ejemplo n.º 14
0
void Turret::logic(Level* level)
{
	mFrameCount++;
	if(mFrameCount%60 == 0)
	{
		float speed = 1.5;
		float shootingArc = (M_PI*(1/4.0f));
		float leftArc = M_PI - shootingArc;
		float angle = M_PI/2.0f;
		
		if(mShots <= 1) {
				if(mDirection == LEFT) angle += M_PI;
				if(mDirection == DOWN) angle -= M_PI/2.0f;
				if(mDirection == UP) angle += M_PI/2.0f;
				float xSpeed=std::sin(angle)*speed, ySpeed=std::cos(angle)*speed;

				level->addEntity(new EnemyBullet(getCenterX(), getCenterY(), xSpeed, ySpeed, 1, angle));

		} else {
			for(int i=0; i<mShots; i++)
			{
				angle = shootingArc*(i/((float)(mShots-1)));
				angle += leftArc/2.0f;
				if(mDirection == LEFT) angle += M_PI;
				if(mDirection == DOWN) angle -= M_PI/2.0f;
				if(mDirection == UP) angle += M_PI/2.0f;
				float xSpeed=std::sin(angle)*speed, ySpeed=std::cos(angle)*speed;

				level->addEntity(new EnemyBullet(getCenterX(), getCenterY(), xSpeed, ySpeed, 1, angle));
			}
		}

	}

	if (getY() + getHeight() + 64 < level->getScrollY())
	{
		mIsToBeDeleted = true;
	}
}
Ejemplo n.º 15
0
//==========================================================
// Force of gravity on this entity
// Calculated by F = mass * acceleration (gravity)
// Using that information creates an always downward force
//	to the Entity
//==========================================================
void Entity::gravityForce(float frameTime)
{
	if (!active)
		return;

	force = gravity * mass;
	VECTOR2 gravityV(getCenterX(), 0-getCenterY());

	Graphics::Vector2Normalize(&gravityV);

	gravityV *= force *frameTime;
	velocity += gravityV;
}
Ejemplo n.º 16
0
void Camera::film(){

    int currentTime = glutGet(GLUT_ELAPSED_TIME);
    int timeInterval = 5;//currentTime - previousTime;

    float tmpEyeX, tmpEyeY, tmpEyeZ;
    tmpEyeX = sin(mouseDirection[1]*M_PI/180)*sin(mouseDirection[0]*M_PI/180);
    tmpEyeZ = sin(mouseDirection[1]*M_PI/180)*cos(mouseDirection[0]*M_PI/180);
    tmpEyeY = cos(mouseDirection[1]*M_PI/180);

    if(move[FORWARD]){
        setEyeX(getEyeX() + (timeInterval * tmpEyeX / 6));
    	setEyeY(getEyeY() + (timeInterval * tmpEyeY / 6));
    	setEyeZ(getEyeZ() + (timeInterval * tmpEyeZ / 6));
    }
    if(move[BACKWARD]){
        setEyeZ( getEyeZ() - (timeInterval * tmpEyeZ / 6));
    	setEyeY( getEyeY() - (timeInterval * tmpEyeY / 6));
    	setEyeX( getEyeX() - (timeInterval * tmpEyeX / 6));
    }
    if(move[LEFT]){
        setEyeX( getEyeX() + (timeInterval * sin((mouseDirection[0]+90)*M_PI/180) / 6));
	    setEyeZ( getEyeZ() + (timeInterval * cos((mouseDirection[0]+90)*M_PI/180) / 6));
    }
    if(move[RIGHT]){
        setEyeX( getEyeX() - (timeInterval * sin((mouseDirection[0]+90)*M_PI/180) / 6));
	    setEyeZ( getEyeZ() - (timeInterval * cos((mouseDirection[0]+90)*M_PI/180) / 6));
    }

    glLoadIdentity();

    setCenterX(getEyeX()+tmpEyeX);
    setCenterY(getEyeY()+tmpEyeY);
    setCenterZ(getEyeZ()+tmpEyeZ);

	gluLookAt(
        getEyeX(),getEyeY(),getEyeZ(),
	    getCenterX(),getCenterY(),getCenterZ(),
	    0.0f, 1.0f,  0.0f
    );

    int xc = glutGet(GLUT_WINDOW_WIDTH)/2;
    int yc = glutGet(GLUT_WINDOW_HEIGHT)/2;

    glutWarpPointer(xc,yc);

    move[0] = false;
    move[1] = false;
    move[2] = false;
    move[3] = false;
}
Ejemplo n.º 17
0
    void Spider::enemyLogic(Room *room)
	{
		mFrameCounter++;
		mStateCounter--;

		if (mHurtTimer > 0)
		{
			mHurtTimer--;
			mY += mDY;
			return;
		}

		int dummy;

		if (solidBelow(room, dummy))
		{
			mDY = (rand() % 2) - 1;
			mStateCounter = rand() % 20 + 15;
		}

		if (mY <= mStartY)
		{
			mDY = (rand() % 2);
			mStateCounter = rand() % 20 + 15;
		}

		if (mStateCounter <= 0)
		{
			if (rand() % 2)
			{
				// Move towards player
				if (getCenterY() < room->getPlayer()->getCenterY())
				{
					mDY = 1;
				}
				else
				{
					mDY = -1;
				}
			}
			else
			{
				// Move randomly
				mDY = (rand() % 3) - 1;
			}
			mStateCounter = rand() % 20 + 15;
		}

		mY += mDY;
	}
Ejemplo n.º 18
0
bool GuideRibbonEllipse::idealize(::pb::GuideRibbon* pOut) const
{
   ::pb::GuideRibbon::Ellipse* idea = pOut->mutable_ellipse();
   {
      idea->mutable_center()->set_x( getCenterX() );
      idea->mutable_center()->set_y( getCenterY() );
      idea->mutable_radius()->set_x( getRadiusX() );
      idea->mutable_radius()->set_y( getRadiusY() );
      idea->set_angle0( getBeginAngle() );
      idea->set_angle1( getEndAngle() );
      idea->set_direction( getDirection() );
   }
   return true;
}
Ejemplo n.º 19
0
void EnemyBase::update()
{
	updateEffects();
	bar.centerToPoint(this->getCenterX(),this->getCenterY() - getHeight()/2 - 10);

	if(road != NULL)
	if(currentRoadTile < road->getRoadLenght() - 1)
	{
		SDL_Point nextTile = road->getPointAt(currentRoadTile + 1);
		SDL_Point curTile = road->getPointAt(currentRoadTile);

		int dirX = nextTile.x - curTile.x;
		int dirY = nextTile.y - curTile.y;


		move(dirX * speed,dirY * speed);

		distance += (double)speed;

		double cpX = nextTile.x * TILEWIDTH + TILEWIDTH/2;
		double cpY = nextTile.y * TILEHEIGHT + TILEHEIGHT/2;
		if(dirX != 0)
		{
			if((cpX - getCenterX()) * dirX <= 0)
			{
				 setX(cpX - getWidth()/2);
				 currentRoadTile++;
			}
		}
		else 
		{
			if((cpY - getCenterY())*dirY <= 0)
			{
				
				setY(cpY - getHeight()/2);
				currentRoadTile++;
			}
		}


	}
	else 
	{
		reachedEnd = true;
	}
}
Ejemplo n.º 20
0
Projectile* Soldier::fire(int _dx,int _dy){
	Projectile* ob;
	int _x=getCenterX();
	int _y=getCenterY();
	if(activ){
		
		Bullet* bul=new Bullet(_x,_y,_dx,_dy);
		return bul;
	}
	else{
		if(vehicleUti->getSymbole()){
			ob = ((Tank*)vehicleUti)->fire(_dx, _dy);
			return ob;
		}
				
	}
	return ob;
}
Ejemplo n.º 21
0
void Vision::fire(int mouseX, int mouseY)
{
	//setFrames(RUGGER_GUN_START, RUGGER_GUN_END);
	if(timeSinceLastShot < visionNS::SHOT_DELAY) return;
	for(int i=0; i<visionNS::NUM_BULLETS; i++)
	{
		if(!bullets[i].getActive())
		{
			timeSinceLastShot = 0;
			VECTOR2 fireVec(mouseX - getCenterX(), mouseY - getCenterY());
			VECTOR2* normalFireVec = D3DXVec2Normalize(&fireVec, &fireVec);
			bullets[i].setX(getX());
			bullets[i].setY(getY());
			bullets[i].setVelocity(fireVec * bulletNS::SPEED);
			bullets[i].setActiveAndVisible(true);
			return;
		}
	}
}
Ejemplo n.º 22
0
void TankHead::fireBullet()
{
    if (shotBuffer.canFire(SHOT_TIME_BUFFER) && numBulletsFired < MAX_PLAYER_SHOTS)
    {
        shotBuffer.start();

        float nozzleRadius = getWidth()/2 * getScale();

        bullet[numBulletsFired].setX(getCenterX() + angleVector.x * nozzleRadius);
        bullet[numBulletsFired].setY(getCenterY() + angleVector.y * nozzleRadius);
        bullet[numBulletsFired].setRadians(spriteData.angle);
        bullet[numBulletsFired].setVelocity(*D3DXVec2Normalize(&angleVector, &angleVector) * bulletNS::SPEED);
        bullet[numBulletsFired].setVisible(true);
    }
    //This is the case where the player has too many bullets on the screen, but he should be able to fire based on the time buffer.


    organizeBullets();
}
Ejemplo n.º 23
0
void FireProjectile::update(float timeElapsed)
{
	// bullet tracer effect
	m_Duration -= timeElapsed;

	addDirection(m_Dx * timeElapsed, m_Dy * timeElapsed);

	m_CollisionBox.x = getPosition().x;
	m_CollisionBox.y = getPosition().y;

	if (m_Duration <= 0)
	{
		m_Destroy = true;
	}

	m_Light.setSize(glm::vec2(m_Size.x, m_Light.getSize().y));
	m_Light.setLightPosition(getX(), getY(), m_Size.x / 2);
	m_Light.setPosition(getCenterX() - m_Light.getSize().x / 2, getCenterY() - m_Light.getSize().y / 2);
}
Ejemplo n.º 24
0
D3DXVECTOR2 Character::getCenter() {

	return D3DXVECTOR2(getCenterX(), getCenterY());
}
Ejemplo n.º 25
0
void Character::update(float frameTime, bool rightButton, bool leftButton, bool jumpButton, bool shootButton, bool reloadButton)
{
	
//Show the Character angle

//Movement based on collision detection
	if (standingOn == 0 || !standingOn->getActive()) {
		D3DXVECTOR2 v (
			body->getVelocity().x, 
			body->getVelocity().y + frameTime * characterNS::GRAVITY_Y
		);

		setVelocity(v);
	} else {
		int xpos = body->getX();

		if (body->getCenterX() + 12 < standingOn->corners[0].x || body->getCenterX() - 12 > standingOn->corners[3].x) {
			standingOn = 0;
		}
	}

//Move left or right
	if (leftButton ^ rightButton) {
		faceDir = rightButton ? 1 : -1;
		body->walking = true;
	} else {
		faceDir = 0;
		body->walking = false;
	}


	if (standingOn != 0) {
		walk(frameTime);

		if (jumpButton) {
			jump();
			body->jumping = true;
		} else {
			body->jumping = false;
		}
	} else {
		walk(frameTime/3);
		body->jumping = true;
	}

//Determine orientation of the player, based on the mouse direction
	if (aimAngle > PI2) { // Quadrant 1
		faceDir = 1;
	}

	if (aimAngle < PI2 && aimAngle > 0.0) { // Quadrant 2
		faceDir = -1;
	}

	if (aimAngle > -PI2 && aimAngle <= 0.0) { // Quadrant 3
		faceDir = -1;
	}

	if (aimAngle < -PI2 && aimAngle <= 0.0) { // Quadrant 4
		faceDir = 1;
	}

//Set the direction of the player
	body->faceDir = faceDir;
//	head->faceDir = faceDir;

	body->update(frameTime);
	//cursor->update(frameTime);
//	head->update(frameTime);

	updateCorners();

	if(currentWeapon != 0)
	{
		currentWeapon->setAngle(aimAngle);
		currentWeapon->setX(getCenterX() + weaponPos.x * std::cos(aimAngle) + weaponPos.y * std::sin(aimAngle) - currentWeapon->getWidth()/2);
		currentWeapon->setY(getCenterY() + weaponPos.y * std::cos(aimAngle) + weaponPos.x * std::sin(aimAngle) -currentWeapon->getHeight()/2);
		currentWeapon->update(frameTime);
		//Reload if r is pressed or the ammoCount is 0
		if(reloadStep == 0 && (reloadButton || reinterpret_cast<Gun*>(currentWeapon)->mag->ammoCount == 0))
		{
			reloadStep = 1;
			reloadTimer = frameTime;
		}
		if(reloadStep != 0)
		{
			reloadTimer += frameTime;
			if(reloadTimer > static_cast<Gun*>(currentWeapon)->reloadTime)
			{
				if(static_cast<Gun*>(currentWeapon)->isMagInGun)
				{
					currentMag->loadAmmo();
				}
				static_cast<Gun*>(currentWeapon)->loadMag();
				reloadStep = 0;
			}
			else if(reloadTimer > static_cast<Gun*>(currentWeapon)->reloadTime/100)
			{
				static_cast<Gun*>(currentWeapon)->removeMag();
				currentMag->loadAmmo();
			}
		}
		currentWeapon->act(frameTime, shootButton, false, false, false, false);
	}
}
Ejemplo n.º 26
0
/**
 * Draw the text on screen
 */
void GuiText::draw(CVideo *pVideo)
{
	if(!text)
		return;

	if(!isVisible())
		return;

    color[3] = getAlpha();
    blurGlowColor[3] = blurAlpha * getAlpha();
	int newSize = size * getScale();

	if(newSize != currentSize)
	{
		currentSize = newSize;

		if(text)
			textWidth = font->getWidth(text, currentSize);
	}

	if(maxWidth > 0 && maxWidth <= textWidth)
	{
		if(wrapMode == DOTTED) // text dotted
		{
			if(textDyn.size() == 0)
				makeDottedText();

			if(textDynWidth.size() != textDyn.size())
            {
                textDynWidth.resize(textDyn.size());

                for(u32 i = 0; i < textDynWidth.size(); i++)
                    textDynWidth[i] = font->getWidth(textDyn[i], currentSize);
            }

			if(textDyn.size() > 0)
				font->drawText(pVideo, getCenterX(), getCenterY(), getDepth(), textDyn[textDyn.size()-1], currentSize, color, alignment, textDynWidth[textDyn.size()-1], defaultBlur, blurGlowIntensity, blurGlowColor);
		}

		else if(wrapMode == SCROLL_HORIZONTAL)
		{
			scrollText(pVideo->getFrameCount());

			if(textDyn.size() > 0)
				font->drawText(pVideo, getCenterX(), getCenterY(), getDepth(), textDyn[textDyn.size()-1], currentSize, color, alignment, maxWidth, defaultBlur, blurGlowIntensity, blurGlowColor);
		}
		else if(wrapMode == WRAP)
		{
			int lineheight = currentSize + 6;
			int yoffset = 0;
			int voffset = 0;

			if(textDyn.size() == 0)
				wrapText();

			if(textDynWidth.size() != textDyn.size())
            {
                textDynWidth.resize(textDyn.size());

                for(u32 i = 0; i < textDynWidth.size(); i++)
                    textDynWidth[i] = font->getWidth(textDyn[i], currentSize);
            }

			if(alignment & ALIGN_MIDDLE)
				voffset = (lineheight * (textDyn.size()-1)) >> 1;

			for(u32 i = 0; i < textDyn.size(); i++)
			{
				font->drawText(pVideo, getCenterX(), getCenterY() + voffset + yoffset, getDepth(), textDyn[i], currentSize, color, alignment, textDynWidth[i], defaultBlur, blurGlowIntensity, blurGlowColor);
                yoffset -= lineheight;
			}
		}
	}
Ejemplo n.º 27
0
	void Player::logic(Room *room)
	{
		//std::cout << "HP:" << getHealth() << " MP:" << getMana() << "/" << getMaximumMana() << " Couter:" << mRegenerateManaCounter << std::endl;
		mStateCounter++;		

		if (mInvincibleCounter > 0) {
			mInvincibleCounter--;
		}

		if (getState() == DEAD) {
			return;
		}

		regenerateMana();
		
		const KeyState &keys = room->getKeyState();
		TileMap *tileMap = room->getTileMap();

		bool onIce = isOnIce(tileMap);

		int acceleration = AIR_ACCELERATION;
		if (getState() == GROUND) {
			if (onIce) {
				acceleration = ICE_ACCELERATION;
			} else {
				acceleration = GROUND_ACCELERATION;
			}
		}

		if (keys.isLeftHeld() && !keys.isRightHeld() && !mHurt) {
			mDX -= acceleration;
			if (mDX < -RUN_SPEED) {
				mDX = -RUN_SPEED;
			}
			mRunFrame += onIce && mDX > -20 ? 3 : 2;
			mFacingLeft = true;
			mRunning = true;
		} else if (!keys.isLeftHeld() && keys.isRightHeld() && !mHurt) {
			mDX += acceleration;
			if (mDX > RUN_SPEED) {
				mDX = RUN_SPEED;
			}
			mRunFrame += onIce && mDX < 20 ? 3 : 2;
			mFacingLeft = false;
			mRunning = true;
		} else if (mDX > 0 && !mHurt) {
			mDX -= onIce ? 1 : 4;
			if (mDX < 0) {
				mDX = 0;
			}
			mRunning = false;
		} else if (mDX < 0 && !mHurt) {
			mDX += onIce ? 1 : 4;
			if (mDX > 0) {
				mDX = 0;
			}
			mRunning = false;
		} else {
			mRunning = false;
		}

		// Crouching
		if (!mRunning && keys.isDownHeld() && getState() == GROUND) {
			if (!mCrouching) {
				mCrouching = true;
				mY += CROUCH_SHRINK;
				mH -= CROUCH_SHRINK;
			}
		} else if (mCrouching) {
			mCrouching = false;
			mY -= CROUCH_SHRINK;
			mH += CROUCH_SHRINK;
		}
		

		if (mDX == 0 || getState() != GROUND) {
			mRunFrame = 0;
		}

		// Interrupting jumping
		if (!keys.isJumpHeld() && getState() == AIR_UP && mDY > JUMP_CONTROL && !mHurt) {
			mDY = JUMP_CONTROL;
		}

		if (!keys.isJumpHeld() && (getState() == AIR_UP || getState() == AIR_DOWN)) {
			mJumpKeyHeld = false;
		}

		// Jumping
		if (keys.isJumpPressed() && getState() == GROUND && !keys.isDownHeld()) {
			mDY = JUMP_STRENGTH;
			setState(AIR_UP);
			mJumpKeyHeld = true;
			mJumpY = getCenterY();
		}
		// Drop off platform
		if (keys.isJumpPressed() && mOnPlatform && keys.isDownHeld()) {
			mDY = 1;
			mY++;
			setState(AIR_DOWN);
			mJumpKeyHeld = true;
			mJumpY = getCenterY();
		}

		// Sideways movement
		if (onIce) {
			if (mDX < 0) {
				mX += (mDX - 7) / 8;
			} else {
				mX += (mDX + 7) / 8;
			}
		} else {
			mX += mDX / 8;
		}
		

		// Left Wall
        int solidLeftOffset;
		if (mDX < 0 && solidLeft(room, solidLeftOffset)) 
        {
			// Align player to solid object
			mX += solidLeftOffset;
            
            mDX = 0;
		}

		// Right Wall
        int solidRightOffset;
		if (mDX > 0 && solidRight(room, solidRightOffset)) 
        {
			// Align player to solid object
			mX -= solidRightOffset;
			mDX = 0;
		}

		// Vertical movement
		if (getState() == AIR_DOWN) {
			mY += mDY > MAX_AIR_SPEED ? MAX_AIR_SPEED : mDY;
		} else if (getState() == AIR_UP) {
			mY -= mDY > MAX_AIR_SPEED ? MAX_AIR_SPEED : mDY;
		}

		// Falling, acceleration
		if (getState() == AIR_DOWN) {
			mDY += 1;
		}

		// Raising, deacceleration
		if (getState() == AIR_UP) {
			mDY--;
			if (mDY < 0) {
				setState(AIR_DOWN);
				mDY = 0;
			}
		}

		// Ceiling bouncing
        int solidAboveOffset;
		if (getState() == AIR_UP && solidAbove(room, solidAboveOffset)) 
        {
			setState(AIR_DOWN);
			mDY = 0;
			// Align player to solid object
			mY += solidAboveOffset;
		}

		// Ground bouncing / landing
        int groundOffset;
		if (getState() == AIR_DOWN && isOnGround(room, groundOffset)) {
			if (keys.isJumpHeld() && !mJumpKeyHeld && !keys.isDownHeld()) {
				// Rejump
				mDY = JUMP_STRENGTH;
				setState(AIR_UP);
				mJumpKeyHeld = true;
			} else {
				// Land
				setState(GROUND);
				mDY = 0;				
			}
			mHurt = false;

			// Align to tile
			mY -= groundOffset;
			mJumpY = getCenterY();
		}

		// Falling
        int fallingOffset;
		if (getState() == GROUND && !isOnGround(room, fallingOffset)) {
			setState(AIR_DOWN);
			mDY = 0;
		}

		// Shooting
		if (keys.isFirePressed())	{
			if (mShotCounter >= SHOT_DELAY) {
				mShotCounter = 0;
				room->addEntity(createShot());
				mShootAfterDelay = false;
			} else {
				mShootAfterDelay = true;
			}
		}
		if (mShotCounter >= SHOT_DELAY && mShootAfterDelay) {
			mShotCounter = 0;
			room->addEntity(createShot());
			mShootAfterDelay = false;
		}
		
		mShotCounter++;


		if (keys.isSpecialPressed()) 
        {
		    if (mShotType == NORMAL)
            {
                mShotType = ICE;
            }
            else if (mShotType == ICE)
            {
                mShotType = FIRE;
            }
            else
            {
                mShotType = NORMAL;
            }
        }
	}
Ejemplo n.º 28
0
//=============================================================================
// update
// typically called once per frame
// frameTime is used to regulate the speed of movement and animation
//=============================================================================
void TankHead::update(float frameTime)
{
    D3DXVECTOR2 mouseLocation(input->getMouseX(), input->getMouseY());

    D3DXVec2Normalize(&angleVector,(const D3DXVECTOR2*)new D3DXVECTOR2(mouseLocation.x - getCenterX(), mouseLocation.y - getCenterY()));


    float headAngle = acos(D3DXVec2Dot(&angleVector, &D3DXVECTOR2(0, -1)));

    spriteData.angle = headAngle;

    if (angleVector.x < 0)
        spriteData.angle = 2 * PI - spriteData.angle;

    Entity::update(frameTime);

    //spriteData.x += velocity.x * frameTime;
    //velocity.x = 0;
    //spriteData.y += velocity.y * frameTime;
    //velocity.y = 0;


    //// wrap around screen
    //if (spriteData.x > GAME_WIDTH)                  // if off screen right
    //    spriteData.x = -tankHeadNS::WIDTH;              // position off screen left
    //else if (spriteData.x < -tankHeadNS::WIDTH)         // else if off screen left
    //    spriteData.x = GAME_WIDTH;                  // position off screen right
    //if (spriteData.y < -tankHeadNS::HEIGHT)             // if off screen top
    //    spriteData.y = GAME_HEIGHT;                 // position off screen bottom
    //else if (spriteData.y > GAME_HEIGHT)            // else if off screen bottom
    //    spriteData.y = -tankHeadNS::HEIGHT;             // position off screen top
}
Ejemplo n.º 29
0
void Gun::multiFire(float frameTime)
{
	int count = frameTime/fireRate.fireTime;
	float recoilTime = frameTime/count;
	if(fireMode != AUTO)//accounts for burst fire
	{
		count = min(burstCount, count);
		burstCount -= count;
	}
	timeSinceLastFired -= fireRate.fireTime*count;
	while(count > 0)
	{
		chamberNextProjectile();
		if(chamberedProjectile != 0)
		{
			float fireAngle = spriteData.angle + spread*PI*(((rand()%1000)-500)/1000.0)/180;
			fire(D3DXVECTOR2(getCenterX()+(fireLocation.x+((count-1)*fireRate.fireTime*chamberedProjectile->muzzelVelocity))*cos(fireAngle), getCenterY()+(fireLocation.x+((count-1)*fireRate.fireTime*chamberedProjectile->muzzelVelocity))*sin(fireAngle)), fireAngle);
			recoil(recoilTime);
		}
		count--;
	}
}
Ejemplo n.º 30
0
void Slime::logic()
{
	stateChangeTimer--;

	if (stateChangeTimer <= 0)
	{
		Player* player = mRoom->getPlayer();
		//std::cout << "type: " << mSlimeType << std::endl;
		int distBeforeAggro = 0;
		if(mSlimeType == 2)
		{
			distBeforeAggro = 120;
		} else if(mSlimeType == 1)
		{
			distBeforeAggro = 60;
		}

		if(getDistance(player) < distBeforeAggro) // && Random::get().getInt(3) = 2)
		{
			if(Random::get().getInt(2) == 1)
			{
				if(player->getCenterX()<getCenterX())
				{
					setState("walkleft");
				} else {
					setState("walkright");
				}
			}
			else
			{
				if(player->getCenterY()<getCenterY())
				{
					setState("walkup");
				} else {
					setState("walkdown");
				}
			}


		}
		else
		{
			switch (Random::get().getInt(5))
			{
			case 0:
				setState("walkleft");
				break;
			case 1:
				setState("walkright");
				break;
			case 2:
				setState("walkup");
				break;
			case 3:
				setState("walkdown");
				break;
			default:
				setState(Random::get().getInt(2) == 0 ? "idleleft" : "idleright");
				break;
			}
		}

		stateChangeTimer = Random::get().getInt(10, 30);
	}

	Actor::move();

	std::vector<Entity*> players = mRoom->collidesWith(this, Entity::PLAYER);

	if (players.size() != 0)
	{
		mRoom->getPlayer()->damage(1, getDirection());
	}
}