Added in game modes for Revitalize. Also fixed bug where players wouldn't update when moving left.

This commit is contained in:
JoshuaNavarro 2019-07-24 14:51:12 -07:00
parent bda8c38c7d
commit d0b9b1f1cd
6 changed files with 338 additions and 64 deletions

View File

@ -37,6 +37,7 @@ namespace Revitalize.Framework.Menus
/// <summary>
/// //TODO: Combine two of these to make an item grab menu.
/// TODO: Display Item information on hover.
/// </summary>
public class InventoryMenu : IClickableMenuExtended
{

View File

@ -24,5 +24,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
Four
}
public enum SSCGameMode
{
None,
ShootingGallery,
PVP,
Story
}
}
}

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies.Spawners;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents;
@ -12,8 +13,14 @@ using StardustCore.UIUtilities.MenuComponents.ComponentsV1;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{
public class Loby:IClickableMenuExtended
/// <summary>
/// A nice little loby screen so that players can select their game modes.
/// </summary>
public class Loby : IClickableMenuExtended
{
/// <summary>
/// The background for the menu.
/// </summary>
StardustCore.UIUtilities.Texture2DExtended background;
string menuText;
Button shootingGalleryButton;
@ -27,32 +34,29 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
public Loby(int x, int y, int width, int height) : base(x, y, width, height, false)
{
this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground");
this.menuText = "The Loby"+System.Environment.NewLine+System.Environment.NewLine+"Choose a game mode";
this.shootingGalleryButton = new Button(new Rectangle(100, 300, 64*4, 32*4), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "ShootingGalleryButton"), new Rectangle(0, 0, 64, 32), 4f);
this.backButton = new Button(new Rectangle(100, 100, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "BackButton"),new Rectangle(0, 0, 16, 16), 4f);
this.menuText = "The Loby" + System.Environment.NewLine + System.Environment.NewLine + "Choose a game mode";
this.shootingGalleryButton = new Button(new Rectangle(100, 300, 64 * 4, 32 * 4), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "ShootingGalleryButton"), new Rectangle(0, 0, 64, 32), 4f);
this.backButton = new Button(new Rectangle(100, 100, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "BackButton"), new Rectangle(0, 0, 16, 16), 4f);
}
/// <summary>
/// What happens when the menu is clicked with the left mouse button.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="playSound"></param>
public override void receiveLeftClick(int x, int y, bool playSound = true)
{
if (this.shootingGalleryButton.containsPoint(x, y))
{
foreach (SSCPlayer p in SeasideScramble.self.players.Values)
{
p.HUD.displayHUD();
//p.statusEffects.addStatusEffect(SE_Burn.SpawnBurnEffect(new Vector2(p.HUD.xPositionOnScreen,p.HUD.yPositionOnScreen),10*1000,1000,1.00d,1));
}
SeasideScramble.self.entities.addSpawner(new Target_Spawner(new Vector2(SeasideScrambleMap.TileSize * -1, SeasideScrambleMap.TileSize * 4), new Vector2(1, 0), Color.White, true, 1000, 5000, true, 0.25f, 3f, true));
SeasideScramble.self.entities.addSpawner(new Target_Spawner(new Vector2(SeasideScrambleMap.TileSize * 17, SeasideScrambleMap.TileSize * 5), new Vector2(-1, 0), Color.White, true, 1000, 5000, true, 0.25f, 3f, true));
SeasideScramble.self.currentMap.spawnPlayersAtPositions();
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(100, 100), Color.Blue);
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(200, 100), Color.Red);
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(300, 100), Color.Green);
SeasideScramble.self.menuManager.closeAllMenus();
this.setUpForGameplay();
}
}
/// <summary>
/// Checks if the menu is ready to close.
/// </summary>
/// <returns></returns>
public override bool readyToClose()
{
return false;
@ -60,12 +64,55 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
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.receiveGamepadLeftClick(SSCEnums.PlayerID.One, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One).mouseCursor.position);
}
if (p2.IsButtonDown(Buttons.A))
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Two, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two).mouseCursor.position);
}
if (p3.IsButtonDown(Buttons.A))
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Three, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three).mouseCursor.position);
}
if (p4.IsButtonDown(Buttons.A))
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Four, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four).mouseCursor.position);
}
}
public void receiveGamepadLeftClick(SSCEnums.PlayerID Player,Vector2 position)
{
this.receiveLeftClick((int)position.X, (int)position.Y);
}
private void setUpForGameplay()
{
SeasideScramble.self.setMode(SSCEnums.SSCGameMode.ShootingGallery);
foreach (SSCPlayer p in SeasideScramble.self.players.Values)
{
p.HUD.displayHUD();
//p.statusEffects.addStatusEffect(SE_Burn.SpawnBurnEffect(new Vector2(p.HUD.xPositionOnScreen,p.HUD.yPositionOnScreen),10*1000,1000,1.00d,1));
}
SeasideScramble.self.entities.addSpawner(new Target_Spawner(new Vector2(SeasideScrambleMap.TileSize * -1, SeasideScrambleMap.TileSize * 4), new Vector2(1, 0), Color.White, true, 1000, 5000, true, 0.25f, 3f, true));
SeasideScramble.self.entities.addSpawner(new Target_Spawner(new Vector2(SeasideScrambleMap.TileSize * 17, SeasideScrambleMap.TileSize * 5), new Vector2(-1, 0), Color.White, true, 1000, 5000, true, 0.25f, 3f, true));
SeasideScramble.self.currentMap.spawnPlayersAtPositions();
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(100, 100), Color.Blue);
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(200, 100), Color.Red);
//SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(300, 100), Color.Green);
SeasideScramble.self.menuManager.closeAllMenus();
}
@ -74,7 +121,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
//Draw background.
b.Draw(this.background.texture, new Vector2(this.xPositionOnScreen, this.yPositionOnScreen), SeasideScramble.self.camera.getXNARect(), Color.White);
Vector2 offset = StardewValley.Game1.dialogueFont.MeasureString(this.menuText);
b.DrawString(StardewValley.Game1.dialogueFont,this.menuText,new Vector2((this.width / 2) - (offset.X / 2), this.height *.1f), Color.White);
b.DrawString(StardewValley.Game1.dialogueFont, this.menuText, new Vector2((this.width / 2) - (offset.X / 2), this.height * .1f), Color.White);
this.shootingGalleryButton.draw(b);
this.backButton.draw(b);

