Skyline displays an animated, side-scrolling, randomly-generated skyline. It was written in Java for an AP Computer Science class project.
This application requires Java, so please ensure it is installed. Then, download and extract the .zip file from the latest release of Skyline. Finally, run Skyline.jar, which may be a little tricky:
- Double clicking on the file may work.
- Right-click the file, look for an "Open With" option, and select the Java runtime. (Such an option may not exist on all operating systems.)
- Open a terminal and enter
java -jar
, followed by the path to Skyline.jar. For example, if Skyline.jar is located inC:\Documents\Skyline_v1.0.0
, enterjava -jar C:\Documents\Skyline_v1.0.0\Skyline.jar
.
Random building generation is handled by the BuildingEngine
class. Here's how it works:
buildings
is a list of all buildings in the skyline.genPosition
is the x-position of the left edge of the next building to be generated.- Each frame, all buildings are translated left by a small amount to create the side-scrolling effect, and
genPosition
is also translated left by the same amount. Then,generate()
is called. generate()
works as follows: whilegenPosition
is onscreen, a new building is generated with left edge atgenPosition
, andgenPosition
is translated right by a random value. WhengenPosition
is offscreen to the right, the method ends.- In the
BuildingEngine
constructor,genPosition
starts at the left edge of the screen, andgenerate()
is called. Thus, the skyline is filled with buildings from the very beginning. - Newly generated buildings have random widths, heights, and colors. They are also inserted into
buildings
at random positions. Since the order of buildings inbuildings
is also the order in which they are painted, this allows for random overlap of buildings.