Archive for the ‘Programming’ Category

Fight Controller Weekly Report: Week #1

Monday, May 4th, 2009

I decided to start posting a weekly report of my progress on the game, so that those who are interested can see how it is going, and to try to provide some accountability for myself and incentive to work on it more.

I just started it last week, and it was primarily time for planning. I’ve also been doing a lot of reading about the science behind airplanes, but that isn’t reflected here. I may start reporting it though.

Right now, I just have a basic XNA foundation for the game itself. I do have some sounds loaded into it, and some code that manipulates the sound, but nothing very significant. I want to download NBehave soon. That is, assuming that I can figure out how to use it despite its severe lack of documentation. Otherwise, I will just be using NUnit with naming conventions to make it more similar to BDD.

Fight Controller Web Site

Set up RSpec and Cucumber

Time: 00:17:28
Days:

  • Friday, May 1: 0:17:28

The first thing I did, of course, was to set up the Rails project, and also install RSpec and Cucumber. That was relatively simple.

Sprint Planning

Time: 01:04:34
Days:

  • Saturday, May 2: 00:31:55
  • Sunday, May 3: 00:32:38

Primarily, I worked on planning and discovery. I spent the time in sprint planning for the upcoming iteration.

So far, my list of features looks like this:

As a first-time visitor
I want to view the front page
So that I can learn what the game is about.
 
As an interested user
I want to subscribe to the mailing list
So that I can keep up-to-date about the game.
 
As an interested user
I want to visit the forums
So that I can check on the game's progress.
 
As an interested user
I want to apply to be a tester
So I can try out the game for free.
 
As a tester
I want to view the front page
So that I can login.
 
As a tester
I want to download the game
So that I can test it.
 
As a tester
I want to visit the forums
So that I can give feedback about the game.

I’ve been trying to group them by role, which has been very useful for me.

Plans for This Week

Today, I need to do some actual planning for the game itself. I also need to check out NBehave to see if it’ll be good enough for testing.

The rest of the week, I really want to get started coding the game, and also make some progress on the web site, so at least I can get the front page up.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Researching for the Game

Monday, April 27th, 2009

I reported on Saturday that I am creating a game involving airplanes.

All weekend, I have been reading and trying to learn some of the math behind it. I want to make it as realistic as possible, but also it is tough because I obviously can’t make every little thing accurate. It is a game, not a simulator, but I think it’ll be a challenge if the player has to control the airplane similarly to how actual airplanes are operated, whilst trying to shoot down enemy airplanes, or execute whatever mission they are sent on.

So, I started reading a free book online called See How It Flies by John S. Denker. It is a book clearly written for pilots, but with enough mathematics to keep me interested, as well as detail on how the controls work, and actually affect the plane. On the first night I started reading it, I only got through the first chapter and a few sections of the second. The second night, I got through part of the second, but then got sucked in by Wikipedia, where their articles have much more math and science explained.

Often, I had to look up a term that I did not know, such as angle of attack. For a while, I did not know the difference between angle of attack, pitch attitude, and angle of climb.

Of course, one article led to another, and soon I found I had been reading articles on Wikipedia for several hours. Kind of scary. :P

The thing is, I read much of chapter 2 without knowing exactly what angle of attack was, so probably missed a lot of what it was talking about. I am planning to re-read those sections of the chapter.

I still don’t understand everything, obviously, but I feel like I have a much better grasp on certain things. I even had a few breakthroughs, where I realized how to calculate certain things.

One thing that confuses me a bit is whether airspeed can be sounded strictly as your horizontal speed, or if it is counted as your speed relative to the wind. I guess Wikipedia says it is relative to the air, which is not always horizontal relative to the ground.

The reason is that I figured out how to calculate the rate of climb if you are climbing at a given angle and airspeed. It is a simple trigonometric problem. The thing is that if airspeed is horizontal, then you take the tangent of the angle, but if it is relative to the air, then you take the sine. I believe it is the latter.

On the other hand, if the plane is taking off, and it is at a given pitch and going at a certain speed, that speed must be horizontal, since it is on the ground, so I believe in that case, the tangent would be the correct answer.

As I have been reading both the book and Wikipedia, I have been writing down all equations I could, that I thought I could use. I have a file of equations that is 174 lines long now.

