|
10 | 10 | } |
11 | 11 | </style> |
12 | 12 | <script src="phaser.js"></script> |
| 13 | + <script src="../../../filters/ColorBars.js" type="text/javascript"></script> |
| 14 | + <script src="../../../filters/BinarySerpents.js" type="text/javascript"></script> |
13 | 15 | </head> |
14 | 16 | <body> |
15 | 17 |
|
16 | 18 | <div id="gameContainer"></div> |
17 | 19 |
|
18 | 20 | <script type="text/javascript"> |
19 | 21 |
|
20 | | -var PIXI = PIXI || {}; |
21 | | - |
22 | | -document.addEventListener('DOMContentLoaded', function() { |
23 | | - |
24 | | -function makeFilter () { |
25 | | - |
26 | | - PIXI.FireFilter = function(width, height, texture) |
27 | | - { |
28 | | - PIXI.AbstractFilter.call( this ); |
29 | | - |
30 | | - this.passes = [this]; |
31 | | - |
32 | | - var d = new Date(); |
33 | | - |
34 | | - var dates = [ |
35 | | - d.getFullYear(), // the year (four digits) |
36 | | - d.getMonth(), // the month (from 0-11) |
37 | | - d.getDate(), // the day of the month (from 1-31) |
38 | | - d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds() |
39 | | - ]; |
40 | | - |
41 | | - this.uniforms = { |
42 | | - resolution: { type: 'f2', value: { x: width, y: height }}, |
43 | | - mouse: { type: 'f2', value: { x: 0, y: 0 }}, |
44 | | - time: { type: 'f', value: 1 } |
45 | | - }; |
46 | | - |
47 | | - // http://glsl.heroku.com/e#11707.0 |
48 | | - |
49 | | - // Heroku shader conversion |
50 | | - this.fragmentSrc = [ |
51 | | - |
52 | | - "#ifdef GL_ES", |
53 | | - "precision mediump float;", |
54 | | - "#endif", |
55 | | - |
56 | | - "uniform float time;", |
57 | | - "uniform vec2 mouse;", |
58 | | - "uniform vec2 resolution;", |
59 | | - |
60 | | - "vec3 iResolution = vec3(resolution.x,resolution.y,100.);", |
61 | | - "vec4 iMouse = vec4(mouse.x,mouse.y,5.,5.);", |
62 | | - "float iGlobalTime = time;", |
63 | | - "uniform sampler2D iChannel0;", |
64 | | - |
65 | | - "// by @301z", |
66 | | - |
67 | | - "float rand(vec2 n) {", |
68 | | - "return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);", |
69 | | - "}", |
70 | | - |
71 | | - "// Genera ruido en función de las coordenadas del pixel", |
72 | | - "float noise(vec2 n) {", |
73 | | - "const vec2 d = vec2(0.0, 1.0);", |
74 | | - "vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));", |
75 | | - "return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);", |
76 | | - "}", |
77 | | - |
78 | | - "// Fractional Brownian Amplitude. Suma varias capas de ruido.", |
79 | | - "float fbm(vec2 n) {", |
80 | | - "float total = 0.0, amplitude = 1.0;", |
81 | | - "for (int i = 0; i < 4; i++) {", |
82 | | - "total += noise(n) * amplitude;", |
83 | | - "n += n;", |
84 | | - "amplitude *= 0.5;", |
85 | | - "}", |
86 | | - "return total;", |
87 | | - "}", |
88 | | - |
89 | | - "void main() {", |
90 | | - "// Colores", |
91 | | - "const vec3 c1 = vec3(0.5, 0.0, 0.1); // Rojo oscuro.", |
92 | | - "const vec3 c2 = vec3(0.9, 0.0, 0.0); // Rojo claro.", |
93 | | - "const vec3 c3 = vec3(0.2, 0.0, 0.0); // Rojo oscuro.", |
94 | | - "const vec3 c4 = vec3(1.0, 0.9, 0.0); // Amarillo.", |
95 | | - "const vec3 c5 = vec3(0.1); // Gris oscuro.", |
96 | | - "const vec3 c6 = vec3(0.9); // Gris claro.", |
97 | | - |
98 | | - "vec2 p = gl_FragCoord.xy * 8.0 / iResolution.xx; // Desfasa las coordenadas para que haya más cambio de un resultado a los colindantes.", |
99 | | - "float q = fbm(p - iGlobalTime * 0.1); // Ruido con offset para el movimiento.", |
100 | | - "vec2 r = vec2(fbm(p + q + iGlobalTime * 0.7 - p.x - p.y), fbm(p + q - iGlobalTime * 0.4));", |
101 | | - "vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);", |
102 | | - "gl_FragColor = vec4(c *", |
103 | | - "cos(1.57 * gl_FragCoord.y / iResolution.y), // Gradiente más ocuro arriba.", |
104 | | - "1.0);", |
105 | | - "}"]; |
106 | | - |
107 | | - |
108 | | - |
109 | | - } |
110 | | - |
111 | | - PIXI.FireFilter.prototype = Object.create( PIXI.AbstractFilter.prototype ); |
112 | | - PIXI.FireFilter.prototype.constructor = PIXI.FireFilter; |
113 | | - |
114 | | - Object.defineProperty(PIXI.FireFilter.prototype, 'iGlobalTime', { |
115 | | - get: function() { |
116 | | - return this.uniforms.time.value; |
117 | | - }, |
118 | | - set: function(value) { |
119 | | - this.uniforms.time.value = value; |
120 | | - } |
121 | | - }); |
122 | | - |
123 | | - |
124 | | -} |
125 | | - |
126 | | - |
127 | | - |
128 | 22 | var game = new Phaser.Game(1024, 672, Phaser.AUTO, 'gameContainer', { preload: preload, create: create, update: update }); |
129 | 23 |
|
130 | | -var filter; |
| 24 | + var filter; |
131 | 25 |
|
132 | 26 | var sky; |
133 | 27 | var land; |
|
175 | 69 |
|
176 | 70 | function create () { |
177 | 71 |
|
178 | | -console.log('dom?'); |
179 | | -console.log(Phaser); |
180 | | -console.log(PIXI); |
181 | | - |
182 | 72 | game.world.setBounds(-64, 0, 1300, 672); |
183 | 73 |
|
184 | 74 | sfxLazer = game.add.audio('sfxLazer', 0.1, false); |
|
187 | 77 | music = game.add.audio('music'); |
188 | 78 |
|
189 | 79 | sky = game.add.sprite(0, 0, 'background'); |
190 | | - makeFilter(); |
191 | | - filter = new PIXI.FireFilter(sky.width, sky.height, sky.texture); |
192 | | - sky.filters = [filter]; |
193 | 80 |
|
194 | | - // sky = game.add.sprite(0, 0, 'background'); |
| 81 | + var t = game.add.sprite(0, 0); |
| 82 | + t.width = 1024; |
| 83 | + t.height = 672; |
| 84 | + filter = game.add.filter('BinarySerpents', 1024, 672); |
| 85 | + // filter.alpha = 0.0; |
| 86 | + t.filters = [filter]; |
| 87 | + |
195 | 88 | land = game.add.tileSprite(0, 544, 1024, 128, 'land'); |
196 | 89 |
|
197 | 90 | bullets = game.add.group(); |
|
285 | 178 |
|
286 | 179 | function update () { |
287 | 180 |
|
288 | | - filter.iGlobalTime = game.time.totalElapsedSeconds(); |
| 181 | + filter.update(); |
289 | 182 |
|
290 | 183 | land.tilePosition.x -= scrollSpeed; |
291 | 184 |
|
|
430 | 323 |
|
431 | 324 | } |
432 | 325 |
|
433 | | -}); |
434 | | - |
435 | 326 | </script> |
436 | 327 |
|
437 | 328 | </body> |
|
0 commit comments