The Corporate Ladder: Technical stuff

Again, I use a variation of the scrolling technique from Warp 1.5 and WW2. But this time it's not quite as easy. Since I don't use any uniform "building blocks" to construct the background, but rather irregularly shaped pieces of furniture, I can't build new floors one horizontal strip at a time. Fortunately, this isn't necessary.

Since the background won't scroll all the time, but only when the player advances upwards -- and often with relatively long breaks in between -- the computer will easily be able to draw a whole new floor before it's time to scroll the screen again.

On the left you can see a snapshot of the main Image object:

  1. The top part is the portion the player sees (essentially the middle graphics buffer, when speaking in terms of triple-buffering techniques), because it gets displayed in the applet region once per animation cycle. It has mobile characters and a bonus counter.
  2. Right below is a small section with graphical pieces used to build the background of new floors.
  3. The biggest part is the farthest graphics buffer, with static objects only.
  4. Within 3, there is something that could be called the "viewable window", which gets copied onto 1, and then all the mobile characters are drawn on top of that. When this "window" is moved upwards, the screen appears to scroll. And when the window reaches the top of part 3, it has to jump down a bit again. To make the transition seamless, the lower portion has to contain duplicates of the upper floors.
  5. The nearest floor above and entirely outside 4 is always under construction. Only when this is finished, and has been duplicated five floors below (see 6), is the screen allowed to scroll up another floor.

When it comes to programming Java arcade games, it has always been my philosophy to spread the computer's work out as thinly and evenly as possible. This ensures that the game will run at a high and constant speed even on slow machines. In the case of this game, drawing a new floor costs only one small drawImage or copyArea operation per animation cycle. This is how I do it:

  • First I copy the thin horizontal segments in part 2 onto the place of the new floor. It takes four of these -- three of one and one of the other. Each segment is 400x16 pixels. Time: 4 animation cycles.
  • Then I draw the stairs, one per cycle, so the time is the same as the number of stairs on that particular floor.
  • Then I draw the furniture, one piece per cycle. For a normal floor this results in a time of about 10-15 cycles.
  • Finally I duplicate the new floor further down in the buffer. For simplicity I do this the same way that I build the empty floor background -- by copying four 400x16-pixel segments. Time: 4 cycles.

This makes the total time to draw a new floor a little over 20 animation cycles on average. The game runs at about 15 cycles per second on most computers, much thanks to the efficient use of resources. This means that unless the player advances to a new floor faster than once about every 1.3 seconds (which is next to impossible due to the people around him), he won't notice any delay whatsoever.