Wednesday, 21 November 2012

DateTimes in C#

A few weeks ago I was working on getting the beginning and end of the week for any given DateTime.
This would've been easy if I realized that the AddDays function of the .NET DateTime actually returned a new DateTime.
I spent a full morning pragmatically working out which month/day/date it was and when.

Once I realized this I re-wrote my code in about 1 minute. Only slowed down by typing speed.
Anyway I hope this is something that you all find useful to know.

Saturday, 3 November 2012

Adding an Existing Project to Visual Studio 2010 Solution

This is just a small post which is less of a tutorial and more of a small piece of information that I would've found useful a little while ago.

When adding an exiting project to a solution in Visual Studio 2010 it does not copy the original project into the new one it just adds a sort of reference to the new project where you can edit the added project.

Friday, 14 September 2012

Navigating one large HTML page with links

This code can be used on things like a table of contents.
It is used to navigate very large html pages and is endlessly helpful.
I also remember when I was trying to learn it tutorials that where actually helpful where few and far between.

The basic concept of the way it works is you create a link to a title or point of interest.

To create the link to the point of interest surround the code that instigates the click with an
< a href = "#TitleOfLink">

and close it with :
</a>

Then navigate to the point of interest and surround it with a
 <b id="TitleOfLink">

and close it with a
</b>

This should work for single page navigation.
Thanks,
Antshockey

Managing Game States in XNA (Menus)

While in a game making competition at the beginning of the year and in the room where my team was placed was one other team, a team of first year programmers.

For the most part they did ok with all four of them working together considering the limited amount of programming experience they had between them.

Later on in the competition there seemed to be a massive fuss coming from them all, they had a programming problem which they hadn't solved all night long...

Being neighbourly I asked what their problem was and if I could help at all.

All night the team had been working on implementing a simple menu system in there game and they where all working on different things. This gave me an idea to write a small guide on how to set a very simple screen management system in XNA.

The basic idea of this menu system is to have an enumerated type with all of the menu/game states.

enum GameState {MainMenu, InGame, EndGame, Pause}
GameState gameState = GameState.MainMenu;

Add this to the top of your Game1 class for a game with all menus mentioned above.

Now inside your Update method...
switch(gameState)
{
case GameState.MainMenu:
break;

case GameState.InGame:
break;

case GameState.EndGame:
break;

case GameState.Pause:
break;
}
Now if you add the exact same thing to your Draw method you have complete control over what is drawn and updated depending on the current status of the game.
I would put this between

spriteBatch.Begin();

And

spriteBatch.End();

This is because in my research I found it to be much more efficient to open the SpriteBatch as few times as possible.

Anyway to change the current state just update the gameState variable and all of the code should update too.
Thanks for reading,
Antshockey

Monday, 19 March 2012

CSS z-index ing

I've been programming websites for a while and I've always avoided using z-index because when I asked my web development teacher about his he just laughed.
I've had a few dabbles at trying to implement it myself with no real guidance and up until till now I haven't figured out why it didn't work.
On the W3Schools info about z-indexing there is one note that is not very prominent that should be the first thing they speak about.
z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).

If I had known about this, I would've been using z-indexing a whole lot more.
I hope you find this helpful.