Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Showcase / Flight
- - By EdwinOdesseiron Date 2013-08-11 10:48
Flight was a small project I did last year, for my Software Engineering project. We had to write a program - anything, in any language - that had at least 5 classes. I found this to be a perfect opportunity to learn Ruby and Gosu, and this simple project was born. Since I was still learning, this project took me about 4 weeks of work. It's simple shooter, that you probably can play infinitely. Today I would probably write it better, faster and more advanced, but well ;)

Download link: Click here

I included both .exe file (used Ocra to compile it) and source code. I'm not sure if it will work on linux and/or OSX, because it uses .gif files, but if that's an issue I will convert graphics to .pngs and reupload the game.
Parent - - By allcaps Date 2013-08-12 20:18
Pretty nice game!  Though a couple things strike me as odd.

Why so many globals?  Things like the players armor and score should be handled by the instances of those objects instead of globally hard-coded.  In general if you're using a global in an object oriented language you're either in a very special situation, or you're making a mistake.

Player1 and Player2 are almost exactly the same.  Would be easy to make a base "Player" class and have player1 and player2 (or player3, or player99) extend it.  Same for bullets.  Can make a simple bullet class that handles hitting other entities and sending callbacks to them, and then have a player_bullet and enemy_bullet that extend it and implement behavior specific to friendly or hostile bullets. (Like moving up instead of down, different graphics, sounds, etc)

You use two identical methods to check for two hard-coded players and adjust their health in global variables.  It'd be cleaner and easier to just send a callback to the player you hit, and have the player manage their health themselves, instead of using globals and checking for each hard-coded player separately.

You store the main Gosu::Window into a global $window (which is fine), but then have the window pass "self" around anyway.

The final product works really well, but under the hood it's kind of spaghetti.  I love the floating healthbars and smooth influx of enemies as they're destroyed, and the pre-rendered menus with moving cursor is smart, instead of setting up a bunch of positioned text.
Parent - By EdwinOdesseiron Date 2013-08-12 20:39
Thanks a lot for the comment!

I do realize most of the things within the code could be done differently, but as I stated, this was my very first thing I ever programmed. I partially lost myself in my own code, and wasn't sure how to achieve some things (like Player classes), so I tried a workaround. I had a limited time to finish that too, so I couldn't really experiment with it, at least not too much. I might soon re-write the code, but at the moment I'm fairly busy with other works.
Parent - - By ml Date 2013-08-13 05:03
I like the welcome screen and menu system a lot. Very straightforward and simple. Thanks for sharing your project.

I'm on Linux, and it seems like the .gifs loaded just fine.... In order to get the game to load I deleted the file 'gosu.rb' from the main folder (/Flight/). Also, I encountered an inexplicable problem with the enemy bullets, so I commented out the line where the enemy bullets get created. Also, going to the high score menu gave me an error. So, I was only able to check out most of the game, without enemy fire. Still I was able to play it a little and check it out. The weapons upgrade is a nice touch.

I am new to programming, and I am not sure what exactly is causing the errors, especially with the enemy bullets. In case it is of interest, this is the error I received (for enemy bullets):
/Flight/Scripts/EnemyBullet.rb:21:in 'initialize': Unknown error (RuntimeError)
  from /Flight/Scripts/EnemyBullet.rb:21:in 'new'
  from /Flight/Scripts/EnemyBullet.rb:21:in 'initialize'
  from /Flight/Scripts/Scene_Game.rb:132:in 'new'
  from /Flight/Scripts/Scene_Game.rb:132:in 'update'
  from /Flight/Scripts/GameWindow.rb:105:in 'update'
  from Main.rb:94:in '<main>'
The game is able to boot up, but as soon as an enemy tries to fire, I get the error above (unless I hash out that line of code).

And for the high scores screen. This error comes up as soon as I try to access the High Scores:
/Flight/Scripts/Scene_Highscore.rb:16:in 'initialize': Unknown error (RuntimeError)
  from /Flight/Scripts/Scene_Highscore.rb:16:in 'new'
  from /Flight/Scripts/Scene_Highscore.rb:16:in 'initialize'
  from /Flight/Scripts/Scene_Title.rb:70:in 'new'
  from /Flight/Scripts/Scene_Title.rb:70:in 'confirm'
  from /Flight/Scripts/Scene_Title.rb:61:in 'button_pressed'
  from /Flight/Scripts/GameWindow.rb:114:in 'button_down'
  from Main.rb:94:in '<main>'

Not sure if other people on Linux would get the same errors, but that's what happened when I tried it. Also, I don't know whether it's worth your time to try to find a solution, but I mention it in case it is of interest.
Parent - - By EdwinOdesseiron Date 2013-08-13 09:17
I checked both codes, and seems to be related to loading graphics, first .png and then .gif. Try adding additional backslash in these lines:
@background =, "/Graphics/Backgrounds/Highscore.gif", false)
                                                                            ^ About here

If error changed to another line, seems that linux requires these when loading graphics.
Parent - By ml Date 2013-08-24 03:07
Hi thanks for the response. I just tried it out and I was able to get everything to work great.

The issue ended up being the usual suspect - case sensitivity - with these two filenames:
Eshot.png Highscore.gif
EShot.png HighScore.gif
Parent - By jlnr (dev) Date 2013-09-21 07:04
To bring up a gameplay issue…you cannot fly diagonally! :) And there is no feedback when enemies get hit. Everything from the presentation here would make the game a lot more fun:

(I realise that the project is probably finished, but I just can't link to the article often enough :))
Up Topic Gosu / Gosu Showcase / Flight

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill