HTML and CSS Reference
In-Depth Information
},
{
type: 'rect',
graphicName: 'BrownSquare',
position: {x: 200, y: 120},
dimension: {width: 10, height:10},
angle: 0
},
]
}
];
game.currentLevel = game.levels[0]; // default the 1st level.
2. In the physics.js file, when we create the physics world, we load the level and
use it to create the obstacle and hoop:
physics.createLevel = function() {
var level = game.currentLevel;
this.createObstacles(level);
this.createHoop(level);
// existing code goes here.
};
3. When creaing the hoop, we use the level deiniion for the posiion of the hoop:
physics.createHoop = function(level) {
var hoopX = level.hoopPosition.x;
var hoopY = level.hoopPosition.y;
// existing code goes here.
}
4. Similar to the hoop, we use the level deiniion for the ball spawning posiion.
The difference is that we add a random range to the ball so it is not exactly the
same posiion on every shot:
physics.spawnBall = function() {
var level = game.currentLevel;
var ball = game.balls[level.ballName];
var positionX = level.ballPosition.x + Math.random()*level.
ballRandomRange.x - level.ballRandomRange.x/2;
var positionY = level.ballPosition.y + Math.random()*level.
ballRandomRange.y - level.ballRandomRange.y/2;
var radius = ball.radius;
 
Search WWH ::




Custom Search