Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                .game
    .game_inner
        .game_inner__end
            %h1 Time up!
            %p Good Job. You helped Ed make $2000 today.
        .game_inner__overlay
        .game_inner__tutorial
            %h1 Good burger mini game.
          
            %p Make the customers order by clicking on the ingredients needed. 
            
            %p Click on the till when you are ready to serve. Get bonus points for getting the ingredients in the correct order.
            %button Begin
        .game_inner__elements
            .lettuce.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_lettuce.png'}
                .tooltip 
                    Lettuce
            .tomato.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_tomato.png'}
                .tooltip
                    Tomato
            .cheese.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_cheese.png'}
                .tooltip
                    Cheese
            .ketchup.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_ketchup.png'}
                .tooltip
                    Ketchup
            .mustard.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_mustard.png'}
                .tooltip
                    Mustard
            .patty.ingredient
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_patty.png'}
                .tooltip
                    Patty
            .burger
                %img.top{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_top.png'}
                %img.bottom{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_bottom.png'}
            .restart 
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_restart.png'}
            .till
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_till.png'}
                .tooltip
                    Serve
            .counter
            .ed
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_ed.png'}
            .car
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_car.png'}
            .game_inner__result
                Perfect
        .game_inner__order
            .message
                %p Welcome to Good Burger! 
                %p Home of the Good Burger! 
                %p Can I take your order?
            .order
        .game_inner__ui
            .game_inner__timer
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_timer.png'}
                %span 90
            .game_inner__score
                %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_score.png'}
                %span $0
 
            
%canvas.grain
              
            
!

CSS

              
                @font-face {
    font-family: 'organic';
    src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/organic_teabags-webfont.woff2') format('woff2'),
        url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/organic_teabags-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

* {
    box-sizing: border-box;    
}

img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

button {
    background: #e1d4cc;
    cursor: poinger;
    border: 4px solid #452c1e;
    padding: 10px 20px;
    font-family: 'organic';
    border-radius: 10px;
    font-size: 20px;
    outline: none;
}
body {
    background: #f7ea96;
    height: 100vh;
    font-family: 'organic';
    overflow: hidden;

    .grain {
        position: absolute;
        top: 0;
        left: 0;
        pointer-events: none;
    }

    & .game {
        position: absolute;
        left:0;
        right: 0;
        margin: auto;
        height: 100vh;


        &_inner {
            &__overlay {
                position: fixed;
                width: 100%;
                height: 100vh;
                z-index: 9;
                background: black;
                opacity: 0.7;
                top: 0;
            }
            
            &__end {
               display: none; 
            }
            
            &__tutorial,
            &__end {
                border: 4px solid #452c1e;
                padding: 30px;
                background: white;
                position: absolute;
                left: 0;
                right: 0;
                z-index: 10;
                width: 400px;
                top: 50%;
                transform: translatey(-50%);
                margin: auto;
                border-radius: 20px;

                h1 {
                    margin: 0;
                }

                p {
                    font-size: 24px;
                }

                button {

                }
            }
            &__order {
                & .order {
                    position: absolute;
                    left: 0;
                    right: -930px;
                    top: 50%;
                    transform: translateY(calc(-50% + 30px));
                    margin: auto;
                    width: 180px;
                    background: #cef5eb;
                    border: 4px solid #3b2314;
                    border-radius: 14px;
                    padding: 50px 20px 20px 20px;
                    font-size: 20px;

                    span {
                        width: 12px;
                        height: 12px;
                        display: block;
                        float: left;
                        margin-right: 10px;
                        border-radius: 4px;
                        border: 2px solid black;
                        top:8px;
                        position: relative;

                    }

                    .cheese {
                        background: yellow;
                    }

                    .lettuce {
                        background: green;
                    }

                    .patty {
                        background: brown;
                    }

                    .ketchup {
                        background: red;
                    }

                    .mustard {
                        background: orange
                    }

                    .tomato {
                        background: red
                    }
                }

                & .message {
                    position: absolute;
                    left: 0;
                    right: -830px;
                    top: 50%;
                    -webkit-transform: translateY(calc(-50% + 30px));
                    transform: translateY(calc(-50% + -108px));
                    margin: auto;
                    width: 210px;
                    z-index: 2;
                    background: #ffffff;
                    border: 4px solid #3b2314;
                    border-radius: 14px;
                    padding: 20px;
                    font-size: 20px;
                }

                p {
                    margin: 0;
                }
            }

            &__result {
                position: absolute;
                width: 1000px;
                display: none;
                background: white;
                left: -50px;
                font-size: 50px;
                right: 0;
                top: 50%;
                transform: translateY(-50%) rotate(-4deg);
                margin: auto;
                padding: 20px;
                text-align: center;
            }

            &__ui {
                position: absolute;
                left: 0;
                right: -330px;
                top: 50%;
                transform: translateY(calc(-50% + -300px));
                margin: auto;
                width: 310px;
                background: #fff;
                border: 4px solid #3b2314;
                border-radius: 84px;
                padding: 30px;

                .game_inner__timer {
                    position: relative;
                    top:-2px;
                    margin-left: 4px;
                    img {
                        position: relative;
                        top: 6px;
                    }    
                }

                .game_inner__score {
                    position: relative;
                    top:-1px;
                    img {
                        position: relative;
                        top: 6px;
                    }    
                }

                div {
                    float: left;
                    margin-right: 20px;
                    font-size: 30px;
                }
            }

            &__elements {
                background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bg.png');
                overflow: hidden;
                width: 900px;
                background-position: 10px -164px;
                background-size: 1000px;
                height: 600px;
                border: 4px solid #3b2314;
                position: absolute;
                left:0;
                right: 0;
                margin: auto;
                top: 50%;
                border-radius: 1000px;
                transform: translateY(-50%);

                @media only screen and (max-width: 1000px) {
                    border-radius:0;
                    transform: translateY(-50%) scale(0.8);
                    width: auto;


                }

                @media only screen and (max-width: 800px) {
                    border-radius:0;
                    transform: translateY(-50%) scale(0.7);
                    width: auto;


                }

                div {
                    cursor: pointer;

                    &:hover {
                        & > .tooltip {
                            opacity: 1;
                            bottom: -16px;
                        }
                    }

                    & .tooltip {
                        background: white;
                        position: absolute;
                        transition: all 0.3s;
                        width: 100px;
                        z-index: 23;
                        opacity: 0;
                        padding: 10px 28px;
                        border-radius: 30px;
                        pointer-events: none;
                        color: #3b2314;
                        border: 4px solid #3b2314;
                        bottom: -26px;
                        font-size: 18px;
                        left: 0;
                        text-align: center;
                        right: 0;
                        margin: auto;

                    }
                }

                & .till {
                    position: absolute;
                    right: -50px;
                    bottom: 108px;

                    .tooltip {
                        right: 120px;
                    }
                }

                & .counter {
                    background: #b96544;
                    width: 1080px;
                    height: 280px;
                    border: 4px solid #382920;
                    position: absolute;
                    right: -80px;
                    z-index: 0;
                    bottom: -158px;
                }

                & .patty {
                    position: absolute;
                    bottom: 114px;
                    left: -30px;
                }

                & .mustard {
                    position: absolute;
                    bottom: 114px;
                    left: 660px;
                }

                & .ed {
                    position: absolute;
                    left: 370px;
                    bottom: 83px;
                    z-index: -1;
                }

                & .car {
                    position: absolute;
                    transition: all 0.3s;
                    bottom: -90px;
                }

                & .ketchup {
                    position: absolute;
                    bottom: 114px;
                    left: 590px;
                }

                & .restart {
                    position: absolute;
                    bottom: 84px;
                    transform-origin: 33px 33px;
                    left: 470px;
                    transition: all 0.3s;
                    z-index: 2;
                    &:hover {
                        transform: rotate(360deg);
                    }
                }

                & .burger {
                    position: absolute;
                    left: 410px;
                    bottom: 130px;


                    img {
                        &.top,
                        &.bottom {
                            position: absolute;
                        }

                        &.bottom {
                            bottom: -12px;
                        }

                        &.top {
                            left: -3px;
                            top: -32px;
                        }
                    }

                    &_lettuce {
                        position: relative;
                        height: 6px;
                        left: -9px;
                    }

                    &_patty {
                        position: relative;
                        height: 14px;
                        left: -2px;
                    }

                    &_cheese {
                        position: relative;
                        height: 6px;
                        left: -4px;
                    }

                    &_tomato {
                        position: relative;
                        height: 9px;
                        left: -2px;
                    }

                    &_mustard {
                        position: relative;
                        height: 11px;
                        left: -5px;
                        //top: -3px;
                    }

                    &_ketchup {
                        position: relative;
                        height: 11px;
                        left: -5px;
                        //top: -3px;
                    }
                }

                & .tomato {
                    position: absolute;
                    bottom: 377px;
                    left: 215px;
                }

                & .lettuce {
                    position: absolute;
                    bottom: 377px;
                    left: 100px;
                }

                & .cheese {
                    position: absolute;
                    bottom: 377px;
                    left: -15px;
                }

            }
        }
    }
}
              
            
!

JS

              
                // Interactive container

const game = $('.game_inner__elements');

// Burger ingredients elements

const ingredients = game.find('div.ingredient');

var currentIngredients = new Array();

// Score element

const scoreElement = $('.game_inner__score span');
const scoreMax = 10;
const scoreMin = 7.50;

var score = 0;

var difficulty = 2;

// Round timer

var roundTime = 90;
const roundTimeElement = $('.game_inner__timer span');



// Till element

const till = game.find('.till');

// Burger element

const burger = game.find('.burger');

// Order element

const orderElement = $('.game_inner__order');

// Create burger stack

function createOrder(difficulty) {
    let order_ingredients = [
        'tomato',
        'lettuce',
        'cheese',
        'ketchup',
        'mustard',
        'patty'
    ];

    let burger_stack = [];

    for(let i = 0; i < difficulty; i++){
        let rand = Math.floor(Math.random() * Math.floor(order_ingredients.length));
        burger_stack.push(order_ingredients[rand]);
    }

    if($.inArray('patty', burger_stack) < 0){
        let rand = Math.floor(Math.random() * Math.floor(burger_stack.length - 1));
        burger_stack.splice(rand, 1, 'patty');   
    }

    burger_stack = {ingredients: burger_stack.join(',')};

    return burger_stack;
}

// Get order and display


function getOrder(order) {
    let currentOrder = order.ingredients.split(',');
    orderElement.find('.order').append('<p>Yes, I would like...</p><br/>')
    currentOrder.forEach(function(ingredient) {
        orderElement.find('.order').append(`<p><span class="${ingredient}"></span> ${ingredient} </p>`);
    });
}

function nextOrder(size) {
    currentIngredients = new Array();
    setTimeout(function(){
        $('.car').css('left', '700px');
    },1)
    setTimeout(function(){
        $('.car').css('transition', 'all 0s');
        $('.car').css('left', '-700px');
    },300)

    setTimeout(function(){
        $('.car').css('transition', 'all 0.3s');
        $('.car').css('left', '0px');
    },1000)

    burger.fadeOut(function(){
        burger.html('<img class="top" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_top.png"><img class="bottom" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_bottom.png">');  
        burger.fadeIn()
    })

    orderElement.find('.order').fadeOut(function(){
        orderElement.find('.order').fadeIn();
        orderElement.find('.order').html('');
        newOrder = createOrder(size)
        getOrder(newOrder);
    });

}


$('.restart').click(function(){
    burger.fadeOut(function(){
        burger.html('<img class="top" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_top.png"><img class="bottom" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_bun_bottom.png">');  
        burger.fadeIn();
        currentIngredients = []
    })
})

nextOrder(difficulty);

// Bind ingredients click

ingredients.click(function() {
    let clickedIngredient = $(this).attr('class').split(' ')[0];

    let clickedIngredientEl = `<div class="burger_${clickedIngredient}">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/gb_burger_${clickedIngredient}.png"></div>`;

    add(clickedIngredient, clickedIngredientEl);
})

// Add ingredients to burger

function add(ingredient, ingredientEl) {

    burger.append(ingredientEl);
    currentIngredients.push(ingredient);
}


// Check if ingredients match the order

function checkIngredients(ingredients, order) {
    let a = ingredients.toString();
    let b = order.toString();

    if(a===b) {
        return 'Perfect';
    }

    let ingredientsAmt = ingredients.reduce(function(countMap, word) { countMap[word] = ++countMap[word] || 1; return countMap }, {});
    let orderAmt = order.reduce(function(countMap, word) { countMap[word] = ++countMap[word] || 1; return countMap }, {});
    let count = 0;

    for(let i in orderAmt) {
        if(typeof ingredientsAmt[i] !== "undefined" && orderAmt[i] === ingredientsAmt[i]) {
            count += orderAmt[i];
        }
        if(count == order.length) {
            return 'Not Bad';
        }
    }

    return 'No Good';
}

// Check order and get the next one when till is clicked

till.click(function() {
    let checkOrder = newOrder.ingredients.split(',');
    let result = checkIngredients(currentIngredients, checkOrder);

    if(result == 'Perfect') {

        score = score + scoreMax;
    }

    if(result == 'Not Bad') {
        score = score + scoreMin;    
    }
    $('.game_inner__result').fadeIn();
    $('.game_inner__result').html(result)

    setTimeout(function(){
        $('.game_inner__result').fadeOut();
    },300)

    scoreElement.html(`$${score}`);

    nextOrder(difficulty);
});

var gameStarted = false;

$('button').click(function(){
    gameStarted = true;
    $(this).parent().hide().prev().hide();
    roundTimer();
})

function roundTimer() {
    console.log(roundTime)

    setInterval(function() {
        if(roundTime > 1) {
            roundTime --;
            roundTimeElement.html(roundTime); 

            if(score > 10) {
                difficulty = 3
            }

            if(score > 30) {
                difficulty = 4
            }

            if(score > 70) {
                difficulty = 5
            }
            if(score > 120) {
                difficulty = 6
            }
            if(score > 170) {
                difficulty = 7
            }
        } else {
            $('.game_inner__end').show();
            $('.game_inner__overlay').show();
            $('.game_inner__end p').html(`Good Job. You helped Ed make $${score} today.`);

        }
    },1000);


}



'use strict';

///console.clear();

class Grain {
    constructor (el) {
        /**
     * Options
     * Increase the pattern size if visible pattern
     */
        this.patternSize = 150;
        this.patternScaleX = 1;
        this.patternScaleY = 1;
        this.patternRefreshInterval = 3; // 8
        this.patternAlpha = 28; // int between 0 and 255,

        /**
     * Create canvas
     */
        this.canvas = el;
        this.ctx = this.canvas.getContext('2d');
        this.ctx.scale(this.patternScaleX, this.patternScaleY);

        /**
     * Create a canvas that will be used to generate grain and used as a
     * pattern on the main canvas.
     */
        this.patternCanvas = document.createElement('canvas');
        this.patternCanvas.width = this.patternSize;
        this.patternCanvas.height = this.patternSize;
        this.patternCtx = this.patternCanvas.getContext('2d');
        this.patternData = this.patternCtx.createImageData(this.patternSize, this.patternSize);
        this.patternPixelDataLength = this.patternSize * this.patternSize * 4; // rgba = 4

        /**
     * Prebind prototype function, so later its easier to user
     */
        this.resize = this.resize.bind(this);
        this.loop = this.loop.bind(this);

        this.frame = 0;

        window.addEventListener('resize', this.resize);
        this.resize();

        window.requestAnimationFrame(this.loop);
    }

    resize () {
        this.canvas.width = window.innerWidth * devicePixelRatio;
        this.canvas.height = window.innerHeight * devicePixelRatio;
    }

    update () {
        const {patternPixelDataLength, patternData, patternAlpha, patternCtx} = this;

        // put a random shade of gray into every pixel of the pattern
        for (let i = 0; i < patternPixelDataLength; i += 4) {
            // const value = (Math.random() * 255) | 0;
            const value = Math.random() * 255;

            patternData.data[i] = value;
            patternData.data[i + 1] = value;
            patternData.data[i + 2] = value;
            patternData.data[i + 3] = patternAlpha;
        }

        patternCtx.putImageData(patternData, 0, 0);
    }

    draw () {
        const {ctx, patternCanvas, canvas, viewHeight} = this;
        const {width, height} = canvas;

        // clear canvas
        ctx.clearRect(0, 0, width, height);

        // fill the canvas using the pattern
        ctx.fillStyle = ctx.createPattern(patternCanvas, 'repeat');
        ctx.fillRect(0, 0, width, height);
    }

    loop () {
        // only update grain every n frames
        const shouldDraw = ++this.frame % this.patternRefreshInterval === 0;
        if (shouldDraw) {
            this.update();
            this.draw();
        }

        window.requestAnimationFrame(this.loop);
    }
}


/**
 * Initiate Grain
 */
const el = document.querySelector('.grain');
const grain = new Grain(el);

// Tut overlay
// Ending screen
              
            
!
999px

Console