O'Reilly logo

Learn Game Programming with Ruby by Mark Sobkowicz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Player Class

Each sprite class in Sector Five manages one kind of sprite. A sprite class is a collection of instance variables that store information about the sprite, and methods, which are commands you give the sprite. When you’re creating a new sprite class, make a list of the information the sprite needs to store and the commands you want it to follow. The player ship sprite stores an image and a position. Because it can rotate, it also stores the angle through which its image has turned. The commands the ship follows include “turn right,” “turn left,” and “draw.” A class diagram shows the instance variables and methods for a class in a box. Here is one for the Player class:

The initialize method is not really a command to the ship, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required