book and page now use the new camera system; added functionality to camera; progress on mainscreen;

This commit is contained in:
2018-11-12 00:33:40 -06:00
parent a2defc5d11
commit 0f10ce3a07
5 changed files with 62 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.Camera;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,11 +11,42 @@ namespace RhythmBullet.Zer01HD.UI.Book
{
class Book
{
Viewport viewport;
Camera2D camera;
Page targetPage;
Dictionary<string, Page> pages = new Dictionary<string, Page>();
public Book(Viewport viewport)
public Book(Camera2D camera)
{
this.viewport = viewport;
this.camera = camera;
}
public void Draw(SpriteBatch batch)
{
for (int page = 0; page < pages.Count; page++)
{
pages.ElementAt(page).Value.Draw(batch, camera);
}
}
public void Update(GameTime gameTime)
{
if (targetPage != null)
{
Vector2 position;
Rectangle targetBounds = targetPage.Bounds;
position.X = targetBounds.X + (targetBounds.Width * 0.5f);
position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
camera.LinearInterpolationToPosition(0.4f, position);
if (camera.Position == position)
{
targetPage = null;
}
}
for (int page = 0; page < pages.Count; page++)
{
pages.ElementAt(page).Value.Update(gameTime);
}
}
public void AddPage(Page page)
@@ -31,15 +64,16 @@ namespace RhythmBullet.Zer01HD.UI.Book
pages.Remove(name);
}
public void Resize(int width, int height)
public void LerpToPage(Page page)
{
viewport.Width = width;
viewport.Height = height;
targetPage = page;
}
public void DisplayPage(string name)
public void GoToPage(Page page)
{
pages[name].DisplayWithViewport(viewport);
Rectangle targetBounds = page.Bounds;
camera.Position.X = targetBounds.X + (targetBounds.Width * 0.5f);
camera.Position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
}
}
}

View File

@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.UI.Modular;
using RhythmBullet.Zer01HD.Utilities.Camera;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -26,11 +27,5 @@ namespace RhythmBullet.Zer01HD.UI.Book
Bounds.Width = width;
Bounds.Height = height;
}
public void DisplayWithViewport(Viewport viewport)
{
viewport.X = Bounds.X;
viewport.Y = Bounds.Y;
}
}
}