<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Darksoda</title>
	<atom:link href="http://darksoda.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://darksoda.com/blog</link>
	<description>Thoughts of a caffeinated mind</description>
	<lastBuildDate>Thu, 28 Apr 2011 00:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A crash course in pointers</title>
		<link>http://darksoda.com/blog/?p=295</link>
		<comments>http://darksoda.com/blog/?p=295#comments</comments>
		<pubDate>Thu, 28 Apr 2011 00:07:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://darksoda.com/blog/?p=295</guid>
		<description><![CDATA[OK, so a crash course on pointers. This will be a long email. But it&#8217;s at least a month worth of classes crushed into a couple of pages. A pointer is a variable literally pointing to an address (any address) in memory. for instance: int nVar = 12; //This is a regular variable! int * [...]]]></description>
			<content:encoded><![CDATA[<p>OK, so a crash course on pointers. This will be a long email. But it&#8217;s at least a month worth of classes crushed into a couple of pages.</p>
<p>A pointer is a variable literally pointing to an address  (any address) in memory.</p>
<p>for instance:</p>
<p>int nVar = 12; //This is a regular variable!<br />
int * pVar = 0;       //This is a pointer variable!</p>
<p><span id="more-295"></span></p>
<p>the variable nVar contains a the number 12. This is located somewhere in the heap. It doesn&#8217;t matter where. We don&#8217;t really care. nVar is an integer an can only take things that are 4 bytes on size.</p>
<p>the variable pVar is a  pointer. This is a variable that takes an address, any address! However, it expects that the address will point to an integer (that bit is important). Right now, it&#8217;s just a zero, meaning that it&#8217;s not pointing to anything at all. It&#8217;s empty, and sad&#8230;</p>
<p>we know pVar is a pointer, and takes an address. So we can give it an address:</p>
<p>pVar = &amp;nVar; //now pVar is pointing to nVar.</p>
<p>If you remember &amp; gets the address of a variable. So we&#8217;re giving pVar, the addresss to nVar. This is important&#8230; We&#8217;re not giving pVar the number 12. We&#8217;re just telling pVar where 12 is located. In other words, if you tried to do a cout on pVar, you would not get 12. Instead, you&#8217;ll see something like: 0x0025fe. If you went inside your computer, and went to this place in memory, you&#8217;d see 12 there.</p>
<p>This presents a problem. You know where something is, but sometimes you point to something and want to know the value! Knowing where 12 is, is pretty useful, but what if you wanted to know what nVar minus 5 is and you only had the address.</p>
<p>That&#8217;s when dereferencing comes into play. Dereferencing is a way to tell the pointer to give you the value of the address it has. In other words, It&#8217;s asking google, who lives at 4275 Solar Circle? This is accomplished by putting a star right before the variable.</p>
<p>int newVar = 0; //Lets create a new variable<br />
newVar = *pVar; //newVar is now 12!</p>
<p>There is something even more interesting than this&#8230; How about if i have the address to nVar, and want to change the value of nVar?</p>
<p>cout &lt;&lt; &#8220;The value is: &#8221; &lt;&lt; nVar &lt;&lt; endl; //&#8221;The value is: 12&#8243;<br />
*pVar += 5;<br />
cout &lt;&lt; &#8220;The new value is: &#8221; &lt;&lt; nVar &lt;&lt; endl; //&#8221;The new value is: 17&#8243;</p>
<p>Why? Well, I went into the address for nVar, and changed the value. nVar is still pointing to the same location. That never changed. But now I changed the value of that specific box.</p>
<p>Enter Arrays:</p>
<p>Arrays, as we talked, are just addresses to a location. So what makes them different from pointers?</p>
<p>int arrayVar[4]; //arrayVar is an address to a place that can contain 4 integers.<br />
int *pVar;         //pVar is an address to a location.</p>
<p>The difference is very succinct. The different lies in that an array is pointing to a location which has a specific number of slots allocated, while a pointer is pointing to any location. It doesn&#8217;t care about size either, which is what makes them great when you&#8217;re allocating memory dynamically! No longer are you held back by that ugly 4&#8230; If you need more space, just ask for it!</p>
<p>int *pVar = new int[whatever]; //and by whatever, i mean 3000 if i want!</p>
<p>This is called, dynamic memory allocation. That &#8220;new&#8221; keyword means: &#8220;give me a brand new location where i can store this many items&#8221;. It&#8217;s then allocated for you on the fly and will stay in memory for as long as you tell it to. However, the rules for arrays still apply. After all, arrays are just pointers. So pointers are also just arrays. What if i need index 4?</p>
<p>pVar[4] = 15; //Lets put a 15 in the 4th space!<br />
cout &lt;&lt; &#8220;Index 4: &#8221; &lt;&lt; pVar[4] &lt;&lt; endl; //Show me what&#8217;s in index 4 -&gt; &#8220;Index 4: 15&#8243;</p>
<p>So why i didn&#8217;t dereference it here? Well, the answer is fairly simple. Remember how a pointer is just an address that expects something the size of the data type? the brackets [] are actually a function in a sense. They say quite literally &#8220;move this many positions&#8221;. But how does it know how far to move&#8230; after all, what if I have a array of very large objects! 4 bytes wouldn&#8217;t be enough. how far each step is, is defined by the data type (int in this case).</p>
<p>Now when you see arrayVar[0], you get the first element because you never moved from the first location! You moved zero steps. Equally with the pointer. pVar[4] is asking the pointer to tell you what&#8217;s contained 4 steps ahead. Each step the size of the data type (int in this case). Now, I lied, it doesn&#8217;t move in reality. Notice that i said &#8220;to tell you what&#8217;s contained 4 steps ahead&#8221;. That&#8217;s because the pointer is still pointing at the beginning of the array. It&#8217;s just &#8220;pretending&#8221; to move, so it can tell you what&#8217;s in the location you asked.</p>
<p>So, what if you moved ahead for reals?</p>
<p>pVar += 4; //oh no&#8230; What&#8217;s going to happen?</p>
<p>First, notice that I didn&#8217;t dereference the point. This time, i&#8217;m actually moving the address. This is a little deceptive. I&#8217;m not moving the address 4 locations. It&#8217;s not going from 0&#215;000001 to 0&#215;00004. The answer is above. When i move, the pointer moves each step the distance of the data type. In this case, the data type is int which is 4 bytes. So the address goes from 0&#215;000001 to 0&#215;000017 (4 steps by 4 bytes). You can go ahead and check it out if you feel ever so skeptical.</p>
<p>Even more interesting is this&#8230; I moved 4 steps, so where exactly am I?</p>
<p>cout &lt;&lt; &#8220;My value is: &#8221; &lt;&lt; pVar[0] &lt;&lt; end; //&#8221;My value is: 15&#8243;</p>
<p>What?! Well, think about it. pVar[4] value is 15. So instead of peaking using brackets [], I actually moved to the location and got the first index.</p>
<p>Now, the fancy math is very dangerous, so DO NOT use it, unless you know what you&#8217;re doing. Otherwise, kaboom goes the system! Stick with the brackets. After all, you just want to know what&#8217;s ahead. You don&#8217;t need to change the location.</p>
<p>Finally and before the grand finale, it brings us to dereferencing a pointer or an array. The answer by now should be fairly obvious. You don&#8217;t need to dereference a pointer when you&#8217;re using it as an array. After all, arrays are just pointers, and pointers can be arrays.</p>
<p>Lastly, and perhaps more important than any other thing: Uncle Ben once told me while driving to the library: &#8220;With great power comes great responsibility&#8221;. He got killed by a robber shortly after&#8230; This lesson cannot be any truer with pointers. Pointers are addresses to locations. So when you allocate memory dynamically (using the &#8220;new&#8221; keyword),  it&#8217;s then allocated for you on the fly and will stay in memory for as long as you tell it to.</p>
<p>pVar = new int[3000]; //I created a new array for 3000 elements.<br />
pVar = new int[2]; //I create another array of 2 elements.</p>
<p>This is bad! Why? Because you first allocated a big array, and then a small one. But what&#8217;s the big deal? you might think. Well, that big array is still in memory. Some where. Just waiting to be used, discarded, or something. Anything! It won&#8217;t disappear until you told it to. Even worse&#8230; You just lost the address to it because you allocated a new one! You don&#8217;t even know where this huge &#8220;memory leak&#8221; is at. Congratulations, you have ruined your computer forever&#8230; Or until you turn it off since the stack memory is wiped out.</p>
<p>But the lesson to be learned is important. Doing this is bad. You need to be responsible with memory. It&#8217;s not free, it&#8217;s not safe, and needs to be managed carefully.</p>
<p>pVar = new int[3000]; //I created a new array for 3000 elements.<br />
delete [] pVar;            //and thus, i release thee from my memory.<br />
pVar = 0;                   // and this for good measure to indicate it&#8217;s empty. Do it! don&#8217;t be lazy!<br />
pVar = new int[2];      //and new life is reborn.<br />
.<br />
.<br />
.<br />
delete [] pVar;            //Ashes to ashes, and so on.<br />
pVar = 0;                   //you&#8217;re ready to rise again&#8230; like a phoenix!</p>
<p>May the force, be with you&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=295</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Need to start posting more often!</title>
		<link>http://darksoda.com/blog/?p=291</link>
		<comments>http://darksoda.com/blog/?p=291#comments</comments>
		<pubDate>Wed, 27 Apr 2011 22:25:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://darksoda.com/blog/?p=291</guid>
		<description><![CDATA[Ok, so between school, work, other projects and getting some gaming done, I just haven&#8217;t been able to post anything. I shall soon, when I get my ruby project going!]]></description>
			<content:encoded><![CDATA[<p>Ok, so between school, work, other projects and getting some gaming done, I just haven&#8217;t been able to post anything.</p>
<p>I shall soon, when I get my ruby project going!</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=291</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WoW Addon: Soda Leveling Stats</title>
		<link>http://darksoda.com/blog/?p=285</link>
		<comments>http://darksoda.com/blog/?p=285#comments</comments>
		<pubDate>Fri, 18 Sep 2009 18:45:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WoW]]></category>

		<guid isPermaLink="false">http://darksoda.com/blog/?p=285</guid>
		<description><![CDATA[I finally finished my addon. Took me just a little over a week or about 8 solid hours of actual programing. But finally, it&#8217;s life at Curse.com. The idea of the addon is simple; Now that I&#8217;m leveling a brand new druid along with my friends, I wanted a simple way to track my progress [...]]]></description>
			<content:encoded><![CDATA[<p>I finally finished my addon. Took me just a little over a week or about 8 solid hours of actual programing. But finally, it&#8217;s life at <a href="http://wow.curse.com/downloads/wow-addons/details/sodalevelingstats.aspx">Curse.com</a>.</p>
<p>The idea of the addon is simple; Now that I&#8217;m leveling a brand new druid along with my friends, I wanted a simple way to track my progress on each session. We all love playing but we have very limited time. Our biggest time constrain at the moment is my wife, who comes home from work at 9pm and after eating it barely leaves us with 2 hours (till midnight) to play. Two hours a night might seem like a good amount of time for most people, but anyone that knows MMOs and how RPGs generally work, knows that 2 hours is such a small window that progress needs to be made efficiently.<span id="more-285"></span></p>
<p>Because of this, I wanted to track where we were getting most of our XP from. Sometimes it&#8217;s easier to complete small quests, and some times you get far more XP by grinding. It really depends on the Zone, the quest and the mobs that you&#8217;re fighting. In our case, and with a party of 4, things die very quickly, but getting drops takes very long. Sometimes a single &#8220;drop&#8221; quest takes about 30 minutes. That works very much against us as we could be completing other chains that require just killing in far less time.</p>
<p>Anyway.. I digress. This is what the addon does:</p>
<p>* Track XP by Level<br />
* Track XP by session<br />
* Track XP by LifeTime</p>
<p>With in each of this categories you can track:</p>
<p>* Number of Kills<br />
* XP gained from kills<br />
* Number of Quests completed<br />
* XP gained from quests.</p>
<p>Additionally because of the data already available, you can make a fair assumption on how many quests or kills are needed to level. The only issue with this is that I make this assumption on a per level basis, so once you level up, you&#8217;re going to need to either kill a mob or complete a quest to get the next forecast. This is to avoid old data from affecting the new set of stats for the level.</p>
<p>Over all, I think it was a fun project that I&#8217;m hoping to keep working on and maybe grow some. I got some ideas that I&#8217;d like to introduce as well as improve the over all architecture of the addon. A lot of work can be done and it has a lot of potential!</p>
<p>That is it for today! Have fun and good bye.</p>
<p><a href="http://media.curse.com/Curse.Projects.ProjectImages/20815/17130/SodaLevelingStats-Current.jpg"><img class="alignnone" title="Soda Leveling Stats: Current Data" src="http://media.curse.com/Curse.Projects.ProjectImages/20815/17130/SodaLevelingStats-Current.jpg" alt="" width="307" height="229" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=285</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making wow addons</title>
		<link>http://darksoda.com/blog/?p=283</link>
		<comments>http://darksoda.com/blog/?p=283#comments</comments>
		<pubDate>Tue, 15 Sep 2009 18:49:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WoW]]></category>

		<guid isPermaLink="false">http://darksoda.com/blog/?p=283</guid>
		<description><![CDATA[My Latest read on writing addons: http://www.tentonhammer.com/node/26419 I&#8217;ve been trying to solve an issue with saving variables between sessions, and after much looking, I came across this particular tutorial. It is very outdated, but the information on it is still very valid. If not accurate, it is still a good reference guide for my first [...]]]></description>
			<content:encoded><![CDATA[<p>My Latest read on writing addons:</p>
<p><a href="http://www.tentonhammer.com/node/26419" target="_blank">http://www.tentonhammer.com/node/26419</a></p>
<p>I&#8217;ve been trying to solve an issue with saving variables between sessions, and after much looking, I came across this particular tutorial. It is very outdated, but the information on it is still very valid. If not accurate, it is still a good reference guide for my first addon.</p>
<p>I will post pics when it&#8217;s in a more fitting working condition.</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=283</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA Mouse Input and Handling</title>
		<link>http://darksoda.com/blog/?p=253</link>
		<comments>http://darksoda.com/blog/?p=253#comments</comments>
		<pubDate>Sun, 22 Mar 2009 08:33:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=253</guid>
		<description><![CDATA[This is short tutorial on how I&#8217;m handling some of the mouse commands. I&#8217;m dumping it here in case some one find it useful: using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics; static public class InputHandler { } Notice the libraries that are included. Only the ones that are strictly necessary. The reason it&#8217;s static [...]]]></description>
			<content:encoded><![CDATA[<p>This is short tutorial on how I&#8217;m handling some of the mouse commands.  I&#8217;m dumping it here in case some one find it useful:</p>
<pre name="code" class="c-sharp">using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

static public class InputHandler
{

}</pre>
<p>Notice the libraries that are included. Only the ones that are strictly necessary.  The reason it&#8217;s static and public, it&#8217;s to allow all other parts of the program access to it. This is handy because it will allow us to control menu selections, and gameplay at the same time without having to initialize the class everywhere. <span id="more-253"></span> This are the initial members of the class:</p>
<pre name="code" class="c-sharp"">static public class InputHandler
{
//Texture
static Texture2D nullTex;
static int spacing = 7;

//GetMouse
static Vector2 mouseRecOrigin = Vector2.Zero;

static MouseState prevMouseState = Mouse.GetState();
static public MouseState MouseState
{ get { return prevMouseState; } }

static Rectangle mouseRec = Rectangle.Empty;
static public Rectangle MouseRec
{ get { return mouseRec; } }

static bool isLeftClick = false;
static public bool LeftClick
{ get { return isLeftClick; } }

static bool isRightClick = false;
static public bool RightClick
{ get { return isRightClick; } }

}</pre>
<p>Tons of variables here, but as we can see, these are all private, and only a few have accessor functions. That&#8217;s because we don&#8217;t want any other class to change the information that it&#8217;s being passed around. The other reason is because we&#8217;re going to use some private variables to track information that will become useful a bit later.  I have also included a texture here. This is because we want to be able to draw a rectangle if the left button is pressed and dragged. The texture is a 1&#215;1 transparent png.  The first function is not a constructor. There is no need because we want to get the mouse information as soon as we start the program. For this reason, we initialize the state of the mouse as soon as it launches. That defeats the whole purpose of having a constructor in this case. All other information will be processed as it is received.  The first function is Update() function:</p>
<pre name="code" class="c-sharp"">static public void Update()
{
MouseHandler();
}</pre>
<p>Tada! Yes.. tis&#8217; that bad. The problem here is that our class is a general input handling class. That means that we don&#8217;t want to limit ourselves to just mouse input (even though it is what we&#8217;re doing initially). Now for the real MouseHandler(). This is a rather large function. So I will break it down into little pieces:  The initialization:</p>
<pre name="code" class="c-sharp">static private void MouseHandler()
{
  MouseState mouseState = Mouse.GetState();
  isLeftClick = false;
  isRightClick = false;</pre>
<p>Get the current state of the mouse is pretty obvious. The little less obvious is isLeftClick and isRightClick. We want to make this two false as soon as we enter the function. We&#8217;re only going to turn them on if there is an action in progress. If there is no action, they will drop all the way down as false. This are the single right and left click variables. That&#8217;s important to know.</p>
<pre name="code" class="c-sharp">  //the left button has been pressed.
  //Create the rectangle
  if (prevMouseState.LeftButton == ButtonState.Released &amp;&amp; mouseState.LeftButton == ButtonState.Pressed)
  {
    mouseRec = new Rectangle((int)mouseState.X, (int)mouseState.Y, 0, 0);
    mouseRecOrigin = new Vector2(mouseState.X, mouseState.Y);
  }</pre>
<p>the first thing we do is compare the previous value to the new value. If it was not pressed before, and it&#8217;s pressed now, we create a rectangle. The X, Y coordinates are set to the position of the mouse. We also set the MouseRecOrigin values to X, Y. This is a private variable which is used to keep track of where the rectangle was started. This will allow us to draw rectangles in every directions.</p>
<pre name="code" class="c-sharp">  //the left button is on hold.
  //Update rec with appropiate dimensions
  if (prevMouseState.LeftButton == ButtonState.Pressed &amp;&amp; mouseState.LeftButton == ButtonState.Pressed)
  {
    //Capture the origin and width
    if (mouseState.X &gt; mouseRecOrigin.X)
      mouseRec.Width = mouseState.X - mouseRec.X;
    else
    {
      mouseRec.Width = (int)mouseRecOrigin.X - mouseState.X;
      mouseRec.X = mouseState.X;
    }

    //capture the origin and height
    if (mouseState.Y &gt; mouseRecOrigin.Y)
      mouseRec.Height = mouseState.Y - mouseRec.Y;
    else
    {
      mouseRec.Height = (int)mouseRecOrigin.Y - mouseState.Y;
      mouseRec.Y = mouseState.Y;
    }
  }</pre>
<p>This chunk is the one that we&#8217;ll probably care the most. I had seen a tutorial <a href="http://www.xnadevelopment.com/tutorials/youhavebeenselected/YouHaveBeenSelected.shtml">here</a> which is a great resource. The problem I found with their way of doing things, is that it didn&#8217;t allow for the mouse to be dragged in a top-right diagonal. So this was my solution to their issue. Not the most elegant, but it certainly gets the job done.</p>
<p>First we make sure that the mouse was previously pressed and it continues being pressed. This is the only time that we want to draw/create a rectangle.  Now, if the current position X of the mouse is greater than the origin X, then that means we&#8217;re dragging the mouse to the right. In this case, the rectangle&#8217;s origin should be X. In this case we only care about the width of the rectangle which we calculate by subtracting the current position from the old position.</p>
<p>However, if the current position X is less than the origin X, then we&#8217;re dragging the mouse to the left. Because of this, we need to not only find the new width of the rectangle, but also find the new origin. We find a new origin because we want to keep the rectangle straight with non-negative width. In this case, we subtract the position X of the mouse from the origin to calculate the width.</p>
<p>Additionally, we store the current location of the mouse to the origin of the rectangle.  The update done for Y is identical, except for the change in the variable name from X to Y.  The only things left to do are capture the single clicks.</p>
<pre name="code" class="c-sharp">  //the left button has been released
  if (mouseState.LeftButton == ButtonState.Released &amp;&amp;
      prevMouseState.LeftButton == ButtonState.Pressed &amp;&amp;
      mouseRec.Width == 0 &amp;&amp; mouseRec.Height == 0)
  {
    isLeftClick = true;
  }

  //Check for right mouse click (No drag allowed)
  if (mouseState.RightButton == ButtonState.Released &amp;&amp; prevMouseState.RightButton == ButtonState.Pressed)
    isRightClick = true;</pre>
<p>very simple code here. In the case of the left click we want to check the previous status of pressed to the new status of released. That means it&#8217;s been let go. However because we do care about the drag characteristics of the left click, we do one more check against if the rectangle has a width or height. This will ensure that it&#8217;s a single click or a drag. For the right click, we&#8217;re just going to check the status. Finally the clean up code:</p>
<pre name="code" class="c-sharp">  //Clear the rectangle
  if (mouseRec != Rectangle.Empty &amp;&amp;
      mouseState.LeftButton == ButtonState.Released &amp;&amp;
      prevMouseState.LeftButton == ButtonState.Released)
    mouseRec = Rectangle.Empty;

  //update the mouse state
  prevMouseState = mouseState;
}//End input handler</pre>
<p>We have three checks here. First we check if the rectangle is empty. If it&#8217;s empty, we just keep going. No need to set it again. If there is a rectangle, then we check if the current status of the mouse is pressed. If it&#8217;s not, it&#8217;s because the user might have just released. If that is the case, we want to leave the rectangle alone, so whatever is next in line can use the rectangle as needed.</p>
<p>If the previous state was released, then it means that it&#8217;s been released for two frames: Clear the rectangle. Finally we just update the previous mouse state. Now, for the drawing! First things first: Load the texture:</p>
<pre name="code" class="c-sharp">static public void Load(ContentManager theContentManager)
{
  if (nullTex == null)
    nullTex = theContentManager.Load(@"gfx/1x1");
}</pre>
<p>Simple enough. I do the null check in case some other part of the program is also trying to load it. In that case we don&#8217;t wanna cause errors so we just return. Now, for the actual drawing:</p>
<pre name="code" class="c-sharp">static public void Draw(SpriteBatch spriteBatch)
{

  spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

  //Set up the rectangle.
  Rectangle dstRec = new Rectangle(mouseRec.X, (int)mouseRec.Y, 1, 1);
  Color color = Color.WhiteSmoke;</pre>
<p>Again, tons of code, so we break it down. First initalize the variables. Pass spriteBatch as an argument, and begin! Now we set up a temporary rectangle. The origin is going to be the origin of the mouseRec. However, the width and height are only 1 because that&#8217;s the size of the border we want for the dragged rectangle.  We also set a color because we&#8217;re going to use it in the draw function. So better to not hardcode something 4 times.</p>
<pre name="code" class="c-sharp">  if (mouseRec.Width &gt; 0)
  {
    int x = mouseRec.Width / spacing;
    for (int i = 0; i &lt;= x; i++)
    {
      //draw horizontal top
      spriteBatch.Draw(nullTex, dstRec, new Rectangle(0, 0, nullTex.Width, nullTex.Height), color);

      if (mouseRec.height &gt; 0)
      {
        //draw horizontal bottom
        dstRec.Y += mouseRec.Height;
        spriteBatch.Draw(nullTex, dstRec, new Rectangle(0, 0, nullTex.Width, nullTex.Height), color);
        dstRec.Y -= mouseRec.Height;
      }

      //advance
      dstRec.X += spacing;
    }
  }</pre>
<p>We&#8217;re going to have to do two independent checks. One for width and one for height. We could potentially do it in one, but it&#8217;s just messy if we do. So much better to have two separate statements. First things first, we set up a sentinel value. This value is the width of the rectangle. The result is the space between each graphical assets to be drawn as a border. I like 7 because it gives you this ton of space between dots. Makes it oddly cool. Now we loop through the entire width.</p>
<p>Notice that the condition is not less than but also equal to. This is because if you don&#8217;t draw one more, you&#8217;re going to have a odd gap on the bottom right corner. This way the extra space is filled by a extra iteration. Now, I draw the bottom horizontal line. For this we first check if the height is greater than zero. If it is not greater than zero, then we don&#8217;t even worry about drawing it. This will certainly save cycles. If the height is greater, then we will move the Y position of our temp rectangle to the bottom of the rectangle. and we draw one more sprite there.</p>
<p>Next we reset it back at the top for good measure. The tutorial I linked above has this whole thing outsourced to a function which is called 2 times. I rather do it in the same loop. it&#8217;s one less jump and we have all the information at hand. The verticals are identical to the horizontals. The only difference is that we&#8217;re moving to the right column if the width is greater than zero:</p>
<pre name="code" class="c-sharp">if (mouseRec.Height &gt; 0)
{
  dstRec.X = mouseRec.X;
  int Y = mouseRec.Height / spacing;
  for (int i = 0; i &lt;= Y; i++)
  {
  //draw vertical right
  spriteBatch.Draw(nullTex, dstRec, new Rectangle(0, 0, nullTex.Width, nullTex.Height), color);

    if(mouseRec.Width &gt; 0)
    {
      //draw vertical left
      dstRec.X += mouseRec.Width;
      spriteBatch.Draw(nullTex, dstRec, new Rectangle(0, 0, nullTex.Width, nullTex.Height), color);
      dstRec.X -= mouseRec.Width;
    }

    dstRec.Y += spacing;
  }
}

  spriteBatch.End();
}</pre>
<p>Finally we close the spriteBatch! PHEWW&#8230; that was long. But I think at the end, it makes for a nice effect and certainly adds a ton of functionality! The final result?</p>
<p><img class="alignnone size-full wp-image-270" title="mouseborder" src="http://www.darksoda.com/wp-content/uploads/2009/03/mouseborder.jpg" alt="mouseborder" width="397" height="297" /></p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=253</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slow progress&#8230;</title>
		<link>http://darksoda.com/blog/?p=252</link>
		<comments>http://darksoda.com/blog/?p=252#comments</comments>
		<pubDate>Wed, 11 Mar 2009 21:21:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=252</guid>
		<description><![CDATA[I have been doing a lot of things lately. One of the most interesting was creating a set of screens for game flow: * Initial Screen * Options * Pause * others This was done thanks to one of the resources in the XNA (again using code from resources&#8230; shame on me). The complexity of [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing a lot of things lately. One of the most interesting was creating a set of screens for game flow:</p>
<p>* Initial Screen<br />
* Options<br />
* Pause<br />
* others</p>
<p>This was done thanks to one of the resources in the XNA (again using code from resources&#8230; shame on me). The complexity of it is a bit above my knowledge, so it was a direct copy/paste and I just did some mark up to get it to work with my own code.</p>
<p>I did this because of several reasons. First of all, I really got to clean up the code and outsource everything out of the main class and into a World class. World class controls everything in the game board through function calls on update for each element. The only logic here is on the AI behavior changes (when enemies shoot or dive).</p>
<p>The second reason is because it let me use a Options screen that lets me load and reaload things without having to quit the game. This was when the big eureka moment hit me. After having traced how each screen worked, i noticed that it didnt&#8217; have a way to pass game options from point to point. In other words, any options that I added to the options screen was lost the moment I left the screen.</p>
<p>This posed a problem to my idea of having options for adding enemies and other elements. Of course, this is the whole purpose of the options screen! The solution was rather inspired by my previous work with the Sound class. So I created a public static GameSettings class. Why static? well, the answer is rather simple, it offers me the option to control them and access them from anywhere. When the options are updated in the options screen, they&#8217;re read by the World class in the GamplayScreen and taken into account when the game loads.</p>
<p>I like this solutions a lot. I think it&#8217;s both elegant and functional. It also led me to create a Level class which can store level options. I can create a array of levels, and then access each level as the game progresses.</p>
<p>I am currently working on a HUD. I just got started on it, so there is no much functionality to it yet. So far I am only drawing a radar and a small marker for where the hero is. I still need to decide how to work the radar in the game. I have 2 options, to display a radius of where things are, or display everything in the playing field. They both have pros and cons. I haven&#8217;t decided because I&#8217;m still strugling with now I want to make the game work. This is a bad thing at this stage&#8230; I really should know where I&#8217;m going, but I have become increasingly worried about what it takes to make any type of RTS work (even on the simplest level). I love the idea of the RTS, but it takes more than one person, and I have been doing this all by myself, which makes it extremely difficult.</p>
<p>I think I will be working on a single controlled ship taking a number of enemies very much Galaga style though the AI will be free roaming.</p>
<p>More to work on =)</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=252</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding solutions to problems&#8230;</title>
		<link>http://darksoda.com/blog/?p=251</link>
		<comments>http://darksoda.com/blog/?p=251#comments</comments>
		<pubDate>Fri, 06 Mar 2009 19:14:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=251</guid>
		<description><![CDATA[I have been enjoying my journey through the XNA very much. It all started with a little project to move a sprite around, and now I can control a number of sprites, spawning different behaviors, animations and sounds. It wouldn&#8217;t be fair to say that I have done all this entirely on my own. The [...]]]></description>
			<content:encoded><![CDATA[<p>I have been enjoying my journey through the XNA very much. It all started with a little project to move a sprite around, and now I can control a number of sprites, spawning different behaviors, animations and sounds. It wouldn&#8217;t be fair to say that I have done all this entirely on my own. The XNA has a great number of resources that I have tried to take as much advantage of as possible. It is not a bad thing to admit that have copied at lot of source code from the resources when it fits my needs. However, more importantly, I have tried to write my own code as much as possible. I have only copied it when it fits my exact needs, and when I think I can learn more from copying it, than from writing my own.</p>
<p><span id="more-251"></span>That was the case of this latest step in the process. Sound was something that I was not entirely sure how to bring into the world. I knew the basics such as initializing the engine, the soundbank and the wav. I had some trouble getting the Cues to play, but that had to do with not knowing much about XACT (the sound rendering engine in the XNA). FYI, if anyone ever has trouble getting their cues to play, just make sure you actually added the cue from the soundbank to the cue list at the bottom. One of the issues with sound (and this is an issue with a number of things when making games), is that a lot of elements in the game need access to the sound engine and sound cues. There are several way to solve this issue; for instance, you can inialize the engine in the &#8220;world&#8221; class, and pass a reference to every sub class. This is not very portable, and certainly makes for a mess of very ugly code. Another option is to allocate a sound engine and intialize it in every sub class. This is portable&#8230; but holy cow would it be expensive and unnecessary use of resources. It also makes for ugly code.</p>
<p>Then I found the Marble Game way. It&#8217;s one of those moments when you find out that the simplest answer is the correct and takes you some time to realize that you have been doing it all wrong. The easiest and most effective way to do this is to create a static class and initialize it in the &#8220;world&#8221;. The great advantage of this is that it makes it portable, accessible, economic, and very elegant code. The static class can be called from any other sub class and the initialization can take place with a single call. It was brilliant. The execution on the example of the Marblet Game was also very elegant. When things meet all this needs, it would be silly to attempt and create my own, so I learned what to do next time, and moved on!</p>
<p>The next step will be setting a player based AI with mouse selection and way points. Looks like a very hard task but it should be fun.</p>
<p>I also need to implement a HUD. I honestly think this should be one of the last things to even think about. Having said that, I also believe that it&#8217;s one of the things that can really bring a game to life.</p>
<p>No screenie today. Source code might be up later this week, after I clean up and make it pretty.</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=251</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with AI</title>
		<link>http://darksoda.com/blog/?p=249</link>
		<comments>http://darksoda.com/blog/?p=249#comments</comments>
		<pubDate>Wed, 25 Feb 2009 19:59:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=249</guid>
		<description><![CDATA[I have been working on a lot of things. Mostly on learning AI implementation. This week I have been working on learning all the simple AI behaviors (I&#8217;m very new to this stuff) and finally got it all working last night. I had been stuck on getting my wondering behavior working. Turns out that while [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a lot of things. Mostly on learning AI implementation. This week I have been working on learning all the simple AI behaviors (I&#8217;m very new to this stuff) and finally got it all working last night. I had been stuck on getting my wondering behavior working. Turns out that while cleaning my code, I had left an old variable laying around. I hate it how this small details give you such headaches.</p>
<p>In the process of learning all this stuff, I have found a new love for AI. The complexities of it and the subtle things that make it great even on the most simple games. The book I&#8217;m reading is <a href="http://ai4g.com/">http://ai4g.com/</a>. It&#8217;s is certainly a great book though I wish the pseudo code was a bit better as far as what each function needs to pass and return. I guess their idea is to make it as open as possible, the downside is that if you&#8217;re learning, you&#8217;re left wondering.</p>
<p><span id="more-249"></span></p>
<p>So I currently have the following behaviors:</p>
<p>Seek: It moves the object to a target at a set speed. Object rotates to face the target and then moves forward.<br />
Flee: It moves the object away from a target at a set speed. Object rotates to face away from the target and then forward<br />
Wander: It moves the object around. First forward and then with a chance of modifying the orientation left or right.<br />
Homebound: This one I kind of invented just to experiment. Homebound moves the object to the defined starting point. It uses the Seek steering and the only real difference is that once it reaches the target, it will return to facing the last stored orientation. This can be useful for &#8220;patrolling&#8221; behaviors.<br />
Static: Does nothing. This is an actual needed behavior. Even if there is no movement involved, having the ability to control what a object does when it&#8217;s not moving, makes it very useful.</p>
<p><a href="http://www.darksoda.com/wp-content/uploads/2009/02/v5.png"><img class="alignnone size-medium wp-image-250" title="v5" src="http://www.darksoda.com/wp-content/uploads/2009/02/v5-300x234.png" alt="Version 5. AI Behaviors" width="300" height="234" /></a></p>
<p>Finally, here is the screenshot of the program. The red rectangle is the bounding box of the object. This is basically the rectangle that determines where an object is being hit or the size of the object when rotated. There are just too many reasons to have this. Obviously, it&#8217;s just debug information to have it colored and drawn. In an actual game, this would certainly be invisible to the user.</p>
<p>I have also added some text on the left side. The Cylon raider are numbered 0-9 (a 10 size array) with the information on rotation and position on the screen. This was very useful when trying to find out if the objects where behaving correctly at the early stages of making the AI. Now, this is a bit redundant. However, having information displayed like that has become essential to me. Learning on my own, I used to struggle a lot trying to trace where things where going or what they were doing. I have since then learned that you can learn a lot by just letting the program run and display as much information as possible about what&#8217;s going on.</p>
<p>The next step will be to add the collision back into the game. I already have working collision behavior for bullets from a previous version. I just need to find a better way to manage all the interaction between the assets to minimize the number of cycles while maximizing the information output.</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=249</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The XNA Clock</title>
		<link>http://darksoda.com/blog/?p=248</link>
		<comments>http://darksoda.com/blog/?p=248#comments</comments>
		<pubDate>Fri, 20 Feb 2009 07:30:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=248</guid>
		<description><![CDATA[The last few months I have been working on XNA. The great thing about the XNA is that it wraps the DirectX interface in some really accessible functions. The downside is that it becomes slightly less flexible. For instance, there is not a function to draw a single textureless rectangle. This is obviously not the [...]]]></description>
			<content:encoded><![CDATA[<p>The last few months I have been working on XNA. The great thing about the XNA is that it wraps the DirectX interface in some really accessible functions. The downside is that it becomes slightly less flexible. For instance, there is not a function to draw a single textureless rectangle. This is obviously not the end of the world. The solution is quite simple, you can just use a 1&#215;1 blank .png and size is to the rectangle size needed.</p>
<p>I actually found working with the XNA very comfortable and fun. C# is very easy to pick up if you already know Java and C++. I&#8217;ve been working in my own project, and helping others with little things here and there. I created this little splash screen in just 30 mins.</p>
<p style="text-align: center;"><a href="http://www.darksoda.com/wp-content/uploads/2009/02/clock.png"><img class="aligncenter size-medium wp-image-247" title="clock" src="http://www.darksoda.com/wp-content/uploads/2009/02/clock-150x150.png" alt="" /></a></p>
<p>Just a logo with a clock like animation. I&#8217;ll put more details on my actual project later on!</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=248</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Battlestar Galactica &#8211;  Sometimes a Great Notion</title>
		<link>http://darksoda.com/blog/?p=246</link>
		<comments>http://darksoda.com/blog/?p=246#comments</comments>
		<pubDate>Mon, 19 Jan 2009 18:43:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://www.darksoda.com/?p=246</guid>
		<description><![CDATA[Thus will it come to pass. A dying leader will know the truth of the Opera House. The missing Three will give you the Five who come from the home of the Thirteenth. You are the harbinger of death, Kara Thrace. You will lead them all to their end. End of Line Spoiler Alert: Episode [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Thus will it come to pass. A dying leader will know the truth of the <a title="Opera House" href="http://en.battlestarwiki.org/wiki/Opera_House">Opera House</a>. The missing <a title="Number Three" href="http://en.battlestarwiki.org/wiki/Number_Three">Three</a> will give you the <a title="Final Five" href="http://en.battlestarwiki.org/wiki/Final_Five">Five</a> who come from the home of the <a title="Earth (RDM)" href="http://en.battlestarwiki.org/wiki/Earth_%28RDM%29">Thirteenth</a>. You are the harbinger of death, Kara Thrace. You will lead them all to their end. End of Line</p></blockquote>
<p><strong>Spoiler Alert: Episode &#8211; Sometimes a Great Notion. January 16th, 2006</strong></p>
<p>This is the last line that the Hybrid gives to Starbuck before being unplugged during the Season 4 (1st half) Episode &#8211; Faith. Why is it so significant? Well, for the second part of season 4 this will be the line to unravel the story (or so my theory goes).</p>
<p>Danielle has an interesting theory actually. She believes that Starbuck is actually a 13th cylon or cylon related &#8220;creature&#8221;. The theory is actually pretty good if you tie it to this specific line. This is go it goes.</p>
<p><span id="more-246"></span></p>
<p>The facts:</p>
<p>There were twelve colonies. One for each sign on the zodiac.<br />
There was a thirteen colony in a planet called Earth. This is also related to a thirteen zodiac sign.<br />
There are twelve cylons.<br />
The remains found in Earth are not human remains but cylon remains.</p>
<p>The speculation:</p>
<p>Danielle&#8217;s theory is actually pretty simple. There are only 12 known cylons. However, just like the 13th, colony, there might be a 13th cylon that is not known to the others. This new cylon is Starbuck. So far,  one part of the line given by the Hybrid has come true. The missing three did give the 4 (5 if you count this episode).</p>
<p>There are the following parts to unfold:</p>
<p>A dying leader will know the truth of the <a title="Opera House" href="http://en.battlestarwiki.org/wiki/Opera_House">Opera House</a>.<br />
You are the harbinger of death, Kara Thrace. You will lead them all to their end.</p>
<p>However, the most interesting line is this:</p>
<p>&#8230;the <a title="Final Five" href="http://en.battlestarwiki.org/wiki/Final_Five">Five</a> who come from the home of the <a title="Earth (RDM)" href="http://en.battlestarwiki.org/wiki/Earth_%28RDM%29">Thirteenth</a>.</p>
<p>There is one interesting issue here. This line does not say anything about the 13th being the colony or a cyclon. The wording is so vague that it&#8217;s entirely plausible that the line is talking about a 13th cylon who is the maker and could potentially be the &#8220;God&#8221; of the cylon religion. It would also explain why &#8220;God&#8221; didn&#8217;t want the other 7 to know about the five since they were created on earth and had reach a human-like society which the other 7 were craving for. I don&#8217;t think Starbuck is the god of the cylons, but I do think she is related to the maker. Maybe a clone of which would tie it to the Caprica series. Making her the original Cylon. This would also explain how she returned from the dead, and why she has the bigger destiny to acomplish.</p>
<p>I don&#8217;t think there is a solid theory out there as to why Starbuck is the &#8220;Harbinger of Death&#8221;. But I think this covers pretty much everything else.</p>
]]></content:encoded>
			<wfw:commentRss>http://darksoda.com/blog/?feed=rss2&amp;p=246</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

