Block Blast banner

Block Blast

28 devlogs
62h 55m 28s

This is an attempt at making a game like the popular Block Blast game. COMPLETELY made in HTML5 Canvas. Its fully desktop and mobile friendly, and has sounds and animations. Making this was very fun and i gained more knowledge. I learnt about algo…

This is an attempt at making a game like the popular Block Blast game. COMPLETELY made in HTML5 Canvas. Its fully desktop and mobile friendly, and has sounds and animations. Making this was very fun and i gained more knowledge. I learnt about algorithms and how to work properly with grid based games and how they actually implement this stuff. I also learnt more about HTML5 canvas as this was my second time ever working with it.

This project uses AI

AI helped me with debugging, questions, algorithms, helped with animations and overall layout.

Demo Repository

Loading README...

Whatsup

Shipped this project!

Hours: 62.92
Cookies: 🍪 559
Multiplier: 8.88 cookies/hr

This was my second time ever working with HTML5 Canvas. I increased my knowledge in implementing animations, sprites, audio system and asset loading. I learnt about algorithms and how to work properly with grid based games and how they actually implement this stuff. This was very fun to make and i put my full effort into this to make it polished as much as im capable of. I hope you like it loveparrot.

Whatsup

Added a readme that explains how the game works. Everything is finished now sob-wx.

Attachment
0
Whatsup

The game is basically done now. I will check on some final polishes but as of this moment i have created every function i wanted to create.happi
Biggest pain about this was the dam layouts. They took so long to get right. Also animations and score display didnt work properly so i had to tend to that aswell.
Anyways heres what i have added:

Added options menu

  • Added an options menu dialog. The dialog opens with the same animation as the Game Over dialog.
  • Toggle game sound on/off.
  • Restart the game.
  • Reset your best score (with confirmation prompt).

Sound toggle

  • Added isSoundOn to gameState to track sound status.
  • All sound effects now check isSoundOn before playing.

UI

  • Increased the number of jewel particles spawned when a block breaks.
  • I didnt have sprites for the texts noo so i created a function to render “sound:”, “replay:”, and “Reset score:” directly to the options dialog. This uses a bold, rounded Fredoka font style with a small shadow effect.
0
Whatsup

Menu with UI

  • Added a start menu with a start button and a title.
  • The start button triggers the startAnim() function that changes the state to START_ANIM, which plays the grid sweep animation, which again changes state to PLAYING when its done.
0
Whatsup

This devlog inlcudes grid animations for start and game over.

Honestly im very proud of this one. Might be one of the more cooler things i have managed to do pf.

Sweep animation

  • I added a sweep animation that triggers whenever a new game starts.

  • Instead of the grid just appearing empty, game picks a row and fills every cell in that row with a random color, then moves to the next row on the next frame. Once the grid is full, it does a second pass of the rows setting every cell back to empty (null). By doing this over several frames it basically creates a “wipe” effect that looks cool.

Silvering animation

  • When you lose, the game scans the board to “freeze” your blocks.
  • The game starts at the top and checks every single cell, moving left to right and then down to the next row. If it finds a block, it changes that blocks color to silver. At the end it basically looks like a wave that kinda “washes” your board. Then the gameover dialog draws.

Sounds

  • Added a score update sound that plays when the score count up animation plays on the gameover screen.

  • There was a bug where the “New Best” sound would not play again after you triggered a new game. Fixed it by setting its variable to false in the updateSilvering function.

Honestly the biggest pain in this was when and where to play the animations lol. Things just wouldnt work so it required alot of testing with delays etc. thumbs-up

0
Whatsup

In this devlog i added a full audio system and new line clear animation aswell as fixing other issues. Also i finally used a little markdown sob-wx.

Added a audio system using the Web Audio API (AudioContext).

  • Added an unlock function so audio works across browsers and devices (basically needs a user gesture to enable sound cuz the browser blocks it).

Added sound effects for all big actions:

  • Block placement, block release, and wrong placement.
  • Button clicks and new game.
  • Block explosion for each block that breaks.
  • Game over event.
  • Sound for the new best score trophy on the game over screen (delayed).

New particle effect for block breaking.

  • Cleared blocks now break in a wave, with each block exploding in sequence and spawning jewel particles.
  • As before, the color of the explosion and particles is always the same color of the shape just placed.

UI improvements:

  • Prevented accidental button clicks on the game over dialog by not registering clicks while the dialog is animating in.

Some challenges faced and their solution:

  • Basically browsers block audio until a user interacts with the page. I solved by listening for the first user gesture (click/tap) and unlocking the audio context at that moment.

  • For the particle animation i needed to keep game logic instant while playing out the visual and sound. I solved by separating the animation layer from the game state, so the grid clears instantly for logic but visuals and sounds play out in a wave.

  • When many blocks explode at once, playing the sound for each was noisy and annoying. Fixed by only playing the explosion sound once per plsced shape.

  • Players could trigger buttons on the game over screen if they were still holding the mouse. Fixed by ignoring clicks until the dialog animation is complete.