So, I will be continuing to read this book, and trying to understand these concepts better. I was not very strong in physics last year, as anyone who has been reading this blog knows (though that was probably partly because of all of the pictures and the failure of the department to help), but I am good at math, and really enjoy this subject. I think it is fascinating, so it is very worthwhile for me to research it like this.

I do want to get started on the game soon, though. After a while, purely theoretical study gets frustrating, and I just want to see something tangible.

On that front, I’ve been researching for BDD frameworks for .NET. That is an entirely different pursuit, though, deserving of its own blog post, especially once I come to a decision.

Until then, I would like to ask those who are reading, do you have any names in mind for such a game? As mentioned the other day, I just entered Flight Shooter on a whim, just to have a project name for Visual Studio. I even registered the domain before posting about it, in case I ever wanted to actually use that name.

So do you like that name, or do you recommend something else? Do you have any other suggestions for this game? Please let me know in the comments.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Creating a Game

Saturday, April 25th, 2009

I have been really wanting to make a game for a while now, but wasn’t sure if I would be able to.

Several years ago, I made a simple game in C++ that allowed you to fly an airplane. It wasn’t very accurate as far as physics is concerned, but I enjoyed it. The challenge of it was mostly in landing, and doing so before the fuel ran out.

It was fairly rudimentary. To indicate speed and altitude, I used the system beep function, since you can set the pitch and duration of it. Of course that wasn’t very realistic, but it was still fun.

Well, I’ve been wanting to do something like that again, but more realistic this time, and with more features. I want to make it as realistic as possible, though with a limit since I can’t learn everything there is to know about aerodynamics. I want to have more realistic sounds as well.

I’m thinking of eventually making it potentially a multi-player game, with players playing against each other, or a player against a computer, to shoot down enemy planes. That’ll be after I get the actual flying down, though.

I’m making this mostly for blind people, because there is nothing like it out there. In addition, I’m not very good with graphics (understatement), for obvious reasons. The tough part is getting good enough audio to make it realistic.

The thing that’s confusing me is how to make the sound respond to user control. For instance, if the plane is taking off, there is a sound associated with that. However, if the player suddenly descends somehow, well the takeoff sound isn’t applicable anymore. I have found several sounds, but putting them together would be the hard part.

Either way, I’m very excited about this. I’ve been reading about how airplanes work to try to make it as realistic as possible, and it is very interesting. It’ll take some work, but it should be fun.

I have no idea what to call it yet, but for now am calling it Flight Shooter. It’s kind of unoriginal though.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Type HTML Tags Quickly in Vim

Tuesday, April 21st, 2009

I’ve been writing my blog posts in Vim, because I want to get used to it faster, and it can often be more efficient than any other editor I use.

Yesterday, I wrote a lot of Linux commands within the post. When I include any kind of code, or commands such as those, I surround them in <quickcode>, so that a Wordpress plugin I installed can recognize them as code.

Of course, writing <quickcode:noclick></quickcode> over and over again can get rather annoying, so I decided to use my rudimentary Vim knowledge to make things easier.

I used a mapping in .vimrc. I can’t actually type <quickcode> because it’ll mess up the code block, so I’ll put a space between the words quick and code.

nmap <Leader>qc i<quick code:noclick></quick code><Esc>F<

Let’s take this one part at a time.

  1. <Leader> specifies to prefix the command keys with the leader character, by default a backslash (\), though I set it to a comma.
  2. qc just finishes the command that you type to execute this map. So in total is \qc, or ,qc in my case.
  3. i puts Vim in insert mode.
  4. Next, it writes everything literally up until <Esc>.
  5. <Esc>> puts Vim back into normal mode.
  6. Finally,F< finds the previous< and moves to that position. That will put the cursor between the opening and closing tags.

So, for any HTML tag you want a shortcut for, the basic template is:

nmap <Leader>cmd i<tag></tag><Esc>F<

If you enjoyed this post, make sure you subscribe to my RSS feed!

Some of the Reasons I Love Programming in Ruby

Saturday, April 18th, 2009

Today, I wrote a really long post on the SitePoint forums. I think that it can benefit other people as well, so wanted to post it here.

Someone asked whether it is worthwhile learning Ruby and Rails, or if they should learn a framework in PHP. This is my response, modified a bit from my post in the thread.

I would go with Ruby and RoR, mostly because it has so many useful, and in my opinion necessary, tools that PHP really doesn’t have, such as RSpec, Cucumber, and Webrat, all for BDD (behavior-driven development — see Introducing BDD). After using these tools, I just couldn’t imagine working without them, at least without introducing more bugs.