View File

@ -13,37 +13,104 @@ using Revitalize.Framework.Minigame.SeasideScrambleMinigame.Interfaces;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
/// <summary>
/// Deals with handling a player.
/// </summary>
public class SSCPlayer : ISSCLivingEntity
{
/// <summary>
/// The character animator.
/// </summary>
public AnimationManager characterSpriteController;
/// <summary>
/// Should the sprite be flipped?
/// </summary>
public bool flipSprite;
/// <summary>
/// The facing direction for the player.
/// </summary>
public SSCEnums.FacingDirection facingDirection;
/// <summary>
/// The position for the player.
/// </summary>
public Microsoft.Xna.Framework.Vector2 position;
/// <summary>
/// Is the player moving?
/// </summary>
public bool isMoving;
/// <summary>
/// Did the player move this frame?
/// </summary>
private bool movedThisFrame;
/// <summary>
/// The draw color for the player.
/// </summary>
public Color playerColor;
/// <summary>
/// The player's id.
/// </summary>
public SSCEnums.PlayerID playerID;
/// <summary>
/// The frame speed for the junimo walking.
/// </summary>
public const int junimoWalkingAnimationSpeed = 10;
/// <summary>
/// The mouse cursor.
/// </summary>
public StardustCore.Animations.AnimatedSprite mouseCursor;
/// <summary>
/// The sensitivity for the mouse.
/// </summary>
public Vector2 mouseSensitivity;
/// <summary>
/// Should the mouse cursor be shown?
/// </summary>
public bool showMouseCursor;
/// <summary>
/// The delay to show the mouse but I dont think I use this.
/// </summary>
public int maxMouseSleepTime = 300;
/// <summary>
/// The current gun the player is holding. UPDATE THIS TO WEILD MULTIPLE GUNS!!!
/// </summary>
public SSCGuns.SSCGun gun;
/// <summary>
/// The hitbox for the player.
/// </summary>
public Rectangle hitBox;
/// <summary>
/// The HUD for the player.
/// </summary>
public SSCMenus.HUD.CharacterHUD HUD;
/// <summary>
/// The current health for the player.
/// </summary>
public int currentHealth;
/// <summary>
/// The max health for the player.
/// </summary>
public int maxHealth;
/// <summary>
/// The movement speed for the player.
/// </summary>
public float movementSpeed;
/// <summary>
/// The status effects on the player.
/// </summary>
public SSCStatusEffects.StatusEffectManager statusEffects;
/// <summary>
/// Is the player dead?
/// </summary>
public bool isDead
{
get
@ -57,6 +124,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public int MaxHealth { get => this.maxHealth; set => this.maxHealth = value; }
public Rectangle HitBox { get => this.hitBox; set => this.hitBox = value; }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="PlayerID">Which player is this? One, two, etc...</param>
public SSCPlayer(SSCEnums.PlayerID PlayerID)
{
this.playerID = PlayerID;
@ -226,6 +297,20 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
/// <param name="Time"></param>
public void update(GameTime Time)
{
if (this.playerID == SSCEnums.PlayerID.One)
{
if (SeasideScramble.self.getMouseDelta().X != 0 || SeasideScramble.self.getMouseDelta().Y != 0)
{
this.mouseCursor.position = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
this.showMouseCursor = true;
}
}
if (this.currentHealth < 0) this.currentHealth = 0;
this.gun.update(Time);
this.HUD.update(Time);
this.statusEffects.update(Time);
this.movedThisFrame = false;
if (this.isMoving == false)
{
@ -272,19 +357,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.flipSprite = false;
}
if (this.playerID == SSCEnums.PlayerID.One)
{
if (SeasideScramble.self.getMouseDelta().X != 0 || SeasideScramble.self.getMouseDelta().Y != 0)
{
this.mouseCursor.position = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
this.showMouseCursor = true;
}
}
if (this.currentHealth < 0) this.currentHealth = 0;
this.gun.update(Time);
this.HUD.update(Time);
this.statusEffects.update(Time);
}
/// <summary>
@ -543,6 +616,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
#endregion
/// <summary>
/// Shoots a bullet in the given direction using projectile information stored in the gun.
/// </summary>
/// <param name="direction"></param>
private void shoot(Vector2 direction)
{
if (SeasideScramble.self.menuManager.isMenuUp) return;
@ -553,6 +630,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
}
/// <summary>
/// Have this player take damage.
/// </summary>
/// <param name="amount"></param>
public void takeDamage(int amount)
{
this.currentHealth -= amount;
@ -562,16 +643,28 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
}
}
/// <summary>
/// Heal the player a certain amount of HP/
/// </summary>
/// <param name="amount"></param>
public void heal(int amount)
{
this.takeDamage(amount * -1);
if (this.currentHealth > this.maxHealth) this.currentHealth = this.maxHealth;
}
/// <summary>
/// Heal the player to full HP.
/// </summary>
public void healToFull()
{
this.currentHealth = this.maxHealth;
}
/// <summary>
/// What happens when the player collides with a projectile.
/// </summary>
/// <param name="projectile"></param>
public void onCollision(SSCProjectiles.SSCProjectile projectile)
{
@ -585,13 +678,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//ModCore.log("Can't get hit by own projectile.");
return;
}
/*if projectile.owner is player and friendly fire is off do nothing.
*
*
*/
//if projectile.owner is player and friendly fire is off do nothing.
if(projectile.owner is SSCPlayer && SeasideScramble.self.friendlyFireEnabled==false)
{
return;
}
}
ModCore.log("Big oof. Player hit by projectile.");
this.CurrentHealth -= projectile.damage;
this.takeDamage(projectile.damage);
this.statusEffects.addStatusEffect(projectile.effect);
}
}