0
Whatsup

Soooo long story short i added float animations flooshed.

In this devlog i built a floating text system, Heres a description of hwo it works:
Every time a piece is dropped, a +Score floats up right from where the piece was placed.
Clearing multiple lines (or extending a combo) now shows a random word (“Good”, “Great”, “Amazing”, “Perfect”) to the center of the screen, with logic to make sure the same word never repeats twice in a row.
Hitting back to back line clears now triggers a gold “Combo x” pop in animation right below the sprite text to let players know they are on a streak. aga-dance

0
Whatsup

Improved the scoring and game over dialog. Added a count up animation for the scoring. When its game over the dialog pops up with a fade animation, then it initiates the score count up animation, then at last if you have a new best it will display the new best trophy.

0
Whatsup

Added a burst animation when you clear a line. Its like the confetti animation just with jewels. It spawns 4-6 jewels on each cell in the line thats cleared. The particles gets the color of the shape you just placed. So much cooler now sunglassesblob

0
Whatsup

Just added a “animation” which isnt really an animation lol, but just adjusting the Y position of the buttons when you click them so it looks like it actually presses it. I also increased the hitbox of the draggable shapes so its easier to actually drag them. Before you had to perfectly press on the shape, now you can press a little outside it to drag it.

0
Whatsup

Summary of what i have added today.

Game States: Cleaned up how the game tracks whats going on. It now use actual states like PLAYING and GAME_OVER instead of just true/false flags. This makes it way easier to pause or show menus without things breaking aswell as making it easier to scale further.

Button Clicks: Created a brand new file (uiEvents.js) just to handle UI buttons and their functions.

Fixed Button Hitboxes: The “New Game” and “Share” buttons were drawn sideways on the screen (cuz they appear sideways in the spritesheets), which messed up where you could click them. I fixed the math so the click areas match the flipped width and height.

Restart Button: The “New Game” button actually works now. It clears the grid, resets the score, hands out new pieces, and starts a new game without you having to refresh the page.

Share Button: Opens the web share for your device so you can share your score. It wont show the actual web share opening in the screen recording tho, because it hides it.

This is basically the same state and click system i used in my Flappy Bird project. It makes it easier to add new buttons and their click events later on aswell as choosing what functions run in which state. It worked so well i decided to use it again. hehee

0
Whatsup

I created the game over screen. Idk how this took so long, the time just went by. Biggest pain is always the layout cuz you have to get it right with the sizes and coordinates. Anyways i thought it looks nice like this. The play button and share button doesnt have any functions as of this moment but will be added soon.

Attachment
0
Whatsup

The scoring system is finished aga-dance. Might be changed later on but this is what i have now:

Points for Placing: You now get base points just for dropping shapes onto the board (1 point per square in the block).

Bigger Multi Line Bonuses: Clearing multiple lines at once now gives a bigger point boost, instead of just a flat rate.

Infinite Combos: Your multiplier will grow endlessly as long as you keep your streak alive, allowing for big scores.

Three turn streak breaker: You have up to 3 turns to clear a line. if you place 3 blocks without a clear, your streak resets to zero.

Saved High Scores: Your high score is saved to your browser.
Basically, the game now rewards multi line clears and long, uninterrupted streaks.yahoo-applause

0
Whatsup

i added UI elements for the score and best score. They are currently only for visuals as i havent properly created the scoring functionality yet, but im working on that right now. The painful thing was placing these correclty because some sizes caused blurriness, so i had to make adjustments. I also had to change some pixels on the spritesheet using piskelapp.com. After all that i finally ended up with a semi finsiehd scoring UI. Lastly i polished the grid by adjusting its positions and sizes so its more centered aswell as adding a background. thumbs-up

Attachment
0
Whatsup

This devlog doesnt contain any visual changes, only code cleanup and better asset management.
Basically my code was a bit cluttered with assets and layouts scattered everywhere so i decided to clean it up a bit by separating asset loading, layout and grid positions. This makes it easier to add more UI elements in the future without alot of problems, and modify them in a more readable manner.
My laptop is alright now so heres a video of the game in its current state.

0
Whatsup

I thought the UI looked a bit plain so i found game assets from freegameassets.net and updated the ui with sprites. It isnt fully implemented yet with some UI inconsistencies plus some values are hard coded. This and the performance will be improved later on.

Attachment
0
Whatsup

This took longer than needed. I basically tried mimicking the hand generation algorithm used in the real game and tried and rewrote many times to make it perfect which i am incapable of as of this moment aww. I tried different algorithms, and could never find the right one. So i have finally landed on one i deem acceptable, and maybe overly complicated, but its alright for now. I added simple scoring and combo system that will improve later. Heres a short summary of the algorithm (which definetly has flaws):

