Added in support for getting proper mouse direction on player.

This commit is contained in:
JoshuaNavarro 2019-07-20 15:11:50 -07:00
parent 384d69aafe
commit 650a852f8a
5 changed files with 294 additions and 212 deletions

View File

@ -101,46 +101,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
this.animatedSprites.Add("P4Color", new StardustCore.Animations.AnimatedSprite("P4Color", new Vector2(this.playerDisplayLocations[SSCEnums.PlayerID.Four].X, this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "BlankTexture"), new Animation(0, 0, 32, 32)), Color.White)); this.animatedSprites.Add("P4Color", new StardustCore.Animations.AnimatedSprite("P4Color", new Vector2(this.playerDisplayLocations[SSCEnums.PlayerID.Four].X, this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "BlankTexture"), new Animation(0, 0, 32, 32)), Color.White));
this.animatedSprites.Add("P1Mouse", new StardustCore.Animations.AnimatedSprite("P1Mouse", new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Cursors"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>()
{
{"Default",new List<Animation>()
{
new Animation(0,0,16,16)
} }
}, "Default"), Color.White));
this.animatedSprites["P1Mouse"].position = new Vector2(Game1.getMouseX(), Game1.getMouseY());
this.animatedSprites.Add("P2Mouse", new StardustCore.Animations.AnimatedSprite("P2Mouse", this.playerDisplayLocations[SSCEnums.PlayerID.Two], new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Cursors"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>()
{
{"Default",new List<Animation>()
{
new Animation(0,0,16,16)
} }
}, "Default"), Color.White));
this.animatedSprites.Add("P3Mouse", new StardustCore.Animations.AnimatedSprite("P3Mouse", this.playerDisplayLocations[SSCEnums.PlayerID.Three], new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Cursors"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>()
{
{"Default",new List<Animation>()
{
new Animation(0,0,16,16)
} }
}, "Default"), Color.White));
this.animatedSprites.Add("P4Mouse", new StardustCore.Animations.AnimatedSprite("P4Mouse", this.playerDisplayLocations[SSCEnums.PlayerID.Four], new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Cursors"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>()
{
{"Default",new List<Animation>()
{
new Animation(0,0,16,16)
} }
}, "Default"), Color.White));
this.buttons = new Dictionary<string, Button>(); this.buttons = new Dictionary<string, Button>();
this.buttons.Add("P1PrevButton", new Button("P1PrevButton", new Rectangle((int)this.playerDisplayLocations[SSCEnums.PlayerID.One].X - 64, (int)this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "lastPageButton"), new Rectangle(0, 0, 32, 32), 2f)); this.buttons.Add("P1PrevButton", new Button("P1PrevButton", new Rectangle((int)this.playerDisplayLocations[SSCEnums.PlayerID.One].X - 64, (int)this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "lastPageButton"), new Rectangle(0, 0, 32, 32), 2f));
this.buttons.Add("P1NextButton", new Button("P1NextButton", new Rectangle((int)this.playerDisplayLocations[SSCEnums.PlayerID.One].X + 64, (int)this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "nextPageButton"), new Rectangle(0, 0, 32, 32), 2f)); this.buttons.Add("P1NextButton", new Button("P1NextButton", new Rectangle((int)this.playerDisplayLocations[SSCEnums.PlayerID.One].X + 64, (int)this.playerDisplayLocations[SSCEnums.PlayerID.One].Y + 250, 64, 64), SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "nextPageButton"), new Rectangle(0, 0, 32, 32), 2f));
@ -163,16 +123,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
} }
/// <summary>
/// Gets the delta change in mouse movement.
/// </summary>
/// <returns></returns>
private Vector2 getMouseDelta()
{
Vector2 ret= -1*(this.oldMousePos - new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y));
return ret;
}
public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds)
{ {
this.xPositionOnScreen = 0; this.xPositionOnScreen = 0;
@ -199,30 +149,65 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
if (p1.IsButtonDown(Buttons.A)) if (p1.IsButtonDown(Buttons.A))
{ {
this.initializeCharacter(SSCEnums.PlayerID.One); if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) == null)
{
this.initializeCharacter(SSCEnums.PlayerID.One);
}
else
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.One, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One).mouseCursor.position);
}
} }
if (p2.IsButtonDown(Buttons.A)) if (p2.IsButtonDown(Buttons.A))
{ {
this.initializeCharacter(SSCEnums.PlayerID.Two); if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two) == null)
{
this.initializeCharacter(SSCEnums.PlayerID.Two);
SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two).mouseCursor.position = this.playerDisplayLocations[SSCEnums.PlayerID.Two];
}
else
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Two, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two).mouseCursor.position);
}
} }
if (p3.IsButtonDown(Buttons.A)) if (p3.IsButtonDown(Buttons.A))
{ {
this.initializeCharacter(SSCEnums.PlayerID.Three); if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three) == null)
{
this.initializeCharacter(SSCEnums.PlayerID.Three);
SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three).mouseCursor.position = this.playerDisplayLocations[SSCEnums.PlayerID.Three];
}
else
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Three, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three).mouseCursor.position);
}
} }
if (p4.IsButtonDown(Buttons.A)) if (p4.IsButtonDown(Buttons.A))
{ {
this.initializeCharacter(SSCEnums.PlayerID.Four); if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four) == null)
{
this.initializeCharacter(SSCEnums.PlayerID.Four);
SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four).mouseCursor.position = this.playerDisplayLocations[SSCEnums.PlayerID.Four];
}
else
{
this.receiveGamepadLeftClick(SSCEnums.PlayerID.Four, SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four).mouseCursor.position);
}
} }
if (p1.IsButtonDown(Buttons.Start))
{
if (SeasideScramble.self.currentNumberOfPlayers > 0)
{
this.setUpForGameplay();
SeasideScramble.self.menuManager.closeAllMenus();
}
}
//P1 is handled automatically since SDV maps keyboard to controller. //P1 is handled automatically since SDV maps keyboard to controller.
this.checkForControllerColorSwap(p2, SSCEnums.PlayerID.Two); this.checkForControllerColorSwap(p2, SSCEnums.PlayerID.Two);
this.checkForControllerColorSwap(p3, SSCEnums.PlayerID.Three); this.checkForControllerColorSwap(p3, SSCEnums.PlayerID.Three);
this.checkForControllerColorSwap(p4, SSCEnums.PlayerID.Four); this.checkForControllerColorSwap(p4, SSCEnums.PlayerID.Four);
this.updateControllerMouseMovement(time, SSCEnums.PlayerID.One, p1);
this.animatedSprites["P1Mouse"].position += this.getMouseDelta(); //Get the delta change in mouse.
this.updateControllerMouseMovement(time, SSCEnums.PlayerID.Two, p2);
this.updateControllerMouseMovement(time, SSCEnums.PlayerID.Three, p3);
this.updateControllerMouseMovement(time, SSCEnums.PlayerID.Four, p4);
this.inputDelays[SSCEnums.PlayerID.One]--; this.inputDelays[SSCEnums.PlayerID.One]--;
this.inputDelays[SSCEnums.PlayerID.Two]--; this.inputDelays[SSCEnums.PlayerID.Two]--;
@ -237,72 +222,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
SeasideScramble.self.camera.snapToPosition(new Vector2(0, 0)); SeasideScramble.self.camera.snapToPosition(new Vector2(0, 0));
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null)
{
this.animatedSprites["P1Mouse"].color = SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One).playerColor;
}
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two) != null)
{
this.animatedSprites["P2Mouse"].color = SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two).playerColor;
}
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three) != null)
{
this.animatedSprites["P3Mouse"].color = SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three).playerColor;
}
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four) != null)
{
this.animatedSprites["P4Mouse"].color = SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four).playerColor;
}
this.oldMousePos = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y); this.oldMousePos = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
} }
private void updateControllerMouseMovement(GameTime time, SSCEnums.PlayerID player,GamePadState state)
{
if(player== SSCEnums.PlayerID.One)
{
this.animatedSprites["P1Mouse"].position += new Vector2(state.ThumbSticks.Right.X,state.ThumbSticks.Right.Y*-1)* controllerMouseSensitivity;
if (SeasideScramble.self.camera.positionInsideViewport(this.animatedSprites["P1Mouse"].position) == false)
{
if (SeasideScramble.self.camera.positionInsideViewport(Game1.getMousePosition()) == true)
{
this.animatedSprites["P1Mouse"].position = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
}
else
{
this.animatedSprites["P2Mouse"].position = this.playerDisplayLocations[player];
}
}
}
if (player == SSCEnums.PlayerID.Two)
{
this.animatedSprites["P2Mouse"].position += new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y * -1)* controllerMouseSensitivity;
if (SeasideScramble.self.camera.positionInsideViewport(this.animatedSprites["P2Mouse"].position) == false)
{
this.animatedSprites["P2Mouse"].position = this.playerDisplayLocations[player];
}
}
if (player == SSCEnums.PlayerID.Three)
{
this.animatedSprites["P3Mouse"].position += new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y * -1) * controllerMouseSensitivity;
if (SeasideScramble.self.camera.positionInsideViewport(this.animatedSprites["P3Mouse"].position) == false)
{
this.animatedSprites["P3Mouse"].position = this.playerDisplayLocations[player];
}
}
if (player == SSCEnums.PlayerID.Four)
{
this.animatedSprites["P4Mouse"].position += new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y * -1) * controllerMouseSensitivity;
if (SeasideScramble.self.camera.positionInsideViewport(this.animatedSprites["P4Mouse"].position) == false)
{
this.animatedSprites["P4Mouse"].position = this.playerDisplayLocations[player];
}
}
}
/// <summary> /// <summary>
/// Looks for controller input for swaping character colors. /// Looks for controller input for swaping character colors.
/// </summary> /// </summary>
@ -448,7 +370,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{ {
if (SeasideScramble.self.getGamepadState(PlayerIndex.One).IsButtonDown(Buttons.A)) if (SeasideScramble.self.getGamepadState(PlayerIndex.One).IsButtonDown(Buttons.A))
{ {
ModCore.log("Button a pressed. Intercepting left click."); //ModCore.log("Button a pressed. Intercepting left click.");
return; return;
} }
ModCore.log("Left clicked for Character selects screen!"); ModCore.log("Left clicked for Character selects screen!");
@ -512,6 +434,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
} }
} }
public void receiveGamepadLeftClick(SSCEnums.PlayerID player, Vector2 position, bool playSound = true)
{
this.receiveGamepadLeftClick(player, (int)position.X, (int)position.Y, playSound);
}
public override void receiveKeyPress(Keys key) public override void receiveKeyPress(Keys key)
{ {
if (key == Keys.Enter || key == Keys.Space) if (key == Keys.Enter || key == Keys.Space)
@ -632,19 +559,19 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null) if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.One) != null)
{ {
this.drawPlayerMouse(b, SSCEnums.PlayerID.One); SeasideScramble.self.getPlayer( SSCEnums.PlayerID.One).drawMouse(b);
} }
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two) != null) if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two) != null)
{ {
this.drawPlayerMouse(b, SSCEnums.PlayerID.Two); SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Two).drawMouse(b);
} }
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three) != null) if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three) != null)
{ {
this.drawPlayerMouse(b, SSCEnums.PlayerID.Three); SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Three).drawMouse(b);
} }
if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four) != null) if (SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four) != null)
{ {
this.drawPlayerMouse(b, SSCEnums.PlayerID.Four); SeasideScramble.self.getPlayer(SSCEnums.PlayerID.Four).drawMouse(b);
} }
} }
@ -657,32 +584,5 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
base.exitMenu(playSound); base.exitMenu(playSound);
} }
public void drawPlayerMouse(SpriteBatch b, SSCEnums.PlayerID player)
{
/*
if (Game1.options.hardwareCursor)
return;
b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, !Game1.options.snappyMenus || !Game1.options.gamepadControls ? 0 : 44, 16, 16)), Color.White * Game1.mouseCursorTransparency, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
*/
if(player== SSCEnums.PlayerID.One)
{
this.animatedSprites["P1Mouse"].draw(b,4f,0f);
}
if (player == SSCEnums.PlayerID.Two)
{
this.animatedSprites["P2Mouse"].draw(b, 4f, 0f);
}
if (player == SSCEnums.PlayerID.Three)
{
this.animatedSprites["P3Mouse"].draw(b, 4f, 0f);
}
if (player == SSCEnums.PlayerID.Four)
{
this.animatedSprites["P4Mouse"].draw(b, 4f, 0f);
}
}
} }
} }

