Categories
Game Development Personal Development

What Happened to my Productivity?!?

It’s April 19th. The Chicago Indie Game Developer meeting is in less than six days. My goals for this month were to continue programming for 5 hours per week and to complete a simple game. While the month isn’t over yet, I haven’t accomplished these goals at all.

Last month was great. I programmed. I learned how to use Kyra. I learned a lot.

This month, I hit a stumbling block right away when my video card needed to be replaced. I also spent some time updating my resume to look for a full-time job. I have a couple of game reviews to do for Game Tunnel. Still, if I claim that all of these things prevented me from accomplishing my goals, I’d be lying to myself. My computer was back up and running within a few days of the problem. I didn’t spend more than a few hours total over a week on my resume. And I haven’t been playing the games too much either.

So where did my time go? Actually, the more accurate question is, “How did I squander my time?” How did I let an hour or two go by without at least doing something for a few minutes that is related to my goals? Even if it was an overwhelming amount to do, which is certainly not the case, at least ONE thing could get completed, right?

This past week I’ve been in a funk because I feel like I haven’t accomplished anything at all. My game review is overdue, my job search hasn’t really started yet, and I haven’t coded anything since I reinstalled. It doesn’t help at all that I may be getting sick as well. I’m feeling stressed and worried, which wastes my energy, which only serves to make me feel more stressed and worried.

So April is a bust.

Or is it?

While I can’t do anything about the delays at the beginning of the month, I’m allowed to reset my goals. Clearly I failed in programming for the past three weeks, but nothing prevents me from doing so for this week. I haven’t created the game, but nothing prevents me from trying to make a simple game in less than a week. It’s been done before, and I’ve already mentioned my intent to participate in my own Game in a Day. Perhaps I won’t finish the game. But attempting to do so puts me in a better position than where I am currently, so that’s reason enough for me.

Nothing prevents me from accomplishing my goals. Except me.

Look at that. My stress is gone. It’s been replaced with resolve. Fancy that.

Categories
General

The Courage to Take a Seat

Last night I went to a seminar hosted by my university’s Alumni Association. It was called Four Under Forty, a play off of Crain’s Chicago Business’ annual Forty Under Forty. Four members of the list were on the panel at the seminar, including this past year’s David Marco and Mike Domek, as well as last year’s Thad Wong and Noreen Abbasi. The panel members were asked a series of questions, and it was an interesting event.

Among a few themese I noticed was the idea of courage. Thad Wong simply exuded confidence and made the claim that he believes he could do anything anyone else has done. Nothing should be impossible for him if someone else can do it. But even then, believing in himeself was key to his success. David Marco made similar comments.

I was thinking about courage when I went home afterwards. I was reading Stephen Covey’s book First Things First and specifically his treatment on the need for courage. And with this topic on my mind, I saw something happen on the train that seemed appropriate.

There was a woman sitting with a bag sitting next to her. The train was getting quite crowded, and I saw some people walking towards the seat, only to turn away once they saw her bag there. Maybe three or four people acted similarly, turning away as if turned away from a fountain. Then one person got on the train, walked up to the seat, and simply asked the woman if she could move her bag. The woman complied. This new person won her seat on the train because she wasn’t afraid of what might happen if she asked. She simply did it.

And if that isn’t an oversimplifed metaphor for what courage can do for your business, I don’t know what is. You can’t win unless you play. Whether it’s just getting a seat on the crowded train or starting your own business, if you don’t attempt to do it, you force yourself to stand and watch as someone else does.

Categories
Geek / Technical

Automating Backups: I Reinvented the Wheel

I already knew that I had reinvented the wheel when it came to writing my automated backup solution. I spent some time researching this topic, and I found a number of resources.

Of course, as soon as I posted my results on the LUNI mailing list, I got email from helpful people pointing out that there are other projects that are out there and have been tested. Way better than what I had, and much more optimized. My solution was making multiple copies of my data, resulting in multiples of gigabytes of storage, whereas some of these solutions are clever and use much less space.

So in true blog fashion, here are some links:

Categories
Geek / Technical

Automating Backups for Fun and Profit

