forked from yining1023/brickBreaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
156 lines (140 loc) · 5.34 KB
/
home.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
// sound
let soundtrack;
// models
let game_start;
let game_title;
// logo orientation
let lastXAngle = 0;
let lastZAngle = 0;
// state & animation progress management
let HOME_STATE_POSTER = 0;
let HOME_STATE_MENU = 1;
let HOME_STATE = HOME_STATE_POSTER;
let menuFrameCount = 0;
function preload() {
soundtrack = loadSound('assets/SpiegelImSpiegelMonoShort.mp3');
game_title = loadModel('sprites/gameplay/3d/game_title.obj', true);
game_start = loadModel('sprites/gameplay/3d/game_start.obj', true);
}
function setup() {
setupCanvas();
soundtrack.loop();
}
function draw() {
background(0);
noStroke();
// background blinking random color squares moving in circle
let circleId = 0;
for (let origX = -width / 2; origX < width/2; origX += 200) {
for (let origY = -height / 2; origY < height/2; origY += 200) {
circleId++;
let orbit_radius = 60 + (circleId % 4) * 15;
for (let a = 0; a < 20; a++) {
push();
translate(origX + orbit_radius * sin(frameCount * 0.01 + a * 10), origY + orbit_radius * cos(frameCount * 0.01 + a * 10), 0);
fill(random(255), random(255), random(255));
plane(3 + random(5));
pop();
}
}
}
if(HOME_STATE == HOME_STATE_POSTER) {
cursor(HAND);
} else {
menuFrameCount++;
cursor(ARROW);
if(min(menuFrameCount/100,1.0) >= 1.0) {
// Start button ellipse
let origX = 0;
let origY = 120;
let orbit_radius_x = 150;
let orbit_radius_y = 50;
for (let a = 0; a < 20; a++) {
push();
translate(origX + orbit_radius_x * sin(frameCount * 0.01 + a * 10), origY + orbit_radius_y * cos(frameCount * 0.01 + a * 10), 0);
if (mouseOverStart()) {
specularMaterial(random(0, 1));
lights();
} else {
fill(random(255), random(255), random(255));
}
rotateX(10);
plane(10 + random(5));
pop();
}
// Start button text
push();
rotateX(80);
rotateX(0.2 * sin(frameCount * 0.01));
translate(0, 50, 120);
normalMaterial();
if (mouseOverStart()) {
cursor(HAND);
specularMaterial(0.1);
lights();
scale(1.2 + 0.1 * sin(frameCount * 0.7));
} else {
cursor(ARROW);
}
model(game_start);
pop();
}
push();
// Make logo go away backwards by scaling down and moving slightly upwards
scale(lerp(1.0, 0.6, min(menuFrameCount/100, 1.0)));
translate(0, lerp(0, -100, min(menuFrameCount/100, 1.0)), 0);
} // END OF HOME_STATE == HOME_STATE_MENU
push();
rotateX(-90);
// POSTER MODE HAS MOUSE-BASED LOGO ROTATION
if(HOME_STATE == HOME_STATE_POSTER) {
lastXAngle += (height / 2 - mouseY) / abs(height / 2 - mouseY) * 0.01;
lastZAngle -= (width / 2 - mouseX) / abs(width / 2 - mouseX) * 0.01;
rotateX(lastXAngle);
rotateZ(lastZAngle);
// MENU MODE LOGO ROTATION IS MOUSE-INDEPENDENT
} else { // if HOME_STATE_MENU
rotateX(0.2*sin(frameCount*0.01));
rotateZ(0.2*sin(frameCount*0.01));
}
normalMaterial();
scale(3 * windowHeight / 980); // sort of responsive scaling
translate(0, 0, 0);
model(game_title);
// orbiting logo sphere
push();
origX = -30;
origY = 0;
orbit_radius = 100;
a = 0;
orbitSpeed = 0.1;
translate(origX + orbit_radius * sin(frameCount * orbitSpeed + a * 10), origY + orbit_radius * cos(frameCount * orbitSpeed + a * 10), 0);
sphere(14, 10, 10);
pop();
push();
translate(0, 0, 100);
scale(2);
pointLight(0, 0, 250, origX + 20 + orbit_radius * sin(frameCount * orbitSpeed + a * 10), origY + orbit_radius * cos(frameCount * orbitSpeed + a * 10), 100);
pointLight(0, 250, 0, origX + 20 + orbit_radius * sin(frameCount * orbitSpeed + a * 10 + 90), origY + orbit_radius * cos(frameCount * orbitSpeed + a * 10 + 90), 100);
pointLight(250, 0, 0, origX + 20 + orbit_radius * sin(frameCount * orbitSpeed + a * 10 + 180), origY + orbit_radius * cos(frameCount * orbitSpeed + a * 10 + 180), 100);
lights();
pop();
camera(0, 0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);
pop();
if(HOME_STATE == HOME_STATE_MENU) {
pop();
}
}
function mouseOverStart() {
return mouseX > 290 && mouseX < 600 && mouseY > 265 && mouseY < 435;
}
function mouseReleased() {
userStartAudio(); // Chrome hack
if(HOME_STATE == HOME_STATE_POSTER) {
if(mouseX < width && mouseX > 0 && mouseY < height && mouseY > 0) {
HOME_STATE = HOME_STATE_MENU;
}
} else if(mouseOverStart()) {
redirectToUrlFor('howto');
}
}