Beispiel #1
0
void Npc::tick()
{
	if(mPlayer->getRect().top+100 >= mRect.top && mPlayer->getRect().top-100 <= mRect.top)
	{
		mIdleSound.setPosition(mRect.left-mPlayer->getRect().left,0,0);
	}else
	{
		mIdleSound.setPosition(mRect.left-mPlayer->getRect().left,9999999,0);
	}
	if(mCurrentAnimationPic >= mAnimationPicX-0.1)
	{
		mIdleSound.stop();
		mIdleSound.play();
		mCurrentAnimationPic = 0;
	}else
		mCurrentAnimationPic += mAnimationSpeed;
	if(mChatting && mTypeID != 29)
	{
		if(!mDialog->getDraw())
			mChatting = false;
		else
		{
		if(mPlayer->getRect().left <= mRect.left)
			mLookLeft = true;
		else
			mLookLeft = false;
		}
	}
	if(mChatting && !mPlayer->getRect().intersects(getHitBox()))
	{
		mChatting = false;
		mDialog->setDraw(false);
	}
}
Beispiel #2
0
void Weapon::render(SDL_Rect cameraRect)
{
	//Render the character
	int subImageX = currentAnimation[currentFrame].x;
	int subImageY = currentAnimation[currentFrame].y;
	int flip = SDL_FLIP_NONE;

	SDL_Rect weaponSpriteRect = { weaponSubimageOffsetX * subImageX,	
				      weaponSubimageOffsetY * subImageY, 
				      weaponImageSizeX, 
				      weaponImageSizeY};  
	if( flipHorizontal )
	  flip = flip | SDL_FLIP_HORIZONTAL;
	if( flipVertical )
	  flip = flip | SDL_FLIP_VERTICAL;


	weaponTexture.render( mPosX - cameraRect.x, mPosY - cameraRect.y , &weaponSpriteRect, rotation, NULL, (SDL_RendererFlip)flip );

	//Render the hitbox
	SDL_Rect hitBox = getHitBox();
	hitBox.x = hitBox.x - cameraRect.x;
	hitBox.y = hitBox.y - cameraRect.y;
	SDL_RenderDrawRect( gRenderer, &hitBox  );
}
void LevelPortal::update(SubLevel* subLevel_p){
	
	auto& ps = PortalSpecs::get();

	if (mIsWaiting){
		++mWaitingFrames; 
	}
	if (mWaitingFrames == PortalSpecs::get().mWaitingFrames){

		auto& player = *mSubLevel_p->getLevel()->getPlayer();
		auto& camera = *mSubLevel_p->getLevel()->getCamera();

		auto nextSubLevel_p = std::shared_ptr<SubLevel>();
		sf::Vector2f newPos;
		{
			nextSubLevel_p = mSubLevel_p->getLevel()->getSubLevel(mTargetLevel);
			auto temp_sp = nextSubLevel_p->getEntity( mTargetPortal ).lock();
			auto nextPortal_p = dynamic_cast<LevelPortal*>(temp_sp.get() );
				//////////////////////////////////////////////////////////////
				// /Get the position of the targetPortal
				// /
				// /Adjust the position so that the player does not spawn
				// /directly into a new portal and is teleported back
				//////////////////////////////////////////////////////////////
			auto& rect = nextPortal_p->getHitBox();
			auto tilesWide = static_cast<int>(rect.width / X_STEP) -1;

			nextPortal_p->setEnabled(false);

			newPos = sf::Vector2f( rect.left + X_STEP * tilesWide, rect.top);
		}

		//////////////////////////////////////////////////////////////
		// /Switch sublevel to the target level.
		// /Move the player to the position previously calculated
		// /Snap the camera to the players position
		// /Lock the camera again (since snapToPosition unlocks it automaticly)
		//////////////////////////////////////////////////////////////
		mSubLevel_p->getLevel()->switchSubLevel( mTargetLevel );
		player.setPosition( newPos );
		player.setFacingDirection(mDirection);
		camera.snapToPosition( GAME_TO_SCREEN * newPos );
		camera.lockCamera();

		auto fade_sp = std::shared_ptr<SubLevelFade>(new SubLevelFade(PortalSpecs::get().mWaitingFrames, SubLevelFade::FADE_IN));
		nextSubLevel_p->addEntity(fade_sp);
		nextSubLevel_p->addDrawable(fade_sp, SubLevel::DRAW_SCREEN);
		mIsWaiting = false;
		mWaitingFrames = 0;
	}	

	mCurrentAnimation_p->updateAnimation();		
}
Beispiel #4
0
void LightPoint::drawSelf() {
	auto& manager = WindowManager::get();
	auto& window = *manager.getWindow();
	auto& states = *manager.getStates();
	auto sprite = mCurrentAnimation_p->getCurrentSprite();
	auto& hitBox = getHitBox();
	auto position = GAME_TO_SCREEN * sf::Vector2f(hitBox.left, hitBox.top);

	sprite.setPosition(position);

	window.draw(sprite, states);
}
void DynamicObject::update(double time)
{
	float deltaX, deltaY, deltaZ;
	deltaX = getPosition()->getX();
	deltaY = getPosition()->getY();
	deltaZ = getPosition()->getZ();
	deltaX = (deltaX + cos(getAngle()* PI / 180)* getSpeed() * time + 0.5 * getAcelaration() * time *time);
	deltaY = (deltaY + sin(getAngle()* PI / 180)* getSpeed() * time + 0.5 * getAcelaration() * time *time);
	

	setPosition(deltaX, deltaY, deltaZ);
	getHitBox()->setPosition(deltaX, deltaY, deltaZ);
}
Beispiel #6
0
//--------------------------------------------------------------
bool ofxMuiBox::hitTest(float screenX, float screenY) const {
    // this function could be overriden w/ via the virtual declaration
    // hitRect is always described in with respect to the content frame 
    ofVec2f contentMousePos = screenToContentBox(ofVec2f(screenX, screenY));
    
    ofRectangle wr = getHitBox();
        
    // +1 issue attempted to be fixed
    return contentMousePos.x > wr.x && 
            contentMousePos.y > wr.y && 
            contentMousePos.x <= (wr.x + wr.width + 1) && 
            contentMousePos.y <= (wr.y + wr.height + 1);
    
}
void SoundScape::draw(){
	auto& manager = WindowManager::get();
	auto& window = *manager.getWindow();
	auto& states = *manager.getStates();

	auto& hitBox = getHitBox();
	auto position = sf::Vector2f(hitBox.left, hitBox.top);
	position = GAME_TO_SCREEN * position;

	for (int i = 0; i < 7; i++){
		position.x += i;

		sf::Vertex vertex[] = {sf::Vertex(position, sf::Color::Yellow)};
		window.draw(vertex, 1, sf::Points, states);

	}
}
Beispiel #8
0
//--------------------------------------------------------------
string ofxMuiBox::boxToString()
{
    
    // THE GUI BOX!
    //   __________________________________________________________
    //  |BOX - RENDERED AS A FILLED QUAD                           |
    //  |   CORNER CAN BE ANYWHERE INSIDE OF PARENT                |
    //  |   (SCREEN OR PANEL OR OBJECT                             |
    //  |    ____________________________________________________  |
    //  | M |BORDER BOX - RENDERED AS A FRAME                    | |
    //  | A |   CORNER ALWAYS @ 0,0                              | |
    //  | A |                                                    | |
    //  | R | B                                                  | |
    //  | G | O     __________________________________________   | |
    //  | I | R    |PADDING BOX - RENDERED AS A FILLED QUAD   |  | |
    //  | N | D    |  CORNER ALWAYS @ 0,0                     |  | |
    //  | N | D    |                                          |  | |
    //  |   | E    | P   ___________________________________  |  | |
    //  |   | R    | A  |CONTENT BOX - RENDERD BY OBJECT   |  |  | |
    //  |   |      | D  |                                  |  |  | |
    //  |   |      | D  |  CORNER ALWAYS @ 0,0             |  |  | |
    //  |   |      | I  |                                  |  |  | |
    //  |   |      | N  |     ___________________________  |  |  | |
    //  |   |      | G  |    |                           | |  |  | |
    //  |   |      |    |    |  CORNER CAN BE ANYWHERE   | |  |  | |
    //  |   |      |    |    |  INSIDE THE CONTENT BOX   | |  |  | |
    //  |   |      |    |    |                           | |  |  | |
    //  |   |      |    |    |  HIT BOX -                | |  |  | |
    //  |   |      |    |    |  RENDERED BY OBJECT       | |  |  | |
    //  |   |      |    |    |  This is the "hot" zone"  | |  |  | |

    
    stringstream ss;
    ss << "[BOX    : " << ofToString(getBox().getX(),0,3,' ') << "/" << ofToString(getBox().getY(),0,3,' ') << "," << ofToString(getBox().getWidth(),0,3,' ') << "/" << ofToString(getBox().getHeight(),0,3,' ') << "]" << endl;
    ss << "[BORDER : " << ofToString(getBorderBox().getX(),0,3,' ') << "/" << ofToString(getBorderBox().getY(),0,3,' ') << "," << ofToString(getBorderBox().getWidth(),0,3,' ') << "/" << ofToString(getBorderBox().getHeight(),0,3,' ') << "]" << endl;
    ss << "[PADDING: " << ofToString(getPaddingBox().getX(),0,3,' ') << "/" << ofToString(getPaddingBox().getY(),0,3,' ') << "," << ofToString(getPaddingBox().getWidth(),0,3,' ') << "/" << ofToString(getPaddingBox().getHeight(),0,3,' ') << "]" << endl;
    ss << "[HIT BOX: " << ofToString(getHitBox().getX(),0,3,' ') << "/" << ofToString(getHitBox().getY(),0,3,' ') << "," << ofToString(getHitBox().getWidth(),0,3,' ') << "/" << ofToString(getHitBox().getHeight(),0,3,' ') << "]" << endl;

    return ss.str();
}
Beispiel #9
0
void MobileEntity::placeAtEdge(const GameEntity& g)
{

		///@todo implement
	// collision detection for walls - so that the player can "land" on them and run into them
	// perhaps abstract it to the Mobileentity level because other mobile entities will need hit detection for walls as well


	CollisionBox b1=getHitBox();
	CollisionBox b2=g.getHitBox();

	//Tells whether or not the midpoint is at all within the mid point of the other box
	vec3 d1=b1.getTranslate()-getVel()-b1.getDimensions()/3-b2.getPoint1();
	vec3 d2=b1.getTranslate()-getVel()+b1.getDimensions()/3-b2.getPoint2();
	vec3 midDist=b1.getTranslate()-b2.getTranslate();

	bool midInX=(d1.x>0)!=(d2.x>0);
	bool midInY=(d1.y>0)!=(d2.y>0);
	bool midInZ=(d1.z>0)!=(d2.z>0);

	if(!midInX&&!midInY&&getVel().z==0||
		!midInX&&!midInZ&&getVel().y==0||
		!midInZ&&!midInY&&getVel().x==0
		)
		return;
	


	vec3 newPos;

	//within the "x prism"
	float dir=0;
	float EASE_VAL=.05;
	float EASE_SCALE_VAL=3.0;
	if(midInY&&midInZ||!midInX){
		if(midDist.x!=0)dir=midDist.x/abs(midDist.x);
		else dir=0;

		if(abs(d1.x)>b1.getDimensions().x/EASE_SCALE_VAL||abs(d2.x)>b1.getDimensions().x/EASE_SCALE_VAL)dir=0;

		if(abs(d1.x)<abs(d2.x)){
			if(getVel().x<0)
			{
				newPos.x=b2.getPoint1().x+b1.getDimensions().x/2;
			}
		}else{
			if(getVel().x>0)
			{
				newPos.x=b2.getPoint2().x-b1.getDimensions().x/2;
			}
		}
		if(newPos.x!=0){
			setTranslateX(newPos.x);
			setVelX(0);
		}
		translate(EASE_VAL*dir,0,0);
	}
	//within the "y prism"
	if(midInX&&midInZ||!midInY){
		if(midDist.y!=0)dir=midDist.y/abs(midDist.y);
		else dir=0;

		if(abs(d1.y)>b1.getDimensions().y/EASE_SCALE_VAL||abs(d2.y)>b1.getDimensions().y/EASE_SCALE_VAL)dir=0;

		if(abs(d1.y)<abs(d2.y)){
			if(getVel().y<0)
			{
				newPos.y=b2.getPoint1().y+b1.getDimensions().y/2;
				_jumpCount=1;
			}
		}else{
			if(getVel().y>0)
			{
				newPos.y=b2.getPoint2().y-b1.getDimensions().y/2;
			}
		}

		if(newPos.y!=0){
			setTranslateY(newPos.y);
			setVelY(0);
		}
		setVel(getVel()*.85);
		if(dot(getVel(),getVel())<.01){
			setVel(0,0,0);
		}
		translate(0,EASE_VAL*dir,0);
	}
	
	//within the "z prism"
	if(midInX&&midInY||!midInZ){
		if(midDist.y!=0)dir=midDist.y/abs(midDist.y);
		else dir=0;

		if(abs(d1.z)>b1.getDimensions().z/EASE_SCALE_VAL||abs(d2.z)>b1.getDimensions().z/EASE_SCALE_VAL)dir=0;

		if(abs(d1.z)<abs(d2.z)){
			if(getVel().z<0)
			{
				newPos.z=b2.getPoint1().z+b1.getDimensions().z/2;
			}
		}else{
			if(getVel().z>0)
			{
				newPos.z=b2.getPoint2().z-b1.getDimensions().z/2;
			}
		}
		
		if(newPos.z!=0){
			setTranslateZ(newPos.z);
			setVelZ(0);
		}
		translate(0,0,EASE_VAL*dir);
	}

	vec3 v=getTranslate()-newPos;
}
Beispiel #10
0
void Car::apply_physics(Map &map)
{
	if(m_physicTimer.ticked())
	{
		//float currentSpeed = norm(m_speedVector);

		sf::Transformable::rotate(m_rotation/**(currentSpeed / m_maxSpeed)*/);
		float rotation = getRotation();
		float accelFactor = m_physicTimer.getFullWaitedDuration().asSeconds();

		//calculate the new speed with the acceleration
		m_speed += accelFactor*m_acceleration;
		if(m_speed > m_maxSpeed)
		{
			m_speed = m_maxSpeed;
			//std::cout<< "max attained\n";
		}
		else if(m_speed < -m_maxSpeed)
		{
			m_speed = -m_maxSpeed;
			//std::cout<< "min attained\n";
		}

		sf::Vector2f posOffset(
		m_speed*accelFactor*std::cos(rotation*M_PI/180)
		, m_speed*accelFactor*std::sin(rotation*M_PI/180)
		);

		//calculate the new position with the speed
		move(posOffset);


		//collisions tests
		bool collided = false;
		int i = 0;
		collision::LineHitBox lineBox;
		for(Map::iterator it = map.begin(); it != map.end() && !collided; it++)
		{	
			collided = collision::collision(getHitBox(), it->getHitBox(), lineBox);
		}
		if(collided)
		{
			move(-posOffset); //return to position before collision
			posOffset = collision::bounceVector(
			posOffset
			,collision::normale(lineBox, getPosition())
			);

			move(posOffset);
			setRotation(angle(posOffset));
			m_speed /= 4;
			std::cout<< getPosition().x<< " ; "<< getPosition().y<< '\n';
		}


		m_acceleration = 0;
		m_physicTimer.restart();

	}

	//draw the speed at the right place
	m_speedIndicator.setPosition(getPosition() - sf::Vector2f(400, 300));
	std::stringstream stream;
	stream<< int(m_speed);
	std::string indicatorString;
	stream>> indicatorString;

	m_speedIndicator.setString(indicatorString);
}
Beispiel #11
0
//--------------------------------------------------------------
float ofxMuiBox::getHitBoxY() const {
    return getHitBox().y;
}
Beispiel #12
0
//--------------------------------------------------------------
float ofxMuiBox::getHitBoxX() const {
    return getHitBox().x;
}
Beispiel #13
0
//--------------------------------------------------------------
float ofxMuiBox::getHitBoxHeight() const {
	return getHitBox().height;
}
Beispiel #14
0
//--------------------------------------------------------------
float ofxMuiBox::getHitBoxWidth() const {
	return getHitBox().width;
}