Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace TopFalling3
- {
- abstract class Movement
- {
- public Movement()
- {
- }
- public abstract void Update(GameTime gameTime,
- Rectangle gameViewPort,
- GameObject movingObject,
- Vector2 newPosition);
- //Standard moving along the rotation
- public void Update(GameTime gameTime, Rectangle gameViewPort, GameObject movingObject)
- {
- //Add the velocity * the direction
- movingObject.position.X += movingObject.Velocity.X * (float)(Math.Cos(movingObject.rotation));
- movingObject.position.Y += movingObject.Velocity.Y * (float)(Math.Sin(movingObject.rotation));
- }
- public bool ReachedWaypoint(GameObject movingObject,
- Vector2 newPosition)
- {
- if (Math.Abs((newPosition.X - movingObject.position.X)) < (movingObject.Velocity.X))
- {//within X
- if (Math.Abs((newPosition.Y - movingObject.position.Y)) < (movingObject.Velocity.Y))
- {//within Y
- return true;
- }
- }
- return false;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace TopFalling3
- {
- class InitialVector : Movement
- {
- public InitialVector()
- {
- //This movement is based soley off the inital rotation/vector of the bullet.
- }
- //move from old point, to new point.
- public override void Update(GameTime gameTime,
- Rectangle gameViewPort,
- GameObject movingObject,
- Vector2 newPosition)
- {
- //Add the velocity * the direction
- movingObject.position.X += movingObject.Velocity.X * (float)(Math.Cos(movingObject.rotation));
- movingObject.position.Y += movingObject.Velocity.Y * (float)(Math.Sin(movingObject.rotation));
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace TopFalling3
- {
- class DM_MaxTurning : Movement
- {
- public DM_MaxTurning()
- {
- }
- //move from old point, to new point.
- public override void Update(GameTime gameTime,
- Rectangle gameViewPort,
- GameObject movingObject,
- Vector2 newPosition)
- {
- //Get the vector to move from 1 point to the other
- float dist_to_waypoint_x = newPosition.X - movingObject.position.X;//currentPosition.X - newPosition.X;
- float dist_to_waypoint_y = newPosition.Y - movingObject.position.Y; //currentPosition.Y - newPosition.Y;
- //Atan is the Arc-Tangent
- //Tan is the Tangent (angle in radians with the given y/x)
- //Store the new rotation
- float adjustToRotation = (float)Math.Atan2(dist_to_waypoint_y,dist_to_waypoint_x);
- float diffBetweenRotations = adjustToRotation - movingObject.rotation;
- if (diffBetweenRotations > 0)
- {
- movingObject.rotation += movingObject.maxRotationSpeed;
- diffBetweenRotations = adjustToRotation - movingObject.rotation;
- if (diffBetweenRotations < 0) //If the rotation changed past the adjustToRotation, set it equal to it
- movingObject.rotation = adjustToRotation;
- }
- else if (diffBetweenRotations < 0)
- {
- movingObject.rotation -= movingObject.maxRotationSpeed;
- diffBetweenRotations = adjustToRotation - movingObject.rotation;
- if (diffBetweenRotations > 0) //If the rotation changed past the adjustToRotation, set it equal to it
- movingObject.rotation = adjustToRotation;
- }
- else
- { } //Do nothing
- //movingObject.rotation += -(float)Math.PI / 2;
- //Add the velocity * the direction
- movingObject.position.X += movingObject.Velocity.X * (float)(Math.Cos(movingObject.rotation));
- movingObject.position.Y += movingObject.Velocity.Y * (float)(Math.Sin(movingObject.rotation));
- //movingObject.rotation += (float)Math.PI / 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement