Work on character select.

This commit is contained in:
JoshuaNavarro 2019-07-18 20:16:41 -07:00
parent bac0f12dc5
commit 7dd02b8b0d
5 changed files with 180 additions and 13 deletions

View File

@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewValley;
using StardustCore.UIUtilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{
public class CharacterSelectScreen: IClickableMenuExtended
{
StardustCore.UIUtilities.Texture2DExtended background;
string menuTitle;
public Color p1DefaultColor = Color.PaleVioletRed;
public Color p2DefaultColor = Color.LightSkyBlue;
public Color p3DefaultColor = Color.LawnGreen;
public Color p4DefaultColor = Color.LightGoldenrodYellow;
public Vector2 p1DisplayLocation;
public bool closeMenu;
public CharacterSelectScreen(int x, int y, int width, int height) : base(x, y, width, height, false)
{
this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground");
this.menuTitle = "Character Selection";
this.p1DisplayLocation = this.getRelativePositionToMenu(.1f, .5f);
}
public CharacterSelectScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height)
{
}
public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds)
{
this.xPositionOnScreen = newBounds.X;
this.yPositionOnScreen = newBounds.Y;
this.width = newBounds.Width;
this.height = newBounds.Height;
base.gameWindowSizeChanged(oldBounds, newBounds);
this.p1DisplayLocation = this.getRelativePositionToMenu(.1f, .5f);
}
public override void update(GameTime time)
{
GamePadState p1 = SeasideScramble.self.getGamepadState(PlayerIndex.One);
GamePadState p2 = SeasideScramble.self.getGamepadState(PlayerIndex.Two);
GamePadState p3 = SeasideScramble.self.getGamepadState(PlayerIndex.Three);
GamePadState p4 = SeasideScramble.self.getGamepadState(PlayerIndex.Four);
if (p1.IsButtonDown(Buttons.A))
{
this.initializeCharacter(SSCEnums.PlayerID.One);
}
if (p2.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 2!");
}
if (p3.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 3!");
}
if (p4.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 4!");
}
}
public void initializeCharacter(SSCEnums.PlayerID player)
{
if (SeasideScramble.self.players.ContainsKey(player))
{
SeasideScramble.self.players[player] = new SSCPlayer(player);
}
else
{
SeasideScramble.self.players.Add(player, new SSCPlayer(player));
}
SeasideScramble.self.getPlayer(player).setColor(this.p1DefaultColor);
}
public override void receiveLeftClick(int x, int y, bool playSound = true)
{
this.initializeCharacter(SSCEnums.PlayerID.One);
}
public override void receiveKeyPress(Keys key)
{
if(key== Keys.Enter)
{
this.setUpForGameplay();
this.closeMenu = true;
}
}
private void setUpForGameplay()
{
}
public override bool readyToClose()
{
if (this.closeMenu == true)
{
return true;
}
return false;
}
/// <summary>
/// Draw everything to the screen.
/// </summary>
/// <param name="b"></param>
public override void draw(SpriteBatch b)
{
//Draw background texture.
b.Draw(this.background.texture, new Vector2(this.xPositionOnScreen, this.yPositionOnScreen), SeasideScramble.self.camera.getXNARect(), Color.White);
Vector2 menuTitlePos = Game1.dialogueFont.MeasureString(this.menuTitle);
b.DrawString(Game1.dialogueFont, this.menuTitle, new Vector2((this.width / 2) - (menuTitlePos.X / 2), this.height / 2),Color.White);
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null)
{
SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One).draw(b,this.p1DisplayLocation);
}
}
public override void exitMenu(bool playSound = true)
{
base.exitMenu(playSound);
}
}
}

View File

