diff options
[WGL/P] Added movement pausing
1 files changed, 14 insertions, 6 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/level.js | 20 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/level.js b/Year 2/Computer Graphics with WebGL/Project/level.js index 65c3cc6..68eed7a 100644 --- a/Year 2/Computer Graphics with WebGL/Project/level.js +++ b/Year 2/Computer Graphics with WebGL/Project/level.js @@ -1,5 +1,7 @@ stars = []; blackHoles = []; +animations = []; + levels = []; Level = function(name, description, cameraCoords) { @@ -8,17 +10,23 @@ Level = function(name, description, cameraCoords) { this.cameraCoords = cameraCoords; this.stars = []; this.blackHoles = []; + this.animations = []; levels.push(this); } -Level.prototype.addStar = function(center, size) { - this.stars.push(new Star(center, size)); +Level.prototype.addStar = function(center, size, animation) { + var star = new Star(center, size); + this.stars.push(star); + if (animation) this.animations.push(() => star.moveTo(animation(star))); } -Level.prototype.addBlackHole = function(center, size) { - this.blackHoles.push(new BlackHole(center, size)); +Level.prototype.addBlackHole = function(center, size, animation) { + var bh = new BlackHole(center, size); + this.blackHoles.push(bh); + if (animation) this.animations.push(() => bh.moveTo(animation(bh))); } Level.prototype.load = function() { stars = this.stars; blackHoles = this.blackHoles; + animations = this.animations; pos = this.cameraCoords; } @@ -27,6 +35,6 @@ function createLevels() { "Star passing behind black hole", "You can see how the black hole (correctly) warps the light of the star behind it when it passes", [1000,0,650]); - l1.addStar([1100,0,1000], 10); - l1.addBlackHole([1000,0,900], 30); + l1.addStar([1100,0,1000], 10, (star) => (vecSum(star.sphere.center, [-0.5,0,0]))); + l1.addBlackHole([1000,0,900], 30, undefined); } |