View File

@ -7,6 +7,9 @@ using StardustCore.Animations;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using StardewValley;
using Revitalize.Framework.Utilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
public class SSCPlayer public class SSCPlayer
@ -15,6 +18,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//TODO: Add movement speed variable //TODO: Add movement speed variable
//TODO: Add in health //TODO: Add in health
//TODO: Add in player HUD //TODO: Add in player HUD
//TODO: Add in player cursor
public AnimationManager characterSpriteController; public AnimationManager characterSpriteController;
public bool flipSprite; public bool flipSprite;
public SSCEnums.FacingDirection facingDirection; public SSCEnums.FacingDirection facingDirection;
@ -26,6 +30,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public const int junimoWalkingAnimationSpeed = 10; public const int junimoWalkingAnimationSpeed = 10;
public StardustCore.Animations.AnimatedSprite mouseCursor;
public Vector2 mouseSensitivity;
public bool showMouseCursor;
public int maxMouseSleepTime = 300;
public SSCPlayer(SSCEnums.PlayerID PlayerID) public SSCPlayer(SSCEnums.PlayerID PlayerID)
{ {
this.playerID = PlayerID; this.playerID = PlayerID;
@ -92,7 +103,29 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
new Animation(16*7,16*4,16,16,junimoWalkingAnimationSpeed), new Animation(16*7,16*4,16,16,junimoWalkingAnimationSpeed),
} }, } },
},"Idle_F",0,true); }, "Idle_F", 0, true);
this.mouseCursor = new StardustCore.Animations.AnimatedSprite("P1Mouse", new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Cursors"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>()
{
{"Default",new List<Animation>()
{
new Animation(0,0,16,16)
} }
}, "Default"), Color.White);
if (this.playerID == SSCEnums.PlayerID.One)
{
this.mouseCursor.position = new Vector2(Game1.getMouseX(), Game1.getMouseY());
}
else
{
this.mouseCursor.position = this.position;
}
this.mouseSensitivity = new Vector2(3f, 3f);
} }
/// <summary> /// <summary>
@ -102,6 +135,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public void setColor(Color color) public void setColor(Color color)
{ {
this.playerColor = color; this.playerColor = color;
this.mouseCursor.color = color;
} }
/// <summary> /// <summary>
@ -119,7 +153,7 @@ 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.draw(b,this.position); this.draw(b, this.position);
} }
/// <summary> /// <summary>
@ -131,7 +165,12 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
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)); 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));
} }
public void drawMouse(SpriteBatch b)
{
this.mouseCursor.draw(b, 4f, 0f);
}
#region
/// <summary> /// <summary>
/// Called every frame to do update logic. /// Called every frame to do update logic.
/// </summary> /// </summary>
@ -141,7 +180,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.movedThisFrame = false; this.movedThisFrame = false;
if (this.isMoving == false) if (this.isMoving == false)
{ {
if(this.facingDirection== SSCEnums.FacingDirection.Down) if (this.facingDirection == SSCEnums.FacingDirection.Down)
{ {
this.characterSpriteController.playAnimation("Idle_F"); this.characterSpriteController.playAnimation("Idle_F");
} }
@ -183,55 +222,29 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
} }
this.flipSprite = false; this.flipSprite = false;
} }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Movement logic //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// Checks for moving the player.
/// </summary>
/// <param name="direction"></param>
public void movePlayer(SSCEnums.FacingDirection direction)
{
this.isMoving = true;
this.movedThisFrame = true;
if(direction== SSCEnums.FacingDirection.Up)
{
this.facingDirection = direction;
this.position += new Vector2(0, -1);
}
if (direction == SSCEnums.FacingDirection.Down)
{
this.facingDirection = direction;
this.position += new Vector2(0, 1);
}
if (direction == SSCEnums.FacingDirection.Left)
{
this.facingDirection = direction;
this.position += new Vector2(-1, 0);
}
if (direction == SSCEnums.FacingDirection.Right)
{
this.facingDirection = direction;
this.position += new Vector2(1, 0);
}
//ModCore.log(this.position);
}
/// <summary>
/// Checks when the player presses a key on the keyboard.
/// </summary>
/// <param name="k"></param>
public void receiveKeyPress(Microsoft.Xna.Framework.Input.Keys k)
{
if (this.playerID == SSCEnums.PlayerID.One) if (this.playerID == SSCEnums.PlayerID.One)
{ {
this.checkForMovementInput(k); 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;
}
} }
ModCore.log("Mouse dir:"+this.getMouseDirection());
} }
public void setMousePosition(Vector2 position)
{
this.mouseCursor.position = position;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Input logic //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
/// <summary> /// <summary>
/// Checks when the gamepad receives input. /// Checks when the gamepad receives input.
/// </summary> /// </summary>
@ -257,10 +270,74 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
this.movePlayer(SSCEnums.FacingDirection.Up); this.movePlayer(SSCEnums.FacingDirection.Up);
} }
if (state.ThumbSticks.Left.X == 0 && state.ThumbSticks.Left.Y == 0 && this.movedThisFrame==false) if (state.ThumbSticks.Left.X == 0 && state.ThumbSticks.Left.Y == 0 && this.movedThisFrame == false)
{ {
this.isMoving = false; this.isMoving = false;
} }
if (state.ThumbSticks.Right.X != 0 || state.ThumbSticks.Right.Y != 0)
{
this.shoot(state.ThumbSticks.Right);
//this.moveMouseCursor(state.ThumbSticks.Right);
}
}
else
{
if (state.ThumbSticks.Right.X != 0 || state.ThumbSticks.Right.Y != 0)
{
this.moveMouseCursor(new Vector2(state.ThumbSticks.Right.X,state.ThumbSticks.Right.Y*-1));
this.showMouseCursor = true;
}
}
}
/// <summary>
/// Move the mouse cursor.
/// </summary>
/// <param name="direction"></param>
private void moveMouseCursor(Vector2 direction)
{
if (SeasideScramble.self.camera.positionInsideViewport(this.mouseCursor.position + new Vector2(direction.X * this.mouseSensitivity.X, direction.Y * this.mouseSensitivity.Y)))
{
this.mouseCursor.position += new Vector2(direction.X*this.mouseSensitivity.X,direction.Y*this.mouseSensitivity.Y);
}
else if (SeasideScramble.self.camera.positionInsideViewport(this.mouseCursor.position + new Vector2(direction.X*this.mouseSensitivity.X, 0)))
{
this.mouseCursor.position += new Vector2(direction.X * this.mouseSensitivity.X, 0);
}
else if (SeasideScramble.self.camera.positionInsideViewport(this.mouseCursor.position + new Vector2(0, direction.Y*this.mouseSensitivity.Y)))
{
this.mouseCursor.position += new Vector2(0, direction.Y*this.mouseSensitivity.Y);
}
}
/// <summary>
/// Gets a normalized direction vector for the player.
/// </summary>
/// <returns></returns>
private Vector2 getMouseDirection()
{
Vector2 dir = this.getRelativeMouseFromPlayer();
dir = dir.UnitVector();
return dir;
}
private Vector2 getRelativeMouseFromPlayer()
{
Vector2 pos = this.mouseCursor.position - SeasideScramble.GlobalToLocal(this.position);
return pos;
}
/// <summary>
/// Checks when the player presses a key on the keyboard.
/// </summary>
/// <param name="k"></param>
public void receiveKeyPress(Microsoft.Xna.Framework.Input.Keys k)
{
if (this.playerID == SSCEnums.PlayerID.One)
{
this.checkForMovementInput(k);
} }
} }
@ -274,26 +351,75 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//throw new NotImplementedException(); //throw new NotImplementedException();
if (K == Keys.A) if (K == Keys.A)
{ {
ModCore.log("A released for Seaside Scramble!");
this.isMoving = false; this.isMoving = false;
} }
if (K == Keys.W) if (K == Keys.W)
{ {
ModCore.log("W pressed for Seaside Scramble!");
this.isMoving = false; this.isMoving = false;
} }
if (K == Keys.S) if (K == Keys.S)
{ {
ModCore.log("S pressed for Seaside Scramble!");
this.isMoving = false; this.isMoving = false;
} }
if (K == Keys.D) if (K == Keys.D)
{ {
ModCore.log("D pressed for Seaside Scramble!");
this.isMoving = false; this.isMoving = false;
} }
} }
public void receiveLeftClick(int x, int y)
{
if (SeasideScramble.self.getGamepadState(PlayerIndex.One).IsButtonDown(Buttons.A))
{
//Do stuf besides shooting.
return;
}
Vector2 clickPos = new Vector2(x, y);
Vector2 direction = this.getMouseDirection();
ModCore.log("Player click: " + direction);
this.shoot(direction);
}
#endregion
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Movement logic //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// Checks for moving the player.
/// </summary>
/// <param name="direction"></param>
public void movePlayer(SSCEnums.FacingDirection direction)
{
this.isMoving = true;
this.movedThisFrame = true;
if (direction == SSCEnums.FacingDirection.Up)
{
this.facingDirection = direction;
this.position += new Vector2(0, -1);
}
if (direction == SSCEnums.FacingDirection.Down)
{
this.facingDirection = direction;
this.position += new Vector2(0, 1);
}
if (direction == SSCEnums.FacingDirection.Left)
{
this.facingDirection = direction;
this.position += new Vector2(-1, 0);
}
if (direction == SSCEnums.FacingDirection.Right)
{
this.facingDirection = direction;
this.position += new Vector2(1, 0);
}
//ModCore.log(this.position);
}
/// <summary> /// <summary>
/// Checks for player movement. /// Checks for player movement.
/// </summary> /// </summary>
@ -305,28 +431,28 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
//Microsoft.Xna.Framework.Input.GamePadState state = this.getGamepadState(PlayerIndex.One); //Microsoft.Xna.Framework.Input.GamePadState state = this.getGamepadState(PlayerIndex.One);
if (K == Keys.A) if (K == Keys.A)
{ {
ModCore.log("A pressed for player");
this.movePlayer(SSCEnums.FacingDirection.Left); this.movePlayer(SSCEnums.FacingDirection.Left);
} }
if (K == Keys.W) if (K == Keys.W)
{ {
ModCore.log("W pressed for player!");
this.movePlayer(SSCEnums.FacingDirection.Up); this.movePlayer(SSCEnums.FacingDirection.Up);
} }
if (K == Keys.S) if (K == Keys.S)
{ {
ModCore.log("S pressed for player!");
this.movePlayer(SSCEnums.FacingDirection.Down); this.movePlayer(SSCEnums.FacingDirection.Down);
} }
if (K == Keys.D) if (K == Keys.D)
{ {
ModCore.log("D pressed for player!");
this.movePlayer(SSCEnums.FacingDirection.Right); this.movePlayer(SSCEnums.FacingDirection.Right);
} }
} }
#endregion #endregion
private void shoot(Vector2 direction)
{
ModCore.log("Shoot: " + direction);
}
} }
} }

