summaryrefslogtreecommitdiff
path: root/konami/js/main.js
blob: 2933594d48708dced14fdd13a9560344db57435f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// LOADER ANIMATION
$(window).on("load", function () {
    console.log("UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, B, A")
    console.log("Biff, Marty, Emmett, Goldie")
    console.log("pie, ufo, walk, cool, balloon, hangover, kirby, no, onmyway, haters, board, snorlax, fly, earth, thankyou, swim, penguin, handsome, tank, jump, winner, fox, mario, joker, rabbit, piggy, psyduck, dragon, salamander, airguitar, pikachu, bravo, ghost, britney, pikarun, catrun, koggy, sonic, doggy, spongebob, gun, money, bird, piqiu, lol, ohhh, nyancat")
})

// SCROLLING TITLE
var space = " ";
var speed = "60";
var pos = 0;
var msg = "// s1n.ical // Landing Page ";

function Scroll() {
    document.title = msg.substring(pos, msg.length) + space + msg.substring(0, pos);
    pos++;
    if (pos > msg.length) pos = 0;
    window.setTimeout("Scroll()", speed);
}
Scroll();

// KONAMI CODE FOR TOASTY

// a key map of allowed keys
var allowedKeys = {
    37: 'left',
    38: 'up',
    39: 'right',
    40: 'down',
    65: 'a',
    66: 'b'
};

// the 'official' Konami Code sequence
var konamiCode = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a'];

// a variable to remember the 'position' the user has reached so far.
var konamiCodePosition = 0;

// add keydown event listener
document.addEventListener('keydown', function (e) {
    // get the value of the key code from the key map
    var key = allowedKeys[e.keyCode];
    // get the value of the required key from the konami code
    var requiredKey = konamiCode[konamiCodePosition];

    // compare the key with the required key
    if (key == requiredKey) {

        // move to the next key in the konami code sequence
        konamiCodePosition++;

        // if the last key is reached, activate cheats
        if (konamiCodePosition == konamiCode.length) {
            activateCheats();
            konamiCodePosition = 0;
        }
    } else {
        konamiCodePosition = 0;
    }
});

function activateCheats() {

    var audio = new Audio('https://s3-eu-west-1.amazonaws.com/wdildnproject2/toasty.mp3');
    audio.play();

    $('.toasty').addClass('animateIn');
    setTimeout(function () {
        $('.toasty').removeClass('animateIn');
    }, 3500);
}

var TxtRotate = function (el, toRotate, period) {
    this.toRotate = toRotate;
    this.el = el;
    this.loopNum = 0;
    this.period = parseInt(period, 10) || 2000;
    this.txt = '';
    this.tick();
    this.isDeleting = false;
};

TxtRotate.prototype.tick = function () {
    var i = this.loopNum % this.toRotate.length;
    var fullTxt = this.toRotate[i];

    if (this.isDeleting) {
        this.txt = fullTxt.substring(0, this.txt.length - 1);
    } else {
        this.txt = fullTxt.substring(0, this.txt.length + 1);
    }

    this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';

    var that = this;
    var delta = 300 - Math.random() * 100;


    setTimeout(function () {
        that.tick();
    }, delta);
};

window.onload = function () {
    var elements = document.getElementsByClassName('txt-rotate');
    for (var i = 0; i < elements.length; i++) {
        var toRotate = elements[i].getAttribute('data-rotate');
        var period = elements[i].getAttribute('data-period');
        if (toRotate) {
            new TxtRotate(elements[i], JSON.parse(toRotate), period);
        }
    }
};

// BIFF, MARTY, EMMETT, GOLDIE

// give $ to jQuery
(function ($) {

    /**==============================================================
         * BTTF CHARACTER EASTER EGGS
         * ==============================================================
         */
    var characters = {};
    var pressedKeys = [];

	/**
	 * Plays the audio clip for a specific easter egg character
	 * @param  {string} character name of character
	 */
    function playAudio(character) {
        setTimeout(function () {
            characters[character].audioFile.play();
            setTimeout(function () {
                toggleShowChar(character);
                updateEggs();
            }, characters[character].audioLength);
        }, 300);
    }

	/**
	 * Toggles the display of an easter egg character
	 * @param  {string} character character name
	 */
    function toggleShowChar(character) {
        $('body').toggleClass(characters[character].name + '-show');
    }

	/**
	 * Add characters' information once page loads
	 */
    $(document).ready(function () {
        characters = {
            'guessed': [],
            'marty': {
                'name': 'marty',
                'nameKeys': "77,65,82,84,89",
                'audioFile': $('audio.marty')[0],
                'audioLength': 1300,
            },
            'docbrown': {
                'name': 'docbrown',
                'nameKeys': "69,77,77,69,84,84",
                'audioFile': $('audio.docbrown')[0],
                'audioLength': 2500,
            },
            'biff': {
                'name': 'biff',
                'nameKeys': "66,73,70,70",
                'audioFile': $('audio.biff')[0],
                'audioLength': 1100,
            },
            'goldie': {
                'name': 'goldie',
                'nameKeys': "71,79,76,68,73,69",
                'audioFile': $('audio.goldie')[0],
                'audioLength': 4000,
            },
            'toasty': {
                'name': 'toasty',
                'nameKeys': "84,79,65,83,84,89",
            }
        };
    });

	/**
	 * Track character names being typed
	 */
    $(window).keydown(function (e) {

        pressedKeys.push(e.keyCode);

        // loop through characters
        for (var character in characters) {

            // if the "pressedKeys" contains the current character name
            if (pressedKeys.toString().indexOf(characters[character].nameKeys) >= 0) {

                // reset the pressedKeys array
                pressedKeys = [];

                // add "show" class to animate the character in
                toggleShowChar(character);

                if ($.inArray(character, characters.guessed) === -1) {
                    characters.guessed.push(character);
                }

                // wait a second and play the character's audio file
                playAudio(character);
            }
        }

        // reset pressedKeys at 50 keypresses to save memory
        if (pressedKeys.length > 500) { pressedKeys = []; }

    });

})(jQuery);