public Player(ContentManager cm, SpriteBatch sb, GraphicsDeviceManager gdm) { //configures the image sheet associated with the player playerImageSheet = new AnimatedImage(cm, sb, gdm.GraphicsDevice, "PlayerImages/PlayerPlaceholderRefined", new Vector2(1372, 469), new Vector2(18, 5)); playerImageSheet.frameTimeLimit = 8; playerImageSheet.Initialize(); playerImageSheet.setFrameConfiguration(0, 0, 1); //playerImageSheet.isAnimating = false; boundingRectangleColor = cm.Load<Texture2D>("CollisionColor"); //sets the references to the spritebatch and content manager so this class can define items in the content pipeline and draw to the same area sbReference = sb; cmReference = cm; gdmReference = gdm; //environment variables previousWorldPosition = Vector2.Zero; currentWorldPosition = Vector2.Zero; velocity = new Vector2(8, 25); momentum = new Vector2(0,0); movingLeft = false; movingRight = false; movingUp = false; movingDown = false; standing = true; isJumping = false; isFalling = false; isFallingFromGravity = false; isDashing = false; exhaustedDash = false; jumpTimer = 0; jumpTimerMax = 20; dashTimer = 0; dashTimerMax = 10; currentActionHurdleReference = null; actionButtonBeingPressed = false; actionStateIsActive = false; hurdleActionStateActive = false; upTheHurdle = false; overTheHurdle = false; hurdleTimer = 0; hurdleTimerMax = 10; hurdleDistance = Vector2.Zero; facingLeft = false; facingRight = true; playerCollisionOccurred = false; collisionOnPlayerLeft = false; collisionOnPlayerRight = false; collisionOnPlayerTop = false; collisionOnPlayerBottom = false; }
public BaseTile(ContentManager cm, GraphicsDeviceManager gdm, SpriteBatch sb, Vector2 pos, AnimatedImage imageName) : base(pos) { cmReference = cm; gdmReference = gdm; sbReference = sb; baseTileImage = imageName; baseTileImage.position = pos; baseTileImage.setFrameConfiguration(0, 0, 0); isCollidable = false; }
//---------------------------------------------------------------------------------------------------------------------------------------------------------- public WaterPlatform(ContentManager cm, SpriteBatch sb, GraphicsDeviceManager gdm, ImageLibrary il, Vector2 platSize, Vector2 pos, bool slidableOnL, bool slidableOnR, bool cOnLeft, bool cOnRight, bool cOnTop, bool cOnBottom) : base(cm, sb, gdm, il, platSize, pos, slidableOnL, slidableOnR, cOnLeft, cOnRight, cOnTop, cOnBottom) { topWater = il.waterCrestTile; topWater.setFrameConfiguration(0, 0, 1); topWater.frameTimeLimit = 15; completeOutsidePlatformImage = il.waterBodyTile; layerDepth = .25f; flipTopWaterCrest = false; }
public BaseTile(ContentManager cm, GraphicsDeviceManager gdm, SpriteBatch sb, Vector2 pos, Vector2 sourceImageSize, Vector2 sourceImageColumnAndRowSize, String imageName, bool cOnLeft, bool cOnRight, bool cOnTop, bool cOnBottom) : base(pos) { cmReference = cm; gdmReference = gdm; sbReference = sb; baseTileImage = new AnimatedImage(cmReference, sbReference, gdmReference.GraphicsDevice, imageName, sourceImageSize, sourceImageColumnAndRowSize); baseTileImage.position = pos; baseTileImage.setFrameConfiguration(0, 0, 0); isCollidable = false; collidableOnLeft = cOnLeft; collidableOnRight = cOnRight; collidableOnTop = cOnTop; collidableOnBottom = cOnBottom; }
public BearTrap(ContentManager cm, GraphicsDeviceManager gdm, SpriteBatch sb, Vector2 worldPos) { cmReference = cm; gdmReference = gdm; sbReference = sb; bearTrapImage = new AnimatedImage(cmReference, sbReference, gdmReference.GraphicsDevice, "GameObjects/Traps/BearTrapPlaceholder", new Vector2(120, 20), new Vector2(3, 1)); bearTrapImage.isAnimating = false; bearTrapImage.animateOnce = false; bearTrapImage.frameTimeLimit = 4; bearTrapImage.setFrameConfiguration(0, 0, 2); worldPosition = worldPos; layerDepth = .5f; wasActivated = false; }
public Spring(ContentManager cm, GraphicsDeviceManager gdm, SpriteBatch sb, ImageLibrary il, Vector2 worldPos, Vector2 momentumToImpart, float springRotation) { cmReference = cm; gdmReference = gdm; sbReference = sb; //probably going to have to have each spring load its own separate texture because this will make it do weird drawing for multiple springs imageSheet = new AnimatedImage(cm, sb, gdm.GraphicsDevice, "GameObjects/Springs/SonicSpring", new Vector2(190, 38), new Vector2(5, 1)); imageSheet.setFrameConfiguration(0, 0, 3); imageSheet.frameTimeLimit = 1; imageSheet.isAnimating = false; layerDepth = .5f; rotation = springRotation; worldPosition = worldPos; momentumImparted = momentumToImpart; }
//---------------------------------------------------------------------------------------------------------------------------------------------------------- public TiledPlatform(ContentManager cm, SpriteBatch sb, GraphicsDeviceManager gdm, Vector2 platSize, Vector2 pos, bool cOnLeft, bool cOnRight, bool cOnTop, bool cOnBottom) { //configures the image sheet associated with the playerOne imageSheet = new AnimatedImage(cm, sb, gdm.GraphicsDevice, "PlatformTextures/Square", new Vector2(16, 16), new Vector2(1, 1)); imageSheet.frameTimeLimit = 8; imageSheet.setFrameConfiguration(0, 0, 0); //imageSheet.isAnimating = false; //sets the references to the spritebatch and content manager so this class can define items in the content pipeline and draw to the same area sbReference = sb; cmReference = cm; gdmReference = gdm; //environment variables position = Vector2.Zero; platformSize = new Vector2(1, 1); //will multiply the playerOne's velocity by the corresponding vectors terrainModifier = new Vector2(1.0f, 1.0f); movingLeft = false; movingRight = false; movingUp = false; movingDown = false; collidableOnLeft = cOnLeft; collidableOnRight = cOnRight; collidableOnTop = cOnTop; collidableOnBottom = cOnBottom; //equivilant of the playerOne class is the boolean "standing", basically default state notMoving = true; //Pretty sure I won't need these and they'll be deprecated for the platform facingLeft = false; facingRight = true; platformSize = platSize; position = pos; }
public Treasure(ContentManager cm, GraphicsDeviceManager gdm, SpriteBatch sb, ImageLibrary il, Vector2 startCenterPos, float treasureRotation) { cmReference = cm; gdmReference = gdm; sbReference = sb; //probably going to have to have each spring load its own separate texture because this will make it do weird drawing for multiple springs imageSheet = il.goldJewelImage; imageSheet.setFrameConfiguration(0, 0, 4); imageSheet.isAnimating = false; layerDepth = .5f; rotation = treasureRotation; centerPosition = startCenterPos; startCenterPosition = startCenterPos; animatingUp = false; animatingDown = true; floatIncrementTimer = 0; floatIncrementTimerMax = 3; }
public void drawAltPosition(Vector2 startSlopePosition, Vector2 endSlopePosition) { //sbReference.Draw(slopeTexture, new Rectangle((int)(altPos.X + xTracker), (int)(altLine.yAtX(altPos.X-xTracker)), (int)slopeTexture.Width, (int)slopeTexture.Height), null, Color.White, (float)(rotation * (Math.PI / 180)), Vector2.Zero, SpriteEffects.FlipHorizontally, 0f); Rectangle tempRectangle = platformSlope.getAltBoundingRectangle(startSlopePosition); if (startSlopePosition.Y > endSlopePosition.Y) { tempRectangle = platformSlope.getAltBoundingRectangle(new Vector2(startSlopePosition.X, endSlopePosition.Y)); } Line altLine = new Line(startSlopePosition, endSlopePosition); float slope = Math.Abs(altLine.getSlope()); float rotation = (float)(180 / Math.PI * Math.Atan((platformSlope.pt2.Y - platformSlope.pt1.Y) / (platformSlope.pt2.X - platformSlope.pt1.X))); //System.Diagnostics.Debug.WriteLine(rotation); float xTracker = 0; //System.Diagnostics.Debug.WriteLine("Start X: " + platformSlope.getBoundingRectangle.X); //System.Diagnostics.Debug.WriteLine("Start Y: " + startYPos); //System.Diagnostics.Debug.WriteLine("Alt Y: " + altPos.Y); //System.Diagnostics.Debug.WriteLine("Width: " + platformSlope.getBoundingRectangle.Width); //System.Diagnostics.Debug.WriteLine(altLine.getSlope()); while (tempRectangle.Left + xTracker < tempRectangle.Right) { if (xTracker == 0) { slopeTexture.setFrameConfiguration(1, 1, 1); } else if (tempRectangle.Left + xTracker != tempRectangle.Right - 16) { slopeTexture.setFrameConfiguration(1, 1, 1); } else if (tempRectangle.Left + xTracker > tempRectangle.Right - 16) { slopeTexture.setFrameConfiguration(1, 1, 1); } if (tempRectangle.Left + xTracker > tempRectangle.Right - 16) { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Right - 16, altLine.yAtX(tempRectangle.Right - 16)), false, rotation, layerDepth + .01f); } else { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Left + xTracker, altLine.yAtX(tempRectangle.Left + xTracker)), false, rotation, layerDepth); } //draws the platform slope texture //------------------------------- float xTrackerModifier = (float)Math.Abs(Math.Cos(rotation) * 16); //System.Diagnostics.Debug.WriteLine(xTrackerModifier); if (xTrackerModifier > 16) { xTracker += 16; } else { if (slope < 1) { xTracker += xTrackerModifier; } else { xTracker += 8; } } } }
public void drawAltPosition(Vector2 startSlopePosition, Vector2 endSlopePosition) { //sbReference.Draw(slopeTexture, new Rectangle((int)(altPos.X + xTracker), (int)(altLine.yAtX(altPos.X-xTracker)), (int)slopeTexture.Width, (int)slopeTexture.Height), null, Color.White, (float)(rotation * (Math.PI / 180)), Vector2.Zero, SpriteEffects.FlipHorizontally, 0f); Rectangle tempRectangle = platformSlope.getAltBoundingRectangle(startSlopePosition); if (startSlopePosition.Y > endSlopePosition.Y) { tempRectangle = platformSlope.getAltBoundingRectangle(new Vector2(startSlopePosition.X, endSlopePosition.Y)); } Line altLine = new Line(startSlopePosition, endSlopePosition); float slope = Math.Abs(altLine.getSlope()); float rotation = (float)(180 / Math.PI * Math.Atan((platformSlope.pt2.Y - platformSlope.pt1.Y) / (platformSlope.pt2.X - platformSlope.pt1.X))); //System.Diagnostics.Debug.WriteLine(rotation); float xTracker = 0; float yTracker = 0; //System.Diagnostics.Debug.WriteLine("Start X: " + platformSlope.getBoundingRectangle.X); //System.Diagnostics.Debug.WriteLine("Start Y: " + startYPos); //System.Diagnostics.Debug.WriteLine("Alt Y: " + altPos.Y); //System.Diagnostics.Debug.WriteLine("Width: " + platformSlope.getBoundingRectangle.Width); //System.Diagnostics.Debug.WriteLine(altLine.getSlope()); while (tempRectangle.Left + xTracker < tempRectangle.Right) { if (xTracker == 0) { if (collidableOnLeftSide) { slopeTexture.setFrameConfiguration(0, 0, 0); } else { slopeTexture.setFrameConfiguration(1, 1, 1); } } else if (tempRectangle.Left + xTracker != tempRectangle.Right - 16) { slopeTexture.setFrameConfiguration(1, 1, 1); } else if (tempRectangle.Left + xTracker > tempRectangle.Right - 16) { if (collidableOnRightSide) { slopeTexture.setFrameConfiguration(2, 2, 2); } else { slopeTexture.setFrameConfiguration(1, 1, 1); } } if (tempRectangle.Left + xTracker > tempRectangle.Right - 16) { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Right - 16, altLine.yAtX(tempRectangle.Right)), false, 0, layerDepth + .01f); } else { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Left + xTracker, altLine.yAtX(tempRectangle.Left + xTracker)), false, rotation, layerDepth); } //draws the platform slope texture //------------------------------- //System.Diagnostics.Debug.WriteLine("slope: " + altLine.getSlope()); float xTrackerModifier = (float)Math.Abs(Math.Cos(rotation) * 16); //System.Diagnostics.Debug.WriteLine(xTrackerModifier); if (xTrackerModifier > 16) { xTracker += 16; } else { xTracker += xTrackerModifier; } } //------------------------ draw body start ----------------------- //DRAW PLATFORM BODY BELOW xTracker = 0; yTracker = 16; float startYPos; while (xTracker < tempRectangle.Width) { startYPos = altLine.yAtX(tempRectangle.Left + xTracker); if (slope >= 0 && slope < .1) { } else if (slope >= .1 && slope < .2) { startYPos -= 1; } else if (slope >= .2 && slope < .3) { startYPos -= 2; } else if (slope >= .3 && slope < .4) { startYPos -= 2; } else if (slope >= .4 && slope < .5) { startYPos -= 4; } else if (slope >= .6 && slope < .7) { startYPos -= 4; } yTracker = 16; while (startYPos <= platformBodyHeight + tempRectangle.Bottom - yTracker) { //left side if (xTracker == 0) { //bottom left if (yTracker == 16) { if (collidableOnLeftSide && collidableOnBottom) { slopeTexture.setFrameConfiguration(6, 6, 6); } else if (collidableOnBottom && !collidableOnLeftSide) { slopeTexture.setFrameConfiguration(7, 7, 7); } else if (collidableOnLeftSide && !collidableOnBottom) { slopeTexture.setFrameConfiguration(3, 3, 3); } else { slopeTexture.setFrameConfiguration(4, 4, 4); } } //right side else { if (collidableOnLeftSide) { slopeTexture.setFrameConfiguration(3, 3, 3); } else { slopeTexture.setFrameConfiguration(4, 4, 4); } } } //between left and right side else if (xTracker > 0 && xTracker < tempRectangle.Width - 16 && tempRectangle.Bottom + platformBodyHeight - yTracker > altLine.yAtX(tempRectangle.Left + xTracker + 16)) { //bottom if (yTracker == 16) { if (collidableOnBottom) { slopeTexture.setFrameConfiguration(7, 7, 7); } else { slopeTexture.setFrameConfiguration(4, 4, 4); } } //center else { slopeTexture.setFrameConfiguration(4, 4, 4); } } //right side else if (xTracker > tempRectangle.Width - 16) { if (yTracker == 16) { if (collidableOnRightSide && collidableOnBottom) { slopeTexture.setFrameConfiguration(8, 8, 8); } else if (collidableOnBottom && !collidableOnRightSide) { slopeTexture.setFrameConfiguration(7, 7, 7); } else if (collidableOnRightSide && !collidableOnBottom) { slopeTexture.setFrameConfiguration(5, 5, 5); } else { slopeTexture.setFrameConfiguration(4, 4, 4); } } else { if (collidableOnRightSide) { slopeTexture.setFrameConfiguration(5, 5, 5); } else { slopeTexture.setFrameConfiguration(4, 4, 4); } } } if (xTracker > tempRectangle.Width - 16) { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Right - 16, tempRectangle.Bottom + platformBodyHeight - yTracker), false, 0, layerDepth + .01f); } else { slopeTexture.DrawAltPosition(new Vector2(tempRectangle.Left + xTracker, tempRectangle.Bottom + platformBodyHeight - yTracker), false, 0, layerDepth + .01f); } yTracker += 16; } xTracker += 16; //modifier helps account for slight discrepancies with drawing //-------------------------------------------------------------------------draw body end -------------------- } }
public virtual void DrawAltPosition(Vector2 altPos) { int xTracker = 0; int xPosition = (int)altPos.X; int yTracker = 0; int yPosition = (int)altPos.Y; //expects you to pass in the converted position variable yTracker = 0; yPosition = (int)altPos.Y; while (yTracker < platformSize.Y) { xTracker = 0; xPosition = (int)(altPos.X); while (xTracker < platformSize.X) { //top left if (xTracker == 0 && yTracker == 0) { if (collidableOnLeft) { completeOutsidePlatformImage.setFrameConfiguration(0, 0, 0); } else { completeOutsidePlatformImage.setFrameConfiguration(1, 1, 1); } } //top else if (yTracker == 0 && xTracker > 0 && xTracker < platformSize.X - 1) { completeOutsidePlatformImage.setFrameConfiguration(1, 1, 1); } //top right else if (yTracker == 0 && xTracker == platformSize.X - 1) { if (collidableOnRight) { completeOutsidePlatformImage.setFrameConfiguration(2, 2, 2); } else { completeOutsidePlatformImage.setFrameConfiguration(1, 1, 1); } } //left else if (yTracker > 0 && yTracker < platformSize.Y - 1 && xTracker == 0) { if (collidableOnLeft) { completeOutsidePlatformImage.setFrameConfiguration(3, 3, 3); } else { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } } //center else if (yTracker > 0 && yTracker < platformSize.Y - 1 && xTracker > 0 && xTracker < platformSize.X - 2) { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } //right else if (yTracker > 0 && yTracker < platformSize.Y - 1 && xTracker == platformSize.X - 1) { if (collidableOnRight) { completeOutsidePlatformImage.setFrameConfiguration(5, 5, 5); } else { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } } //bottom left else if (yTracker == platformSize.Y - 1 && xTracker == 0) { if (collidableOnLeft && collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(6, 6, 6); } else if (collidableOnLeft && !collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(3, 3, 3); } else if (!collidableOnLeft && collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(7, 7, 7); } else { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } } //bottom else if (yTracker == platformSize.Y - 1 && xTracker > 0 && xTracker < platformSize.X - 1) { if (collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(7, 7, 7); } else { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } } //bottom right else if (yTracker == platformSize.Y - 1 && xTracker == platformSize.X - 1) { if (collidableOnRight && collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(8, 8, 8); } else if (collidableOnRight && !collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(5, 5, 5); } else if (!collidableOnRight && collidableOnBottom) { completeOutsidePlatformImage.setFrameConfiguration(7, 7, 7); } else { completeOutsidePlatformImage.setFrameConfiguration(4, 4, 4); } } completeOutsidePlatformImage.DrawAltPosition(new Vector2(xPosition, yPosition), false, layerDepth); xPosition += (int)completeOutsidePlatformImage.frameSize.X; xTracker++; } yTracker++; yPosition += (int)(completeOutsidePlatformImage.frameSize.Y); } }
//TO DO: make an environment class for the stages to pass in so I know how to modify the movement accordingly // potential modifiers: wind, terrain slickness(may just handle this in the wall collision class), gravity, etc // in the mean time just keep track of items individually public Vector2 calculateNewPosition(Vector2 gravity) { //saves the old position before modifying it and updating it accordingly previousWorldPosition = currentWorldPosition; Vector2 newPosition = currentWorldPosition; if (actionStateIsActive) { if (hurdleActionStateActive) { if (currentActionHurdleReference != null) { //TO DO: have it run through the hurdle's action state sequence here if (upTheHurdle) { hurdleTimer++; if (movingLeft) { newPosition.X += hurdleDistance.X/hurdleTimerMax; } if (movingRight) { newPosition.X -= hurdleDistance.X / hurdleTimerMax; } newPosition.Y -= hurdleDistance.Y/hurdleTimerMax; if (hurdleTimer > hurdleTimerMax) { upTheHurdle = false; overTheHurdle = true; if (movingLeft) { hurdleDistance.X = currentActionHurdleReference.getBoundingBox.Left - boundingRectangle.Right; } if (movingRight) { hurdleDistance.X = currentActionHurdleReference.getBoundingBox.Right - boundingRectangle.Left; } hurdleDistance.Y = currentActionHurdleReference.getBoundingBox.Top - boundingRectangle.Bottom; hurdleTimer = 0; hurdleTimerMax = 10; } } if (overTheHurdle) { hurdleTimer++; newPosition.X += hurdleDistance.X / hurdleTimerMax; newPosition.Y -= hurdleDistance.Y / hurdleTimerMax; if (hurdleTimer > hurdleTimerMax) { overTheHurdle = false; if (movingLeft) { momentum.X = -50; } if (movingRight) { momentum.X = 50; } } } if (!upTheHurdle && !overTheHurdle) { hurdleActionStateActive = false; } } else { hurdleActionStateActive = false; } //resets the action state flag if nothing is pressed if (hurdleActionStateActive) { actionStateIsActive = true; } else { currentActionHurdleReference = null; actionStateIsActive = false; } } return newPosition; } else { //accounts for movement in these directions if (movingLeft) { newPosition.X -= velocity.X; } if (movingRight) { newPosition.X += velocity.X; } //accounts for the action states, standing, jumping, falling, dashing if (isJumping) { if (jumpTimer < jumpTimerMax) { //This basically ups the velocity of the player and diminishes it based on the duration of the jump, the longer the jump the less high you will go //Abe: If you want to do it based on progress, use a parabolic velocity function - e.g. x(t) = v * t * cos(angle), y(t) = v * t * sin(angle) - 0.5 * g * t^2 if (isDashing) { //don't update player jump values } else { newPosition.Y -= velocity.Y - (velocity.Y * ((float)jumpTimer / (float)jumpTimerMax)); } } else { isJumping = false; //possibly set the falling animation here and then on any collision have the player check if they're falling and set the animation accordingly isFalling = true; playerImageSheet.setFrameConfiguration(72, 72, 72); playerImageSheet.frameTimeLimit = 8; } jumpTimer++; //System.Diagnostics.Debug.WriteLine(jumpTimer); } if (isFalling) { //if falling this is added to counteract gravity, set to 0 for no effect or remove as well if (isDashing) { //dont update vector } else { newPosition -= new Vector2(0, 6); } } //tracks dashing modifiers, if dashing and within the duration modifies the position accordingly //else it's outside duration and sets dashing to false, but that it's been exhausted, the exhaustedDash //needs to be reset by collision objects otherwise it breaks if (isDashing) { if (dashTimer < dashTimerMax && exhaustedDash == false) { //if you want to be able to dash without having to move change these to "facingLeft" and "facingRight" if (facingLeft) { newPosition.X -= 10f; } if (facingRight) { newPosition.X += 10f; } } else { isDashing = false; exhaustedDash = true; if ((movingLeft || movingRight) && (!isFalling && !isFallingFromGravity && !isJumping)) { playerImageSheet.setFrameConfiguration(18, 18, 25); playerImageSheet.frameTimeLimit = 8; } else { if (isFalling) { playerImageSheet.setFrameConfiguration(72, 72, 72); playerImageSheet.frameTimeLimit = 8; } else if (isFallingFromGravity) { playerImageSheet.setFrameConfiguration(73, 73, 73); playerImageSheet.frameTimeLimit = 8; } else if (isJumping) { playerImageSheet.setFrameConfiguration(36, 36, 42); playerImageSheet.frameTimeLimit = 6; } } } dashTimer++; } //adds environment modifying vectors if (isJumping || isDashing) { newPosition -= gravity; } newPosition += gravity; newPosition += momentum; momentum.X = (float)(momentum.X *.9); momentum.Y = (float)(momentum.Y*.9); return newPosition; } }