-
Notifications
You must be signed in to change notification settings - Fork 157
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
Changes from 1 commit
2ac448f
5caf4fd
450a72a
40de265
56b349f
a6d2da1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
this._name = name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does name com from? |
||
this._score = 0; | ||
|
@@ -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(){ | ||
|
@@ -59,21 +69,62 @@ function newLevel(name,backgroundLayers,obstaclesLayer){ | |
} | ||
|
||
function AlllevelObjects(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everytime you start a game this function should be executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect getAllLevels to return the same levels all the time. There are several ways to meet this expectation, which I see:
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"]); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?