Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Making a Sprite

Sometimes, when you’re making a video game, there are just so many things to keep track of with variables that it becomes impossible! When this happens, it’s time to start looking at a better way to keep track of the characters, monsters, spaceships, or what have you. Fortunately, BASIC lets us define our own custom user-defined type. Think of a TYPE as a group or container for a family of variables that are all closely related. Here is a TYPE called Sprite that we’ll use for the game in this chapter:

TYPE Sprite
    alive AS INTEGER
    x AS INTEGER
    y AS INTEGER
    width AS INTEGER
    height AS INTEGER
END TYPE

The important thing to remember when making up your own TYPE is that the variables have to be specifically defined using AS—we can’t get away with using a symbol like & (for a long integer) or $ (for a string).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint