No Brakes! (Beep Yeah!) Mac OS

No Brakes! (Beep Yeah!) Mac OS

May 25 2021

No Brakes! (Beep Yeah!) Mac OS

Become a videogame developer master with Gosu and Ruby.

Bored of develop amazing websites? Want to try something totally different, but without leaving our beloved Ruby? If the answer to these two questions is yes, we'll see a way to do something new while having fun. Let's go!

Is there a way to play a system beep on Mac OS using C and Xcode? I understand that I need to use a library. Is there a library that works across both the Mac and Windows platforms? Why does the rear brake bowden have no housing below the frame of the bike? The Mac OS is getting so layered and congested with Mail, Messages, FaceTime and, the dreaded “You don’t have enough access privileges to do THAT!”, that it becomes a tedious drain. Having made money on my Macs since their inception, I’d really like to have Snow Leopard back or, the choice of an OS with little-to-no excessive tripe. Jul 05, 2016 Reset the SMC on Mac desktop computers Follow these steps for iMac, Mac mini, Mac Pro, and Xserve. Shut down the Mac. Unplug the power cord. Wait 15 seconds. Plug the power cord back in. Wait 5 seconds, then press the power button to turn on the Mac.

But... What's Gosu?

Gosu is a 2D game development library for Ruby and C++, available for Mac OS X, Windows and Linux. It's open source (MIT License), and the C++ version is also available for iPad, iPhone and iPod Touch. Provides basic building blocks for games:

  • A window with a main loop and callbacks
  • 2D graphics and text, accelerated by 3D hardware
  • Sound samples and music in various formats
  • Keyboard, mouse, and gamepad input

We're going to use the Ruby flavor, so we need to install the Gosu gem with gem install gosu. But first, in order to be able to use it, we need to install some dependencies. I'm going to use Mac OS X, so I only need to install sdl2 library via Homebrew executing brew install sdl2. Here you have the links to the official documentation for all OS:

  • Mac OS X: Getting Started on OS X
  • Linux: Getting Started on Linux
  • Windows: Getting Started on Windows

Ready, steady... let's do some code!

Ok, we have all installed. so the next step is start the development. We could use Gosu and develop our game as a simple Ruby application (without structure of any kind), throwing some files with our code into a folder, but in order to maintain a minimum structure, we're going to do it as a regular Rails gem. I'm going to name my game 'Simplelogica: The Game', so:

This generate the following basic structure:

To store all the assets that we'll use in our game (images, sounds, music...), we're going to create the assets folder in our project, with some other folders inside it (images, fonts, fixtures...). At the end we're going to have a structure like this:

We're a great developers, but if art is our weak point, to make the design of the scenarios, characters, etc... of our game, we can go to communities of artists who share their resources to everyone can make use of them, e.g. http://opengameart.org/.

Well, let's explain very quickly the basis of the development with the help of the official Gosu Ruby introduction (you have the complete documentation of Gosu here if you want to go deeper).

Don't worry, as always, at the end of the post I'll put links to the repo with the final code to the game I made so you can see all detail

Spoiler! The examples shown here are directly extracted of the Gosu wiki. All the explanations and example codes of the next parts belongs to them.

Overriding Window's callbacks

Every Gosu application starts with a class that derives from Gosu::Window. A minimal window class looks like this:

The constructor initializes the Gosu::Window base class. The parameters shown here create a 640x480 pixels large window. It also sets the caption of the window, which is displayed in its title bar. You can create a fullscreen window by passing :fullscreen => true after the width and height.

update() and draw() are overrides of Gosu::Window's methods. update() is called 60 times per second (by default) and should contain the main game logic: move objects, handle collisions...

draw() is called afterwards and whenever the window needs redrawing for other reasons, and may also be skipped every other time if the FPS go too low. It should contain the code to redraw the whole screen, but no updates to the game's state.

Then follows the main program. We create a window and call its show() method, which does not return until the window has been closed by the user or by calling close().

The window loop it's something like this:

Brakes

Using images

Gosu::Image#initialize takes two arguments, the filename and an (optional) options hash. Here we set :tileable to true. Basically, you should use :tileable => true for background images and map tiles.

The window's draw() member function is the place to draw everything, so we override it and draw our background image.

Player and movement

  • Player#accelerate makes use of the offsetx/offsety functions. They are similar to what some people use sin/cos for: For example, if something moved 100 pixels at an angle of 30°, it would move a distance of offset_x(30, 100) pixels horizontally and offset_y(30, 100) pixels vertically.
  • When loading BMP files, Gosu replaces #ff00ff with transparent pixels.
  • Note that draw_rot puts the center of the image at (x, y) - not the upper left corner as draw does! This can be controlled by the centerx/centery arguments if you want.
  • The player is drawn at z=1, i.e. over the background.

Using our Player class inside Window

No Brakes (beep Yeah ) Mac Os X

Gosu::Window provides two member functions button_down(id) and button_up(id) which can be overridden, and do nothing by default. While getting feedback on pushed buttons via button_down is suitable for one-time events such as UI interaction, jumping or typing, it is not place to implement actions that span several frames - for example, moving by holding buttons down. This is where the update() member function comes into play, which calls the player's movement methods depending on which buttons are held down during this frame.

Text and sound

We could add some sounds and custom fonts using the Gosu classes Gosu::Font and Gosu::Sample, like this:

Ok, I get it, but... how should I put all together to develop my game?

After you've tried these simple examples and have delved a little deeper into the Gosu's documentation, you're ready to code your game. The basic idea is to create a class for any resource you want to have in your game (window, sprite, player, enemy, bullet...). On the main class of the project (in my case, lib/simplelogica_the_game.rb file), you have to require all this files, and do something like this:

Then, create a file in bin folder (e.g. bin/simplelogica_the_game.rb), which is the one that you'll execute and initialize the game, with this code:

Make sure that this last file is executable (chmod +x bin/simplelogica_the_game), and try to run it by typing bin/simplelogica_the_game from console. With a little effort and some lines of code, you could have something like this running:

Title screen

No Brakes (beep Yeah ) Mac Os 8

GameplayGame over screen

Please, clone my repo and try to play the game so you can see all this pixels in action! :D

I hope you liked the post, and I encourage you to begin with game development and become the new master indie developer (or at least try it with Gosu), but please, while you develop some great game, listen to this song... So many good old memories... Kirby for the win! :_D

Any place where I can see the result?

Yeah! Here you have the Github repo for this example, so you can clone it, change it, play with it... whatever you want! :)

Please enable JavaScript to view the comments powered by Disqus.comments powered by Disqus

No Brakes! (Beep Yeah!) Mac OS

Leave a Reply

Cancel reply