-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
131 lines (114 loc) · 4.41 KB
/
test.ts
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
// WAVY DINO TEST
/*
class WavyVertexShader extends affine.Gpu.VertexShader {
dim: Fx8;
constructor(src: affine.Vertex[], dim: number) {
super(src);
this.dim = Fx8(dim);
}
public transform(index: number, xfrm: affine.Transform): void {
const src = this.src[index];
const dst = this.verts[index];
xfrm.transformToRef(src.pos, dst.pos);
const t = Fx8(this.frameId);
const angle = Fx.toFloat(Fx.add(t, Fx.mul(this.dim, src.uv.u))) * 180 / Math.PI;
const s = affine.trig.sin(angle);
const offset = Fx.mul(xfrm.localScl.x, s);
dst.pos.y = Fx.add(dst.pos.y, offset);
}
}
class TestScene extends affine.Scene {
sprite: affine.MeshSprite;
scale: number;
constructor() {
super();
this.scale = 1;
const img = helpers.getImageByName("_test_dino");
const dim = 6;
const size = 60;
this.sprite = new affine.MeshSprite(this, dim, dim, size / dim, size / dim,
(src: affine.Vertex[]) => new WavyVertexShader(src, dim),
() => new affine.Gpu.TexturedPixelShader(img));
this.sprite.debug = true;
}
startup() {
controller.setRepeatDefault(1, 1);
controller.up.onEvent(ControllerButtonEvent.Pressed, () => this.moveUp());
controller.up.onEvent(ControllerButtonEvent.Repeated, () => this.moveUp());
controller.down.onEvent(ControllerButtonEvent.Pressed, () => this.moveDown());
controller.down.onEvent(ControllerButtonEvent.Repeated, () => this.moveDown());
controller.left.onEvent(ControllerButtonEvent.Pressed, () => this.moveLeft());
controller.left.onEvent(ControllerButtonEvent.Repeated, () => this.moveLeft());
controller.right.onEvent(ControllerButtonEvent.Pressed, () => this.moveRight());
controller.right.onEvent(ControllerButtonEvent.Repeated, () => this.moveRight());
controller.A.onEvent(ControllerButtonEvent.Pressed, () => this.scaleUp());
controller.B.onEvent(ControllerButtonEvent.Pressed, () => this.scaleDown());
}
draw() {
this.sprite.draw();
}
moveSpeed = Fx8(2);
moveUp() {
this.sprite.xfrm.localPos.y = Fx.sub(this.sprite.xfrm.localPos.y, this.moveSpeed);
}
moveDown() {
this.sprite.xfrm.localPos.y = Fx.add(this.sprite.xfrm.localPos.y, this.moveSpeed);
}
moveLeft() {
this.sprite.xfrm.localPos.x = Fx.sub(this.sprite.xfrm.localPos.x, this.moveSpeed);
}
moveRight() {
this.sprite.xfrm.localPos.x = Fx.add(this.sprite.xfrm.localPos.x, this.moveSpeed);
}
scaleUp() {
this.scale *= 1.5;
this.sprite.xfrm.localScl = new affine.Vec2(Fx8(this.scale), Fx8(this.scale));
}
scaleDown() {
this.scale /= 1.5;
if (this.scale < 0.1) this.scale = 0.1;
this.sprite.xfrm.localScl = new affine.Vec2(Fx8(this.scale), Fx8(this.scale));
}
}
affine.Scene.pushScene(new TestScene());
*/
// DUCK TEST
/*
class TestScene extends affine.Scene {
sprite: affine.ImageSprite;
constructor() {
super();
this.sprite = new affine.ImageSprite(this, helpers.getImageByName("_test_duck"));
this.sprite.xfrm.localScl = new affine.Vec2(Fx8(3), Fx8(3));
this.sprite.debug = true;
}
startup() {
controller.setRepeatDefault(1, 1);
controller.left.onEvent(ControllerButtonEvent.Pressed, () => {
this.sprite.xfrm.localRot += 1;
});
controller.left.onEvent(ControllerButtonEvent.Repeated, () => {
this.sprite.xfrm.localRot += 1;
});
controller.right.onEvent(ControllerButtonEvent.Pressed, () => {
this.sprite.xfrm.localRot -= 1;
});
controller.right.onEvent(ControllerButtonEvent.Repeated, () => {
this.sprite.xfrm.localRot -= 1;
});
controller.up.onEvent(ControllerButtonEvent.Pressed, () => {
const scale = Fx.add(this.sprite.xfrm.localScl.x, Fx.oneFx8);
this.sprite.xfrm.localScl = new affine.Vec2(scale, scale);
});
controller.down.onEvent(ControllerButtonEvent.Pressed, () => {
const scale = Fx.max(Fx.oneFx8, Fx.sub(this.sprite.xfrm.localScl.x, Fx.oneFx8));
this.sprite.xfrm.localScl = new affine.Vec2(scale, scale);
});
}
draw() {
this.sprite.draw();
}
}
affine.Gpu.broadphaseDebug = true;
affine.Scene.pushScene(new TestScene());
*/