At the end of last month, I mentioned that I had bought a new hard drive for the purposes of backing up my data. I just now installed it in my second computer. Was getting the backup system in place important? Yes, absolutely! I don’t think that a hard drive might fail. I know it WILL fail.

While I could just simply copy files from one drive to the other manually, it depends on me to do so regularly. I’m only human, and I can forget or get sick, resulting in potentially lost data. Computers are meant to do repetitive tasks really well, so why not automate the backup process? My presence won’t be necessary, so backups can take place even if I go on vacation for a few weeks or months. The backups can be scheduled to run when I won’t be using the computer. Copying lots of data while trying to write code, check email, and listen to music at the same time can be annoyingly slow, but if it happens while I am sleeping, it won’t affect my productivity at all. Also, while the computer can faithfully run the same steps each time successfully, I might mess up if I run the steps manually and in the wrong order. So with an automated system, my backups can be regularly recurring, convenient, and reliable. Much better than what I could do on my own week after week. I decided to make those concerns into my three goals for this system.

I’ll go over my plan, but first I’ll provide some background information.

Some Background Information
LauraGB is my main Debian GNU/Linux machine. MariaGB is currently my Windows machine. The reason for the female names is because I am more a computer enthusiast than a car enthusiast. People name their cars after women, so I thought it was appropriate to name my computers similarly. For the record, my car’s name is Caroline, but she doesn’t get nearly the same care as Laura or Maria. My initials make up the suffix, GB. I guess I am not very creative, as my blog, my old QBasic game review site, and my future shareware company will all have GB. Names can change of course, but now I see I am on a tangent, so let’s get back to the backup plan.

LauraGB has two hard drives. She can run on the 40GB drive, as it has the entire filesystem on it, but the 120GB drive acts as a huge repository for data that I would like to keep. Files like my reviews for Game Tunnel, the game downloads, my music collection, funny videos I’ve found online, etc. It’s a huge drive.

For the most part, I’ve simply had backup copies of data from the 40GB drive to the 120GB drive. I also had data from an old laptop on there. Then I started collecting files there, but they don’t have a second copy anywhere. If I lose that 120GB drive, I could recover some of the files, but there is no recovery for a LOT of data. Losing that drive spells doom.

At this point, MariaGB can become much more useful than its current role as my Games OS. With the new 160GB drive, I can now have at least two copies of any data I own.

The Backup System
I spent the past few weeks or months looking up information on automating backups. I wanted something simple and non-proprietary, and so I decided to go with standard tools like tar and cron. I found information on sites like About.com, IBM, and others. I’m also interested in automating builds for projects, and so I got a lot of ideas from the Creatures 3 project.

On Unix-based systems, there is a program called cron which allows you to automate certain programs to run at specific times. Each user on the system can create his/her own crontab file, and cron will check it and run the appropriate commands when specified. For example, here is a portion of my crontab file on LauraGB:

# Backup /home/gberardi every Monday, 5:30 AM
30 5 * * 1 /home/gberardi/Scripts/BackupLaura.sh

The first line is a comment, signified by the # at the beginning, which means that cron will ignore it. The second line is what cron reads. The first part tells cron when to run, and the second part tells cron what to run. The first part, according to the man page for crontab, is divided as follows:

field allowed values
—– ————–
minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-7

So as you can see, I have told cron that my job will run at 5:30 AM on Mondays (30 5 * * 1). The asterisks basically tell cron that those entries do not matter.

The second part tells cron to run a Bash script I called BackupLaura.sh, which is where most of the work gets done.

Essentially, it gets the day of the month (1-31) and figures out which week of the month it is (1-5). There are five because it is possible to have five Mondays in a single month. Once it figures out which week it is, it then goes to my 120GB drive and removes the contents of the appropriate backup directory. I called them week1, week2, etc. It then copies all of the files from my home directory to the weekX directory using the rsync utility. I use rsync because using a standard copy utility would change the file data, resulting in files that look like they were all accessed at once. Rsync keeps the same permissions and date access times as they were before the backup.

So tomorrow at 5:30 AM, this script will run. As it will find that the date is 11 (April 11th), it knows that it is in the second week. So the directory week2 will be emptied, and then all files will be copied from my home directory to week2.

