BREAK THROUGH!!! I have worked out MOST of the kinks!
What you want to do is make a NEW class file called 'blocks', copy paste this code in it, yes it's pretty much the same as the gem without the movement
CODE
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
namespace XNA_Platform
{
/// <summary>
/// A valuable item the player can collect.
/// </summary>
class Blocks
{
Random randy = new Random((int)DateTime.Now.Ticks);
private Texture2D texture;
private Vector2 origin;
//private SoundEffect collectedSound;
public const int PointValue = 30;
public readonly Color Color = Color.Yellow;
int textureNumber;
// The block is animated from a base position along the Y axis.
private Vector2 basePosition;
public Level Level
{
get { return level; }
}
Level level;
/// <summary>
/// Gets the current position of this block in world space.
/// </summary>
public Vector2 Position
{
get
{
return basePosition + new Vector2(0.0f, 0.0f);
}
}
/// <summary>
/// Gets a circle which bounds this block in world space.
/// </summary>
public Circle BoundingCircle
{
get
{
return new Circle(Position, Tile.Width / 2.6f);
}
}
/// <summary>
/// Constructs a new block.
/// </summary>
public Blocks(Level level, Vector2 position)
{
this.level = level;
this.basePosition = position;
LoadContent();
}
/// <summary>
/// Loads the block texture and collected sound.
/// </summary>
public void LoadContent()
{
textureNumber = randy.Next(1, 7);
texture = Level.Content.Load<Texture2D>("Tiles/BlockA" + textureNumber);
origin = new Vector2(texture.Width / 2.0f, texture.Height / 2.0f);
//collectedSound = Level.Content.Load<SoundEffect>("Sounds/GemCollected");
}
/// <summary>
/// Bounces up and down in the air to entice players to collect them.
/// </summary>
public void Update(GameTime gameTime)
{
// Bounce control constants
// Bounce along a sine curve over time.
// Include the X coordinate so that neighboring gems bounce in a nice wave pattern.
}
/// <summary>
/// Called when this gem has been collected by a player and removed from the level.
/// </summary>
/// <param name="collectedBy">
/// The player who collected this block. Although currently not used, this parameter would be
/// useful for creating special powerup gems. For example, a gem could make the player invincible.
/// </param>
public void OnCollected(Player collectedBy)
{
//Blocks..PointValue = 0;
//collectedSound.Play();
}
/// <summary>
/// Draws a gem in the appropriate color.
/// </summary>
public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, Position, null, Color, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);
}
}
}
Now we need to set up a destructable thing in the level class..I don't know the correct name for it in under 'instantiates a gem' code block you want to add this section of code
CODE
/// <summary>
/// Instantiates a destructable block and puts it in the level.
/// </summary>
private Tile LoadDestructble(int x, int y)
{
Point position = GetBounds(x, y).Center;
blocks.Add(new Blocks(this, new Vector2(position.X, position.Y)));
if (!blocks.Equals(null))
{
return new Tile(null, TileCollision.Passable);
}
else
{
return new Tile(null, TileCollision.Impassable);
}
}
What this does is sets the block to impassible by default and then passable if it has a null value aka destroyed.
Right now you want to scroll up at
CODE
private Tile LoadTile(char tileType, int x, int y)
and make the tile ".destructable", it should look like this:
CODE
case '#':
return LoadDestructble(x, y);
You could ALWAYS use a different letter, I'm using this now.
Now we want to update it add this code under allt he other updates:
CODE
/// <summary>
/// Update the block to destroy here
/// </summary>
private void UpdateBlocks(GameTime gameTime)
{
for (int i = 1; i < blocks.Count; ++i)
{
Blocks bl = blocks[i];
//int bl2 = blocks[0];
if (bl.BoundingCircle.Intersects(Player.BoundingRectangle))
{
blocks.Equals(null);
blocks.RemoveAt(i--);
}
bl.Update(gameTime);
}
Run the code, it -=SHOULD=- WORK!
When you hit an object it SHOULD destroy, it's different from collect because we removed it, and added all that other stuff in, I bet we could even remove if you jump off the block

.
So THERE WE HAVE IT, I have solo worked this out, i'm VERY proud of it!
Maybe I should make a tutorial, this pretty much is a tutorial lol.