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] = 1;
24 this.blocks[7] = 1;
25 this.blocks[8] = 2;
26 this.blocks[9] = 3;
27 28 this.addBlocks();
29 30 return this;
31 }
32 33 /** 34 Adds the blocks to the screen by creating VisualGameObjects 35 */ 36 this.addBlocks = function()
37 {
38 for (var x = 0; x < this.blocks.length; ++x)
39 {
40 for (var y = 0; y < this.blocks[x]; ++y)
41 {
42 new VisualGameObject().startupVisualGameObject(g_block, x * this.blockWidth, 400 - (y + 1) * this.blockHeight, 4);
43 }
44 }
45 }
46 47 /** 48 @return The block under the specified x position 49 @param x The x position to test 50 */ 51 this.currentBlock = function(x)
52 {
53 return parseInt( x / this.blockWidth);
54 }
55 56 /** 57 @return The hieght of the ground under the specified block 58 @param blockIndex The block number 59 */ 60 this.groundHeight = function(blockIndex)
61 {
62 if (blockIndex < 0 || blockIndex > this.blocks.length) return 0;
63 64 return this.blocks[blockIndex] * this.blockHeight;
65 }
66 }
Top