Monthly Archives: February 2011

Game Redux

Remember when I said that I was creating a video game in my spare time? Well, if eight months of inactivity has told you anything, that hasn’t exactly gone to plan for a number of reasons, some of which are programming related (see my last post).

I am happy to say that I’ve gotten back into writing a video game, although as usual the story is completely different, as is my approach to writing the game. Instead of working on visual mechanics like smooth scrolling of the screen and animation of the character sprite, I’m worrying about inventory interaction and item alterations, all of which are done through a network of interconnected modules and classes. It’s a much cleaner approach, plus it’s much easier to test sets of class methods when that’s all I’m working with.

I’m taking a very micro-to-macro approach too, starting with single items, moving onto inventory, moving onto a character shell (which will eventually be greatly inflated, but no need to worry about that now!). Yes, a few important things are missing from the small set of code I have written (items having a special effect on the character or other items, for example), but much of that will flow once I figure out how I want the game to progress. Check out the two (partial) modules I have now:

# Superclass for all in-Game Items
class Item(object):
  def __init__(self, name, amount=1):
    self.name = name
    self.amount = amount

  def adjust_amount(self, amount):
    self.amount += amount

# Subclass to handle key items
class KeyItem(Item):
  def adjust_amount(self, amount):
    pass

# Class to store Items for Player within Game
class Inventory(object):
  def __init__(self):
    self.inventory = []

  def add_item(self, item):
    self.inventory.append(item)

  def remove_item(self, item):
    self.inventory.remove(item)

  def adjust_item(self, item, amount):
    changing_item = self.inventory[self.inventory.index(item)]
    changing_item.adjust_amount(amount)
    if changing_item.amount == 0:
      self.remove_item(item)

  def order_inventory(self, item, new_position):
    temp = self.inventory[self.inventory.index(item)]
    self.remove_item(item)
    self.inventory.insert(new_position, temp)
# Creates Player class to be controlled by user
class Player(object):
  def __init__(self, name, inventory):
    self.name = name
    self.money = 500
    self.inventory = inventory

  def adjust_money(self, amount):
    self.money += amount

  # Controls inventory object changes
  def adjust_inventory(self, item, amount=1):
    if item in self.inventory.inventory:
      pass
    else:
      self.inventory.add_item(item)
    self.inventory.adjust_item(item, amount)

  def change_inventory(self, item, new_position):
    self.inventory.order_inventory(item, new_position)

Pretty simple, and only 40 lines when you ignore whitespace and comments, but the fact that everything works the way I want it to right now is a big deal. I could throw in a few other necessary variables and function calls right now, but I do have my first exam of the semester in… six hours… so I’ll just leave this here for now.

In bashnews, I fixed a problem with grep where no matter what I did, grep just didn’t work. It ended up being some extraneous commands in my .bash_profile that I must have put in while adding aliases and setting the color scheme for ls -G, since the commands came right after those lines. Now it works, and I’m back to being a happy camper!

Advertisements

Graduation Drawing Near

It’s already February. Not such a scary thought, except when you consider that in two-and-a-half months’ time I’ll know what I’ll be doing for at least the next four years, and in three months’ time I’ll have graduated. Right now, I’m just trying to make it through the semester that’s ahead of me, but with the prospect of the rest of my life looming ahead, it’s a little hard to focus. Here’s a few things that are distracting me:

Quidditch
Yep, the sport from Harry Potter. I joined one of the intramural teams this past fall, which has been great, and spent three hours in the sixteen-some inches of snow for tryouts for the travel team. The game is exceedingly fun to play, and it always garners a barrage of questions whenever it comes up that I play (wherever I may be at the time). It’s also pretty funny to look at the strange looks employees give me when I walk into, say, McDonald’s holding a broom in one hand and cleats in the other. With practices only once a week (or more, depending if my tryouts today went favorably), and games pretty infrequent, it doesn’t take up as much time as that other MSU sport I played, not like these semester grades mean that much anyway…

Here’s a State News article about the team following the World Cup (held in November in New York), and a video of the team playing Syracuse. Since I joined late, I wasn’t there, but hopefully I can go this upcoming fall, depending on what happens in my life.

Programming
I’m teaching myself C++! Why, might you ask? Well, I figured that, since I’ll eventually have to learn it anyway, I might as well. That of course was my initial reasoning, but now it’s also because I can get a job programming in C++, which will definitely help me out in the long run. Right now, I have two books on the subject, with one of them arriving earlier today (Programming Embedded Systems in C and C++ by Michael Barr). I haven’t started reading that one yet, since I’m still in the middle of my other book, but most likely I’ll flip back and forth between the two, especially since large sections of my first book were covered in one of my math courses last semester.

To go along with that, I’m still slowly working on my senior thesis. It’s just frustrating when scientific papers don’t include all of the details of their simulation runs, like what initial or final values they’re using for such uncommon variables as time or temperature, so I’ve been busy sifting through about a half-dozen articles trying to piece together some idea of how to move forward. Yes, I’m a little behind, but once I find those magic numbers, I just need to set it up and go and move on. In other words, mostly because of my newfound enjoyment of C/C++, I don’t like Fortran that much any more…

Grad School Applications
While all of my applications have been in for at least a month, that doesn’t mean that they aren’t still at the back of my mind all of the time. This is half of where my life might lead me, so it’s a big deal! I did, however, breathe a sigh of relief earlier this week when I found out that I was accepted into the Notre Dame Physics PhD program, meaning that at the very least I won’t be moving back home upon graduation! It actually kind of surprised me that I got wind of it so soon, but I think that it was just part of their first-round “draft picks,” as at least one of my other friends was also accepted.

Job Opportunities
Well, the last three things all hinted at this, but I may not be going to grad school come summer/fall. Obviously, that won’t be because I didn’t get in anywhere, but more a change in who I am as a person over the past two months (yes, the change was that quick!). You see, I’m not sure if grad school is something that I want to do right away, and what could I get out of it? A lot, in fact, but I’m not sure if I will still want what I get out of it when I get out of it. To that end, I’ve applied to a job that fits with all of my likes and dislikes, strengths and weaknesses, hopes and dreams, etc. that I may take (if accepted) over grad school. I’m not going to mention that job here, but if you’ve talked to me recently you know what it is. I just think that, right now, being a commercial programmer for a growing company involved in one of my biggest interests may be a better prospect than continuing on in school.

Don’t get me wrong, though! I’ll still go to grad school eventually, just further down the road after working, and probably in a different field. I do think that continuing my education is important (hence teaching myself an additional programming language in my spare time), and I don’t plan to ever stop learning.

I’ll just be learning in a different way.

In other news, today is now the one-year anniversary of the end of my Mars Desert Research Station mission. It’s strange to think that a year ago I was leaving the Hab with five other people who had become family for good, after spending two weeks working and laughing and enjoying Carla’s amazing cooking. I wouldn’t trade that experience for anything in the world.