Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a prototype for Level #117

Merged
merged 6 commits into from
Aug 5, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 72 additions & 21 deletions javascript/levels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Level(home, backgroundLayers, obstaclesLayer){
this._backgrounds = backgroundLayers;
this.obstacleLayer = obstaclesLayer;
function Level(name, backgrounds, obstacles){
this._backgrounds = backgrounds;
this.obstacles = obstacles;
this._obstacles = createObstacles(obstaclesLayer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do?

this._name = name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does name com from?

this._score = 0;
Expand All @@ -9,17 +9,27 @@ function Level(home, backgroundLayers, obstaclesLayer){
Level.prototype = {

show: function(){
show_layer(this.obstaclesLayer);
for (layer in this.backgrounds){
show_layer(layer);

for (background in this.backgrounds){
show_layer(background["layer"]);
}

for(obstacle in this.obstacles){
show_layer(obstacle["layer"]);
}

},

hide: function(){
hide_layer(this.obstaclesLayer);
for (layer in this.backgrounds){
hide_layer(layer);

for (background in this.backgrounds){
hide_layer(background["layer"]);
}

for(obstacle in this.obstacles){
hide_layer(obstacle["layer"]);
}

},

getBackgrounds(): function(){
Expand Down Expand Up @@ -59,21 +69,62 @@ function newLevel(name,backgroundLayers,obstaclesLayer){
}

function AlllevelObjects(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be executed several times? Can you remove this function and make the spec a global variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everytime you start a game this function should be executed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect getAllLevels to return the same levels all the time.
Thus, I expect AlllevelObjects() to be called only once.

There are several ways to meet this expectation, which I see:

  • Run this function in this file when it is loaded and make it "private"
  • Remove the function around the for-loop and execute the for-loop when the file is loaded.

What is your perspective on this?

// Need to be properly Modified
levels = ["level1","level2"];

backgrounds = {
"level1":[],
"level2":[]
};

obstacles = {
"level1":"obstacle for level1",
"level2":"obstacle for level2",

var all_level_specifications = {
"desert":{

"obstacles":[
{
"layer": "cactus",
"velocity": 10,
},
],

"backgrounds":[
{
"layer" : "DayAndNight",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you format these lines?

Also, the usage of tabs and spaces should be consistent throughout the project. If not, we mix it and the source code appears depending on the editor settings.
What would you like to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with anything. I ll go with what is already there in the project.

"velocity" : -20
},
{
"layer" : "background",
"velocity" : -7
},
{
"layer" : "SunAndMoon",
"velocity" : 1
},
{
"layer" : "sky",
"velocity" : 0
}
]

},

"gotham":{

"obstacles":[
{
"layer":"Gotham_Obstacles",
"velocity": -7
},
],

"backgrounds":[
{
"layer":"Gotham",
"velocity": -7
}
],
},

};

for(level in levels){
all_levels[level] = newLevel(level,backgrounds[level],obstacles[level]);

for( level in all_level_specifications ){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like these lines. This is short, understandable and says the levels know what to do with the specification.

specs = all_level_specifications[level];
all_levels[level] = newLevel(level,specs["backgrounds"],specs["obstacles"]);
}
}

Expand Down