Rails is rather easy to get started in, too, and simple to deploy. To me, Ruby is much mor eintuitive than PHP.

There are several things in Ruby that just would take more work in PHP. In PHP, it feels like OO has just been hacked into the language. They try to fix that a bit in PHP5 but it doesn’t negate the mess created in the previous versions.

In contrast, in Ruby, absolutely everything is an object. It makes it much more intuitive to work with the language, because objects are an integral part of the language.

Also, I love blocks/procs/closures.

Example:

(1..10).select { |num| num % 2 == 0 }
#=> [2, 4, 6, 8, 10]

Or:

(1..10).to_a.delete_if do |num|
  num > 3
end
#=> [1, 2, 3]

Sorting is very flexible:

class Widget
  attr_accessor :name, :price
  def initialize name, price
    self.name, self.price = name, price
  end
end
 
def print_widgets widgets
  widgets.each do |widget|
    puts "#{widget.name}: #{widget.price}"
  end
end
 
# Creating some widgets
widgets = []
widgets << Widget.new('Foo', 4.99)
widgets << Widget.new('Bar', 2.98)
widgets << Widget.new('Baz', 9.99)
 
print_widgets widgets
# Foo: 4.99
# Bar: 2.98
# Baz: 9.99
 
# Sort by price
widgets.sort! do |w1, w2|
  w1.price <=> w2.price
end
 
print_widgets widgets
# Bar: 2.98
# Foo: 4.99
# Baz: 9.99

Another cool thing is that you can extend classes. I don’t know the proper word for it. I don’t mean inheritance, but you can actually add methods to an existing class.

class String
  def foo
    puts 'I am foo. I have infultrated String.'
  end
end
 
"hello".foo
# Outputs: "I am foo. I have infultrated String."

There are also mixins, the ability for classes to include and extend modules.

module Foo
  def do_something
    puts "I am doing something."
  end
end
 
module Calculator
  def add a, b
    a + b
  end
end
 
class Bar
  include Foo
  include Calculator
end
 
bar=Bar.new
bar.do_something
# Outputs: "I am doing something."
bar.calc 1, 2
#=> 3

And there is so much more that I love about Ruby. The syntax is just so much better. After working in it for a while now, I couldn’t imagine going back to PHP.

Of course, RSpec does a lot to make Ruby favorable for me as well. I really love using it, and it really improves the quality of my code.

Of course, that’s only Ruby, and I haven’t discussed anything from Rails, which is really great in its own right. There are frameworks inspired by Rails in PHP, but Rails does everything much more elegantly, because PHP just isn’t capable of some things that Ruby is. In PHP, there is nothing really resembling blocks/procs in Ruby. They can really simplify code.

I also love that you can overload operators in Ruby, because most operators are just methods of an object. Ruby doesn’t have the limitations that PHP does in the characters you can include in a method name. Many methods include the characters ? or !. For instance, the String class has a method called include? to check if the given string is contained within it.

foo.include? 'o'
#=> true

Again, none of this even touches Rails, which is an amazing framework itself. It is better than any framework I have used in PHP.

If nothing else, I think you should learn it just for the experience of another language. I don’t think there’s ever harm in learning a new language and perspective on programming.

For more information on Ruby and Rails, see the following resources:

If you enjoyed this post, make sure you subscribe to my RSS feed!

Driving Application Design with BDD

Friday, April 10th, 2009

I started a new project recently, and decided to use BDD (behavior-driven development) to drive its design. I have never really done this before.

I can see so many benefits with it. As I continue, I make sure I write each example/spec first, and then write code to meet only that spec. Then I write another, and write more code to meet that, as well as the first. If I’m missing a feature, I write the specs to describe that feature, and then write the code to meet the specs.

There are times that I wasn’t sure how I would implement a certain feature. Instead of analyzing it very much up front, I just started writing the specs, and observed where it was taking me. It was definitely a unique feeling, like I was coding with only the specs to show me where I was going. In the end, though, a design started to emerge that I was satisfied with.

It is definitely a different way of thinking. It is hard not to take too large of steps, but only so much as to meet the spec I just wrote. Sometimes I see an error, and I specifically just write the code to pass that error, especially when I’m not so sure how to continue.

