Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about vvvvvv game, Game development, HTML5, Javascript and Phaser.

For its 10 year anniversay, the incredible VVVVVV game goes open source on GitHub.

This is an incredible gift Terry Cavanagh made to all developers, and while you can find the complete source code both for desktop and mobile versions on his GitHub page, I am publishing a little HTML5 prototype built with Phaser which replicates the way you control VVVVVV character.

As you should know, in VVVVVV you can only move left or right, but you can switch the gravity, giving a great twist to this platformer which is much more than a Jet Set Willy clone.

Have a look at the prototype, which is using the same map I created for Yeah Bunny tutorial series, using Tiled:

Move left and right with LEFT and RIGHT arrow keys, switch gravity with SPACEBAR, but once you switch the gravity, you’ll have to wait for the character to land on the ground – or on the ceiling – to be able to switch gravity once more.

The code needed to build this prototype is one of the easiest ever published in the blog, thanks obviously to the power of Phaser which these days has also be updated to version 3.22

let game;
let gameOptions = {
    playerGravity: 1200,
    playerSpeed: 200
}
window.onload = function() {
    var gameConfig = {
        type: Phaser.AUTO,
        backgroundColor: 0x444444,
        scale: {
            mode: Phaser.Scale.FIT,
            autoCenter: Phaser.Scale.CENTER_BOTH,
            parent: "thegame",
            width: 640,
            height: 480
        },
        physics: {
            default: "arcade",
            arcade: {
                gravity: {
                    y: 0
                }
            }
        },
        scene: playGame
    }
    game = new Phaser.Game(gameConfig);
}
class playGame extends Phaser.Scene{
    constructor(){
        super("PlayGame");
    }
    preload(){
        this.load.tilemapTiledJSON("level", "level.json");
        this.load.image("tile", "tile.png");
        this.load.image("hero", "hero.png");
    }
    create(){
        this.gravityDirection = 1;
        this.map = this.make.tilemap({
            key: "level"
        });
        let tile = this.map.addTilesetImage("tileset01", "tile");
        this.map.setCollision(1);
        this.layer = this.map.createStaticLayer("layer01", tile);
        this.hero = this.physics.add.sprite(300, 376, "hero");
        this.hero.body.gravity.y = gameOptions.playerGravity;
        this.canFlipGravity = true;
        this.cameras.main.setBounds(0, 0, 1920, 1440);
        this.cameras.main.startFollow(this.hero);
        this.cursors = this.input.keyboard.createCursorKeys();
        let spaceKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
        spaceKey.on("down", function(key, event){
            if(this.canFlipGravity){
                this.hero.body.gravity.y *= -1;
                this.canFlipGravity = false;
                this.hero.flipY = this.hero.body.gravity.y < 0
            }
        }, this);
    }
    update(){
        this.hero.body.velocity.y = Phaser.Math.Clamp(this.hero.body.velocity.y, -800, 800);
        this.hero.body.velocity.x = this.cursors.left.isDown ? (this.cursors.right.isDown ? 0 : -1 * gameOptions.playerSpeed) : (this.cursors.right.isDown ? gameOptions.playerSpeed : 0);
        this.hero.flipX = this.hero.body.velocity.x == 0 ? this.hero.flipX : (this.hero.body.velocity.x > 0 ? false : true);
        this.physics.world.collide(this.hero, this.layer, function(hero, layer){
            if(hero.body.blocked.down || hero.body.blocked.up){
                this.canFlipGravity = true;
            }
        }, null, this);
    }
}

And we were able to build a little tribute to VVVVVV game in just 70 lines of code. Big kudos to Terry for sharing his work, and download the source code.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.