That’s all well and good, but you have probably noted that every week, the weekly backup erases the same week’s backup from the month before. When this script runs on May 9th, week2 will be erased, losing all of April’s 2nd week backup data! I’m ok with that.

Here’s why: every 1st Monday of the month, the script will make the week1 backup, but it will ALSO make a monthly backup. It takes week1 and runs another utility on it called tar. Multiple files can be combined into one giant file by using tar. The resulting file can also be compressed. Most people on Windows will create .zip files using similar utilities, but tar fits the Unix programming philosophy: a robust tool that does one thing really well.

Usually tar is used with utilities like gzip or bzip2, but sometimes compression is avoided for stability reasons in corporate environments. Compressing might save you a lot of space, but on the off chance that something goes wrong, you can lose data. And if that data is important enough, the risk isn’t worth the space savings.

In my case, I decided to use bzip2 since it compresses much better than gzip or LZW (what .zip files are compressed with). If I corrupt something, it isn’t the end of the world, since bzip2 has the ability to recover from such problems. So the script will take the directory week1 and compress it into a file with the date embedded in the name. The appropriate line in the script is:

tar -cvvjf $BACKUP_DIR_ROOT/monthly/LauraGBHomeBackup-$(date +%F).tar.bz2 $BACKUPDIR

The $BACKUPSOMETHING are variables in the Bash script that I had defined earlier, but they basically tell the script where to go in my filesystem. The file created is “LauraGBHomeBackup- “+ the date in YYYY-MM-DD format + .tar.bz2. The script runs date +%F and inserts the result in the filename. The file is placed in the directory called monthly. I can manually clean that directory out as necessary, and since the dates will all be unique, none of the monthly backups will get erased and overwritten like the weekly backups.

Conclusion
And so now the need to do backups has been automated. Every week, a copy of my home directory is synced to a second hard drive. Every month, a copy of the data will be compressed into a single file named by date to make it easy for me to search for older data. What’s more, cron will send me an email to let me know that the job ran and also tell me what the output was. If I forgot to mount the second hard drive for some reason and the script couldn’t copy files over, I’ll know about it Monday morning when I wake up.

Once MariaGB is up and running, I can configure the two systems to work together regarding the monthly backups. After the .tar.bz2 file is created, I can then copy it from LauraGB’s monthly directory over to MariaGB in a directory to be determined later. Of course, normally when I copy a file from one machine to another, I would need to manually enter the username and password. I can get around this by letting the two systems consider each other “trusted”, meaning that the connection between the two can be automated, which is consistent with one of the goals of this system. I’m very proud about what I have created, and I am also excited about what I can do in the future.

Currently LauraGB’s home directory has images, code, homework files, game downloads, and other files taking up 4GB of space, which clearly won’t fit on a CDROM uncompressed. To improve my backup system, I will need to purchases a DVD burner. I can place a blank CD in the drive and have the computer automatically burn the monthly backup when it occurs, giving me another copy of my data, one that I can then bring anywhere. Ideally, remote backups would complete my system, but I think I will use those only for specific data, such as my programming projects and business data when I get some. Losing my music files and pictures in a house fire aren’t going to be as big of a conern as the fire itself, but losing sales info, game code, and the customer database, essentially THE BUSINESS, would be something that I probably won’t easily recover from.

For now, I am mitigating the disaster of a failing hard drive, which is my main concern. If you do not have your own backup system in place, either something homemade like my setup or through some commercial product, you’re walking on thin ice. Remember, hard drive failure isn’t just a potential event. It’s a certainty. It WILL fail. Prepare accordingly.

Categories
Games Politics/Government

Senior Advisor to Governor Responds to My Concerns

Awhile back I had sent a letter to Illinois Governor Rod Blagojevich. I received a generic form letter that didn’t address any of my concerns. I sent a second email to Safe Games Illinois asking someone to answer my questions. I figured I would receive a response from someone other than the Governor, but not the Senior Advisor!

Anyway, here’s the content of the letter (misspellings or other typos are likely mine):

Mr. Berardi:

