Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

added gameLevel.js#57

Open
professionalzack wants to merge 1 commit intoketanhwr:masterfrom
professionalzack:gamelevel-builder
Open

added gameLevel.js#57
professionalzack wants to merge 1 commit intoketanhwr:masterfrom
professionalzack:gamelevel-builder

Conversation

@professionalzack
Copy link

@professionalzack professionalzack commented Dec 15, 2018

Whilst waiting for @ketanhwr to merge #55 written by @KenyStev , i am just adding this class constructor based on the level JSON object definition in that pull request. this is for ease of use as well as a possible future live screen level creation.
here are the instructions for use, which are also available in the .js file:
To create a new level, type let <levelname> = new GameLevel(<enemy ship x-coordinate>, <enemy ship y-coordinate>, <spacestation x-coordinate>, <spacestation y-coordinatie>).
To add mirrors, type <levelname>.addMirror(<x-coordinate><y-coordinate>, <width>, <height>);. If you want the mirrors position to be fixed, add "fixed" or true in the parameters after the height. Default width/height is 100.
For circular mirrors, use the same function but leave out the width and height (add "fixed" after the y-coordinate instead).
To add an asteroid, a moving asteroid, or another spacestation, the methods are .addAsteroid, .addMovingAsteroid, and .addSpacestation respectively, with the X- and Y- coordinates included as arguments.
Any of these methods can also be called in bulk by putting multiple sets of arguments in brackets.

As an example, here is how level one could be written out. i wrote out the mirrors and asteroids one-by-one for the example, but they could be written in bulk, as shown in examples of levels nine and ten below.

let one = new GameLevel(width-140, 100, midx-70, 100); one.addMirror(200, 150); one.addMirror(600, 400, 100, -100); one.addAsteroid(1000, 100); one.addAsteroid(1000, 200); one.addAsteroid(1100, 240);

let nine = new GameLevel(-15, 520, 13, 90); nine.addSpacestation(1067, 90); nine.addAsteroid([95, 545], [105, 465], [37, 430]); nine.addMirror([350, 520, 17, 80], [1040, 320, -100, -80], [910, 480, 100, -50], [250, 170, 47.8, -100]);

let ten = new GameLevel(width-90, 250, midx+370, 200) ten.addSpacestation(370, 100); ten.addMirror([380, 520], [600, 400, 100, 0]); ten.addCircMirror(200, 300); ten.addAsteroid([900, 1], [900, 50], [900, 150], [900, 250], [900, 350], [1090, 170], [1095, 350], [1150, 390]);

levelsDefinition.push(one, nine, ten)

also included is a console log of the object for the first level of the game built as above
level one

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant