|
5 | 5 | import org.openpatch.scratch.extensions.timer.Timer; |
6 | 6 |
|
7 | 7 | public class MyStage extends Stage { |
8 | | - public MyStage() { |
9 | | - var shader = this.addShader("blobby", "Shader/blobby.glsl"); |
10 | | - shader.set("depth", 1.5); |
11 | | - shader.set("rate", 1.5); |
12 | | - shader = this.addShader("glitch", "Shader/glitch.glsl"); |
13 | | - shader.set("rate", 0.0001); |
14 | | - shader = this.addShader("light", "Shader/light.glsl"); |
15 | | - this.switchShader("light"); |
| 8 | + public MyStage() { |
| 9 | + var shader = this.addShader("blobby", "Shader/blobby.glsl"); |
| 10 | + shader.set("depth", 1.5); |
| 11 | + shader.set("rate", 1.5); |
| 12 | + shader = this.addShader("glitch", "Shader/glitch.glsl"); |
| 13 | + shader.set("rate", 0.0001); |
| 14 | + shader = this.addShader("light", "Shader/light.glsl"); |
| 15 | + this.switchShader("light"); |
16 | 16 |
|
17 | | - this.add(new MySprite()); |
18 | | - this.add(new NormalSprite()); |
| 17 | + this.add(new MySprite()); |
| 18 | + this.add(new NormalSprite()); |
19 | 19 |
|
20 | | - for (int i = 0; i < 8; i++) { |
21 | | - var sprite = new LightSprite(); |
22 | | - this.add(sprite); |
23 | | - sprite.goToRandomPosition(); |
24 | | - } |
| 20 | + for (int i = 0; i < 8; i++) { |
| 21 | + var sprite = new LightSprite(); |
| 22 | + this.add(sprite); |
| 23 | + sprite.goToRandomPosition(); |
25 | 24 | } |
| 25 | + } |
26 | 26 |
|
27 | | - public void whenKeyPressed(int keyCode) { |
28 | | - if (keyCode == KeyCode.VK_A) { |
29 | | - this.nextShader(); |
30 | | - } |
31 | | - if (keyCode == KeyCode.VK_S) { |
32 | | - this.resetShader(); |
33 | | - } |
| 27 | + public void whenKeyPressed(int keyCode) { |
| 28 | + if (keyCode == KeyCode.VK_A) { |
| 29 | + this.nextShader(); |
34 | 30 | } |
| 31 | + if (keyCode == KeyCode.VK_S) { |
| 32 | + this.resetShader(); |
| 33 | + } |
| 34 | + } |
35 | 35 |
|
36 | | - public void run() { |
37 | | - this.display("Press A for the next stage shader. Press S to remove the stage shader. Press N for the next sprite shader. Press M to remove the sprite shader."); |
38 | | - var shader = this.getCurrentShader(); |
39 | | - if (shader != null) { |
40 | | - shader.set("time", Timer.millis() / 1000.0); |
41 | | - shader.set("resolution", (float) this.getWidth(), (float) this.getHeight()); |
42 | | - if ("light".equals(shader.getName())) { |
43 | | - var lights = this.findSpritesOf(LightSprite.class); |
44 | | - var lightPos = new double[lights.size() * 3 + 3]; |
45 | | - // light at mouse position |
46 | | - lightPos[0] = this.getMouseX(); |
47 | | - lightPos[1] = this.getMouseY(); |
48 | | - lightPos[2] = 1; |
49 | | - int i = 3; |
50 | | - for (var light : lights) { |
51 | | - var x = light.getX(); |
52 | | - var y = light.getY(); |
53 | | - lightPos[i] = x; |
54 | | - lightPos[i + 1] = y; |
55 | | - lightPos[i + 2] = 1; |
56 | | - i += 3; |
57 | | - } |
58 | | - shader.set("lights", lightPos, 3); |
59 | | - } |
60 | | - |
| 36 | + public void run() { |
| 37 | + this.display( |
| 38 | + "Press A for the next stage shader. Press S to remove the stage shader. Press N for the" |
| 39 | + + " next sprite shader. Press M to remove the sprite shader."); |
| 40 | + var shader = this.getCurrentShader(); |
| 41 | + if (shader != null) { |
| 42 | + shader.set("time", Timer.millis() / 1000.0); |
| 43 | + shader.set("resolution", (float) this.getWidth(), (float) this.getHeight()); |
| 44 | + if ("light".equals(shader.getName())) { |
| 45 | + var lights = this.findSpritesOf(LightSprite.class); |
| 46 | + var lightPos = new double[lights.size() * 3 + 3]; |
| 47 | + // light at mouse position |
| 48 | + lightPos[0] = this.getMouseX(); |
| 49 | + lightPos[1] = this.getMouseY(); |
| 50 | + lightPos[2] = 1; |
| 51 | + int i = 3; |
| 52 | + for (var light : lights) { |
| 53 | + var x = light.getX(); |
| 54 | + var y = light.getY(); |
| 55 | + lightPos[i] = x; |
| 56 | + lightPos[i + 1] = y; |
| 57 | + lightPos[i + 2] = 1; |
| 58 | + i += 3; |
61 | 59 | } |
| 60 | + shader.set("lights", lightPos, 3); |
| 61 | + } |
62 | 62 | } |
| 63 | + } |
63 | 64 | } |
0 commit comments