protected override void Update(GameTime gameTime) { // For Mobile devices, this logic will close the Game when the Back button is pressed if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } SpriteBase sb = gm.Sprites[0]; Vector3 p = Vector3.Zero; KeyboardState keyState = Keyboard.GetState(PlayerIndex.One); if (keyState.IsKeyDown(Keys.Up)) { p = lets.GoRotatedDirection(sb.Location, sb.Size, sb.Rotation, 1f); lets.ValidTrasform(sb, Transforms.Translate, p); } else if (keyState.IsKeyDown(Keys.Down)) { p = lets.GoRotatedDirection(sb.Location, sb.Size, sb.Rotation, -1f); lets.ValidTrasform(sb, Transforms.Translate, p); } if (keyState.IsKeyDown(Keys.Left)) { lets.ValidTrasform(sb, Transforms.Rotate, sb.Rotation - .057f); } else if (keyState.IsKeyDown(Keys.Right)) { lets.ValidTrasform(sb, Transforms.Rotate, sb.Rotation + 0.057f); } // TODO: Add your update logic here base.Update(gameTime); }
public void ValidTrasform(SpriteBase sb, Transforms mode, params object[] args) { if (mode == Transforms.Rotate) { float newRot = (float)args[0]; if (sb.Rotation != newRot) { float oldRot = sb.Rotation; sb.Rotation = newRot; if (!gm.HandleTransforms(sb)) { sb.Rotation = oldRot; } } } else if (mode == Transforms.Translate) { Vector3 location = (Vector3)args[0]; if (sb.Location.X != location.X || sb.Location.Y != location.Y) { Vector3 oldLoc = sb.Location; sb.Location = location; if (!gm.HandleTransforms(sb)) { sb.Location = oldLoc; } } } }
public bool HandleTransforms(SpriteBase sb) { for (int i = 0; i < Sprites.Count; i++) { bool kjl = !sb.Equals(Sprites[i]); Vector3 v1 = sb.Location - sb.Origin, v2 = Sprites[i].Location - sb.Origin; if (!sb.Equals(Sprites[i]) && Pixels.IntersectPixels(sb.TransformMatrix, (int)sb.Size.X, (int)sb.Size.Y, sb.ColorArray, Sprites[i].TransformMatrix, (int)Sprites[i].Size.X, (int)Sprites[i].Size.Y, Sprites[i].ColorArray)) { // Colors.IntersectPixels(new Rectangle((int)v1.X, (int)v1.Y, (int)sb.Size.X, (int)sb.Size.Y), sb.ColorArray, // new Rectangle((int)v2.X, (int)v2.Y, (int)Sprites[i].Size.X, (int)Sprites[i].Size.Y), Sprites[i].ColorArray)) { return(false); } } Current = sb; if (ValidTransform != null) { ValidTransform(this, EventArgs.Empty); } return(true); }
public GameManager(params SpriteBase[] sprites) { Sprites = new List <SpriteBase>(); Sprites.AddRange(sprites); Current = Sprites.Last(); }