“Hundreds” Flash game ported to HTML5 using Phaser and ARCADE physics

Read all posts about "" game

My “Hundreds” tutorial series is dated back to 2013, a previous gaming era with Flash still on the run on desktop computers.

Time passed, Flash died and hyper casual games now are mostly played in portrait mode.

So I kept the original concept of making circles grow while avoiding collisions, but I changed some rules:

1 – Circles do not collide, they tun on their own and simply overlap. Having circles colliding and bounce would make the game too unpredictable.

2 – Each circle is bound to a button with the same number.

3 – Tap and hold a button to make corresponding circle grow.

4 – Release the button to stop circle growth.

5 – If a growing circle overlaps any other circle, both circles get halved

6- You can make a circle grow only once.

Does it sound complicate? Have a try:

Tap and hold a button to make the corresponding circle grow. Release before it overlaps another circle.

What’s your best score?

The source code is a bit more than 100 lines, still uncommented because I need to add a couple more features, but easy to understand:

let game;
let gameOptions = {
    ballSpeed: 300,
    balls: 8,
    ballRadius: 50,
    growRate: 1
}
window.onload = function() {
    let gameConfig = {
        type: Phaser.AUTO,
        scale: {
            mode: Phaser.Scale.FIT,
            autoCenter: Phaser.Scale.CENTER_BOTH,
            parent: "thegame",
            width: 750,
            height: 1334
        },
        physics: {
            default: "arcade",
        },
        scene: playGame
    }
    game = new Phaser.Game(gameConfig);
    window.focus();
}
class playGame extends Phaser.Scene{
    constructor(){
        super("PlayGame");
    }
    preload(){
        this.load.image("ball", "ball.png");
        this.load.image("button", "button.png");
    }
    create(){
        this.physics.world.setBounds(0, 0, game.config.width, game.config.width);
        this.ballGroup = this.physics.add.group();
        this.ballArray = [];
        this.textArray = [];
        this.score = 0;
        let gameArea = new Phaser.Geom.Rectangle(0, 0, game.config.width, game.config.width);
        let buttonsPerRow = gameOptions.balls / 2;
        let buttonWidth = game.config.width / buttonsPerRow;
        this.buttonGroup = this.add.group();
        for(let i = 0; i < gameOptions.balls; i++){
            let randomPosition = Phaser.Geom.Rectangle.Random(gameArea);
            let directionVector = Phaser.Math.RandomXY(new Phaser.Math.Vector2, gameOptions.ballSpeed);
            let ball = this.ballGroup.create(randomPosition.x, randomPosition.y, "ball");
            this.ballArray.push(ball);
            ball.setCircle(256);
            ball.displayHeight = gameOptions.ballRadius;
            ball.displayWidth = gameOptions.ballRadius;
            ball.index = i;
            ball.setCollideWorldBounds(true);
            ball.setVelocity(directionVector.x, directionVector.y);
            ball.setBounce(1);
            let ballText = this.add.text(randomPosition.x, randomPosition.y, i, {
                fontFamily: "Arial",
                fontSize: 24,
                color: "#000000"
            });
            ballText.setOrigin(0.5, 0.5)
            this.textArray.push(ballText);
            let button = this.add.sprite(buttonWidth * (i % (gameOptions.balls / 2)), game.config.width + buttonWidth * Math.floor(i / (gameOptions.balls / 2)), "button");
            button.setOrigin(0, 0);
            button.index = i;
            button.displayWidth = buttonWidth;
            button.displayHeight = buttonWidth;
            this.buttonGroup.add(button);
            let buttonText = this.add.text(button.getBounds().centerX, button.getBounds().centerY, i, {
                fontFamily: "Arial",
                fontSize: 64,
                color: "#000000"
            });
            buttonText.setOrigin(0.5, 0.5)
        }
        this.ballToGrow = null
        this.scoreText = this.add.text(0, game.config.height, "Score: 0", {
            fontFamily: "Arial",
            fontSize: 64
        });
        this.scoreText.setOrigin(0, 1);
        this.input.on("pointerdown", this.startGrowing, this);
        this.input.on("pointerup", this.stopGrowing, this);
        this.physics.add.overlap(this.ballGroup, this.ballGroup, this.handleOverlap, null, this);
    }
    startGrowing(pointer){
        this.buttonGroup.getChildren().forEach(function(button){
            if(Phaser.Geom.Rectangle.Contains(button.getBounds(), pointer.x, pointer.y) && button.alpha == 1){
                button.alpha = 0.5;
                this.ballToGrow = button.index;
                this.ballArray[this.ballToGrow].body.onOverlap = true;
            }
        }, this);
    }
    stopGrowing(){
        this.ballToGrow = null;
    }
    handleOverlap(ball1, ball2){
        if(this.ballToGrow != null && (ball1.index == this.ballToGrow || ball2.index == this.ballToGrow)){
            this.cameras.main.flash();
            ball1.displayWidth = Math.max(ball1.displayWidth / 2, gameOptions.ballRadius);
            ball2.displayWidth = Math.max(ball1.displayWidth / 2, gameOptions.ballRadius)
            ball1.displayHeight = ball1.displayWidth ;
            ball2.displayHeight = ball2.displayWidth ;
            this.ballToGrow = null;
        }
    }
    update(){
        this.score = 0;
        for(let i = 0; i < gameOptions.balls; i++){
            this.textArray[i].x = this.ballArray[i].x;
            this.textArray[i].y = this.ballArray[i].y;
            this.score += this.ballArray[i].displayWidth - gameOptions.ballRadius;
        }
        this.scoreText.text = this.score;
        if(this.ballToGrow != null){
            console.log("grow")
            this.ballArray[this.ballToGrow].displayWidth += gameOptions.growRate;
            this.ballArray[this.ballToGrow].displayHeight += gameOptions.growRate;
        }
    }
}

This is actually a pretty new concept as there isn’t that much of the original “Hundreds” game, but I can see some potential in it, especially if you consider you can play with one thumb.

Download the source code.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stairs
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers