Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Managing the Ribbons

RibbonsManager is mainly a router, sending move method calls and update() and display() calls to the multiple Ribbon objects under its charge. Initially, it creates the Ribbon objects, so it acts as a central storage for their GIFs and move factors.

The initialization phase is carried out in the constructor:

    // globals
    private String ribImages[] = {"mountains", "houses", "trees"};
    private double moveFactors[] = {0.1, 0.5, 1.0};
       // applied to moveSize
       // a move factor of 0 would make a ribbon stationary

    private Ribbon[] ribbons;
    private int numRibbons;
    private int moveSize;
       // standard distance for a ribbon to 'move' each tick


    public RibbonsManager(int w, int h, int brickMvSz, ImagesLoader imsLd)
    { moveSize = brickMvSz;
            // the basic move size is the same as the bricks map

      numRibbons = ribImages.length;
      ribbons = new Ribbon[numRibbons];

      for (int i = 0; i < numRibbons; i++)
         ribbons[i] = new Ribbon(w, h, imsLd.getImage( ribImages[i] ),
                                    (int) (moveFactors[i]*moveSize));
    }  // end of RibbonsManager()

The choice of GIFs is hardwired into ribImages[], and the constructor loops through the array creating a Ribbon object for each one.

The basic move size is the same as that used by the bricks layer but multiplied by a fixed moveFactors[] value to get a size suitable for each Ribbon.

Tip

A move size is the amount that a background layer moves in each animation period.

A move factor will usually be less than one, to reduce the move size for a Ribbon in comparison to the bricks ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page