@ -18,7 +18,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
public TitleScreen(int x, int y, int width, int height):base(x,y,width,height,false) public TitleScreen(int x, int y, int width, int height):base(x,y,width,height,false)
{ {
this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground"); this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground");
this.menuText = new StardustCore.UIUtilities.MenuComponents.BlinkingText("Sea Side Scramble: Lite Edition" + System.Environment.NewLine + "Click to start.",1000); this.menuText = new StardustCore.UIUtilities.MenuComponents.BlinkingText("Sea Side Scramble: Lite Edition" + System.Environment.NewLine + "Click or press A to start.",1000);
} }
public TitleScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height) public TitleScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height)
@ -50,7 +50,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
public override void receiveLeftClick(int x, int y, bool playSound = true) public override void receiveLeftClick(int x, int y, bool playSound = true)
{ {
if (SeasideScramble.self.menuManager.isThisActiveMenu(this) == false) return; if (SeasideScramble.self.menuManager.isThisActiveMenu(this) == false) return;
this.closeMenu = true; SeasideScramble.self.menuManager.addNewMenu(new CharacterSelectScreen(SeasideScramble.self.camera.viewport));
} }
/// <summary> /// <summary>
@ -83,8 +83,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
/// <param name="b"></param> /// <param name="b"></param>
public override void draw(SpriteBatch b) public override void draw(SpriteBatch b)
{ {
if (SeasideScramble.self.menuManager.isThisActiveMenu(this) == false) return;
b.GraphicsDevice.Clear(Color.Black);
this.drawTitleBackground(b); this.drawTitleBackground(b);
this.drawTitleText(b); this.drawTitleText(b);
this.drawMouse(b); this.drawMouse(b);
@ -111,5 +110,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
} }
public override void exitMenu(bool playSound = true)
{
base.exitMenu(playSound);
}
} }
} }

View File

@ -119,7 +119,17 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
/// <param name="b"></param> /// <param name="b"></param>
public void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch b) public void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch b)
{ {
this.characterSpriteController.draw(b, SeasideScramble.GlobalToLocal(SeasideScramble.self.camera.viewport,this.position), this.playerColor, 4f, this.flipSprite == true ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (this.position.Y) / 10000f)); this.draw(b,this.position);
}
/// <summary>
/// Draws the character to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="position"></param>
public void draw(SpriteBatch b, Vector2 position)
{
this.characterSpriteController.draw(b, SeasideScramble.GlobalToLocal(SeasideScramble.self.camera.viewport, position), this.playerColor, 4f, this.flipSprite == true ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (this.position.Y) / 10000f));
} }
/// <summary> /// <summary>

View File

@ -11,6 +11,10 @@ using Revitalize.Framework.Minigame.SeasideScrambleMinigame;
using StardustCore.UIUtilities; using StardustCore.UIUtilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
/// <summary>
/// TODO: Finish character select screen. Ensure that camera snapping doesn't happen until game starts.
/// Also add interface for game entity for camera to consistently have a focus target.
/// </summary>
public class SeasideScramble : StardewValley.Minigames.IMinigame public class SeasideScramble : StardewValley.Minigames.IMinigame
{ {
@ -46,9 +50,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.quitGame = false; this.quitGame = false;
this.players = new Dictionary<SSCEnums.PlayerID, SSCPlayer>(); this.players = new Dictionary<SSCEnums.PlayerID, SSCPlayer>();
this.players.Add(SSCEnums.PlayerID.One, new SSCPlayer(SSCEnums.PlayerID.One)); //this.players.Add(SSCEnums.PlayerID.One, new SSCPlayer(SSCEnums.PlayerID.One));
//this.getPlayer(SSCEnums.PlayerID.One).setColor(Color.PaleVioletRed);
this.getPlayer(SSCEnums.PlayerID.One).setColor(Color.PaleVioletRed);
this.menuManager = new SSCMenus.SSCMenuManager(); this.menuManager = new SSCMenus.SSCMenuManager();
@ -297,11 +300,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
this.currentMap.update(time); this.currentMap.update(time);
} }
foreach(SSCPlayer player in this.players.Values)
{
if(player.playerID== SSCEnums.PlayerID.One) this.camera.centerOnPosition(player.position);
player.update(time);
}
if (this.menuManager.activeMenu != null) if (this.menuManager.activeMenu != null)
{ {
@ -311,6 +310,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.menuManager.closeActiveMenu(); this.menuManager.closeActiveMenu();
} }
} }
else
{
foreach (SSCPlayer player in this.players.Values)
{
if (player.playerID == SSCEnums.PlayerID.One) this.camera.centerOnPosition(player.position);
player.update(time);
}
}
return false; return false;
//throw new NotImplementedException(); //throw new NotImplementedException();

View File

@ -69,6 +69,7 @@
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScrambleMap.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScrambleMap.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCCamera.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCCamera.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCEnums.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCEnums.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\CharacterSelectScreen.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\SSCMenuManager.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\SSCMenuManager.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\TitleScreen.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\TitleScreen.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" />