As a teacher, I see a lot of student hobby projects that fail. Invariably, the single highest reason for failure is overscope: the project starts out as this grand vision of a huge thing that's too big to possibly complete, more and more people are brought on until it collapses under the weight of its own design, and everyone leaves feeling frustrated and demoralized.
The best remedy for this is to constrain your scope ruthlessly. Instead of saying "how do I keep my energy up enough to finish a long project?" you should instead be saying "how do I design a project that's short enough that I can finish it before I get bored with it?"
"Game jam" events (make-a-game-in-a-weekend sorts of things) are a great way to get started, and they're great for building good habits when making rapid prototypes. At WORST, you spend a weekend making a lousy game... you probably learned something in the process... AND you saved yourself months of working on an idea that ended up not being as cool as you originally thought. At best, you find that you have something really special, and can start adding small features one at a time until you have a full-featured project.
On my own small hobby projects, the other thing I've found that helps is to start with a complete list of all known development tasks that need to be done, ordered, and scaled down so that each individual task is doable and testable in maybe 30 to 60 minutes, tops. It is very energizing to do a small task, see it working in the game, and crossing it off the list... which then just makes it that much more likely I'll do the next thing on the list since the last one was so easy, and then the next... sort of like eating potato chips.
Another hint: whenever you successfully implement a new feature, make a backup (or use source-code control, which is basically the same thing, but not everyone uses source control if it's just them working on their own personal project). That way if you totally screw up the code at 2am and can't figure out how to get it back in a working state, the project isn't dead and doesn't have to be restarted from scratch; instead, you just roll back to the last completed and working milestone, and try again.