Finished color picking for character selection screen!

This commit is contained in:
JoshuaNavarro 2019-07-18 22:10:05 -07:00
parent 7dd02b8b0d
commit 9d58b4b15e
3 changed files with 176 additions and 19 deletions

View File

@ -12,6 +12,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public xTile.Dimensions.Rectangle viewport;
public Vector2 Position
{
get
{
return new Vector2(this.viewport.X, this.viewport.Y);
}
}
public SSCCamera()
{
this.viewport = new xTile.Dimensions.Rectangle(StardewValley.Game1.viewport);

View File

@ -16,22 +16,55 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
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 Dictionary<SSCEnums.PlayerID, int> playerColorIndex;
public Vector2 p1DisplayLocation;
public Vector2 p2DisplayLocation;
public Vector2 p3DisplayLocation;
public Vector2 p4DisplayLocation;
public List<Color> possibleColors;
public bool closeMenu;
public Dictionary<SSCEnums.PlayerID, int> inputDelays;
public int maxInputDelay = 20;
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);
this.p1DisplayLocation = new Vector2(this.width *.2f, this.height / 2);
this.p2DisplayLocation = new Vector2(this.width *.4f, this.height / 2);
this.p3DisplayLocation = new Vector2(this.width *.6f, this.height / 2);
this.p4DisplayLocation = new Vector2(this.width *.8f, this.height / 2);
this.possibleColors = new List<Color>()
{
Color.PaleVioletRed,
Color.LightSkyBlue,
Color.LawnGreen,
Color.LightGoldenrodYellow,
Color.HotPink,
Color.Red,
Color.Purple
};
this.playerColorIndex = new Dictionary<SSCEnums.PlayerID, int>()
{
{ SSCEnums.PlayerID.One,-1},
{ SSCEnums.PlayerID.Two,-1},
{ SSCEnums.PlayerID.Three,-1},
{ SSCEnums.PlayerID.Four,-1},
};
this.inputDelays = new Dictionary<SSCEnums.PlayerID, int>()
{
{ SSCEnums.PlayerID.One,0},
{ SSCEnums.PlayerID.Two,0},
{ SSCEnums.PlayerID.Three,0},
{ SSCEnums.PlayerID.Four,0},
};
}
public CharacterSelectScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height)
@ -45,9 +78,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
this.yPositionOnScreen = newBounds.Y;
this.width = newBounds.Width;
this.height = newBounds.Height;
base.gameWindowSizeChanged(oldBounds, newBounds);
//base.gameWindowSizeChanged(oldBounds, newBounds);
this.p1DisplayLocation = this.getRelativePositionToMenu(.1f, .5f);
//this.p1DisplayLocation = new Vector2(this.width/10,this.height/2);
}
public override void update(GameTime time)
@ -63,30 +96,124 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
}
if (p2.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 2!");
this.initializeCharacter(SSCEnums.PlayerID.Two);
}
if (p3.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 3!");
this.initializeCharacter(SSCEnums.PlayerID.Three);
}
if (p4.IsButtonDown(Buttons.A))
{
throw new NotImplementedException("Need to support player 4!");
this.initializeCharacter(SSCEnums.PlayerID.Four);
}
this.inputDelays[SSCEnums.PlayerID.One]--;
this.inputDelays[SSCEnums.PlayerID.Two]--;
this.inputDelays[SSCEnums.PlayerID.Three]--;
this.inputDelays[SSCEnums.PlayerID.Four]--;
if (this.inputDelays[SSCEnums.PlayerID.One] < 0) this.inputDelays[SSCEnums.PlayerID.One] = 0;
if (this.inputDelays[SSCEnums.PlayerID.Two] < 0) this.inputDelays[SSCEnums.PlayerID.Two] = 0;
if (this.inputDelays[SSCEnums.PlayerID.Three] < 0) this.inputDelays[SSCEnums.PlayerID.Three] = 0;
if (this.inputDelays[SSCEnums.PlayerID.Four] < 0) this.inputDelays[SSCEnums.PlayerID.Four] = 0;
}
/// <summary>
/// Initializes a given character.
/// </summary>
/// <param name="player"></param>
public void initializeCharacter(SSCEnums.PlayerID player)
{
if (SeasideScramble.self.players.ContainsKey(player))
{
SeasideScramble.self.players[player] = new SSCPlayer(player);
return;
}
else
{
SeasideScramble.self.players.Add(player, new SSCPlayer(player));
this.iteratePlayerColorIndex(player, 1);
}
this.setPlayerColor(player);
}
/// <summary>
/// Sets a given player's color.
/// </summary>
/// <param name="player"></param>
private void setPlayerColor(SSCEnums.PlayerID player)
{
if (SeasideScramble.self.getPlayer(player) == null) return;
SeasideScramble.self.getPlayer(player).setColor(this.possibleColors[this.playerColorIndex[player]]);
}
/// <summary>
/// Iterates the player's color index to get the next possible color.
/// </summary>
/// <param name="player"></param>
/// <param name="amount"></param>
private void iteratePlayerColorIndex(SSCEnums.PlayerID player,int amount)
{
if(player== SSCEnums.PlayerID.One)
{
if (this.inputDelays[player] != 0) return;
this.inputDelays[player] = this.maxInputDelay;
while (this.doesAnyOtherPlayerHaveThisColor(player) == true)
{
if (this.playerColorIndex[player] >= this.possibleColors.Count)
{
this.playerColorIndex[player] = 0;
}
else if (this.playerColorIndex[player] < 0)
{
this.playerColorIndex[player] = this.possibleColors.Count-1;
}
else
{
this.playerColorIndex[player]+=amount;
}
}
this.playerColorIndex[player] += amount;
if (this.playerColorIndex[player] >= this.possibleColors.Count)
{
this.playerColorIndex[player] = 0;
}
else if (this.playerColorIndex[player] < 0)
{
this.playerColorIndex[player] = this.possibleColors.Count - 1;
}
}
SeasideScramble.self.getPlayer(player).setColor(this.p1DefaultColor);
this.setPlayerColor(player);
}
/// <summary>
/// Checks if a given player has the same color index as another to prevent color duplicates.
/// </summary>
/// <param name="self"></param>
/// <param name="other"></param>
/// <returns></returns>
private bool doesOtherPlayerHaveThisColor(SSCEnums.PlayerID self, SSCEnums.PlayerID other)
{
if (SeasideScramble.self.getPlayer(other) == null) return false;
if (this.playerColorIndex[self] == this.playerColorIndex[other]) return true;
else return false;
}
/// <summary>
/// Checks if any other player has the same color index to prevent color duplicates.
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
private bool doesAnyOtherPlayerHaveThisColor(SSCEnums.PlayerID self)
{
for(int i = 0; i < 4; i++)
{
SSCEnums.PlayerID other = (SSCEnums.PlayerID)i;
if (other == self) continue;
if (this.doesOtherPlayerHaveThisColor(self, other) == false) continue;
else return true;
}
return false;
}
public override void receiveLeftClick(int x, int y, bool playSound = true)
@ -96,11 +223,22 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
public override void receiveKeyPress(Keys key)
{
if(key== Keys.Enter)
if(key== Keys.Enter || key== Keys.Space)
{
if (SeasideScramble.self.currentNumberOfPlayers > 0)
{
this.setUpForGameplay();
SeasideScramble.self.menuManager.closeAllMenus();
}
}
if(key== Keys.A)
{
this.setUpForGameplay();
this.closeMenu = true;
}
this.iteratePlayerColorIndex(SSCEnums.PlayerID.One, -1);
}
if(key== Keys.D)
{
this.iteratePlayerColorIndex(SSCEnums.PlayerID.One, 1);
}
}
private void setUpForGameplay()
@ -125,10 +263,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
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);
b.Draw(this.background.texture, new Vector2(0,0), 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);
b.DrawString(Game1.dialogueFont, this.menuTitle, new Vector2((this.width / 2) - (menuTitlePos.X / 2), this.height / 10),Color.White);
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null)
{

View File

@ -23,7 +23,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
SeasideScrambleMap currentMap;
public Dictionary<string, SeasideScrambleMap> SeasideScrambleMaps;
public int currentNumberOfPlayers = 0;
public int currentNumberOfPlayers
{
get
{
return this.players.Count;
}
}
public const int maxPlayers = 4;
public Dictionary<SSCEnums.PlayerID, SSCPlayer> players;
@ -196,6 +202,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
player.receiveKeyPress(k);
}
if (this.menuManager.isMenuUp)
{
this.menuManager.activeMenu.receiveKeyPress(k);
}
}
/// <summary>