Monday, November 30, 2009

Well, I did it. I created a tokenizing program, which tokeninzes a square. I had a reference file, but the thing was coded so poorly that I didn't even bother reading or understanding the darn thing. Here is the source code to the terribly written file: http://cplusplus.com/files/fraction.zip

This program took me about 30 minutes to write, and 2 hours to debug. I had multiple bugs, and wrote the loop that creates the "middle" of the square about 4 times before I finally created something clean looking and easy to read. A common error I made, was during the draw function, I would often reset the value of a or b to the incorrect corresponding variables width and height. If I were to label my variables as something extremely intuitive, I could have saved myself a lot of trouble :P

Here is the code for my square tokenizing program, it should look nothing like my reference (which I didn't ever reference), and be easier to read:

That is a podclass made by DigiPen. It is an interview of two programmers, and is extremely interesting and relevant to anyone aspiring to become a professional programmer for the games industry. Right click on the link, and select "Save target as", or "Save link as".

Tomorrow, I will be going back to school. I plan to still do a little coding, so expect to have another blog post to read.

Sunday, November 29, 2009

Today, I created a program that adds two fractions together, and then reduces them. This took me about 2 hours to complete, and about 25 minutes to write. Yep, that means I sat there and debugged the program for over an hour and a half. Sheesh, I hope this isn't what programming is always like ;)

The way this program works, is I set up the main function to call all of the other functions. However, in function Addition, I call the reduce function. This is because I needed to pass on the data from the addition function directly into the reduce function. If I were to call the reduce fraction from within the main function, the private data of function addition wouldn't have been passed onto being reduced. Here is my code:

And there she is! The program should work without the & symbol in the functions' parameters, my reference code used it, so so did I :)

While creating this program, I used this source as a reference, although, I made sure to only look at it when I completely forgot how to do something, and throughout when I was debugging. Here is the link to my reference source code: http://cplusplus.com/files/fraction.zip

Speaking of that bug, take a look at what I had wrong! Look up in my source code, you see that red code? That is what I had mixed up, here is what I had when my code was bugged:

Num = a;

Denom = b;

Num2 = a;

Denom2 = b;

Pretty ridiculous eh? That simple, tiny, infinitesimal error cost me over an hour and a half of debugging!

That is what I completed for the day. While creating that, I gained understanding of the % (modulo) symbol, and one of it's practical uses. I also gained an understanding of a very useful loop; the do while loop. The do while loop, which is what my entire main function was constructed of, will complete it's task, and then complete a comparison. So basically, the while loop makes the comparison before it executes code, and the do while loop executes its code before the comparison.

After creating this program in a few minutes, I went on to try something a bit more challenging. This program below took me about two hours to write; a lot of debugging. At first, I tried to write the entire program within the main function, although, that didn't really challenge me or enhance my abilities in any way, and it was extremely buggy. I decided to seperate each step in the process of matrix multiplication into seperate functions, and create my main function as a do while loop. It turned out producing correct results! Here is the code, keep in mind this only works with 2x2 matrices:

#include<iostream>
using namespace std;

/*The functions in this program are fired in the order of top to bottom for readability*/

I feel like I'm getting a little better each day I do this! Tomorrow, I plan to write out a program that will add, subtract, and reduce fractions. I will be using a reference source code, found here: http://cplusplus.com/files/fraction.zip

I can't wait to start moving onto programs using windows coding! I plan to become accustomed to using arrays, functions, structures, pointers, and dynamic memory before I move onto more advanced concepts though. If I can write simple programs using the tools I just listed, I'll have some fundamental skills to use for those more advanced concepts.

A friend of mine mentioned to me today that I should keep a blog of my journeys on becoming a video game programmer; I have been accepted to my top choice college: DigiPen! I'm ridiculously excited to start school there next August! I'll be starting in a Bachelor's Degree of CS in Real Time Interactive Simulation (RTIS). Here is a link to DigiPen's site: https://www.digipen.edu/

The goal of this blog is to keep a detailed and prolific log of what it is like to start from no programming experience, to becoming a professional programmer.

Sadly, I already have a small amount of programming experience. My first language I ever built a program in was AS3, which is the language behind Flash. This was the ever popular Hello World program. From this point, I ventured into forums and online tutorials, and within a couple weeks of study I was able to create a simple game (which I currently still have on my flash drive), and then continue additions to the game once the tutorial was over.

I couldn't, even if I wanted to, recode this game from scratch -I only had a deep enough understanding of AS3 to modify pre-existing code from the tutorial. So, the goal of this blog is still attainable!

After this little flash game, I stopped coding altogether.

Now, two years later, I am accepted to a great college, am learning C++ from the ground up on my spare time, and finishing up my senior year of highschool.

The reason I have chose to spend my time learning C++, is because the language that 90% of video games are made with is C and C++, not to mention C and C++ are taught extensively at DigiPen, so anything I learn now will be very valuable during college.

I've spent two days reading through the tutorial found on this website http://cplusplus.com/, and I've gained a working knowledge of all categories up to Classes(1). I've learned to use variables, constants, basic input/output via cin and cout, control structures (like for and while loops, if and else statements) , arrays, pointers, dynamic memory, and data structures.

While progressing through this tutorial, I take effort into not only understanding the concepts taught by the examples, but I go and create my own programs similar to the examples from scratch best I can.

Over these two days, I have written two console programs. Here is the code for the my first program created during this tutorial, it's function is to have the user guess what number the number input by the user is being muliplied by. It only works with integers:

I'm finding that coding in C++ is actually extremely rewarding! Just creating these two programs, from scratch, without any help has revitalized me and peaked my interest of programming even more so than it was before!

I am now currently reading an article about 2d physics engines here: http://www.gamedev.net/reference/programming/features/verletPhys/ and should finish reading it before I finally get to sleep. The article is fairly simple in terms of concepts, but the actual code is way over my head.. Ugh. I can understand the math and the concepts, but I can't wrap my head around every bit of code presented.