1 /** 2 A class to represent the level 3 @author <a href="mailto:matthewcasperson@gmail.com">Matthew Casperson</a> 4 @class 5 */ 6 function Level() 7 { 8 this.blocks = new Array(); 9 this.blockWidth = 64; 10 this.blockHeight = 48; 11 12 /** 13 Initialises this object 14 */ 15 this.startupLevel = function() 16 { 17 this.blocks[0] = 3; 18 this.blocks[1] = 2; 19 this.blocks[2] = 1; 20 this.blocks[3] = 1; 21 this.blocks[4] = 1; 22 this.blocks[5] = 1; 23 this.blocks[6] = 2; 24 this.blocks[7] = 3; 25 this.blocks[8] = 2; 26 this.blocks[9] = 1; 27 this.blocks[10] = 2; 28 this.blocks[11] = 3; 29 this.blocks[12] = 4; 30 this.blocks[13] = 5; 31 this.blocks[14] = 4; 32 this.blocks[15] = 3; 33 34 this.addBlocks(); 35 36 return this; 37 } 38 39 /** 40 Adds the blocks to the screen by creating VisualGameObjects 41 */ 42 this.addBlocks = function() 43 { 44 for (var x = 0; x < this.blocks.length; ++x) 45 { 46 for (var y = 0; y < this.blocks[x]; ++y) 47 { 48 new VisualGameObject().startupVisualGameObject(g_block, x * this.blockWidth, 400 - (y + 1) * this.blockHeight, 4); 49 } 50 } 51 } 52 53 /** 54 @return The block under the specified x position 55 @param x The x position to test 56 */ 57 this.currentBlock = function(x) 58 { 59 return parseInt( x / this.blockWidth); 60 } 61 62 /** 63 @return The hieght of the ground under the specified block 64 @param blockIndex The block number 65 */ 66 this.groundHeight = function(blockIndex) 67 { 68 if (blockIndex < 0 || blockIndex > this.blocks.length) return 0; 69 70 return this.blocks[blockIndex] * this.blockHeight; 71 } 72 }