/// <summary> /// Function initializes the crate instance and loads the animations /// from the XML definition sheet /// </summary> public void Initialize() { // Define initial state of the crate AnimationRunning = false; currentState = CrateState.Idle; // Load multiple animations form XML definition XDocument doc = XDocument.Load("Content/Textures/Crate/AnimationsDef.xml"); XName name = XName.Get("Definition"); var definitions = doc.Document.Descendants(name); // Loop over all definitions in XML foreach (var animationDefinition in definitions) { // Get a name of the animation string animatonAlias = animationDefinition.Attribute("Alias").Value; Texture2D texture = contentManager.Load <Texture2D>( animationDefinition.Attribute("SheetName").Value); // Get the frame size (width & height) Point frameSize = new Point(); frameSize.X = int.Parse(animationDefinition.Attribute("FrameWidth").Value); frameSize.Y = int.Parse(animationDefinition.Attribute("FrameHeight").Value); // Get the frames sheet dimensions Point sheetSize = new Point(); sheetSize.X = int.Parse(animationDefinition.Attribute("SheetColumns").Value); sheetSize.Y = int.Parse(animationDefinition.Attribute("SheetRows").Value); // Defing animation speed TimeSpan frameInterval = TimeSpan.FromSeconds((float)1 / int.Parse(animationDefinition.Attribute("Speed").Value)); Animation animation = new Animation(texture, frameSize, sheetSize); // If definition has an offset defined - means that it should be // rendered relatively to some element/other animation - load it if (null != animationDefinition.Attribute("OffsetX") && null != animationDefinition.Attribute("OffsetY")) { animation.Offset = new Vector2( int.Parse(animationDefinition.Attribute("OffsetX").Value), int.Parse(animationDefinition.Attribute("OffsetY").Value)); } animations.Add(animatonAlias, animation); } // Load the idle texture idleTexture = contentManager.Load <Texture2D>(idleTextureName); int xOffset = isAI ? positionXOffset : -positionXOffset - idleTexture.Width; Position = catapultCenter + new Vector2(xOffset, positionYOffset); }
private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "crate") { speed = 0.0f; state = CrateState.Resting; if (gameObject.transform.position.x >= -3.449123 && gameObject.transform.position.y > 2.259) { spawnManager.StopCrateSpawning(); uiManager.ShowGameOverMessage(); } } }
public void Update(GameTimerEventArgs gameTime) { CrateState postUpdateStateChange = 0; if (gameTime == null) { throw new ArgumentNullException("gameTime"); } // The crate is destroyed, so there is nothing to update if (IsDestroyed) { // base.Update(gameTime); return; } switch (currentState) { case CrateState.Idle: // Nothing to do break; case CrateState.Hit: // Progress hit animation if (animations["explode"].IsActive == false) { IsDestroyed = true; } animations["explode"].Update(); break; default: break; } lastUpdateState = currentState; if (postUpdateStateChange != 0) { currentState = postUpdateStateChange; } //base.Update(gameTime); }
private void ScatterOntoDepositArea() { state = CrateState.Scattering; }
public void StopMoving() { speed = 0.0f; state = CrateState.Resting; }
/// <summary> /// Start Hit sequence on crate /// </summary> public void Hit() { AnimationRunning = true; animations["explode"].PlayFromFrameIndex(0); currentState = CrateState.Hit; }
public void Update(GameTimerEventArgs gameTime) { CrateState postUpdateStateChange = 0; if (gameTime == null) throw new ArgumentNullException("gameTime"); // The crate is destroyed, so there is nothing to update if (IsDestroyed) { // base.Update(gameTime); return; } switch (currentState) { case CrateState.Idle: // Nothing to do break; case CrateState.Hit: // Progress hit animation if (animations["explode"].IsActive == false) { IsDestroyed = true; } animations["explode"].Update(); break; default: break; } lastUpdateState = currentState; if (postUpdateStateChange != 0) { currentState = postUpdateStateChange; } //base.Update(gameTime); }
/// <summary> /// Function initializes the crate instance and loads the animations /// from the XML definition sheet /// </summary> public void Initialize() { // Define initial state of the crate AnimationRunning = false; currentState = CrateState.Idle; // Load multiple animations form XML definition XDocument doc = XDocument.Load("Content/Textures/Crate/AnimationsDef.xml"); XName name = XName.Get("Definition"); var definitions = doc.Document.Descendants(name); // Loop over all definitions in XML foreach (var animationDefinition in definitions) { // Get a name of the animation string animatonAlias = animationDefinition.Attribute("Alias").Value; Texture2D texture = contentManager.Load<Texture2D>( animationDefinition.Attribute("SheetName").Value); // Get the frame size (width & height) Point frameSize = new Point(); frameSize.X = int.Parse(animationDefinition.Attribute("FrameWidth").Value); frameSize.Y = int.Parse(animationDefinition.Attribute("FrameHeight").Value); // Get the frames sheet dimensions Point sheetSize = new Point(); sheetSize.X = int.Parse(animationDefinition.Attribute("SheetColumns").Value); sheetSize.Y = int.Parse(animationDefinition.Attribute("SheetRows").Value); // Defing animation speed TimeSpan frameInterval = TimeSpan.FromSeconds((float)1 / int.Parse(animationDefinition.Attribute("Speed").Value)); Animation animation = new Animation(texture, frameSize, sheetSize); // If definition has an offset defined - means that it should be // rendered relatively to some element/other animation - load it if (null != animationDefinition.Attribute("OffsetX") && null != animationDefinition.Attribute("OffsetY")) { animation.Offset = new Vector2( int.Parse(animationDefinition.Attribute("OffsetX").Value), int.Parse(animationDefinition.Attribute("OffsetY").Value)); } animations.Add(animatonAlias, animation); } // Load the idle texture idleTexture = contentManager.Load<Texture2D>(idleTextureName); int xOffset = isAI ? positionXOffset : -positionXOffset - idleTexture.Width; Position = catapultCenter + new Vector2(xOffset, positionYOffset); }