Thank you for your two letters concerning the Governor’s Safe Games Illinois initiative. Although this administration may disagree with many of the arguments in your letters, we appreciate your interest in the issue.

You outline four broad concerns in your letter and I will try to address them one at a time.

Your first question deals with existing laws that limit minors’ access to materials such as books or movies with violent or sexually explicit content. Illinois law already restricts minors’ access to certain harmful material, as dictated by the state’s Harmful Material Statute (720 ILCS 5/11-21). This law prohibits minors from buying a broad range of sexually explicit material – materials such as pornographic books or magazines. So laws do in fact exist that prohibit children’s access to media other than video games.

Your second concern questions why the Blagojevich administration is singling out violent and sexually explicit material in video games and not in other media that may be potentially harmful to children. It has become painfully apparent that video game retailers are not self-regulating and that they continue to sell adult-rated video games to minors. In October of 2003 the Federal Trade Commission released a study which found that underage teens were able to purchase M-Rated games 69% of the times they tried. A press release for this study is available on the web http://www.ftc.gov/opa/2003/10/shopper.htm. Last January State Representative Paul Froehlich (R-Shaumburg) sent a 15-year-old boy to 15 retail stores in the Northwest Suburbs and found that this boy was able to purchase M-rated games at 11 stores. Whether such inappropriate purchases are part of a widespread problem or not, this administration thinks that no child should be able to purchase these types of video games without his or her parents’ supervision.

Your third concern is regarding the administration’s efforts to educate parents about inappropriate video game content. One of the critical components of the Safe Games Illinois initiative is to educate parents about the harmful effects that violent of sexually explicit video games have on children. A large portion of the Safe Games Illinois website is dedicated to providing parents with information on particularly violent or sexually explicit video games as well as with links to organizations that consistently monitor and rate the various video games that are arriving on the market. Here are three Safe Games links that you might find useful:

Also, one of the mandates of the Safe Games Illinois Task Force, a body comprised of many individuals who are parents, is to educate parents on the harmful effects that violent or sexually explicit video games have on children. It is the opinion of this administration that if parents are educated about the dangers of these video games and their children cannot legally buy these games without parental permission, then violent video games are less likely to be played by an inappropriate audience.

Your final concern dealt with the wording of the propose Safe Games Illinois legislation and the legislation’s definition of violent. The legislation’s current definition of “violent” video games include those games with:

Depictions of or simulations of human-on-human violence in which the player kills, seriously injures, or otherwise causes serious physical harm to another human, including but not limited to depictions of death, dismemberment, amputation, decapitation, maiming, disfigurement, mutilation of body parts, or rape.

I don’t think any reasonable interpreation of this definition would exclude children from purchasing age-appropriate games – such as Super Mario Bros or Donkey Kong.

If you have further questions about the bill, I strongly encourage you to take a look at the web site for House Bill 4023, maintained by the Illinois Legislature:

http://www.ilga.gov/legislation/billstatus.asp?DocNum=4023&GAID=8&GA=94&DocTypeID=HB&LegID=20889&SessionID=50

Thank you again for your letter.

Sincerely,
Sheila Nix
Senior Advisor to the Governor
State of Illinois

I’ll admit that I am ignorant of the laws regarding materials deemed harmful for children. According to Sheila, this law prohibits children from being sold pornographic books or magazines. So, where’s the analogous violent content law that does the same, which is what I was mainly concerned about?

The statistics they were using were presented in a way to insinuate that children are buying violent video games in droves or that it is an epidemic. For example, in this letter “underage teens were able to purchase M-Rated games 69% of the times they tried”. Ok, but how about commenting on studies that say that it isn’t happening that often in real life? That children DO tend to get their parents’ permission or have their parents present when they buy these games?

Another choice quote: “Whether such inappropriate purchases are part of a widespread problem or not, this administration thinks that no child should be able to purchase these types of video games without his or her parents’ supervision.” Ok, and because the motion picture industry is so effective at self-regulation, we won’t pass a similar law to stop the one or two instances when a child CAN get into an R-rated movie? I mean, even if it isn’t part of a widespread problem, doesn’t this administration think that no child should be able to view such movies? Perhaps I’m being petty, but I think the example is analogous.