I definitely want to continue this. It was slow at first, but now I am getting faster at it. I will be writing more posts about BDD, especially using RSpec, in the future, as there are many things I am learning in this project.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Withdrawing from College and Transferring Closer to Home

Thursday, April 2nd, 2009

This marks a huge transition.

I didn’t mention, but several weeks ago, I decided to transfer to the University of Pittsburgh at Johnstown. It is about half the cost of Duquesne, and Duquesne is just too expensive. I decided to take computer science at UPJ, too, because I got burned out with music again, and just couldn’t put in the necessary work.

Well, I tried to put in the work. I’ve been keeping a practice journal on this blog since late December, and I always complained how I wasn’t putting in as much work as I wanted to. It started at around 45 minutes to an hour per day, and gradually increased. It did get to around 10-14 hours per week, but that’s still not nearly the amount I need to put in.

I pushed myself so hard to try to put in the work, but just couldn’t do it. Then I started to get physically sick, not once, but at least two or three times. I know twice, I went home over it, and took a week off of classes both times.

It was just getting too stressful, and I didn’t enjoy it at all.

Over spring break, I found somewhere to practice, but that made it worse because all I wanted to do was to take a nice long break. By Saturday, I could hardly touch the piano, which extended into the next several weeks.

Burnout, stress, sickness exacerbated by everything else.

After my mom was taking me back to college on Monday, well I just couldn’t handle it. I had held everything in all semester, trying to deal with it myself. I broke down and told her all the problems I’ve been having.

To be honest, she wasn’t sure what to do. She consulted with her friend and co-worker, and had her talk to me as well. it was good just to get everything out.

We made the decision to withdraw for the semester. I’m transferring anyway, and not many of my credits, especially the credits I’m taking this semester, will transfer. It’s just not worth getting physically sick over it.

I was really afraid at first that she would be upset over it, but she wasn’t at all, which relieved me. I felt like a huge weight was taken off of my shoulders.

So we went back, talked to my adviser, went to health services to pick up my shots, say goodbye to the nurse that I became pretty close to, and get the director to send a letter to the dean for me since I’m trying to do a medical withdrawal, and then picked up some of my stuff.

We are going back tomorrow to move out everything. Also I just want to spend some time saying goodbye to my friends.

It’s been a rough semester. I was able to keep it afloat for a while, thanks to my talent at the piano, but it got to be way too much, especially with missing two weeks of classes.

I’m so relieved to be off now, and plan to use this time to work on starting up my business, Azavia Technologies. I registered it two years ago, but then I went to college and just got sidetracked. I have my server, a project management system I will post about soon, and I started using Ruby, so that’ll hopefully be my primary language.

I feel a lot better about this than I expected. I guess I’m just looking forward to next semester when I can hopefully go to UPJ. It’s a smaller campus, is about a mile away from home, has much better Greek life than Duquesne does, and all around just seems a lot nicer for me.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Renaming Files Dynamically in Bash — Kind of

Tuesday, March 24th, 2009

I was working on creating Cucumber features and step definitions last night. I was naming the files like foo-bar.feature.

I saw the webrat_steps.rb file in the steps_definition folder, and thought it’s probably not good to have a different naming schema for different files. So I set about renaming my files to use underscores instead of dashes.

I have 29 features though, and a couple of step definition files so far. After renaming two or three of the features, it got old, and I knew there must be a better way, without scripting it in another language.

