For many novice users, one of thier biggest concerns is protecting their PCs from viruses and malware. Why should you spend hundreds of pounds just for your computer to become slow and useless?
Well, good news, I am here to help with 6 quick steps to improving performance on your computer, keeping everything easy to find and protecting it from viruses.
1. Install Malware Bytes at http://www.malwarebytes.org/products/malwarebytes_free
Run it every week, it will delete all malware and protect you.
2. Install a good Anti-virus. I suggest Microsoft Security Essentials, it is free and works flawlessly
http://windows.microsoft.com/en-GB/windows/products/security-essentials
3. Install CCleaner at http://www.piriform.com/ccleaner
CCleaner will help you remove temporary files that you do not need as well as hidden files that are taking up space that you didnt know about. You can also use it to remove start-up items that slow down your computer at start-up. Run once a week
4. Install Defraggler at http://www.piriform.com/defraggler
The windows defrag is a bit weak and will leave holes. Use Defraggler for the best clean. Use every week or month dependant upon PC usage.
5. Make a folder system.
If you keep all your files tidy and in folders, you will greatly reduce the time it will take to find things. When used with the next thing on the list, you will save loads of time.
6. Name all your files.
Name your files suitably and smartly! This will save you the hassle of opening things to find what they are.
Thursday, 2 February 2012
XNA Tile Engine - Class Implementation
Now that we have made our class, we are ready to implement it into Game1.cs
As it is easier, I will list all of the code as I have in the previous parts and then section it out via comments.
Everything that is part of the base class I will section off in RED, my comments will stay green, with added code going untouched.
namespace TileEngine
{
public class Game1 : Microsoft.Xna.Framework.Game
{
/* First of all up in global variables section, we want to define our variables /*
/* Firstly we have our actual level "object", this is what we will manipulate and use to create our tile map */
TileMap tilemap = new TileMap();
/* Secondly is our "MapArray", this is the array that we want our tiles to represent. For now, this must be represented in 1's and 0's as we only have 2 textures */
int[,] levelmap = new int[,]
/* The actual array can involve any shape you want, as long as it square and complete, for example we have a "T" shape shown below, this will create a dirt path in the shape of a T surrounded by grass */
{
{1,1,1,1,1,1,1,1,1},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
};
public Game1()
{
graphics =
Content.RootDirectory = new GraphicsDeviceManager(this);"Content";protected override void Initialize()
}
/* In the initialize section we define what we want to happen on the game's start-up. This is going to include the initialization of our level, as well as resolution of the gamescreen */
/* Firstly we initialize our tilemap, with the levelmap that we created in our variable section, as that is what we said we needed when we created the initialize function */
tilemap.Initialize(levelmap);
/* We now need to ensure that the gamescreen is scaled to the size of the tilemap. This is done by just multiplying the tilemap height and width by 32 (32 is the size of our textures in pixels) */
graphics.PreferredBackBufferHeight = 32 * tilemap.Height;
graphics.PreferredBackBufferWidth = 32 * tilemap.Width;
graphics.ApplyChanges();
base.Initialize();
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);/* In the LoadContent section... we do what you might guess, Load Content. */
/* First lets load in our textures, you want to find a 32x32 grass and mud texture from somewhere and just load them into your project, save them as "grass" and "mud" */
Texture2D grass = Content.Load<Texture2D>("grass");
Texture2D mud = Content.Load<Texture2D>("mud");
/* We then want to add these textures to our tilemaps texture list. We must do them in the correct order, as dependant upon thier position they will have a different number to associate them with. Do grass first, as that will be "0" */tilemap.tiletextures.Add(grass);
tilemap.tiletextures.Add(mud);}
protected override void UnloadContent(
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
/* Finally, we just need to draw our tilemap, all the hard work was done in the class, so we simply just tell it to draw */spriteBatch.Begin();
tilemap.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
Thats it!
You should now be able to run the program and get a tilemap with a T in it. This is very simple but can be adapted and improved on to do anything. I would recommend making Tower Defence games with something this simple, to improve your knowledge.
As it is easier, I will list all of the code as I have in the previous parts and then section it out via comments.
Everything that is part of the base class I will section off in RED, my comments will stay green, with added code going untouched.
namespace TileEngine
{
public class Game1 : Microsoft.Xna.Framework.Game
{
/* First of all up in global variables section, we want to define our variables /*
/* Firstly we have our actual level "object", this is what we will manipulate and use to create our tile map */
TileMap tilemap = new TileMap();
/* Secondly is our "MapArray", this is the array that we want our tiles to represent. For now, this must be represented in 1's and 0's as we only have 2 textures */
int[,] levelmap = new int[,]
/* The actual array can involve any shape you want, as long as it square and complete, for example we have a "T" shape shown below, this will create a dirt path in the shape of a T surrounded by grass */
{
{1,1,1,1,1,1,1,1,1},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0},
};
public Game1()
{
graphics =
Content.RootDirectory = new GraphicsDeviceManager(this);"Content";protected override void Initialize()
}
/* In the initialize section we define what we want to happen on the game's start-up. This is going to include the initialization of our level, as well as resolution of the gamescreen */
/* Firstly we initialize our tilemap, with the levelmap that we created in our variable section, as that is what we said we needed when we created the initialize function */
tilemap.Initialize(levelmap);
/* We now need to ensure that the gamescreen is scaled to the size of the tilemap. This is done by just multiplying the tilemap height and width by 32 (32 is the size of our textures in pixels) */
graphics.PreferredBackBufferHeight = 32 * tilemap.Height;
graphics.PreferredBackBufferWidth = 32 * tilemap.Width;
graphics.ApplyChanges();
base.Initialize();
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);/* In the LoadContent section... we do what you might guess, Load Content. */
/* First lets load in our textures, you want to find a 32x32 grass and mud texture from somewhere and just load them into your project, save them as "grass" and "mud" */
Texture2D grass = Content.Load<Texture2D>("grass");
Texture2D mud = Content.Load<Texture2D>("mud");
/* We then want to add these textures to our tilemaps texture list. We must do them in the correct order, as dependant upon thier position they will have a different number to associate them with. Do grass first, as that will be "0" */tilemap.tiletextures.Add(grass);
tilemap.tiletextures.Add(mud);}
protected override void UnloadContent(
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
/* Finally, we just need to draw our tilemap, all the hard work was done in the class, so we simply just tell it to draw */spriteBatch.Begin();
tilemap.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
Thats it!
You should now be able to run the program and get a tilemap with a T in it. This is very simple but can be adapted and improved on to do anything. I would recommend making Tower Defence games with something this simple, to improve your knowledge.
Wednesday, 1 February 2012
XNA Tile Engine - Class Functions
Now that we have our variables covered (and understand their uses to a certain extent) we can have a look at the functions we will need to call to use our class.
At this stage, we need our tile engine to do 2 things. Initialize, which is another way of saying "start" or "begin", and draw, which will draw our tile map to the screen.
/* Starting with our Initialize class, we want to firstly ensure it is a "void" function. This tells the compiler that this function does not return a value. Secondly, we need to define what we need in order initialize our tile map. What we need is an array, this array will be the map which will define our tile map. This is entered in the brackets after the function name. The name also should not conflict with our variable of a similar name*/
public void Initialize(int[,] maparray)
{
/* Now, want to take the array that has been given to us and store it inside our variable, essentially saving it and making it easier to re-use */
MapArray = maparray;
/* We then want to store the height and width of our array. Unlike you would expect, height is the first dimension of an array (therefore a 0 is used) and width is the 2nd dimension (therefore a 1 is used) /*
Height = maparray.GetLength(0);
Width = maparray.GetLength(1);
}
/* Moving on to the draw method now. The draw method will be utilized within Game1's draw method and use its spritebatch, so we ensure that our function needs one /*
public void Draw(SpriteBatch spritebatch)
{
/* We first need to loop through our MapArray, we will go through each co-ordinate via the Width and Height that we defined earlier. We need to ensure we apply some constraints to stop us looping too far. SO we define x and y as less than their worded counter-parts */
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
/* Within the loop we are purely finding the value that resides in the chosen MapArray co-ordinate and storing it in a local variable names tileindex */
int tileindex = MapArray[y, x];
/* Now we need to find the texture that corresponds to the number stored in tileindex(the co-ordinate we are currently on in looping of the MapArray). The tiletextures list will store each texture into it linearly, meaning that the first texture loaded into it will be number 0 and so on. Thats how we find what texture corresponds to each number in our MapArray */
Texture2D tiletexture = tiletextures[tileindex];
/* It is now time to draw the texture we have founbd to the corresponding square on the grid, we take the spritebatch and command it to draw the following /*
spritebatch.Draw(tiletexture, new Rectangle(x * 32, y * 32,
32, 32),Color.White);
/* firstly we tell the spritebatch the texture it needs to draw(tiletexture), then tell it where the square it needs to draw to is located(new rectangle 32 pixels by 32 pixels with the x and y corresponding to where it was located in the MapArray, and finally the color is white for transparent(no tint)) */
}
In the next tutorial, we will look at how we use our class and finally wrap this up into a tile map that you can see!
At this stage, we need our tile engine to do 2 things. Initialize, which is another way of saying "start" or "begin", and draw, which will draw our tile map to the screen.
/* Starting with our Initialize class, we want to firstly ensure it is a "void" function. This tells the compiler that this function does not return a value. Secondly, we need to define what we need in order initialize our tile map. What we need is an array, this array will be the map which will define our tile map. This is entered in the brackets after the function name. The name also should not conflict with our variable of a similar name*/
public void Initialize(int[,] maparray)
{
/* Now, want to take the array that has been given to us and store it inside our variable, essentially saving it and making it easier to re-use */
MapArray = maparray;
/* We then want to store the height and width of our array. Unlike you would expect, height is the first dimension of an array (therefore a 0 is used) and width is the 2nd dimension (therefore a 1 is used) /*
Height = maparray.GetLength(0);
Width = maparray.GetLength(1);
}
/* Moving on to the draw method now. The draw method will be utilized within Game1's draw method and use its spritebatch, so we ensure that our function needs one /*
public void Draw(SpriteBatch spritebatch)
{
/* We first need to loop through our MapArray, we will go through each co-ordinate via the Width and Height that we defined earlier. We need to ensure we apply some constraints to stop us looping too far. SO we define x and y as less than their worded counter-parts */
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
/* Within the loop we are purely finding the value that resides in the chosen MapArray co-ordinate and storing it in a local variable names tileindex */
int tileindex = MapArray[y, x];
/* Now we need to find the texture that corresponds to the number stored in tileindex(the co-ordinate we are currently on in looping of the MapArray). The tiletextures list will store each texture into it linearly, meaning that the first texture loaded into it will be number 0 and so on. Thats how we find what texture corresponds to each number in our MapArray */
Texture2D tiletexture = tiletextures[tileindex];
/* It is now time to draw the texture we have founbd to the corresponding square on the grid, we take the spritebatch and command it to draw the following /*
spritebatch.Draw(tiletexture, new Rectangle(x * 32, y * 32,
32, 32),Color.White);
/* firstly we tell the spritebatch the texture it needs to draw(tiletexture), then tell it where the square it needs to draw to is located(new rectangle 32 pixels by 32 pixels with the x and y corresponding to where it was located in the MapArray, and finally the color is white for transparent(no tint)) */
}
In the next tutorial, we will look at how we use our class and finally wrap this up into a tile map that you can see!
XNA Tile Engine - Introduction
In some 2D games, it can be very useful to use a tile based engine for your gameplay. If you think about a tower defence game, they are nearly always tile-based, with the towers taking up a square and a path being drawn in squares throughout the map. In old fashioned 2D RPG's we also see a tile engine taking the forefront, with the character moving through a tile-based world with 1 item taking up 1 tile.
In this tutorial I aim to introduce the beginning of a tile engine. It is VERY simple and isn't written in the best possible way. I must also note that this tutorial is written for XNA 4.0. I am also to assume you can at least code a little bit and can use Visual Studio.
As you already know, Game1.cs is used as a catalyst, to bring all your classes and such together. So we need to create a new class to handle the creation of our tile map. Name this TileMap.cs.
Within TileMap.cs, we now need to import some XNA libraries. This is simple, just copy and paste the following from Game1.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
And place it by all the other "using" statements.
Once that is over and done with, we can get on with the real programming!
In this tutorial, I will just cover the variables that we need, the functions and usage will be covered later
So, our variables. These are the things that our class needs in order to function, the pieces of information that are held and piece together our tile map.
When in coded sections like below, all the information regarding what is going on will be found in the "commented sections" which I will colour green.
namespace TileEngine
{
class TileMap
{
/* Firstly we have our MapArray, this is what will store our tile map's shape and decide what resides in the map. This is an array because the square shape of an array can represent a grid. Later on we will see how this works. /*
public int[,] MapArray;
/* This is a simple variable to store the height of our array (how many squares our tile map will be) */
public int Height;
// This is the same as above but for the width
public int Width;
/* This is the list of textures that will make our tiles different from each other. This is where you would store the different images for say a path or for some grass. The usage of this will be revealed later */
public List<Texture2D> tiletextures = new List<Texture2D>();
In the next tutorial we will cover our class's functions, our class will then be ready to use.
Subscribe to:
Comments (Atom)