Ejemplo n.º 1
0
	void Player::Update()
	{
		// GRAB INPUT AND ACCELERATE
		if (Input::IsKeyMaskHeld("left"))
		{
			scale.x = -1;
			if(cling < 0)
			{
				velocity.x -= ACCELERATION * Monocle::deltaTime;
			}
			sprite->Play("run");
			direction = false;
			scale.x = -1;
		}
		else if (Input::IsKeyMaskHeld("right"))
		{
			scale.x = 1;
			if(cling < 0)
			{
				velocity.x += ACCELERATION * Monocle::deltaTime;
			}
			sprite->Play("run");
			direction = true;
			scale.x = 1;
		}
		else
		{
			sprite->Play("stand");

			// friction
			if(onGround)
			{
                                velocity.x = APPROACH(velocity.x, 0, FRICTION_GROUND * Monocle::deltaTime);
			}
			else
			{
                                velocity.x = APPROACH(velocity.x, 0, FRICTION_AIR * Monocle::deltaTime);
			}
		}

		// JUMP INPUT
                if (Input::IsKeyMaskPressed("jump") && (onGround || cling > 0 || !doubleJump))
		{
			// jump
                        velocity.y = - JUMP;

			if(!onGround)
			{
				// wall jump
				if(cling > 0)
				{
                                        velocity.x = clingDir * WALLJUMP;
					cling = -1;
				}

				// double jump
				if(cling < 0)
				{
					doubleJump = true;
				}
			}
		}

		// gravity
		velocity.y += GRAVITY * Monocle::deltaTime;

		// maxspeed
		int maxspeed = onGround ? MAXSPEED_GROUND : MAXSPEED_AIR;
                if(abs(velocity.x) > maxspeed) { velocity.x = SIGN(velocity.x, 1) * maxspeed; }
		// Motion
		Motion(velocity.x, position.x);
		Motion(velocity.y, position.y);

		//check for ground

		if(CollideAt("WALL", position.x, position.y + 1))
		{
			onGround = true;
			doubleJump = false;
		}
		else
		{
			onGround = false;

			//change sprite
			if(velocity.y < 0)
			{
				sprite->Play("jumpUp");
			}
			else
			{
				sprite->Play("jumpDown");
			}

			//check for wall jump
			if(CollideAt("WALL", position.x + 1, position.y) && Input::IsKeyMaskHeld("right")) 
			{ 
				cling = 10; 
				clingDir = -1; 
			}
			if(CollideAt("WALL", position.x - 1, position.y) && Input::IsKeyMaskHeld("left")) 
			{ 
				cling = 10; 
				clingDir = 1;
			}
		}

		//decrease how long we can cling to a wall for
		cling --;

		//and at the end of the day, are we dead?
		if(Collide("SPIKE"))
		{
			World::ResetCoins();
		}
	
	}