Just on a whim, I typed `replace’. This is what I love about Linux (Cygwin in this case). You think something should exist, and you type it and it does.

So then I read the man page on it, and tried to use it. Of course I didn’t want to replace anything in a file, but just through STDIN, which of course was an option.

The next problem was making it recognize the dash without thinking it was part of an option. I spent about 5 minutes on that before realizing I could escape the dash.

So I came up with a little script as follows:

files='*.feature'
for file in $files
do
  git mv "$file" $(echo "$file" | replace '\-' '_' --)
done

If you enjoyed this post, make sure you subscribe to my RSS feed!

Apache Misconfiguration

Saturday, March 14th, 2009

After the transfer to my new server, everything was going along just fine, but eventually I noticed my new posts had a view count of 0. I thought that strange, since my posts usually get at least 15-20 views, but thought maybe it was just because I hadn’t posted for a while.

Then I went to post my last blog post on Twitter, and clicked the link to make sure it was right. I got a 404 error.

Right away I suspected .htaccess was trying to use mod_rewrite but couldn’t, because this has happened to me almost every time I transfer somewhere. I always forget to change:

AllowOverride None

To:

AllowOverride All

Admittedly, that’s probably not the best way to do it, but this just contains my own sites right now, and will probably always just contain sites I have developed.

Many other people probably don’t run into this problem, but in case you do, there it is. Always check your httpd.conf.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Hopping on to the Rails

Thursday, March 12th, 2009

I finally gave in. I’ve been hearing about how Ruby on Rails is the greatest thing since sliced bread for a few years now. I refused to learn it because I figured that it was just a developer fad that would descend into obscurity soon enough. After all, I had never heard of Ruby before.

I don’t know what triggered it. Perhaps it is because I was tired of relearning symfony every time I started a new project after a break. The documentation is extensive, which is great, but one of the downfalls of extensive documentation is that it takes forever to read enough of it to learn your way around.

Further, much of the documentation is outdated. Much of what is says about forms, for instance, does not apply anymore. The only way to learn the new forms API is to read the very incomplete forms book.

Then, they moved to Doctrine. Well, they wanted to replace the Propel ORM with Doctrine eventually. Therefore, I thought it was smart to switch over to Doctrine. Unfortunately, almost all of the documentation still refers to Propel. Also, very few plugins implement Doctrine, severely limiting your choices.

So, when I wanted to start a new project recently, all of these factors together made me rethink using symfony. I should note I’ve not used it for a few months, so it may have changed, but I wasn’t much in the mood to go through all of the documentation again to find out.

Using PHP without a framework was out of the question. It just made things much faster, and I knew that if I didn’t use one, I’d be virtually making my own, which would take a lot longer.

I have been through several frameworks. Besides symfony, I’ve also used CakePHP, and Prado. I’d heard enough about the Zend Framework that I was pretty sure I didn’t want to use it.

A thought arose: what about Ruby on Rails? I have my own server now in preparation for the new project, so I could really install anything I wanted. I wasn’t entirely sure, though, so I searched a bit about why RoR is so hyped.

I found a few things, but nothing significant. I did stumble upon a book called why’s (poignant) guide to ruby. I told myself I’d read it if I found a good reason to learn Ruby.

I ended up reading the first chapter or two, and the book was so funny that I couldn’t stop reading, so I continued and finished reading it the next day.

Of course, it only taught Ruby, not Rails. However, I really liked the syntax of Ruby, though it was a bit alien to me. Never before had I seen anything even remotely similar to:

[1,2,3,4].each { |number| puts number }

I mean, you can guess what’s going on, and you’d probably be right, but it is so different from what I’m used to that it was a bit weird. I liked it, though.

So, then I tried to see how I could learn Rails. Luckily, I found the book Simply Rails 2 at SitePoint. Also luckily, they had a PDF version of it, so that I could read it. With a final stroke of luck, it was cheaper than the hardcopy.

As if my luck would not end, I got sick this week. OK, no I don’t like being sick. But it got so bad that I came home yesterday. That means that between sleeping and feeling relatively terrible, well, I can read this book.

Before I wrote this post, I just finished chapter 6. It is covering a lot, so I’m taking a break so as to not forget everything.

It is funny, because each time a new topic is introduced, I am certain it will be complicated and will be hard to understand. Then it turns out to only take a few simple lines.

As I proceed, I see where the PHP copies of Rails got their ideas, but also where they went wrong. Almost everything you can do in those frameworks, which seem great by themselves, are even better and easier in Rails.

For instance, I remember in CakePHP that to create associations, you had to create a large array of them in the model. However, in Rails it is simply something like:

class Author < ActiveRecord::Base
  has_many :books
end

Even the testing is simpler than anything you could dream of in PHP. Here’s an example (modified a bit) of a unit test from the book:

test "should not be valid without name" do
  # Try to create a story without a name
  s = Story.create :name => nil,
  :link => 'http://www.example.com'
  
  # Assert that the name field has errors
  assert s.errors.on :name
end

And a functional test:

test "should show index" do
  get :index
  
  # Test that the HTTP response is 200
  assert_response :success
  
  assert_template 'index'
  
  # The instance variable @story is not nil
  assert_not_nil assigns :story
 
end

So yes, I’m learning Rails. I’ll probably post in the future about how I set up my environment both on my local computer and remote server.

If you enjoyed this post, make sure you subscribe to my RSS feed!