Neuroplay

by Nikitas01

HTML

<script src="https://braincomputer.io/development/assets/js/notifyObject-1.0.0.js"></script>
<script src="https://braincomputer.io/development/assets/js/neuroplay-1.0.0.js"></script>
<div style="background: url('https://i.imgur.com/o3mSLzk.png'); no-repeat; background-size; position: absolute; top: 0; left: 0; width: 100%; height: 100%;">
	<p style="color: white;">Режим игры:
		<select id="modesel">
			<option value="1">Концентрация</option>
			<option value="0">Медитация</option>
		</select>
	</p>
	<div id="inp" style="text-shadow: 2px 2px 3px #FFFFFF; color: black; text-align: center; position: absolute; left: 220px; top: 15px; font-size: 125%;"><strong>???</strong></div> <img src="https://i.imgur.com/HImYYw8.png" alt="" width="65" height="75" />
	<div id="day" style="color: black; text-align: center; position: absolute; left: 20px; top: 65px; font-size: 125%;">1</div>
	<div style="text-align: center; position: absolute; left: 10px; top: 88px; font-size: 70%;">Декабрь</div>
	<p><img style="margin: 135px 350px 160px 350px; position: absolute;" src="https://i.imgur.com/WDNjO4H.png" alt="" width="110" height="110" /><img id="tree" style="position: absolute; left: 376px; top: 240px; transform-origin: center bottom;" src="https://i.imgur.com/gFuPZMK.png" width="64" height="60" /><img id="ball1" style="position: absolute; left: 335px; top: 190px; visibility: hidden;" src="https://i.imgur.com/L2tzZKN.png" width="30" height="30" /><img id="ball2" style="position: absolute; left: 425px; top: 150px; visibility: hidden;" src="https://imgur.com/e3himGq.png" width="25" height="25" /><img id="ball3" style="position: absolute; left: 395px; top: 225px; visibility: hidden;" src="https://i.imgur.com/2vWRVrn.png" width="30" height="30" /><img id="ball4" style="position: absolute; left: 380px; top: 90px; visibility: hidden;" src="https://i.imgur.com/f6TLR8D.png" width="35" height="35" /><img id="star" style="position: absolute; left: 380px; top: 5px; visibility: hidden;"...

JavaScript

var mode = 0;
var input = 0;
var pause = false;
var tree = null;
var calendar = null;
var win = null;

function start()
{
    tree = new Tree();
    setInterval(function() { if(!pause) tree.grow(input); }, 1000);
    
    calendar = new Calendar();
    setInterval(function() { if(!pause) calendar.proceed(); }, 2500);
    
    win = new WinScreen();
}

function tick()
{
    mode = $("#modesel").val();
    if(!pause) win.check();
}

function bci(npdata)
{
    input = getInput(npdata.concentration, npdata.meditation);
    tick();

  $("#inp").html(input + "%");
}

function getInput(con, med)
{
    var primArg = mode == 1 ? con : med;
    var secArg = mode == 1 ? med : con;
    var value = primArg - Math.floor(secArg * 0.2);
    return value < 0 ? 0 : value;
}

$(function() {
  start();
	var neuroplay = new NeuroplayConnector();
	neuroplay.connect();  
	neuroplay.on('bci', bci);
	setInterval(function() { if(!pause) neuroplay.send('bci'); }, 600);
});

class Tree
{
    constructor()
    {
        this.growth = 0;
        this.size = 64;
        this.stage = 1;
        this.decorations = [
  			new TreeDecor("ball1", 75, 80),
  			new TreeDecor("ball2", 80, 85),
  			new TreeDecor("ball3", 85, 90),
        new TreeDecor("ball4", 90, 95),
        new TreeDecor("star", 95, 100),
				];
    }

    grow(value)
    {
        value = Math.floor(value * 0.02);

        this.growth += value;
        if (this.growth >= 75)
        {
        		this.decorate(this.growth);
        }
        else
       	{
        		this.increaseSize(value);
        }
    }
    
    decorate(growth)
   	{		
				for (let i = 0; i < this.decorations.length; i++)
        {
  					this.decorations[i].put(growth);
				}
    }

    increaseSize(value)
    {
        this.size += value * 3;
        var t = $('#tree');
        t.width(this.size);
        t.height(this.size - 4);
        t.css("left", 376 - this.growth * 1.5);
        t.css('top', '-=' + value * 3 + 'px');

        if (this.growth >= 10 &&...