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:
buildingsis a list of all buildings in the skyline.genPositionis 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
genPositionis also translated left by the same amount. Then,generate()is called. generate()works as follows: whilegenPositionis onscreen, a new building is generated with left edge atgenPosition, andgenPositionis translated right by a random value. WhengenPositionis offscreen to the right, the method ends.- In the
BuildingEngineconstructor,genPositionstarts 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
buildingsat random positions. Since the order of buildings inbuildingsis also the order in which they are painted, this allows for random overlap of buildings.
