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, ...
Get Learn Game Programming with Ruby now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.