├── LICENSE
├── README.markdown
├── faces
├── addy.jpeg
├── passy.jpeg
└── stephen.jpeg
├── game.js
├── index.html
└── sindre.jpg
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # Sindre's Birthday Bash 2015
2 |
3 | https://passy.github.io/sindrebday
4 |
5 | ## Credits
6 |
7 | - Original Game: [chris-creditdesign](http://codepen.io/chris-creditdesign/pen/emKQwY)
8 | - Spaces and Bugs: [Pascal](https://github.com/passy)
9 | - Graphics and Codes: [Addy](https://github.com/addyosmani)
10 | - Rainbows and Tabs: [Addy](https://github.com/stephenplusplus)
11 |
--------------------------------------------------------------------------------
/faces/addy.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/passy/sindrebday/ada2e23389a73137eb7a6939b3e3268358a74326/faces/addy.jpeg
--------------------------------------------------------------------------------
/faces/passy.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/passy/sindrebday/ada2e23389a73137eb7a6939b3e3268358a74326/faces/passy.jpeg
--------------------------------------------------------------------------------
/faces/stephen.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/passy/sindrebday/ada2e23389a73137eb7a6939b3e3268358a74326/faces/stephen.jpeg
--------------------------------------------------------------------------------
/game.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | Copyright (c) 2015 by chris-creditdesign (http://codepen.io/chris-creditdesign/pen/emKQwY)
5 |
6 | With modifications from the TasteJS team (Addy, Stephen, Passy). https://github.com/tastejs
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 | */
14 |
15 | var scene;
16 | var cube;
17 | var camera;
18 | var renderer;
19 | var clock;
20 | var holder;
21 | var intersects;
22 | var particles = [];
23 | var level = 1;
24 | var totalLevels = 1;
25 | var score = 0;
26 | var totalTargets = 3;
27 | var speed = 0.01;
28 | var complete = false;
29 | var comments = ['Easy', 'Tricky', 'Almost there'];
30 | var myLevel = document.getElementById('level');
31 | var myScore = document.getElementById('score');
32 | var intro = document.getElementById('intro');
33 | var faces = ['passy', 'addy', 'stephen']
34 | .map(function(o) {
35 | return 'faces/' + o + '.jpeg';
36 | }).map(function(o) {
37 | var texture = new THREE.ImageUtils.loadTexture(o);
38 | texture.wrapS = THREE.RepeatWrapping;
39 | texture.wrapT = THREE.RepeatWrapping;
40 | texture.name = o;
41 | return texture;
42 | });
43 |
44 | var raycaster = new THREE.Raycaster();
45 | var mouse = new THREE.Vector2();
46 |
47 | function myScene() {
48 | scene = new THREE.Scene();
49 | var light = new THREE.AmbientLight(0xffffff);
50 | var width = window.innerWidth;
51 | var height = window.innerHeight;
52 | camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
53 | camera.position.z = 18;
54 |
55 | renderer = new THREE.WebGLRenderer({
56 | antialias: true,
57 | alpha: true
58 | });
59 | renderer.setSize(width, height);
60 | document.getElementById('webgl-container').appendChild(renderer.domElement);
61 | clock = new THREE.Clock();
62 |
63 | var sLight = new THREE.SpotLight(0xffffff);
64 | sLight.position.set(-100, 100, 100);
65 | scene.add(sLight);
66 |
67 | var aLight = new THREE.AmbientLight(0xffffff);
68 | scene.add(aLight);
69 | }
70 |
71 | function spinner() {
72 | var geometry = new THREE.BoxGeometry(1, 1, 1);
73 | var material = new THREE.MeshPhongMaterial({
74 | color: 'hotpink',
75 | ambient: 'hotpink'
76 | });
77 |
78 | var cube = new THREE.Mesh(geometry, material);
79 | cube.position.x = 10;
80 | var spinner = new THREE.Object3D();
81 | spinner.rotation.x = 6;
82 |
83 | spinner.add(cube);
84 | scene.add(spinner);
85 | }
86 |
87 | function addHolder() {
88 | holder = new THREE.Object3D();
89 | holder.name = 'holder'
90 |
91 | for (var i = 0; i < totalTargets; i++) {
92 | var ranCol = new THREE.Color();
93 | ranCol.setRGB(Math.random(), Math.random(), Math.random());
94 |
95 | var geometry = new THREE.BoxGeometry(2, 2, 2);
96 | var material = new THREE.MeshPhongMaterial({
97 | map: faces[i]
98 | });
99 |
100 | var cube = new THREE.Mesh(geometry, material);
101 | cube.position.x = i * 5;
102 | cube.name = 'cubeName' + i;
103 |
104 | var spinner = new THREE.Object3D();
105 | spinner.rotation.x = i * 2.5 * Math.PI;
106 | spinner.name = 'spinnerName' + i;
107 |
108 | spinner.add(cube);
109 | holder.add(spinner);
110 | };
111 | scene.add(holder);
112 | }
113 |
114 | function addExplosion(point) {
115 | var timeNow = clock.getElapsedTime();
116 |
117 | for (var i = 0; i < 4; i++) {
118 | var geometry = new THREE.BoxGeometry(1, 1, 1);
119 | var material = new THREE.MeshBasicMaterial({
120 | color: 0x999999
121 | });
122 | var part = new THREE.Mesh(geometry, material);
123 | part.position.x = point.x;
124 | part.position.y = point.y;
125 | part.position.z = point.z;
126 | part.name = 'part' + i;
127 | part.birthDay = timeNow;
128 | scene.add(part);
129 | particles.push(part);
130 | };
131 | }
132 |
133 | function animate() {
134 | requestAnimationFrame(animate);
135 | render();
136 | }
137 |
138 | function render() {
139 |
140 | holder.children.forEach(function(elem, index, array) {
141 | elem.rotation.y += (speed * (6 - index));
142 | elem.children[0].rotation.x += 0.01;
143 | elem.children[0].rotation.y += 0.01;
144 | });
145 |
146 | if (particles.length > 0) {
147 | particles.forEach(function(elem, index, array) {
148 | switch (elem.name) {
149 | case 'part0':
150 | elem.position.x += 1;
151 | break;
152 | case 'part1':
153 | elem.position.x -= 1;
154 | break;
155 | case 'part2':
156 | elem.position.y += 1;
157 | break;
158 | case 'part3':
159 | elem.position.y -= 1;
160 | break;
161 | default:
162 | break;
163 | }
164 |
165 | if (elem.birthDay - clock.getElapsedTime() < -1) {
166 | scene.remove(elem);
167 | particles.splice(index, 1);
168 | }
169 | })
170 |
171 | };
172 |
173 | renderer.render(scene, camera);
174 | }
175 |
176 | function onDocumentMouseDown(event) {
177 | event.preventDefault();
178 |
179 | if (complete) {
180 | return;
181 | }
182 |
183 | // calculate mouse position in normalized device coordinates
184 | // (-1 to +1) for both components
185 | mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
186 | mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
187 |
188 | // update the picking ray with the camera and mouse position
189 | raycaster.setFromCamera(mouse, camera);
190 |
191 | if (score < totalTargets) {
192 | holder.children.forEach(function(elem, index, array) {
193 | intersects = raycaster.intersectObjects(elem.children);
194 | if (intersects.length > 0 && intersects[0].object.visible) {
195 | intersects[0].object.visible = false;
196 |
197 | addExplosion(intersects[0].point);
198 | score += 1;
199 |
200 | if (score < totalTargets) {
201 | myScore.innerHTML = 'HIT! Score: ' + score + '/' + totalTargets;
202 | } else {
203 | complete = true;
204 |
205 | if (level < totalLevels) {
206 | myScore.innerHTML = 'You got \'em all! Click the screen for level ' + (level + 1) + '.';
207 | } else {
208 | // OMG, please make this prettier!
209 | myScore.innerHTML = 'You win! Happy Birthday, Sindre! ';
210 | intro.hidden = true;
211 | }
212 | };
213 | }
214 | });
215 | }
216 | }
217 |
218 | function restartScene() {
219 | myScore.innerHTML = '';
220 | intro.hidden = false;
221 |
222 | if (level < totalLevels) {
223 | speed += 0.005;
224 | totalTargets += 1;
225 | level += 1;
226 | } else {
227 | speed = 0.01;
228 | totalTargets = 3;
229 | level = 1;
230 | }
231 |
232 | myLevel.innerText = 'Sindre Birthday Bash'
233 | scene.remove(holder);
234 | addHolder();
235 | }
236 |
237 | document.getElementById('webgl-container').addEventListener('mousedown', onDocumentMouseDown, false);
238 |
239 | function onWindowResize() {
240 |
241 | camera.aspect = window.innerWidth / window.innerHeight;
242 | camera.updateProjectionMatrix();
243 |
244 | renderer.setSize(window.innerWidth, window.innerHeight);
245 |
246 | render();
247 | }
248 |
249 | window.onload = function() {
250 | myLevel.innerText = 'Sindre Birthday Bash'
251 | myScene();
252 | addHolder();
253 | animate();
254 |
255 | window.addEventListener('resize', onWindowResize, false);
256 | };
257 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
It was Sindre's Birthday! You can still hit the boxes!
52 | 53 |