The game needs to give you 3 pieces every round that are playable but not random garbage.

  1. Read the board. Count how full it is (fill%) and find rows/columns that are 1-2 cells away from clearing.

  2. Pick piece categories using weighted dice. Empty board? Mostly chunks and fillers to build up. Half full? Mix in line pieces. Nearly full? Spam small helpers so you dont die. The weights shift gradually.

  3. Generate candidates. Roll 3 pieces from those weights, check each one individually fits somewhere on the board. If yes, score the hand by simulating “what if the player placed each piece in its best spot?” then count how many lines would clear and how many lines get pushed to 6-7/8 filled (setup moves).

  4. Pick from the top 3. Do this up to 60 times, keep the 8 best hands, then randomly pick from the top 3.

its not perfect but its better than the complete random algorithm i had before. Also my old laptop gave up on me a little so i couldnt take a screenrecording, but atleast theres a picture pf .

Attachment
0
Whatsup

Created more shapes like diffrerent rotation of the T, L, Z shapes and a new diagonal shape aswell as vertical lines.

Attachment
0
Whatsup

I added a highlight feature that shows which rows and columns will be cleared when placing a block.

First i created a temporary grid simulation by copying the current grid and applying the ghost block placement to it. Then i checked which rows and columns would be completely full using the same logic as the clearing function.

Then i created a separate highlightLine function that draws full color blocks on any cell thats part of a clearable row or column.

0
Whatsup

phewwwww this took a long time hellmo . But my big brain did it big-brain

I made the game playable. Added recursive hand validation to ensure all pieces are placeable. Also separated the hand logic from blocks.js where it was previously.

Created a function that recursively checks if all 3 pieces in a generated hand can be placed on the grid in some sequence. The function:

  • Simulates placement of each piece at every valid position
  • Recursively validates remaining pieces can fit on the updated grid
  • Ensures generated hands are always solvable (player must find the strategy)
  • Triggers game over only when no valid 3-piece combination exists

Right now game over is displayed in the console and nothing happens after. I havent tested every possible bug that can be made, but hopefully there wont be any. thumbs-up

0
Whatsup

Added a function that clears the rows and columns when all cells are filled. Also just realized i havent shown mobile version so heres a video of the game in its current state on IOS Safari. yahoo-applause

0
Whatsup

In this devlog i created a ghost preview of where the shape is about to be placed on the grid. Lowkey didnt know what to do when starting cuz i have never done this, but then i realized the calculation is more or less the same as placing it on the grid, but instead of placing it you just draw it with an offset. big-brain

0
Whatsup

Solved the problem from previous devlog. Basically when dragging and dropping block shapes onto the grid, certain shapes would place one cell off from where the mouse cursor indicated. Some shapes placed correctly while others didnt. Some would also overlap other blocks already on the grid. noo

It had two problems: hmm_sus

  1. When picking up a shape, the code immediately centered it on the cursor, causing a “jump” effect. The original click position relative to the shapes center wasnt preserved during dragging.

  2. The pointerup handler calculated grid placement from the shapes center using Math.floor(shapeSize / 2) offsets. This created inconsistent results. Even sized shapes (2x2, 4x1) center falls between grid cells. Odd sized shapes (3x3, 1x5) center falls on a grid cell using the same offset calculation for both caused the 1 cell placement error. Solved this by calculating from top left instead of center and then rounding with Math.round() giving it a better “snapping” to grud behaviour.

The overlap issue was a because of this misalignment. the shapes would calculate their grid position incorrectly which woulsd bypass the isValid checks intended cell allowing placement on cells that were already filled. sobdissolve

Yeah anyways other than that bloody issue, i added a feature that removes placed shapes from the hand and generates a new hand when the current one runs out.hehehehaw

1

Comments

Whatsup
Whatsup about 2 months ago

Maybe too many emojis think

Whatsup

The shapes are now placable on the grid by dragging them. They should not be able to be placed if the shape is outside the grid or if the shape overlaps other blocks. As you can see in the video it still places the shape as long as the start position is inside the grid. It should only place when the whole shape fits. I will fix this next time.

0
Whatsup

Finally finished the dragging function happi it works on both mobile and pc. On mobile the browser started to scroll when dragging the pieces so i used “touch-action: none;” in the css for the Canvas element which solved the problem. I also separated shapes, game config etc into own files so they are better managed.thumbs-up

0
Whatsup

Just wanted to make a quick devlog. I have made it possible to create a hand of three shapes that generates randomly. Currently im working on making them draggable but that will come in the next devlog so all this time didnt just go into placing them lol.

Attachment
0
Whatsup

Worked on the shapes and a function to place them on the grid. Heres a little showcase of some of the shapes like S shape, Z shape, Big small L shapes, corner shapes, squares etc placed on the grid using the new function. You can also look at the console to see how the grid updates. thumbs-up

Attachment
0
Whatsup

created the blocks and the glossy effect which was a little more difficult than expected. Also adjusted grid and background color.

Attachment
0
Whatsup

Started with the setup of the canvas. Then i created the grid layout for the game. Might change later as perfect styling isnt the priority yet.

Attachment
0