Ejemplo n.º 2
0
void PlayerOptions::Approach( const PlayerOptions& other, float fDeltaSeconds )
{
#define APPROACH( opt ) \
	fapproach( m_ ## opt, other.m_ ## opt, fDeltaSeconds * other.m_Speed ## opt );
#define DO_COPY( x ) \
	x = other.x;

	APPROACH( fTimeSpacing );
	APPROACH( fScrollSpeed );
	APPROACH( fMaxScrollBPM );
	fapproach( m_fScrollBPM, other.m_fScrollBPM, fDeltaSeconds * other.m_SpeedfScrollBPM*150 );
	for( int i=0; i<NUM_ACCELS; i++ )
		APPROACH( fAccels[i] );
	for( int i=0; i<NUM_EFFECTS; i++ )
		APPROACH( fEffects[i] );
	for( int i=0; i<NUM_APPEARANCES; i++ )
		APPROACH( fAppearances[i] );
	for( int i=0; i<NUM_SCROLLS; i++ )
		APPROACH( fScrolls[i] );
	APPROACH( fDark );
	APPROACH( fBlind );
	APPROACH( fCover );
	APPROACH( fRandAttack );
	APPROACH( fNoAttack );
	APPROACH( fPlayerAutoPlay );
	APPROACH( fPerspectiveTilt );
	APPROACH( fSkew );
	APPROACH( fPassmark );
	APPROACH( fRandomSpeed );

	DO_COPY( m_bSetScrollSpeed );
	for( int i=0; i<NUM_TURNS; i++ )
		DO_COPY( m_bTurns[i] );
	for( int i=0; i<NUM_TRANSFORMS; i++ )
		DO_COPY( m_bTransforms[i] );
	DO_COPY( m_bMuteOnError );
	DO_COPY( m_FailType );
	DO_COPY( m_sNoteSkin );
#undef APPROACH
#undef DO_COPY
}
Ejemplo n.º 3
0
	void Player::Update()
	{
        bool heldLeft;
        bool heldRight;
        bool jumpKey;
        
        Entity::Update();
        
        heldLeft = (Input::IsKeyMaskHeld("left") || Input::IsTouchInRect(Vector2(0,0),
                                                                        Vector2(position.x-1,120)));
        heldRight = (Input::IsKeyMaskHeld("right") || Input::IsTouchInRect(Vector2(position.x,0),
                                                                          Vector2(160,120)));
        
        // Jump touch is below screen or in the top bit of screen
        jumpKey = (Input::IsKeyMaskPressed("jump") || Input::IsTouchInRect(Vector2(0,121),Vector2(160,1000),TOUCH_PHASE_BEGIN) || Input::IsTouchInRect(Vector2(0,0),Vector2(800,10),TOUCH_PHASE_BEGIN));
        
		// GRAB INPUT AND ACCELERATE
		if (heldLeft)
		{
			scale.x = -1;
			if(cling < 0)
			{
				velocity.x -= ACCELERATION * Monocle::deltaTime;
			}
			sprite->Play("run");
			direction = false;
			scale.x = -1;
		}
		else if (heldRight)
		{
			scale.x = 1;
			if(cling < 0)
			{
				velocity.x += ACCELERATION * Monocle::deltaTime;
			}
			sprite->Play("run");
			direction = true;
			scale.x = 1;
		}
		else
		{
			sprite->Play("stand");

			// friction
			if(onGround)
			{
				velocity.x = APPROACH(velocity.x, 0, FRICTION_GROUND * Monocle::deltaTime);
			}
			else
			{
				velocity.x = APPROACH(velocity.x, 0, FRICTION_AIR * Monocle::deltaTime);
			}
		}

		// JUMP INPUT
		if (jumpKey && (onGround || cling > 0 || !doubleJump))
		{
			// jump
			velocity.y = - JUMP;

			if(!onGround)
			{
				// wall jump
				if(cling > 0)
				{
					velocity.x = clingDir * WALLJUMP;
					cling = -1;
				}

				// double jump
				if(cling < 0)
				{
					doubleJump = true;
				}
			}
            
            if (sfxJump)
                sfxJump->Play(1,1.0,0.0,(doubleJump)?1.0:0.6); // Play at a lower pitch off the ground
		}

		// gravity
		velocity.y += GRAVITY * Monocle::deltaTime;

		// maxspeed
		int maxspeed = onGround ? MAXSPEED_GROUND : MAXSPEED_AIR;
		if(abs(velocity.x) > maxspeed) { velocity.x = SIGN(velocity.x, 1) * maxspeed; }
		// Motion
		Motion(velocity.x, position.x);
		Motion(velocity.y, position.y);

		//check for ground

		if(CollideAt("WALL", position.x, position.y + 1))
		{
			onGround = true;
			doubleJump = false;
		}
		else
		{
			onGround = false;

			//change sprite
			if(velocity.y < 0)
			{
				sprite->Play("jumpUp");
			}
			else
			{
				sprite->Play("jumpDown");
			}

			//check for wall jump
			if(CollideAt("WALL", position.x + 1, position.y) && heldRight) 
			{ 
				cling = 10; 
				clingDir = -1; 
			}
			if(CollideAt("WALL", position.x - 1, position.y) && heldLeft) 
			{ 
				cling = 10; 
				clingDir = 1;
			}
		}

		//decrease how long we can cling to a wall for
		cling --;

		//and at the end of the day, are we dead?
		if(Collide("SPIKE"))
		{
			World::ResetCoins();
		}

	}