And regarding the wording of the law in question, I’ve played games where the main character dies as a result of non-human characters or where the main character isn’t human. Are those allowed to depict death or dismemberment without falling under this law?

Someone in the ASP games newsgroup pointed out that if a law like this is passed, who pays for the rating system? How much would it cost to get a rating on a game to sell it in Illinois? How long will it take to get the rating? A mainstream game might have a million dollar budget and so the publisher might consider the cost to be a drop in the bucket, but an indie title does not usually have the means. Whatever the cost is, it will be significant to the indie. In any case, such a requirement would be harmful to the industry while having only dubious arguments to support it at the most.

Looks like I have another letter to write.

Categories
Games Geek / Technical

LAN Par-tay! or Stupid Processor…

This past weekend I went to a LAN party at my friend’s dorm. For those of you new to the term, you basically take your PC to this party and everyone connects to a Local Area Network (hence the LAN part) to play games for hours on end. This party was in the basement of the dormitory, and it started at 2PM on Saturday and ended at 12PM on Sunday. I think. It was a long night. B-)

While my Debian GNU/Linux system has a new video card and has a slightly faster processor than my Windows system, the fact was that we were playing games, and a lot of them aren’t available for GNU/Linux yet. So I took my Windows machine.

I had problems right away. My Windows machine didn’t have as complete a cooling system as my Debian system. I barely use it, so there was never a need. And I have played games on it before. Yet this weekend of all weekends, games would crash to the desktop. At first I thought that it was possibly Windows 98. I’ve refused to install Windows XP for reasons I may go into another day, but at the urging of others, I installed WIndows XP. Luckily I had brought the CD that I got for free for attending some Microsoft seminar on .NET. Still crashed to the desktop when playing games. So rule out the OS.

I opened the system and found that the ATI Radeon 8500 video card was really, really hot. I think the ribbon cables were blocking airflow. Someone had a spare GeForce 2 MX, so I installed that. I still had crashes, so I opened the case to find that the video card was hot after only a few moments in the system. Was it overheating?

My friend let me use his fan to cool my system. It was funny seeing the case opened and a giant fan blowing into the system, but it kept it quite cool. Unfortunately, games would still crash to the desktop. So rule out overheating.

Someone else insisted I should lower the clock speed on my processor. I had a motherboard that allowed me to flip switches to lower the speed, and I didn’t want to do it at first. I paid money for an AMD XP 2100+, so why lower it? Well, it did the trick. Games stopped crashing, and it still ran quite fast to handle games like Alien vs Predator 2 and Unreal Tournament 2004. I’m still upset that I had to lower the speed, but apparently the processor is overheating otherwise. Perhaps the CPU fan isn’t working well anymore.

Me and my computer woes, eh? Two other people had some issues, but we all eventually got to play.

I haven’t been to a LAN party in a long time, and these days it is less likely since I work 40 hour weeks. It was a completely different situation when I just had school to worry about. It was a good time. I think everyone should attend a LAN party. Besides reminding you that playing games is important if you are going to make good games, it also reminds us that gaming is every bit as social an activity as any other. The next time someone tells you to “put down the controller, go outside, and get a life” remind them that playing video games with friends is a bit more healthy than getting overly drunk at bars and smoking. And arguably more fun.

Categories
Game Development Games

I’m Making teh Best MMORPG/FPS/RTS Game Ever!

I’m going to be making the greatest MMO game ever! It will be cross-genre, so people who like first-person shooters, real-time strategy games, and role-playing games will all enjoy it.

It will have an amazing story that spans many arcs, but it won’t be linear at all. The entire world will be highly reactive to how you play, just like a paper-and-pencil RPG.

It will also span time, so you can play from prehistoric times using rocks as weapons all the way up to the future where there will be lasers and mechs!

So here’s where you come in. I need someone to help me build this game. I need programmers, artists, musicians (a full orchestral score!), and writers. I can’t pay you since I am doing this for free, but once we get it out there, we can paid based on royalties. Or maybe a publisher might pick us up.

What do you think?

