XNA Tutorials
| XNA Platformer Starter Kit - Checkpoint Tutorial |
| Written by Jeff Brown |
Adding checkpoints to Platform Starter KitHere's a video showing off the final product of this tutorial:
Checkpoint = 3, in Level.cs After this line: private Vector2 start;
Add this:public Vector2 checkpoint;
Now find the following: public void StartNewLife() { Player.Reset(start); } And change it to this: public void StartNewLife() { if(checkpoint != Vector2.Zero) Player.Reset(checkpoint);
else
Player.Reset(start);
}
In ‘private Tile LoadTile(...)’ add this near the others. //Checkpoint case 'P': return LoadTile("BlockA0", TileCollision.Checkpoint); Now in Player.cs find the following: TileCollision collision = Level.GetCollision(x, y); And add this after it: if (collision == TileCollision.Checkpoint)
level.checkpoint = new Vector2(x, y) * Tile.Size;
Now make sure you add some 'P's to your levels so you can try out the checkpoints. Currently they just use the BlockA0 texture so you'll have to add your own to the Tiles folder and change the case 'P': ... texture argument to match your own checkpoint texture. |