Conway’s Defense Reaches 1000 lines.

February 24th, 2010

It seems as if Conway’s Defense has reached a landmark of one thousand lines! I wonder if it will get to 2000.

Input Management in C#

February 23rd, 2010

Today I feel like talking about how I implemented input management into Conway’s Defense, and I think it’s pretty nifty.

The first thing I decided to do is create a class with a Dictionary called Bindings, which I used to store bindings for keys. This way the user can change the keys to whatever he wants, without requiring a huge amount of extra code. I also added variables for the current Keyboard State and the previous one, which we use for checking the state of the key. Finally, I created an enum representing the possible states of the keys.

//Throw in your using statements here...

namespace InputManagement
{
	public class InputManagement : GameComponent
	{
		private KeyboardState CurrentFrame;
		private KeyboardState LastFrame;
		private Dictionary<string, string> Bindings;

		public InputManagement(Game1 game) : base(game)
		{
			CurrentFrame = Keyboard.GetState();
			LastFrame = CurrentFrame;
		}
	}

	public enum KeyStates
	{
		None,
		Pressed,
		Held,
		Released
	}
}

Now that our variables have been created, I created an override function for Update(), to change the Keyboard states. I also added a function called InitDefaultControls(); to store the default controls into the dictionary. It is also a good idea to have a CheckBinding() method for our game to use to easily find out the state of a binding.

public void InitDefaultControls()
{
	Bindings = new Dictionary<string, string>();
	Bindings.Add("Left", "Left");
	Bindings.Add("Right", "Right");
	Bindings.Add("Jump", "Up");
	Bindings.Add("Duck", "Down");
}

public KeyStates CheckBinding(string binding)
{
	if(Bindings.ContainsKey(binding))
	{
		string value = Bindings[binding];
		bool Lks = LastFrame.IsKeyDown((Keys)Enum.Parse(typeof(Keys), value, true)); //Set the Last keystate bool to check if the key was pressed. We convert the string for the binding to a Keys enum value.
		bool Tks = CurrentFrame.IsKeyDown((Keys)Enum.Parse(typeof(Keys), value, true));
		if(!Lks && !Tks) { return KeyStates.None; }
		else if(Lks && Tks) { return KeyStates.Held; }
		else if(Lks) { return KeyStates.Released; }
		else { return KeyStates.Pressed;}
	}
	return KeyStates.None; //We will return none if the binding does not exist. You could make an error state if you want, but we'll just use KeyStates.None
}

public override void Update(GameTime gameTime)
{
	base.Update(gameTime);

	LastFrame = CurrentFrame;
	CurrentFrame = Keyboard.GetState();
}

To implement the class, you simply have to add a reference to this class, create an instance of InputManagement and add it to the Components list in your Game class. Once you’ve done that, you can at any time call the CheckBinding() method of your InputManagement instance and grab the KeyStates value.

That’s really all you need. If you want to expand on the concept, you could add another function to return true if the binding is at the specified KeyStates value. You can also modify the code to use GamePad button states. You could even go so far as to add a class that stores the button type and use that instead of the second string for the Dictionary. This way, you could have it store both GamePad values and JoyStick values. You also might want to return a float for analog sticks, instead of a enum value, too.

The Daily Gynlorf: February 22, 2010

February 22nd, 2010

Awesomely Unexciting Event of the Day

I got back from Church camp yesterday. It was a great experience.

The Daily Thought or Question

People often speak too much. It’s as if they are afraid of silence, but silence is, in itself, a great thing.

Finally, Today’s Dosage of Coding Crap

Here’s a sample of what I’ve been working on ;D

The Daily Gynlorf: February 17, 2010

February 17th, 2010

Awesomely Unexciting Event of the Day

We viewed some of the videos in Media Productions today. Mine wasn’t finished, and it went first =(

The Daily Thought or Question

Why do I have to learn Spanish to be able to attend a university? Really, what is the real world application in that if I’m probably going to get some type of software development degree?

The Daily Gynlorf: February 15, 2010

February 15th, 2010

Awesomely Unexciting Event of the Day

I failed at life today. We got a new knife sharpener, so I thought, “Hmm, why not sharpen this old, dull knife!”. I did two passes on the old knife, and thought, “hehehe, let’s see if it worked!! #$^&$#!!!!!!” I think you know what happened next..

The Daily Thought or Question

What do people get out of insulting others? I see it all the time and I think, does it really make them happy? The answer is no, it doesn’t.

EEPPIICC

February 14th, 2010

View his profile for more =O

And stay out!

February 13th, 2010

I finally removed the malware that some jerk put on my website >:|

Now, I can get back to blogging! >_>

The Daily Gynlorf: February 9, 2010

February 9th, 2010

Awesomely Unexciting Event of the Day

I was told about this website, and it’s really interesting. It basically describes all of the flaws with evolutionist beliefs. I encourage you to check out the videos.

http://www.answersingenesis.org/media#/video/ondemand/

The Daily Thought or Question

Why does Christianity scare people? It seems like whenever I bring up Christian topics in class, everyone starts squirming around.

The Not-So-Daily Gynlorf: February 8, 2010

February 8th, 2010

Awesomely Unexciting Event of the Day

Wow, I haven’t posted in a while. I guess today’s event could be that I posted something! No, just kidding. That would be silly. Today’s real event was that I spent about 2 hours trying to find a program that would convert my MS Word Docs to HTML. After all of that work, I found out that MS Word has a built in feature for that.

The Daily Thought or Question

People are such hypocrites, all the time.

The Daily Gynlorf: February 4, 2010

February 4th, 2010

Awesomely Unexciting Event of the Day

Two things happened today, actually.. First of all, I saw the movie, “To Save a Life”. I think it was a great movie, and if given the opportunity, I would watch it again. It really makes you think about the way you’re leading your life, and how it has a huge impact on others (Yeah, I know it sounds lame, but seriously, it’s really good!)

Second, I got a new toy to play with. The toy being a new Digital Camera to use for Media Productions. I can’t wait!

The Daily Thought or Question

I’ve been thinking a lot lately, and I’ve come to the conclusion that thinking really helps out with everything. It’s as if we (as people) get too caught up with our busy lives, that we never just take some alone time and think.

(Is anyone even reading this? o_O)