-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathindex.js
71 lines (64 loc) · 1.35 KB
/
index.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
import * as PIXI from "PIXI.js";
import {
h,
initRuntimeCanvas,
ref,
defineComponent,
reactive,
watch,
} from "./runtime-canvas/index";
import Plane from "./game/Plane";
import Bullet from "./game/Bullet";
window.PIXI = PIXI;
let app = initPixi();
const { renderer } = initRuntimeCanvas(app);
const RootComponent = createRootComponent();
const root = renderer.createApp(RootComponent);
root.mount(app.stage);
function createRootComponent() {
return {
setup() {
// 存储所有的子弹
const selfBullets = reactive([]);
return {
selfBullets,
};
},
render(ctx) {
console.log(
h(Bullet, {
props: {
x: ref(100),
y: 200,
},
})
);
return h(
"Container",
{
width: 500,
height: 500,
},
[
h(Plane, {
onAttack(pos) {
ctx.selfBullets.push(pos);
},
}),
...ctx.selfBullets.map((bulletInfo) => {
return h(Bullet, {
x: bulletInfo.x,
y: bulletInfo.y,
});
}),
]
);
},
};
}
function initPixi() {
let app = new PIXI.Application({ width: 500, height: 500 });
app.renderer.backgroundColor = 0x061639;
document.body.appendChild(app.view);
return app;
}