View File

@ -8,6 +8,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Revitalize.Framework.Minigame.SeasideScrambleMinigame; using Revitalize.Framework.Minigame.SeasideScrambleMinigame;
using StardewValley;
using StardustCore.UIUtilities; using StardustCore.UIUtilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
@ -48,6 +49,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public SSCMenus.SSCMenuManager menuManager; public SSCMenus.SSCMenuManager menuManager;
public Vector2 oldMousePosition;
public SeasideScramble() public SeasideScramble()
{ {
self = this; self = this;
@ -69,7 +72,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.menuManager = new SSCMenus.SSCMenuManager(); this.menuManager = new SSCMenus.SSCMenuManager();
this.menuManager.addNewMenu(new SSCMenus.TitleScreen(this.camera.viewport)); this.menuManager.addNewMenu(new SSCMenus.TitleScreen(this.camera.viewport));
this.oldMousePosition = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
} }
public SSCPlayer getPlayer(SSCEnums.PlayerID id) public SSCPlayer getPlayer(SSCEnums.PlayerID id)
@ -146,6 +149,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
foreach(SSCPlayer p in this.players.Values) { foreach(SSCPlayer p in this.players.Values) {
p.draw(b); p.draw(b);
if(p.playerID== SSCEnums.PlayerID.One)
{
p.drawMouse(b);
}
} }
/* /*
@ -255,6 +262,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
this.menuManager.activeMenu.receiveLeftClick(x, y, playSound); this.menuManager.activeMenu.receiveLeftClick(x, y, playSound);
} }
foreach(SSCPlayer player in this.players.Values)
{
player.receiveLeftClick(x, y);
}
//throw new NotImplementedException(); //throw new NotImplementedException();
} }
@ -332,6 +343,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
this.menuManager.closeActiveMenu(); this.menuManager.closeActiveMenu();
} }
foreach (SSCPlayer player in this.players.Values)
{
player.update(time);
}
} }
else else
{ {
@ -341,11 +356,21 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
player.update(time); player.update(time);
} }
} }
this.oldMousePosition = new Vector2(Game1.getOldMouseX(), Game1.getOldMouseY());
return false; return false;
//throw new NotImplementedException(); //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> /// <summary>
/// Called when the minigame is quit upon. /// Called when the minigame is quit upon.
/// </summary> /// </summary>

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
namespace Revitalize.Framework.Utilities
{
public static class Vector2Utilities
{
public static double Magnitude(this Vector2 vec)
{
return Math.Sqrt(Math.Pow(vec.X, 2) + Math.Pow(vec.Y, 2));
}
/// <summary>
/// Returns the unit vector.
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
public static Vector2 UnitVector(this Vector2 vec)
{
double mag = Magnitude(vec);
return new Vector2((float)(vec.X / mag),(float)(vec.Y / mag));
}
}
}

View File

@ -108,6 +108,7 @@
<Compile Include="Framework\Utilities\Serialization\Converters\Vector2Converter.cs" /> <Compile Include="Framework\Utilities\Serialization\Converters\Vector2Converter.cs" />
<Compile Include="Framework\Utilities\Serialization\Serialization.cs" /> <Compile Include="Framework\Utilities\Serialization\Serialization.cs" />
<Compile Include="Framework\Utilities\Serialization\SpriteBatchUtilities.cs" /> <Compile Include="Framework\Utilities\Serialization\SpriteBatchUtilities.cs" />
<Compile Include="Framework\Utilities\Vector2Utilities.cs" />
<Compile Include="ModCore.cs" /> <Compile Include="ModCore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>