View File

@ -11,12 +11,33 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
{
public class SSCProjectile
{
/// <summary>
/// The sprite for the projectile/
/// </summary>
public AnimatedSprite sprite;
/// <summary>
/// The direction the projectile travels.
/// </summary>
public Vector2 direction;
/// <summary>
/// The speed for the projectile.
/// </summary>
public float speed;
/// <summary>
/// The scale of the projectile.
/// </summary>
public float scale;
/// <summary>
/// The hitbox for the projectile.
/// </summary>
public Rectangle hitBox;
/// <summary>
/// The damage the projectile does upon contact.
/// </summary>
public int damage;
/// <summary>
/// The position of the projectile. Also resets the bounding box x,y location.
/// </summary>
public Vector2 position
{
get
@ -28,6 +49,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
this.sprite.position = value;
}
}
/// <summary>
/// The color of the projectile.
/// </summary>
public Color color
{
get
@ -40,7 +64,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
}
}
/// <summary>
/// The max amount of frames this projectile lives for.
/// </summary>
public int maxLifeSpan;
/// <summary>
/// The current lifespan for the projectile.
/// </summary>
public int currentLifeSpan;
/// <summary>
@ -48,6 +78,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
/// </summary>
public object owner;
/// <summary>
/// The velocity of the projectile.
/// </summary>
public Vector2 Velocity
{
get
@ -55,9 +88,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
return this.direction * this.speed;
}
}
/// <summary>
/// The status effect the projectile inflicts upon contact.
/// </summary>
public SSCStatusEffects.StatusEffect effect;
/// <summary>
/// Constructor.
/// </summary>
public SSCProjectile()
{
@ -153,9 +191,12 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
this.die();
}
/// <summary>
/// What happens when the projectile collides with something.
/// </summary>
/// <param name="other"></param>
public virtual void onCollision(object other)
{
//Move this if to the player class.????
if(other is SSCPlayer)
{
if (this.hasOwner())
@ -165,12 +206,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
//ModCore.log("Can't get hit by own projectile.");
return;
}
/*if projectile.owner is player and friendly fire is off do nothing.
*
*
*/
//if projectile.owner is player and friendly fire is off do nothing.
else if (SeasideScramble.self.friendlyFireEnabled == false && this.owner!=other)
{
return;
}
}
ModCore.log("Big oof. Player hit by projectile.");
}
this.collisionLogic();
}