Anyway, thanks for your time. This is going to be so cool.
Perhaps we can discuss this in a private forum? I
remember trying to do something similar in QBasic.
I got pretty far, too, but then I stopped and
looked at it and thought that I could do better.

Fun and cool with cool ideas! Maybe the main character can have
ocular implants, so you can see in the dark or through walls?
Oops, I’m saying too much in public. I don’t want someone
looking here and stealing my ideas.
So long!

Categories
Geek / Technical

My Computer is Back and Badder Than Ever!

Last time I mentioned how my Debian GNU/Linux system needed to be upgraded due to a malfunctioning video card.

I am happy to say that my system is running quite fine now. Here is a listing of some of the upgrades and changes:

  • nVidia GeForce2 GTS to nVidia GeForce FX 5500
  • Linux kernel 2.4.24 to Linux kernel 2.6.11
  • Deprecated OSS sound drivers to the new standard ALSA
  • A restrictive hard drive partition scheme to a less restrictive one

The video card runs amazingly well, although my true test is to verify that Quake 3 Arena will run on the system. So far, Tuxracer and Frozen Bubble runs fine. The 2.6 kernel is a good iteration over the 2.4 kernel since it allows the system to respond faster and has more supported hardware under its belt. The OSS sound drivers, for example, have been deprecated in 2.6, but I’ve always used them before since ALSA was iffy at best, requiring a separate download and kernel recompile. Now ALSA is actually part of the kernel, and I am pleased that my system is so much more up to date. Debian is the distro that people make fun of for being less than on the cutting edge, but it makes up for it by being stable.

The hard drive partition scheme I had before made it difficult. I had a lot of space for my home directory, which is where I keep data files and the like, but less space for /usr, which I need for programs, and /tmp, which made installation of new programs difficult. The new scheme doesn’t differentiate between /usr and /tmp, and they share a LOT more space, since I have a bigger hard drive to store any data anyway.

So my system is faster, more convenient, and more compatible with what’s new in the world of technology. Games that were out of reach before are now playable. Not bad for an emergency repair.

Categories
Geek / Technical

Stupid Video Card…

Long story short: I don’t have a working GNU/Linux system at the moment.

Long story long:

Two days ago, my Debian GNU/Linux system worked fine.

Yesterday, the video card was acting up.

The display was a little off, as if the monitor cable was getting interference. I switched cables with the Windows 98 machine I have, so I eliminated the monitor and the cable as the culprits. The GeForce2 GTS that I had won in my first ever eBay auction years ago had finally started to fail.

Just to make sure, I tried to reinstall the Nvidia drivers. For those of you who don’t know, driver installation on a Linux-based system is not a matter of downloading an executable and running it. Nvidia actually does provide something like that, but the drivers have to be made part of the kernel, usually by making a module, and you do that by compiling it.

Well it complained that the compiler used to make the kernel isn’t the same as the compiler I currently have on my system. It’s been awhile, and I’ve upgraded Debian a few times, so that made sense. I decided to try to recompile my kernel since I haven’t done that in a long time and I have been meaning to get some extra features such as USB drive support anyway.

Recompiled, rebooted, and voila! I upgraded the kernel from version 2.4.24 to version 2.4.27, and I was surprised that it only took a few minutes to do so since I’ve had older/slower machines take a half hour or more. It turns out that it was a good thing it was so fast. I apparently forgot to add network support for my onboard ethernet. Whoops.

I attempt to recompile, but then I get strange errors about modules not existing, even though I did the same exact steps to recompile. So I try to install one of the older kernels since I still have some of the packages I had created in the past. Still no network support? ARGH!!

I’ve been meaning to do a fresh install of Debian on this machine anyway. The hard drive partition scheme is more limiting than I had originally anticipated years ago (who thought it was a good idea to make /tmp only 50MB?!).

