This is a graphical version of the Roguelike game from Academy Pittsburgh Session 9 Week 3. The grid is displayed with images instead of text, and sound effects have been added. For the sake of comparison, here's the original roguelike code that John made during class.
This uses a library called Gosu to handle graphics, sound, and input. You must install it before running the script. Of course, Ruby must also be installed. (See below for instructions)
- The game code is now contained within a class 'Game'. This class extends 'Gosu::Window', which is required for Gosu's features. An update() function runs every frame to handle game logic, and a draw() function runs every frame to produce the graphics you see onscreen.
- Sound effects play when you move, run into a wall, pick up treasure, or get teleported.
- The grid is shown using graphical tiles instead of text symbols.
- The fact that tiles, various tile types, and the player were already contained within classes makes it pretty simple to add graphics to the game without too many changes. This is a testament to the usefulness of OOP.
Simply type this into a command line:
gem install gosu
These steps should work even if you can't log in as root on your Mac (su/sudo).
-
Install Homebrew, then use that to install SDL2 (required for Gosu to work):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install sdl2
-
Skip if Ruby is installed and working. If you haven't done a proper Ruby install, do that now. Even though macOS includes Ruby, it may be outdated/incomplete:
brew install rbenv rbenv install 2.6.5
-
Skip if Ruby is installed and working. Close and re-open Terminal!
-
Finally, run this command:
gem install gosu
Once Gosu is installed, you should clone the repository, then you can run ruby-roguelike like any other script.
git clone https://github.com/coljonesdev/ruby-roguelike.git
cd ruby-roguelike
ruby roguelike.rb
Use the WASD or Arrow keys to move the player. Press 'Escape' or 'Q' to quit.