- Filter blocks which Xposition is x > 2 or x < 10
- Create a Pixels set based on current active pixels
- Remmove previous brick from Pixels
- Add current brick to Pixels A. if in aming mode (pixel.y === 1) just add new brick to the set (there is no risk of colision) B. if in drop mode (pixel.y > 0) check if there is a colision a. if setBrickPixel.y === curBrickPixel.y + 1 and setBrickPixel.x === curBrickPixel.x add pixel to set, quit the set loop and test another curPixel. b. if setBrickPixel.y !== curBrickPixel.y + 1 add pixel to set, quit the set loop and test another curPixel.
- Save in state: current brick as prevBrick, Pixels as activePixels
- If (pixel.y > 13) startAiming()
return true if there is colision with the stack
- Check if pixel.y + 1 is contained in Pixels set
// should be triggered at start, if brdck hit the flor or if there is a colision
- Clear drop interval
- Reset Xposition, Yposition, prevBrick
- Start aiming in intervals
variables: Xposition, startLeft, moveRight, counter, brickLength
- Change X position depending on direction if moveRight Xposition + 1 if !moveRight Xposition - 1
- Save changed X position in state
- Check if direction should be changed If Xposition is 9, change direction to left If Xposition is 1, change direction to right
- Add 3 blocks to the newBrick array (first bolock X position is equal to current X position, two other are moved by +1 and +2)
- setActivePixels
variables: Xposition, Yposition, brickLength
- Clear drop interval when Y > 13
- Change Y position by + 1
- Save changed Y position in state
- Add 3 blocks to the brick array (first bolock X position is equal to current X position, two other are moved by +1 and +2. Y positon is equal to current Y positon) x. Detect colision a. If set
- setActivePixels
Behaviour
Brick Pixels should fall untill each of them collide with either bottom or pixels from stack. I it is level 0 all pixels should be added to the stack. Add to the stack pixels that colide with the highest pixel of the stack
DetectColision should return:
- pixels that should be added to the stack
- pixels that ahould be set as a brick in state
1 2 | 3 4 5 6 7 8 9 |
End of game:
Number of pixels that didn't sucessfully colide is equal to the length of brick.