Since the video card was failing, I decided it was time to get a new one. So I went to Fry’s which was 20 minutes away from my house. I bought a GeForce FX 5500 (w00t!), as well as a Western Digital 160GB drive and some quieter case fans. I bought the drive because I don’t want to end up like Lachlan Gemmell. I already have a 120GB drive that holds a lot of my files. Some of it is backups from my main drive, but a lot of it is made up of data that doesn’t have a copy anywhere. I would hate to lose the .ogg files I’ve ripped from CD or bought from Audio Lunchbox, the games I’ve reviewed for Game Tunnel, pictures of me and my friends, and of course my Subversion repositories for the projects I have been working on. I opted for a second huge hard drive since it would be easier and faster to make at least a second copy of my data. I can decide to get a DVD burner later.

And the fans? My system sounded like a jet engine starting up. I’ve been meaning to fix that problem as well.

Last night I installed the fans, and it was definitely a lot quieter. I decided to leave off the video card and hard drive until today since it was getting late and I needed to figure out how to setup the drive in the first place.

So at the moment, I have a system that can’t connect to the Internet. It still can’t display anything, so it is rendered useless for the most part. All because I tried to fix it when the video card acted up.

The good thing is that I’ve made it quieter, and when I am through with it, it will be even more powerful than before. Doom 3 and Unreal Tournament 2004 are now more easily within my grasp. And I will finally get around to designing an automated backup system. Phoenix rising, indeed.

Categories
Game Development

Learning Kyra: Attack of The Clones

The third entry in the Learning Kyra series. The series to date:

  1. Learning Kyra
  2. Learning More Kyra

Last time I was able to create a non-interactive moving body with a head attached. It simply walked from the top to the bottom of the window. Fairly simple, just like the graphics created for it.

In this entry, I will describe how I tackled the following tasks:

  • Adding multiple characters to move around at once
  • Adding interactivity
  • Adding collision detection

I began with trying to add multiple characters to the program since it seemed like the simplest task. I did run into some problems, but in the end I managed to accomplish what I wanted.

To start, I needed to create a new character. I decided to make a clone of myself, goatee and all, as I described in the first part of this series.

I figure that as a clone he didn’t need his own body, so I can just reuse the existing one. Kyra allows you to change the colors on the fly, so I could always tint his appearance later. For now, he also gets a blue shirt with brown pants.

Kyra creates sprites based on resources. I already had two resources: gbHeadRes and gbBodyRes, both of which can make the sprites gbHead and gbBody. I simply used similar code to create the first clone: I grabbed the new resource gbCloneHeadRes and created gbCloneHead from it.

I then created a new sprite from gbBodyRes called gbCloneBody. For all intents and purposes, it is a copy of the already existing gbBody, but Kyra needs to know about each sprite. I then added the gbCloneHead as a child of the clone body. I set the position of the clone so that it would start a little higher than the regular character. This way, it will look like he is chasing him.

It actually turned out decent. I then tried to add multiple clones. I thought they would be great in a triangle formation, chasing after the poor original. It was at this point that I started having problems. I thought that since the head would be the same I could probably just add it as a child of all of the new bodies, but Kyra didn’t like that since it would seg fault when I run it. I just created multiple heads to go with the multiple bodies. I then found I had an off-by-one error. I wanted to create a triangle of characters, but I forgot to actually count how many I would need. I needed six, but I only created five, but then I was trying to set six, and so I kept getting seg faults until I figured this one out. /me smacks self in head for that one.

Still, I was victorious in, as you can see:

Objective accomplished! Now onto the next.

Interactivity is the stuff that games are made of. Up until now, I’ve only had an animated graphics demo. Once I get it to be interactive, I’m that much closer to making simple game demos. w00t!!

Kyra did not provide facilities to handle input, so I just followed the demo’s lead and used Simple Directmedia Layer to do so. Since I didn’t want to create multiple images just to have the body move left, right, and up, it would be fairly simplistic. I wanted to make it so the user can press the arrow keys left and right, and the main character would move accordingly while running down the screen.

It was actually fairly simple to implement, and I managed to get it working quite quickly. I simply added a variable for the movement speed and then if SDL detects that the left or right arrow is pressed, I would set the movement speed accordingly. For example:

// These will control the movement based on input
int moveX = 0;
int moveSpeed = 6;

...

