![]() |
|||||||||||
| Home | Projects | Articles | Archives | Forums | About | ||||||
Xbox 360 2D Tutorial - A Quick Critique 01/06/2009 Last week I discussed starting with Xbox development, and mentioned the first tutorial that's available from the XNA Creator's Club. The tutorial runs through the creation of a simple two-dimensional game in which the player scores points by shooting at UFOs using a rotating cannon. It's a good setup as far as tutorials go with introducing the concepts of C# and XNA Game Studio, but it fails to follow some key development practices for the sake of brevity. This article will discuss some of the important issues regarding the tutorial, along with the fixes required to not only program a two-dimensional game with the tutorial, but to also follow sound coding practices. Public Vs. Protected Methods FireCannonBall, UpdateCannonBalls and UpdateEnemies are all created in the tutorial to execute specific pieces of the game logic. These are all called from the protected method Update, which is responsible for running game logic, such as gathering input, updating the screen, checking for object interactions, and anything else that should be periodically changed. In the tutorial, we're told to make all three of these method public, when they should instead be protected.
Methods should be protected when the only classes that should access them is themselves and their inherited classes. All three of the above functions are only called from a protected Update method, and no other class should have any business calling them. Public Variables in Classes GameObject is a class created in the tutorial that holds information about any game object on the screen, including the UFOs, the cannon and cannonballs. The class contains a constructor which sets a Texture2D to represent the on-screen sprite, as well as setting default values for the other variables. These variables include the following: - Position - Rotation - Velocity - Center - Dead/Alive All of these variables, including the sprite, are set in the tutorial as public variables. These variables are then set directly from the main program. This is bad programming practice to the extreme - software engineers are taught in their first class about public variables in classes. Fixing this issue takes a couple of steps: - Setting the public variables to private variables will protect the contents of the variables.
- Write functions to get and set the values of the variables
- Use the get and set functions to access the variables in the main code Example:
Organization The tutorial had us adding variables and methods haphazardly to the code in an effort to make a running demonstration. In doing so, we've created a mess out of our variables! Look at the following mess:
That's a lot of variables to sort through, which can be quite troublesome when we're looking for a specific variable! Here are some suggestions on cleaning this up: - Load constants through a property file or constants file, then access them through a getProperty/setProperty method. This easily cleans up the constants and makes them easier to manage and change. Property files are extremely useful in tweaking values without recompiling. - Consider encapsulting like variables/methods. We see some variables that only concern themselves with cannons, other with cannonballs, even others with UFOs. It's a good idea to make these their own classes for better management. - Sort variables either by object or by interaction. When none of the above work, it can be easier on the eyes to sort the variables by type, so you can easily look through ints/floats/GameObjects/etc. Another way to organize is put all the cannon objects together, then the cannonball objects, and so on. Unit Testing No program is complete without unit testing. Unit testing has many purposes, including a sanity check for the software engineer. This tutorial doesn't mention any testing in the slightest, which can make it difficult if a novice makes a logic mistake. Unit testing will be covered more in-depth in another article, but a good starting place for C# unit testing is NUnit, which is initially ported from JUnit for Java. It can be found at http://www.nunit.org/index.php. Xbox 360 Development Setup 12/31/2008 The Xbox 360 is one of the most popular video game consoles currently available. With access to a vast library of games, a marketplace to download games, trailers and demos, plus wonderful multiplayer support with voice chat, it proves to be a wonderful playground for all. How does one develop for this console? I'll be addressing this through a series of articles based on beginner Xbox programming, including installation and setup of developer tools and useful resources. Development Tools Xbox 360 development is done though the .NET framework with XNA Game Studio. Note that XNA Game Studio requires a Windows machine to run. There are a couple of steps required to fully use the software. 1) Update Windows (Windows XP w/ Service Pack 3, or Windows Vista w/ Service Pack 1) 2) Download and install Microsoft Visual C# 2008 Express Edition. This can be found at http://www.microsoft.com/express/download/ 3) Download and install XNA Game Studio 3.0. This can be found at http://www.microsoft.com/downloads/details.aspx?FamilyId=7D70D6ED-1EDD-4852-9883-9A33C0AD8FEE&displaylang=en Joining the XNA Creators Club The XNA Creators Club is a resource available for Xbox 360 developers. The features are as follows: - Quick-step guides to creating your first Xbox game - Game submission to Xbox Live Marketplace - Peer Review Tools - Downloads for Xbox community games This can all be found at http://creators.xna.com/ Creating your first game The XNA Creator's Club comes with some basic tutorials - the one that I've completed so far is the 2D tutorial. This tutorial is sectioned into many video segments, each of which cover a specific piece of the game creation. The videos are excellent for beginners, but are very slow-paced for advanced software developers. I found myself skipping ahead in the video often, or predicting and typing out the lines before the video explanation. The first tutorial can be found at http://creators.xna.com/en-US/education/gettingstarted/bg2d/chapter1 What's next? This article covers the basics to get started, and is the first in a chain of articles based around Xbox programming. The next article will be a critique of the first video tutorial, as well as ideas to improve upon the game's basic gameplay. The Game Industry: Getting Your Foot in the Door 06/02/2007 The computer game industry is rather unique in that even in entry-level positions, the company requires some level of expertise in programming or modifying computer games already. This even goes for college students fresh out of classes: there were many a times when I would send out resumes only to not get any response back whatsoever. A small amount of companies did respond back, however, and gave me some tidbits of information that would have been invaluable during my years of college learning. In an effort to help those currently attending classes or wishing to switch fields into the computer gaming industry, here are some pointers that will help your chances of getting hired into your dream job! Which Class will you Play? In a typical computer game company, there are many different roles that you can fulfill. Breaking them down one level, you can easily get positions such as game designer, artists, programmer, and tester. Digging deeper, however, these branch out into various smaller positions that make up the whole. Game designers can be broken down into level designers, gameplay designers, etc. Artists have different focuses as well, from computer animation, modeling,music and texturing. Programmers can probably be broken down the most, into graphics, network, sound, user interface, artificial intelligence, and so on. The key to breaking into the industry is to find what focus works out for you the most, and starting to do some research into what this role entails. For example, when most people think about computer game programmers, one of the more immediate roles that comes up is graphics programming. However, there are many other programming jobs that are as important. I personally have better luck at programming logic rules and artificial intelligence than I do with graphics, and if I had to pick a role to play, it would probably be AI programmer. Research, Research, Research. Now that you have your focus, you can hone in on certain skill sets that you'll need in your endeavors. The sources for these is almost limitless. Here are a couple of good ones: Classes: This usually applies to college students, but can apply for anyone who wishes to take a night or online course in a specific topic. Classes are one of the easiest ways to learn a topic, however, the disadvantages are the length of time and the monetary cost. The cost is well worth it though: helpful professors are an excellent resource: besides the lectures and class time, professors can also offer insights into a particular field and answer many questions that you may have about the material. Additionally, college students majoring in computer science will do well to take as many computer science electives as possible. By doing so, you gain exposure to many facets of computer programming, which will prove invaluable in your learning process. When I was in college, I took many courses that didn't have a direct correlation to game programming, but just by having seen the material, I can gain a bigger appreciation for all the facets of computer science. Libraries: Many libraries are coming to grasp the exciting impact that computer science is having on the world as a whole, and as such, have many programming books on hand. Some books will be out of date (which is the primary issue with libraries in general), but it's a good tool to get a general grasp of a certain topic. Online References: John Carmack said it best in the book Masters of Doom, when talking about the general accessibility of the internet to the modern programmer: “In the information age, the barriers just aren't there. The barriers are self-imposed. If you want to set off and go develop some grand new thing, you don't need millions of dollars of capitalization. You need enough pizza and Diet Coke to stick into your refrigerator, a cheap PC to work on, and the dedication to go through with it.” The internet is one of the best resources that you have out there in order to program anything that you can imagine. There are plenty of HOW-TOs, FAQs, tutorials, documentation, and forums out there that you can take your programming knowledge however far you want to carry it. In fact, this website's primary goal is to become one of these hubs of information on the internet, so that people like yourself can take your skills to the next level. Acquaint Yourself with the Tools of the Trade Every good tradesman knows the tools of his trade. Game programmers have their tools as well, which cover everything from planning and resource management up to tools to write the code itself. With computer game programmers, though, not all the tools are obvious. Here's a very short list of the tools that you'll most likely find on your journey: IDEs: The most obvious tool of the bunch. An IDE, or Integrated Development Environment, is a computer software that has a compiler/interpreter, a code editor, and other various tools that make programming code incredibly simple. Finding the right IDE for programming is an important task, since this is where you will be spending a majority of your time. SDKs: Software Development Kits are the programming and developing gateway to many architectures and technologies. For example, most programming can be done in a Windows, Linux, or MacOS environment, but the end target of the code might be something completely different, such as video game machines (Wii, Xbox 360, Playstation 3), PDA's, cell phones, etc. In fact, when I was talking with a company during the hiring process, I found that most of their games were for the Playstation 2 market. As such, they were looking for candidates that had programmed with a Playstation 2 SDK. Unfortunately, I hadn't done so at that point, but if I had, I would have had a good shot at being employed on the spot. Instead, the employee was extremely helpful and directed me to the website of a free PS2 SDK site. If there's a certain video game console you're aiming at programming for, by all means, search for a free/inexpensive SDK that's available, and try to write a small game in it. This is a wonderful resume booster that will make you look favorable when applying for a job in the video game markets. Project Management Software: This allows you to graph out the various pieces of a larger project, assign resources to these tasks, and create milestones and completion dates for these pieces. It's a wonderful way to see the forest for the trees, and especially which tasks are on schedule and how far they are from being completed. Even when you're the sole programmer, it's an invaluable tool since it forces you to break a larger problem into smaller parts, which makes for easier design and coding. A code repository: Repositories are a way to store a large amount of code in one logical spot, and then grant access to the code to the various members of your team. Repositories also allow source control, version merging, file locking, and code checkin/checkout. It's a great way to keep tabs on all version of your software, especially when multiple programmers need to have access to the code. Backup Systems: Don't shrug this off: Regular backups will be the lifesaver of any project that you'll ever do. I've lost plenty of code, from version overwrites to hard drive crashes. Backup regularly, and back up often: re-writing code isn't a good use of your time. Resume Builder Finally, the most crucial step to the entire process is that you produce something in your spare time that can show others that you have the skills that it takes to go out into the industry! If you're unsure of where to start, think of the following possibilities: Program a small game by yourself. It may one of the slower options, since you'll be playing designer, programmer, artist, and tester all in one, but it's a wonderful way to get acquainted with all the pieces of the game development process. I'm currently doing some work in this route, and even though I'm not the best artist or tester, I'm definitely gaining a new appreciation for what it takes to do these things. I'm gaining a stronger sense of programming in a certain language, thinking about effective game and user interface design, and trying to do as much testing on my end as possible. I do have my own beta tester, though, so I am cheating a bit here. Program a game with some friends/colleagues. This option works out better when you have several people that are also aspiring to program a game, but have different foci and strong suits. It's easier here to find an artist to dedicate themselves to creating artwork and sounds, while game designers can design to their heart's content. This is also another route that I'm doing some work in, mostly as the AI lead programmer. AI is one of my stronger programming suits, and something that I enjoy working with day-in and day-out, so I became the perfect person of the group to take on this responsibility. There are other team members as well, with all of their specialties, whom I can learn from as the project progresses. Join a game modification group: Games have been modified by outside groups ever since they've been created. In fact, one of Doom's greatest design decisions revolved around the idea of outside people taking the code and the data, modifying it for themselves, and creating something completely new using id's framework. Before Doom was released, usually the original code was destroyed in the modification process, so id created a .wad file (known as “Where's All the Data?”) that kept the information about how Doom works. In order to modify the game, one could just create a new .wad file and then point the game to use that .wad file instead of the default one. Modifications skyrocketed since this innovation, and started to be used by the industry to find new talent out there in the field. One of the greatest examples of this was when a small counter terrorism modification emerged for Half-Life. Created by Cliffe and Gooseman, this game went from a very unpopular first beta release to one of the most popular modifications for a first person shooter ever created. It eventually led to both of them being hired by the company that created the original game (Valve). All of these can be great starting places for getting a first start at creating games, whether it be as a resume booster to join the industry, or to make it out there on your own as an independent game producer. Go Out There and Do It! With all of this being said, the next step is to go out there and do it! Start doing these things today! Look up some programming concepts that you may be rusty on, or start learning a new language that you've been dying to program in. Start designing a small game that you can complete in a month or two, either to show other companies or to sell out there yourself! The first step is now, and it's yours to take. Trust me, it's worth it. Squeezing the Most out of your Motivation 05/28/2007 Most of us can agree that we have certain goals that we'd like to accomplish within a certain period of time. It can range from short-term goals ("I want to finish that small project at work by the end of the week") to long-term goals ("I want to start my own business"). All of these goals have varying amounts of motivation attached to them, which is the drive that we have to see these goals become completed. There can be many sources of motivation, among them including: - Personal Motivation: A willingness on a person level to see something accomplished. They can be aligned towards personal values, or even by something like childhood dreams. - External Motivation: These are incentives, bonuses, or even threats that are linked to the accomplishment of the goal. Positive motivators include bonuses (monetary, possessions, or otherwise), whereas negative motivators can be looming deadlines or threats such as failing, firing, etc. Both of these types of motivators can be powerful, as we see in most of our waking lives. However, there's a big difference between the two. Personal motivation can be extremely flexible, even to a fault. It can gush forward if you intend it to, and it can withdraw as well. It can be brought to full attention when you will it to, but can also be pushed aside when more urgent things happen. It can be one of the biggest motivators on the universe, but it is also the easiest to neglect and squander. External motivators are rigid, since they decide when and where they will strike, at what force, and the consequences will be there upon completion or not. Deadlines are set, and unless you're an extremely awesome negotiator, will not be moved without some sort of penalty. These motivators are outside of your control, and as such, remain constant sources of power to get the job done. Taking these into consideration, I was pondering earlier about my programming styles and atmospheres at work vs. being at home. First, I'll take a look at work. First, I'd like to say that I've never missed a deadline with my projects, and that's because I usually don't have deadlines to uphold. Most of my work is done in a timely matter, so it's only the extremely important projects that have deadlines (those types of projects also usually come with a 'take your phone off the hook' clause, which makes me extremely giddy). Regardless, I do have external motivators that keep me programming here, such as my continued employment and the potential for good reviews. There are some internal motivators on some projects as well (mostly the desire of knowledge and learning), but not nearly as much as the external motivators. Now, let's take programming in my spare time. I don't have any external motivators here, since I theoretically have no deadlines that I can't change, bonuses or incentives that I have no control over, etc. If I tried to put any of these in place, it would require an extreme amount of discipline to uphold them, and *then* they might be considered external. However, most of the motivation is internal: the desire to see the things get done because of my own intrinsic values. This is a double-edged sword. There are some days that I program and get exactly what I wanted done accomplished, which brings up such powerful and awesome emotions in me that I don't really experience anywhere else. However, I do have those days where I'm frustrated beyond belief, nothing works correctly, and I throw my hands up in abandon and curse. These moments can usually stop my programming right there, because there are no concrete external motivators that are telling me to keep on going and persevere. Knowing how my motivations work is one of the steps to figuring out what I can do to help it along. First, I know for a fact that Thursdays are one of the worst days for me to program. Thursdays are the busiest day at my work, and despite being as productive and positive as I can, it does take a toll on my energy levels and general internal happiness. On these days, sometimes I don't even want to look at another computer screen when I get home, much less program on it! The key: Think of the wonderful, excited and ecstatic feeling that I get when I finish a piece of code that I really wanted to finish. Have you ever done something so cool that you jump around your house? Yeah, that's the feeling that I get. I need to remember that those are the moments that I really enjoy, and pursue it. Second, I have days where I do social things, and get into the trap of "Oh, I'll program it before/after," but that never comes along. If I do try and start the project, I think "Oh, I don't have enough time to start diving into the code." The Key: Just do a small piece, or even plan out the next details. Any small bits of time that I have can help a project go along. Even if it's just reading a couple of pages out of a textbook, it's better than nothing. Third, there are times when I have doubts about the project, especially about not completing it (essentially, failing). The Key: Being afraid of failure is counterproductive to success. Everything in life has a chance of failing, so if we're afraid of failing, then we can't do anything. Additionally, we learn from our failures, which allows us to learn from them and get a success later on. Plus, the project is for my benefit, my happiness. If the project is no longer making me happy, then maybe I need to step back, take a look at the larger picture, and see if there's something I can change to get the happiness back. If so, do it. If not, know when to step away, write off the failure, and start on something else that I enjoy. These can be ways of solidifying your personal motivation, and making it work more for what you want it to help you accomplish. The Proactive Approach 05/28/2007 One of the many books that I've been reading recently is The 7 Habits of Highly Effective People by Covey, and I've just started the chapter on the first habit, also known as 'Being Proactive'. One of the interesting tidbits of advice that the chapter started with what to read through the habits like if you were going to teach it to someone else. I decided to apply it to parts of my life and talk about the proactive approach in that respect. Most people know of the word 'proactive' as one of the recently popular management buzzwords (I know, since it's one of those buzzwords that I hear the most). It's usually demonstrated as 'Proactive vs. Reactive' in this context, where the employers argue that one should get things done in a preemptive fashion rather than just sitting around, waiting for things to happen and then reacting to the events. They usually don't explain more than that when demonstrating the values behind proactive, when it just might be in their best interests to. The theory behind proactive is that you are ultimately in charge of how you feel, act, think, and prosper. Sure, there are many outside 'influences', but that's all they are, just influences: they do not dictate the ultimate behavior patterns of who you are unless you want them to. Proactive people understand that they are where they are at today because of their past actions. For lack of a better example, let's examine some facets of my existence to make the point. Physically: I am where I am at today physically based on past actions. In college, I was actually a very active person who was enrolled in fitness classes as well as walking around a large campus. When I decided to graduate and get a 40 hour/wk desk job for income purposes, I decided not to keep up my current exercise routine and not watch what I ate too closely. As a result, my body is where it's at now. I've recently decided to start paying more attention to these things, and as a result, my body is changing in response. Professionally: I am where I am at today professionally based on past actions. I completed my schooling at the Colorado School of Mines and decided to get my first job. It was here that I decided to learn all all I could about the languages that I would be programming in, making some excellent projects that help the company, etc. I also decided to put programming games on the wayside for a while to focus more on learning business politics, the languages that I was currently using, etc. Nowadays, I've started learning more things that would lend itself easier to programming games. Romantically: I am where I am at today romantically based on past actions. After the decisions that my ex-girlfriend and I made about our relationship and how it should end, I decided that I value my time more when I can spend it on myself versus when I have to devote it to someone else. This ultimately means that I have no romantic prospects, but that's because I decided it to be that way, and was fine with it at that point. Now, I believe that I have a lot of my framework planned out, and may in the future decide to pursue something romantically. The facets can go on and on, but I'll stop with just three. The common feature between all of these evaluations is one thing: for each facet of my existence, I chose the actions that I wanted to do, planned them out, and that's why I'm where I'm at today. Proactive people can choose how they want to live their life and their day-to-day dealings, and very little can actually effect how they feel about themselves or what they want to accomplish. Reactive people can be somewhat different. Proactive people can see the weather outside and make a note of it, but for reactive people, it can change their very mood. For example, in one day in April, it was snowing outside, something that actually isn't too strange for Colorado at this time of year (We sometimes get more snow during Easter than we do at Christmas!). One thing that I've noticed a lot in my office is that the number of technical calls I get are proportional to how bad the weather is, among other factors. When it starts snowing or the thunder and lightning come out to play, I find that my colleagues are more agitated, fearful, or easily angered. I spend more time trying to relax them as I fix whatever ends up being wrong. I often joke that it's the IT gods, and that they don't like weather, but in actuality, I say that joke just to calm down their agitated spirits. Since I try my best to be proactive at work, it doesn't matter what the weather is out there, it has no bearing whatsoever on how my work should progress. Proactive people can base their happiness on static values instead of things that change on a constant basis, such as the weather, their relationships with friends, comments made about them, financial situations, etc. Most people can take a look at any one of these things and use it as an excuse to feel any way that they want to; I know, since I still do from time to time. The more that I move away from that system and go towards a more stable base for my emotions and feelings, the happier and more centered I feel towards the world as a whole. I know that I'll still be happy and living when everything else in my life turns upside down, and if I continue with what makes me feel happy and productive, then my life will only continue to be plentiful. So take the time to think about something that really sets you off right now: it can be a certain person or situation that drags you down and makes you feel below the weather. Now, realize how reactive that is, and rise above it. Realize that the situation is controlling your emotions and your motivation, when instead *you* could be controlling your emotions and motivation. Find a value that is attuned to you, be it truth, honesty, integrity, happiness, peace, etc., and focus on that instead. Base your emotions on that immovable value, and resolve whatever object used to hold your emotions in such constant sway. Realize that it doesn't matter what happens to that person or situation, it won't have a hold of you like that ever again. You are in charge of your happiness, and you are the only one who should have access to that awesome power. This is being proactive. |
|||||||||||
| Copyright © 2007-2009 Wolvie Games, LLC | |||||||||||