/// <summary> /// Construcs a player object, that can live in a physical realm /// </summary> /// <param name="content">Content manager for the game</param> /// <param name="name">Name of the image resource for the player</param> /// <param name="initialPosition">Initial posisition in the level</param> /// <param name="scalingFactors">Factor for the image resource(i.e. half the size would be (.5,.5))</param> /// <param name="controlScheme">Controller scheme for the player(Controller or keyboard)</param> public Player(ContentManager content, String name, Vector2 scalingFactors, Vector2 initialPosition,ref PhysicsEnvironment environment, IControlScheme controlScheme) : base(content, name, scalingFactors, initialPosition,ref environment) { mControls = controlScheme; mSpawnPoint = initialPosition; }
/// <summary> /// Constructs a PhysicsObject; Loads the required info from the content pipeline, and defines its size and location /// </summary> /// <param name="content">Content pipeline</param> /// <param name="spriteBatch">The drawing canvas of the game. Used for collision detection with the level</param> /// <param name="name">Name of the physics object so that it can be loaded</param> /// <param name="scalingFactors">Factor for the image resource(i.e. half the size would be (.5,.5)</param> /// <param name="initialPosition">Position of where this object starts in the level</param> public PhysicsObject(ContentManager content, String name, Vector2 scalingFactors, Vector2 initialPosition, ref PhysicsEnvironment environment) { mName = name; Load(content, name); mEnvironment = environment; mPosition = initialPosition; mSize = new Vector2(mTexture.Width * scalingFactors.X, mTexture.Height * scalingFactors.Y); UpdateBoundingBoxes(); }
/// <summary> /// Construcs a player object, that can live in a physical realm /// </summary> /// <param name="content">Content manager for the game</param> /// <param name="name">Name of the image resource for the player</param> /// <param name="initialPosition">Initial posisition in the level</param> /// <param name="controlScheme">Controller scheme for the player(Controller or keyboard)</param> public Player(ContentManager content, ref PhysicsEnvironment environment, IControlScheme controlScheme, float friction, EntityInfo entity) : base(content, ref environment,friction, entity) { mControls = controlScheme; mSpawnPoint = mPosition; mRotation = 0.0f; mGoalRotation = 0.0f; mFaceGoalRotation = 0.0f; mFaceRotation = 0.0f; ID = entity.mId; PlayerFaces.Load(content); mCurrentTexture = PlayerFaces.FromString("Smile"); mSize = new Vector2(mCurrentTexture.Width, mCurrentTexture.Height); mPreviousDirection = GravityDirections.Down; }
/// <summary> /// Constructs a PhysicsObject; Loads the required info from the content pipeline, and defines its size and location /// </summary> /// <param name="content">Content pipeline</param> /// <param name="spriteBatch">The drawing canvas of the game. Used for collision detection with the level</param> /// <param name="name">Name of the physics object so that it can be loaded</param> /// <param name="scalingFactors">Factor for the image resource(i.e. half the size would be (.5,.5)</param> /// <param name="initialPosition">Position of where this object starts in the level</param> public PhysicsObject(ContentManager content, ref PhysicsEnvironment environment, float friction, EntityInfo entity) : base(content, friction, entity) { mEnvironment = environment; mVelocity = new Vector2(0, 0); mOriginalPosition = mOriginalInfo.mLocation; mIsRail = mOriginalInfo.mProperties.ContainsKey(XmlKeys.RAIL); if (mIsRail) if (mOriginalInfo.mProperties[XmlKeys.RAIL] == XmlKeys.RAIL_X) { mHiBound = GridSpace.GetDrawingCoord(mOriginalPosition).X + (int.Parse(mOriginalInfo.mProperties[XmlKeys.LENGTH]) * 64); mLowBound = GridSpace.GetDrawingCoord(mOriginalPosition).X; mAxis = GridSpace.GetDrawingCoord(mOriginalPosition).Y; } else { mHiBound = GridSpace.GetDrawingCoord(mOriginalPosition).Y + (int.Parse(mOriginalInfo.mProperties[XmlKeys.LENGTH]) * 64); mLowBound = GridSpace.GetDrawingCoord(mOriginalPosition).Y; mAxis = GridSpace.GetDrawingCoord(mOriginalPosition).X; } else mHiBound = mLowBound = mAxis = 0; UpdateBoundingBoxes(); mMass = 1; }
/// <summary> /// Constructs a tile that reacts to gravity in the opposite direction /// </summary> /// <param name="content">The games content manager</param> /// <param name="name">Name of the Object("Images/{Type}/{Name}"</param> /// <param name="initialPosition">Starting position</param> /// <param name="friction">Friction that reacts to physics objects</param> /// <param name="isSquare">True if the object should behave like a square</param> /// <param name="isHazardous">True if the object should kill the player when touched</param> public ReverseTile(ContentManager content, ref PhysicsEnvironment environment, float friction, EntityInfo entity) : base(content, ref environment, friction, entity) { mBeingAnimated = false; mAnimationTexture = new AnimatedSprite(); }
/// <summary> /// Initializes a new instance of the <see cref="Level"/> class. /// </summary> /// <param name="name">The name of the level</param> /// <param name="controls">The controls scheme</param> /// <param name="viewport">The viewport for the cameras</param> public Level(String filepath, IControlScheme controls, Viewport viewport) { Filepath = filepath; mControls = controls; mCam = new Camera(viewport); mScreenRect = viewport.TitleSafeArea; mRails = new List<EntityInfo>(); mObjects = new List<GameObject>(); mCollected = new List<GameObject>(); mRemoveCollected = new List<GameObject>(); mActiveAnimations = new Dictionary<Vector2, AnimatedSprite>(); mTrigger = new List<Trigger>(); mPhysicsEnvironment = new PhysicsEnvironment(); mTimerStar = mDeathStar = mTimerStar = 0; }
/// <summary> /// Initializes a new instance of the <see cref="Level"/> class. /// </summary> /// <param name="name">The name of the level</param> /// <param name="controls">The controls scheme</param> /// <param name="viewport">The viewport for the cameras</param> public Level(String filepath, IControlScheme controls, Viewport viewport) { Filepath = filepath; mControls = controls; mCam = new Camera(viewport); mBounds = viewport.Bounds; mScreenRect = viewport.TitleSafeArea; mRails = new List<EntityInfo>(); mObjects = new List<GameObject>(); mCollected = new List<GameObject>(); mRemoveCollected = new List<GameObject>(); mActiveAnimations = new Dictionary<Vector2, AnimatedSprite>(); mTrigger = new List<Trigger>(); mPhysicsEnvironment = new PhysicsEnvironment(); mTimerStar = mDeathStar = mTimerStar = 0; bw = new BackgroundWorker { WorkerReportsProgress = false, WorkerSupportsCancellation = false }; bw.DoWork += UpdateParticles; }
public GenericObject(ContentManager content, String name, Vector2 scalingFactors, Vector2 initialPosition, ref PhysicsEnvironment environment) : base(content, name, scalingFactors, initialPosition, ref environment) { }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { mGraphics.PreferredBackBufferWidth = mGraphics.GraphicsDevice.DisplayMode.Width; mGraphics.PreferredBackBufferHeight = mGraphics.GraphicsDevice.DisplayMode.Height; mGraphics.ToggleFullScreen(); mGraphics.ApplyChanges(); mObjects = new List<PhysicsObject>(); mCurrentLevel = new Level(); mPhysicsEnvironment = new PhysicsEnvironment(); base.Initialize(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyboardState keyboard = Keyboard.GetState(); // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape)) this.Exit(); Random rand = new Random(); PhysicsEnvironment environment = new PhysicsEnvironment(); environment.TerminalSpeed = rand.Next(100)+1; environment.GravityDirection = (GravityDirections)(rand.Next()%4); environment.GravityMagnitude = rand.Next(3)+1; if (keyboard.IsKeyDown(Keys.N)) { if (rand.Next() % 3 == 0) environment = mPhysicsEnvironment; mObjects.Add(new GenericObject(Content, "Player", new Vector2(1, 1), new Vector2(rand.Next(), rand.Next()), ref environment)); } foreach (PhysicsObject pObject in mObjects) { pObject.Update(gameTime); if (pObject is Player) ChangeValues((Player)pObject, keyboard); pObject.fixForBounds(mGraphics.PreferredBackBufferWidth, mGraphics.PreferredBackBufferHeight); } base.Update(gameTime); }