case SDL_KEYDOWN:
{

// NEW CODE
if (event.key.keysym.sym == SDLK_LEFT) {
moveX = -moveSpeed;
}
else if (event.key.keysym.sym == SDLK_RIGHT) {
moveX = moveSpeed;
}
//END OF NEW CODE
else {
done = true;
}
}
break;

// MORE NEW CODE
case SDL_KEYUP:
{
moveX = 0;
}
break;
//END OF NEW CODE

I then modified it so that the SetPos for the gbBody would always modify the X coordinate by moveX. Then, just to add some useless complexity, I made it so that two of the clones would also move as you moved. The two middle clones will separate and move together as you move from left to right. It was here that I experienced the issue of z-ordering. Kyra will draw the sprites in the order that you added them to the engine, so while the top row would rightly be behind the second row, the second row would walk over the head of the first clone! To correct this issue, I simply added the clones from front to back.

But what happens when I want to make a sprite run in multiple directions? For example, the Kyra demo shows the Bug Eyed Monster program where the creatures can walk around in a circle, which means that a creature that might be closer to the viewer must be drawn on top of the other creatures, but that same creature can move to a point where another creature will become closer. The demo obviously handles it correctly, so dynamically changing the z-order is clearly possible. I’ll save learning this task for another day.

For now, another objective can be stricken off my todo list. It may not be very complex, but it’s a start.

Time to tackle collision avoidance. At the moment, the clones in the middle row can walk through each other, which is not something I want them to do. I found that the shooter demo makes use of collision detection, so I tried to follow what it did. Unfortunately it wasn’t very clear to me how it was handling it:


KrSprite* newMonster = AddMonsters();

// Flush the changes to this point and then look for
// collisions between the bullets and everything else.
engine->Tree()->Walk();

GlDynArray< KrImage* > hit;
// Can we keep the monster we just added -- or did it collide?
if ( newMonster && engine->Tree()->CheckSiblingCollision( newMonster, &hit, mainWindow ) )
{
engine->Tree()->DeleteNode( newMonster );
newMonster = 0;
}
else if ( newMonster )
{
// This add will not be collision detected.
StatusAdd( newMonster );
}

So it creates a creature, but somehow it is able to determine if there is a collision even if it didn’t set its position? I plan on asking about that on the Kyra forums. (NOTE: I have since discovered that AddMonsters() actually sets the position, so nevermind) For now, I was able to determine that I needed to use the Walk() function to set the tree to check for collisions. I also needed to compare what I had to what was in the list of collided sprites returned by CheckSiblingCollision(). I spent a bit of time here because I was unfortunately trying to grab the wrong information.

I was trying to do this:


if (gbCloneBody[2] == (KrSprite*)(hit.ItemPointer(i))

but I was supposed to do this:


if (gbCloneBody[2] == (KrSprite*)(hit.Item(i))

It turns out that Item() already returns the pointer I needed, so I was getting a pointer to the pointer, which is why I couldn’t detect the collision. Once I figured out this part, I was able to add code to move the clones away from each other if they intersect. They now bounce off of each other, which is closer to what I want.

So hours later, the third task is solved. Mission accomplished!

Recap: Today, I learned how to create multiple characters and display them on the screen simultaneously. I learned how to reuse existing sprites to make new composite sprites. I learned how to add interactivity to my project while also adding some crude collision detection. What does it all mean? It means that I can not only have the clones avoid walking into each other, but I can also check if they intersect other objects, such as powerups or projectiles or anything I can throw at them. I’m excited about the possibilities, and my own demos are fairly crude.

Next time:

  • I want to learn about dynamic z-ordering.
  • I want to create tiles and backgrounds.
  • I want to make a simple game using what I’ve learned, probably something like Pac-man or Lock-n-Chase.

For now, I’ve accomplished enough to go to the Chicago Indie Game Developer meeting on Sunday with pride. B-)


You can download the updated version of the code:
KyraTest-r15.tar.gz
KyraTest-r15.zip
Kyra Source in .tar.gz format
Kyra Source in .zip format

NOTE: You will need Kyra v2.0.7 to use this code. Also, the comments in the code weren’t all updated to reflect the fact that I’ve changed it. It is licensed under the GPL or LGPL as specified.