-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
205 lines (152 loc) · 3.39 KB
/
sketch.js
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
var world, gift, g;
let jingle, blip;
var framectr =0;
var count = 0;
/*
You, and elf, accidentally dropped all your presents while on your sleigh... Click and move through the snow to collect all the
presents you dropped. Burgers are just a distraction- they are not harmful...or ARE they?
Collect TEN presents.
*/
function preload(){
jingle = loadSound("sounds/jingle.mp3");
blip = loadSound("sounds/blip.mp3");
snow = loadSound("sounds/snow.mp3");
}
function setup() {
noCanvas();
world = new World("VRScene");
jingle.play();
jingle.setVolume(.6);
// create a plane to serve as our "ground"
g = new Plane({
x:0, y:0, z:0,
width:100, height:100,
asset: 'snow',
repeatX: 100,
repeatY: 500,
rotationX:-90, metalness:0.25
});
// add the plane to our world
world.add(g);
}
var gifts = [];
var particles = [];
var burgers = [];
function draw() {
framectr+=1;
var part = new Particle(world.getUserPosition().x+ random(-4, 4), world.getUserPosition().y + 3, world.getUserPosition().z - random(.5, 6));
particles.push( part );
for (var i = 0; i < particles.length; i++) {
var result = particles[i].move();
if (result == "gone") {
particles.splice(i, 1);
i-=1;
}
}
if (mouseIsPressed) {
world.moveUserForward(0.05);
}
for (var i = 0; i < gifts.length; i++) {
var result = gifts[i].move();
if (result == "gone") {
gifts.splice(i, 1);
i-=1;
}
}
for (var i = 0; i < burgers.length; i++) {
var result = burgers[i].move();
if (result == "gone") {
burgers.splice(i, 1);
i-=1;
}
}
if(count > 9){
if(jingle.isPlaying()){
jingle.stop();
}
if(!snow.isPlaying()){
snow.play();
}
return;
}
if(gifts.length < 10){
if (framectr%30 ==0){
var temp = new Gift(world.getUserPosition().x + random(-1, 1), g.getY()+1, world.getUserPosition().z - random(.5, 6));
gifts.push(temp);
}
if (framectr%50 ==0){
var temp = new Burger(world.getUserPosition().x + random(-1, 1), g.getY()+1, world.getUserPosition().z - random(.5, 6));
burgers.push(temp);
}
}
}
function Particle(x,y,z) {
this.myBox = new Sphere({
x:x, y:y, z:z,
red: 173, green: 216, blue: 230,
radius: 0.1
});
// add the box to the world
world.add(this.myBox);
this.move = function(){
this.myBox.nudge(0, -.05, 0);
if(y<0){
world.remove(this.myBox);
return "gone";
}
if(z>world.getUserPosition().z){
world.remove(this.myBox);
return "gone";
}
}
}
function Gift(x,y,z){
this.gift = new OBJ({
asset: 'gift_obj',
mtl: 'gift_mtl',
x: x,
y: y,
z: z,
rotationX:0,
rotationY:180,
scaleX:1.5,
scaleY:1.5,
scaleZ:1.5
});
world.add(this.gift);
this.move = function(){
if(z>world.getUserPosition().z){
world.remove(this.gift);
return "gone";
}
if(dist(this.gift.x, this.gift.y, this.gift.z, world.getUserPosition().x, world.getUserPosition().y, world.getUserPosition().z)<.18){
console.log("HIT");
count++;
blip.play();
world.remove(this.gift);
return "gone";
}
}
}
function Burger(x,y,z){
this.burger = new OBJ({
asset: 'burger_obj',
mtl: 'burger_mtl',
x: x,
y: y,
z: z,
rotationX:0,
rotationY:180,
scaleX:.6,
scaleY:.6,
scaleZ:.6,
});
world.add(this.burger);
this.move = function(){
this.burger.spinY(1);
if(z>world.getUserPosition().z){
world.remove(this.burger);
return "gone";
}
}
}