protected override void UpdateCore(AnimatedSprite subject) { //Rectangle viewportRect = SpriteManager.Instance.Game.GraphicsDevice.Viewport.Bounds; viewportRect = new Rectangle(0, 0, 1280, 720); subject.screenPos += subject.velocity; // Check for collision with right edge, if so, bounce if (subject.screenPos.X + subject.sourceRect.Width / 2 > viewportRect.Right) { //subject.velocity.X *= +1; //subject.screenPos.X = (viewportRect.Left +40) - subject.sourceRect.Width / 2; } else if (subject.screenPos.X - subject.sourceRect.Width / 2 < viewportRect.Left) { //subject.velocity.X *= +1; //subject.screenPos.X = (viewportRect.Right -100) + subject.sourceRect.Width / 2; } else if (subject.screenPos.Y - subject.sourceRect.Height / 2 < (viewportRect.Top - 600)) { //subject.velocity.Y *= -1; //subject.screenPos.Y = viewportRect.Top + subject.sourceRect.Height / 2; } else if (subject.screenPos.Y + subject.sourceRect.Height / 2 > viewportRect.Bottom) { //subject.screenPos.Y = viewportRect.Top - subject.sourceRect.Height / 2; //subject.velocity.Y *= -1; //subject.screenPos.Y = viewportRect.Bottom - subject.sourceRect.Height / 2; } }
// blue gem method private AnimatedSprite createGem(Vector2 position, Vector2 velocity) { ContentManager content = ScreenManager.Game.Content; textures.ContentManager = ScreenManager.Game.Content; sounds.ContentManager = ScreenManager.Game.Content; fonts.ContentManager = ScreenManager.Game.Content; Texture2D enemygemTexture = content.Load<Texture2D>("Textures\\loading_w"); AnimatedSprite d = new AnimatedSprite( enemygemTexture, new Vector2(105, 15), position, new Rectangle(0, 0, 210, 30), velocity, // allows random velocity 1, 1, 1); // tilesheet animation, rows, columns, frames d.Behaviour = normalBehaviour; // sets behaviour return d; }
protected abstract void UpdateCore(AnimatedSprite subject);
protected abstract void EndCore(AnimatedSprite subject);
protected abstract void BeginCore(AnimatedSprite subject);
public void Update(AnimatedSprite subject) { UpdateCore(subject); }
public void End(AnimatedSprite subject) { EndCore(subject); }
public void Begin(AnimatedSprite subject) { BeginCore(subject); }
protected override void EndCore(AnimatedSprite subject) { }
protected override void BeginCore(AnimatedSprite subject) { }
protected override void UpdateCore(AnimatedSprite subject) { subject.screenPos += 5 * subject.velocity; subject.velocity.X *= -1; subject.velocity.Y *= -1; }
private AnimatedSprite createAsteroid01(Vector2 position, Vector2 velocity) { AnimatedSprite d = new AnimatedSprite( asteroid01, new Vector2(75, 56), position, new Rectangle(0, 0, 150, 113), velocity, 6, 6, 36); // tilesheet animation, rows, columns, frames d.Behaviour = normalBehaviour; // sets behaviour return d; }