View File

@ -65,6 +65,15 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public SSCFonts.SSCFont gameFont;
/// <summary>
/// The current game mode.
/// </summary>
public SSCEnums.SSCGameMode gameMode;
public bool friendlyFireEnabled;
/// <summary>
/// RNG.
/// </summary>
public Random random
{
get
@ -73,6 +82,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
}
}
/// <summary>
/// Constuctor.
/// </summary>
public SeasideScramble()
{
self = this;
@ -110,6 +122,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
else return null;
}
/// <summary>
/// Loads in all of the necessary textures for Seaside Scramble.
/// </summary>
private void LoadTextures()
{
this.textureUtils = new SSCTextureUtilities();
@ -134,12 +149,18 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.textureUtils.addTextureManager(enemies);
}
/// <summary>
/// Loads in all of the maps for Seaside Scramble.
/// </summary>
private void LoadMaps()
{
this.SeasideScrambleMaps = new Dictionary<string, SeasideScrambleMap>();
this.SeasideScrambleMaps.Add("TestRoom", new SeasideScrambleMap(SeasideScrambleMap.LoadMap("TestRoom.tbin").Value));
this.SeasideScrambleMaps.Add("ShootingGallery", new SSCMaps.ShootingGallery(SeasideScrambleMap.LoadMap("ShootingGallery.tbin").Value));
}
/// <summary>
/// Loads in a default map for Seaside Scramble.
/// </summary>
private void loadStartingMap()
{
this.currentMap = this.SeasideScrambleMaps["ShootingGallery"];
@ -209,15 +230,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
b.End();
}
/// <summary>
/// What happens when the left click is held.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void leftClickHeld(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// The id of the minigame???
@ -229,6 +242,48 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//throw new NotImplementedException();
}
/// <summary>
/// Sets the game mode for the game.
/// </summary>
/// <param name="Mode"></param>
public void setMode(SSCEnums.SSCGameMode Mode)
{
if (Mode == SSCEnums.SSCGameMode.None)
{
this.friendlyFireEnabled = false;
}
if(Mode== SSCEnums.SSCGameMode.ShootingGallery)
{
this.friendlyFireEnabled = false;
}
if(Mode== SSCEnums.SSCGameMode.PVP)
{
this.friendlyFireEnabled = true;
}
if(Mode== SSCEnums.SSCGameMode.Story)
{
this.friendlyFireEnabled = false;
}
this.gameMode = Mode;
}
//~~~~~~~~~~~~~~~~~//
// Input Logic //
//~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// What happens when the left click is held.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void leftClickHeld(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// Does this override free mous emovements?
/// </summary>
@ -327,17 +382,31 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
}
}
/// <summary>
/// What happens when left click is released.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void releaseLeftClick(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// What happens when right click is released.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void releaseRightClick(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// Receive input from a specific gamepad.
/// </summary>
/// <param name="state"></param>
/// <param name="ID"></param>
private void receiveGamepadInput(GamePadState state,SSCEnums.PlayerID ID)
{
if (state == null) return;
@ -350,6 +419,20 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
}
}
/// <summary>
/// Returns the delta for mouse movement.
/// </summary>
/// <returns></returns>
public Vector2 getMouseDelta()
{
Vector2 ret = -1 * (this.oldMousePosition - new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y));
return ret;
}
#endregion
/// <summary>
/// Called every update frame.
/// </summary>
@ -410,16 +493,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//throw new NotImplementedException();
}
/// <summary>
/// Returns the delta for mouse movement.
/// </summary>
/// <returns></returns>
public Vector2 getMouseDelta()
{
Vector2 ret = -1 * (this.oldMousePosition - new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y));
return ret;
}
/// <summary>
/// Called when the minigame is quit upon.
/// </summary>
@ -429,6 +502,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
ModCore.log("Exit the game!");
}
//~~~~~~~~~~~~~~~~~~~~//
// Static Functions //
//~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// Translates the position passed in into the relative position on the viewport.
/// </summary>
@ -449,5 +529,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
return new Vector2(globalPosition.X - (float)SeasideScramble.self.camera.viewport.X, globalPosition.Y - (float)SeasideScramble.self.camera.viewport.Y);
}
#endregion
}
}