![]() The draw() function will also be used to clear old position of the shape. Once the shape is added to the game board, the draw() function will be called to render the shape on to the canvas using the context passed to it. This.b4 = new Block(shp.b4.x, shp.b4.y, shp.b4.key) This.b3 = new Block(shp.b3.x, shp.b3.y, shp.b3.key) This.b2 = new Block(shp.b2.x, shp.b2.y, shp.b2.key) This.b1 = new Block(shp.b1.x, shp.b1.y, shp.b1.key) clr - The colour the shape should be drawn with.shp - A Shape object containing the selected shape's coordinates.Here is the constructor to our Shape object which will receive the following parameters:. When the shape is added to the game board, then the starting position in the board array will be applied to the Shape object coordinates. We'll use this number as the index into the Shapes array which we can then use to construct a Shape object by passing the relative coordinates to its constructor. When the game loop starts, we will call a function to select the next shape by generating a random number between 1 and 7. More on that when we come to implement the rotation method. The reason for having a key block is to provide a rotation point. Mostly the key block will be 0, 0 although this may not always be the case. Each block having an x, y coordinate relative to its key block. Z shapeĪs you can see from the array, each shape is made from four blocks. Let's now create a Shapes array to store the relative coordinates for each block:- Shapes: [ ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |