The Ballworld side-scroller game


(S1) Concept

This is a game like the Mario side-scroller games. Your player moves to the right through a long world, that is, a world with a big x size and a small y size. Objects come towards you and you avoid letting them hit you.

(S2) Appearance

Below is a screen capture of how the game looks.

(S3) Controls

The player uses the Hopper Controls. The idea is to hop over the balls and maybe land on top of them. The Hopper Controls move the player left and right with the Left and Right Arrow keys. The Up Arrow key hops the player up into the air, but continuing to depress the Up key will not produce a continued hopping effect. You need to tap the Up key repeatedly if you want to add a hop to a hop.

(S4) Behavior

Your player starts at the left end of the world. Your goal is to use the Arrow keys to move your player to the right end of the screen and jump into a hoop you'll find there.

The Ballworld game


There are balls bouncing along the bottom of the world from right to left. When you collide with a ball, the effect on you depends on your height relative to the ball. If the player's low edge is higher than the ball's center, the player gets a score point. But, if the player's position is lower than the ball, the player loses a health point. In either case the ball is destroyed. Every time a ball is destroyed a new one is added to the world to the right of the player.

At the right end there is a hoop that gives you extra score when you jump into it. After you jump into the hoop, the player is moved back to the left end of the world.


We call _border.set(100.0, 12.0, 0.0) in the constructor to make the world long and thin. In order to zoom in, we have a call to pviewer->zoom(4.0); in cGameBallworld::initializeViewpoint(cCritterViewer *pviewer). In order to keep the player in view, we have a call to pview->pviewpointcritter() ->setTrackplayer(TRUE) in cGameBallworld::initializeView(CPopView *pview).

A final tweak regarding the view of a side-scroller world is that we add this line to the header of the cGameBallworld.

virtual int worldShape(){return cGame::SHAPE_XSCROLLER;} /* Need this 
    to signal the cCritterViewer to not wobble up and down when 
    _trackplayer is on. */ 

If we were creating a long thin vertical world, we'd want to return cGame::SHAPE_YSCROLLER.

A fair amount of experimentation went into developing the cListenerHopper and tweaking the cCritterBallworldPlayer constructor so that the player has good hopping behavior with the cListenerHopper.

The collide methods of both cCritterBallworldPlayer and cCritterTreasure are overridden to control the interactions between the critters.

The method used to make the ball-shaped cCritterBallProp critters move to the left is to give them a gravity force that points slightly to the left, with this line in the cCritterBallProp constructor. addForce(new cForceGravity(25.0, cVector(-0.03, -1, 0.0)));. As always, more detail can be found in the source code: gameballworld.cpp.

An essential part of both the Ballworld and the Dambuilder games is that they use gravitational forces on the players. It's worth mentioning that when you have gravity, in general (a) you want drag or friction forces to keep the objects from speeding up too much; (b) don't have wrap, otherwise the objects go around and around the y-axis faster and faster; (c) if you don't want things to bounce too much off the bottom edge, you can use setBounciness(0.9) to make them lose energy with each bounce, alternately you can use setWrapflag(cCritter::CLAMP) to make them not bounce at all.

    Part I: Software Engineering and Computer Games
    Part II: Software Engineering and Computer Games Reference