void camera_update(CIndieLib &engine, IND_Camera2d &cam, IND_Camera2d &bcam, float &dx, float &dy, float &cam_x, float &cam_y, float d) {
	

	// Move up
	if (engine.Input->IsKeyPressed(IND_W)) {
		cam_y -=		d;
		dy -=			d;
	}

	// Move down
	if (engine.Input->IsKeyPressed(IND_S)) {
		cam_y +=		d;
		dy +=			d;
	}

	// Move right
	if (engine.Input->IsKeyPressed(IND_D)) {
		cam_x +=		d;
		dx +=			d;
	}

	// Move left
	if (engine.Input->IsKeyPressed(IND_A)) {
		cam_x -=		d;
		dx -=			d;
	}

	// Zoom in
	if (engine.Input->OnKeyPress(IND_E) && cam.GetZoom() < 1)
		cam.SetZoom(cam.GetZoom() + 0.05f);

	// Zoom out
	if (engine.Input->OnKeyPress(IND_Q) && cam.GetZoom() > 0.35)
		cam.SetZoom(cam.GetZoom() - 0.05f);

	cam.SetPosition((int) cam_x, (int) cam_y);
	bcam.SetPosition((int) cam_x, (int) cam_y);
}
Exemple #2
0
virtual int render()
{
		STX_TRY;
		mI->Input->Update ();

		// ----- Delta Time -----
		fElapsedTime = mI->Render->GetFrameTime() / 1000.0f;

		// Toggle show bounding boxes
		if (mI->Input->OnKeyPress(KEY_p))
			bShowBoundsToggle = !bShowBoundsToggle;

		// Walk Left!
		if (mI->Input->IsKeyPressed(KEY_LEFT))
		{
			VelocityX -= speed * fElapsedTime;
			if (!playerJumping)
				Player.SetSequence(0);		//walk
			Player.SetMirrorX(1);
		}
		// Walk Right!
		else
		if (mI->Input->IsKeyPressed(KEY_RIGHT))
		{
			VelocityX += speed * fElapsedTime;
			if (!playerJumping)
				Player.SetSequence(0);		//walk
			Player.SetMirrorX(0);

		}
		else
		{
			if (!playerJumping)
				Player.SetSequence(1);		// stand
			VelocityX = 0.0f;			// 0 = no slide
		}

		// JUMP!
		if(mI->Input->OnKeyPress(KEY_SPACE) && !playerJumping)
		{
			VelocityY -= fJumpForce;	// jump force (minus is up)
			Player.SetSequence(2);		// jump
			playerJumping = true;
		}

		// TODO - if no key press then apply friction.  We want the player to move instantly
		// yet slide to a stop.

		VelocityY += gravity * fElapsedTime;	// apply gravity (value is gravity)
		y += VelocityY * fElapsedTime;			// position

		// Check falling limits (poor man collision detection!)
		if (y > 500)
		{
			VelocityY = 0;
			y = 500;
			playerJumping = false;
		}

		// Clamp walking velocity
		float Length = sqrtf(VelocityX * VelocityX);
		if ( Length > MaxVelocityX )
		{
			VelocityX *= ( MaxVelocityX / Length );
		} // End if clamp X velocity

		x += VelocityX * fElapsedTime;
		if (x < 0)
			x = 0;

		// Move the player
		Player.SetPosition(x, y, 0);

		// Apply slide friction
		float Dec = -Dir * slideFriction * fElapsedTime;

		if (mI->Entity2dManager->IsCollision (&Player, "/IndieLib-Animation-Collision/entire", &Beetle, "/IndieLib-Animation-Collision/beetle_boy_head"))
		{
			VelocityY = 80;	// force him downward
			VelocityX = 0;
		}

		if (x > mI->Window->GetWidth() / 2)
			Cameras2d.SetPosition((int)x, MiddleScreenY);


		mI->Render->BeginScene ();
		mI->Render->ClearViewPort (60, 60, 60);
		mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight());
		mI->Render->SetCamera2d (&Cameras2d);

		for (int i = 0; i < 16; i++)
		{
			mI->Entity2dManager->RenderEntities2d ( i );
			if (bShowBoundsToggle)
				mI->Entity2dManager->RenderCollisionAreas (i, 255, 0, 0, 255);
		}
		//???mI->Render->ShowFpsInWindowTitle("");
		mI->Render->EndScene ();
		STX_CATCH;
		return 0;
	}