-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
253 lines (201 loc) · 7.59 KB
/
index.html
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.1.3/pixi.min.js"></script>
<style>
body {
margin: 0;
}
canvas {
display: block;
background-color: aquamarine;
}
</style>
</head>
<body>
<canvas id="mycanvas"></canvas>
<script>
const canvas = document.getElementById("mycanvas");
// settings for canvas sizes
const settings = {
height: 250,
width: 630,
// set true if you want resize and want height and width equal 100%
windowFitting: false,
};
const getFullSize = () => ({
width: settings.windowFitting ? window.innerWidth : settings.width,
height: settings.windowFitting ? window.innerHeight : settings.height,
});
const app = new PIXI.Application({
view: canvas,
width: getFullSize().width,
height: getFullSize().height,
autoResize: true
});
document.body.appendChild(app.view);
// load sprite with all images
PIXI.Loader.shared.add("images/sprite.json").load(setup);
// help text foe start labels
let help;
function setup() {
let sheet = PIXI.Loader.shared.resources["images/sprite.json"].spritesheet;
const background = sheet.textures["office.png"];
background.frame.width = getFullSize().width;
background.frame.height = getFullSize().height;
background.interactive = true;
let backgroundTiling = new PIXI.TilingSprite(
background,
getFullSize().width,
getFullSize().height
);
const midTexture = sheet.textures["floor.jpg"];
midTexture.frame.width = getFullSize().width;
midTexture.frame.height = getFullSize().height;
let midTextureTiling = new PIXI.TilingSprite(
midTexture,
getFullSize().width,
40,
);
midTextureTiling.position.y = 225;
app.stage.addChild(backgroundTiling);
app.stage.addChild(midTextureTiling);
let button = PIXI.Sprite.from("images/button.png");
button.width = 400;
button.height = 400;
button.interactive = true;
button.cursor = 'pointer';
button.hitArea = new PIXI.Rectangle(button.top, button.left, button.width, button.height);
button.position.x = (settings.width / 2) - (button.width / 2);
button.position.y = (settings.height / 2) - (button.height / 2) + 20;
button.on('pointerdown', (event) => {
window.location.assign("http://www.mozilla.org");
});
// inital settings for psyduck
const psyMovie = new PIXI.AnimatedSprite(sheet.animations["psyduck"]);
psyMovie.position.set(130, 190);
psyMovie.anchor.set(0.5);
psyMovie.width = 240;
psyMovie.height = 180;
psyMovie.animationSpeed = 0.1;
// initial settings for shell
let shellMovie = new PIXI.AnimatedSprite(sheet.animations["shell"]);
shellMovie.position.set(530, 198);
shellMovie.anchor.set(0.5);
shellMovie.width = 240;
shellMovie.height = 180;
shellMovie.animationSpeed = 0.1;
shellMovie.play();
shellMovie.interactive = true;
shellMovie.cursor = 'pointer';
shellMovie.hitArea = new PIXI.Rectangle(0, 0, 200, 100);
// need to resolve click function
shellMovie.name = 'shell';
shellMovie.ticker = 0;
shellMovie.on('pointerdown', (event) => onClick(shellMovie));
shellMovie.on('pointerover', (event) => onPointerOver(shellMovie));
shellMovie.on('pointerout', (event) => onPointerOut(shellMovie));
function onClick(object) {
object.tint = 0xFF4444;
object.scale.x /= 1.18;
object.scale.y /= 1.18;
if (object.name == 'shell') {
help.text = 'You are good! Click one more';
shellMovie.ticker++;
}
if(object.scale.x < 0.35) {
app.stage.removeChild(object);
object.x = -200;
object.name == 'shell' ? help.text = 'Prepare for the next! Defeat him by clicking!' : help.text = 'Great work!';
return;
}
}
function onPointerOver(object) {
object.tint = 0xaaaaaa;
}
function onPointerOut(object) {
object.tint = 0xFFFFFF;
}
// initial settings for pig
const pigMovie = new PIXI.AnimatedSprite(sheet.animations["pig"]);
pigMovie.position.set(730, 190);
pigMovie.anchor.set(0.5);
pigMovie.width = 240;
pigMovie.height = 180;
pigMovie.animationSpeed = 0.1;
pigMovie.interactive = true;
pigMovie.cursor = 'pointer';
pigMovie.hitArea = new PIXI.Rectangle(0, 0, 200, 100);
// need to resolve click function
pigMovie.name = 'pig';
pigMovie.ticker = 0;
pigMovie.on('pointerdown', (event) => onClick(pigMovie));
pigMovie.on('pointerover', (event) => onPointerOver(pigMovie));
pigMovie.on('pointerout', (event) => onPointerOut(pigMovie));
app.stage.addChild(psyMovie);
app.stage.addChild(shellMovie);
app.stage.addChild(pigMovie);
let count = 0;
app.ticker.add(() => {
count += 0.005;
let blurFilter = new PIXI.filters.BlurFilter();
let coloredFilter = new PIXI.filters.ColorMatrixFilter();
coloredFilter.greyscale(0.2);
if(shellMovie && shellMovie.x > -105) {
// show labels and muted bg and psyduck
psyMovie.filters = [blurFilter, coloredFilter];
backgroundTiling.filters = [blurFilter, coloredFilter];
midTextureTiling.filters = [blurFilter, coloredFilter];
if (!help) {
help = new PIXI.Text('Click on Shell to defeat her!', { font: 'bold 12pt Arial', fill: 'white' });
help.position.y = 25;
help.position.x = 10;
app.stage.addChild(help);
}
if (shellMovie.ticker > 1) {
shellMovie.x -= 1;
backgroundTiling.tilePosition.x -= 0.3;
midTextureTiling.tilePosition.x -= 0.7;
psyMovie.play();
//remove filters
psyMovie.filters = null;
backgroundTiling.filters = null;
midTextureTiling.filters = null;
help.style.fill = 'black';
}
} else {
pigMovie.x -= 1;
pigMovie.play();
backgroundTiling.tilePosition.x -= 0.3;
midTextureTiling.tilePosition.x -= 0.7;
psyMovie.play();
if (pigMovie && pigMovie.x > -110 && !button) {
help.text = 'Prepare for the next! Defeat him by clicking!'
}
}
if ((shellMovie.x < psyMovie.x && shellMovie.x > 0) || (pigMovie.x < psyMovie.x && pigMovie.x > 0)) {
psyMovie.tint = Math.random() * 0xFFFFFF;
(shellMovie.x < psyMovie.x && shellMovie.x > 0) ? help.text = 'Oh no, poor psyduck!' : help.text = 'Oh no.. but you still can win!'
} else {
psyMovie.tint = 16777215;
}
if(help.text === 'Great work!' || help.text === 'Oh no.. but you still can win!') {
psyMovie.filters = [blurFilter];
backgroundTiling.filters = [blurFilter];
midTextureTiling.filters = [blurFilter];
app.stage.addChild(button);
}
});
function onresize() {
app.renderer.resize(getFullSize().width, getFullSize().height);
backgroundTiling.width = getFullSize().width;
backgroundTiling.height = getFullSize().height;
}
if(settings.windowFitting) window.addEventListener("resize", onresize);
}
</script>
</body>
</html>