@guinetik/gcanvas 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yaml +70 -0
- package/.jshintrc +4 -0
- package/.vscode/settings.json +22 -0
- package/CLAUDE.md +310 -0
- package/blackhole.jpg +0 -0
- package/demo.png +0 -0
- package/demos/CNAME +1 -0
- package/demos/animations.html +31 -0
- package/demos/basic.html +38 -0
- package/demos/baskara.html +31 -0
- package/demos/bezier.html +35 -0
- package/demos/beziersignature.html +29 -0
- package/demos/blackhole.html +28 -0
- package/demos/blob.html +35 -0
- package/demos/demos.css +289 -0
- package/demos/easing.html +28 -0
- package/demos/events.html +195 -0
- package/demos/fluent.html +647 -0
- package/demos/fractals.html +36 -0
- package/demos/genart.html +26 -0
- package/demos/gendream.html +26 -0
- package/demos/group.html +36 -0
- package/demos/home.html +587 -0
- package/demos/index.html +364 -0
- package/demos/isometric.html +34 -0
- package/demos/js/animations.js +452 -0
- package/demos/js/basic.js +204 -0
- package/demos/js/baskara.js +751 -0
- package/demos/js/bezier.js +692 -0
- package/demos/js/beziersignature.js +241 -0
- package/demos/js/blackhole/accretiondisk.obj.js +379 -0
- package/demos/js/blackhole/blackhole.obj.js +318 -0
- package/demos/js/blackhole/index.js +409 -0
- package/demos/js/blackhole/particle.js +56 -0
- package/demos/js/blackhole/starfield.obj.js +218 -0
- package/demos/js/blob.js +2263 -0
- package/demos/js/easing.js +477 -0
- package/demos/js/fluent.js +183 -0
- package/demos/js/fractals.js +931 -0
- package/demos/js/fractalworker.js +93 -0
- package/demos/js/genart.js +268 -0
- package/demos/js/gendream.js +209 -0
- package/demos/js/group.js +140 -0
- package/demos/js/info-toggle.js +25 -0
- package/demos/js/isometric.js +863 -0
- package/demos/js/kerr.js +1556 -0
- package/demos/js/lavalamp.js +590 -0
- package/demos/js/layout.js +354 -0
- package/demos/js/mondrian.js +285 -0
- package/demos/js/opacity.js +275 -0
- package/demos/js/painter.js +484 -0
- package/demos/js/particles-showcase.js +514 -0
- package/demos/js/particles.js +299 -0
- package/demos/js/patterns.js +397 -0
- package/demos/js/penrose/artifact.js +69 -0
- package/demos/js/penrose/blackhole.js +121 -0
- package/demos/js/penrose/constants.js +73 -0
- package/demos/js/penrose/game.js +943 -0
- package/demos/js/penrose/lore.js +278 -0
- package/demos/js/penrose/penrosescene.js +892 -0
- package/demos/js/penrose/ship.js +216 -0
- package/demos/js/penrose/sounds.js +211 -0
- package/demos/js/penrose/voidparticle.js +55 -0
- package/demos/js/penrose/voidscene.js +258 -0
- package/demos/js/penrose/voidship.js +144 -0
- package/demos/js/penrose/wormhole.js +46 -0
- package/demos/js/pipeline.js +555 -0
- package/demos/js/scene.js +304 -0
- package/demos/js/scenes.js +320 -0
- package/demos/js/schrodinger.js +410 -0
- package/demos/js/schwarzschild.js +1023 -0
- package/demos/js/shapes.js +628 -0
- package/demos/js/space/alien.js +171 -0
- package/demos/js/space/boom.js +98 -0
- package/demos/js/space/boss.js +353 -0
- package/demos/js/space/buff.js +73 -0
- package/demos/js/space/bullet.js +102 -0
- package/demos/js/space/constants.js +85 -0
- package/demos/js/space/game.js +1884 -0
- package/demos/js/space/hud.js +112 -0
- package/demos/js/space/laserbeam.js +179 -0
- package/demos/js/space/lightning.js +277 -0
- package/demos/js/space/minion.js +192 -0
- package/demos/js/space/missile.js +212 -0
- package/demos/js/space/player.js +430 -0
- package/demos/js/space/powerup.js +90 -0
- package/demos/js/space/starfield.js +58 -0
- package/demos/js/space/starpower.js +90 -0
- package/demos/js/spacetime.js +559 -0
- package/demos/js/svgtween.js +204 -0
- package/demos/js/tde/accretiondisk.js +418 -0
- package/demos/js/tde/blackhole.js +219 -0
- package/demos/js/tde/blackholescene.js +209 -0
- package/demos/js/tde/config.js +59 -0
- package/demos/js/tde/index.js +695 -0
- package/demos/js/tde/jets.js +290 -0
- package/demos/js/tde/lensedstarfield.js +147 -0
- package/demos/js/tde/tdestar.js +317 -0
- package/demos/js/tde/tidalstream.js +356 -0
- package/demos/js/tde_old/blackhole.obj.js +354 -0
- package/demos/js/tde_old/debris.obj.js +791 -0
- package/demos/js/tde_old/flare.obj.js +239 -0
- package/demos/js/tde_old/index.js +448 -0
- package/demos/js/tde_old/star.obj.js +812 -0
- package/demos/js/tiles.js +312 -0
- package/demos/js/tweendemo.js +79 -0
- package/demos/js/visibility.js +102 -0
- package/demos/kerr.html +28 -0
- package/demos/lavalamp.html +27 -0
- package/demos/layouts.html +37 -0
- package/demos/logo.svg +4 -0
- package/demos/loop.html +84 -0
- package/demos/mondrian.html +32 -0
- package/demos/og_image.png +0 -0
- package/demos/opacity.html +36 -0
- package/demos/painter.html +39 -0
- package/demos/particles-showcase.html +28 -0
- package/demos/particles.html +24 -0
- package/demos/patterns.html +33 -0
- package/demos/penrose-game.html +31 -0
- package/demos/pipeline.html +737 -0
- package/demos/scene.html +33 -0
- package/demos/scenes.html +96 -0
- package/demos/schrodinger.html +27 -0
- package/demos/schwarzschild.html +27 -0
- package/demos/shapes.html +16 -0
- package/demos/space.html +85 -0
- package/demos/spacetime.html +27 -0
- package/demos/svgtween.html +29 -0
- package/demos/tde.html +28 -0
- package/demos/tiles.html +28 -0
- package/demos/transforms.html +400 -0
- package/demos/tween.html +45 -0
- package/demos/visibility.html +33 -0
- package/disk_example.png +0 -0
- package/docs/README.md +222 -0
- package/docs/concepts/architecture-overview.md +204 -0
- package/docs/concepts/lifecycle.md +255 -0
- package/docs/concepts/rendering-pipeline.md +279 -0
- package/docs/concepts/tde-zorder.md +106 -0
- package/docs/concepts/two-layer-architecture.md +229 -0
- package/docs/getting-started/first-game.md +354 -0
- package/docs/getting-started/hello-world.md +269 -0
- package/docs/getting-started/installation.md +157 -0
- package/docs/modules/collision/README.md +453 -0
- package/docs/modules/fluent/README.md +1075 -0
- package/docs/modules/game/README.md +303 -0
- package/docs/modules/isometric-camera.md +210 -0
- package/docs/modules/isometric.md +275 -0
- package/docs/modules/painter/README.md +328 -0
- package/docs/modules/particle/README.md +559 -0
- package/docs/modules/shapes/README.md +221 -0
- package/docs/modules/shapes/base/euclidian.md +123 -0
- package/docs/modules/shapes/base/geometry2d.md +204 -0
- package/docs/modules/shapes/base/renderable.md +215 -0
- package/docs/modules/shapes/base/shape.md +262 -0
- package/docs/modules/shapes/base/transformable.md +243 -0
- package/docs/modules/shapes/hierarchy.md +218 -0
- package/docs/modules/state/README.md +577 -0
- package/docs/modules/util/README.md +99 -0
- package/docs/modules/util/camera3d.md +412 -0
- package/docs/modules/util/scene3d.md +395 -0
- package/index.html +17 -0
- package/jsdoc.json +50 -0
- package/package.json +55 -0
- package/readme.md +599 -0
- package/scripts/build-demo.js +69 -0
- package/scripts/bundle4llm.js +276 -0
- package/scripts/clearconsole.js +48 -0
- package/src/collision/collision-system.js +332 -0
- package/src/collision/collision.js +303 -0
- package/src/collision/index.js +10 -0
- package/src/fluent/fluent-game.js +430 -0
- package/src/fluent/fluent-go.js +1060 -0
- package/src/fluent/fluent-layer.js +152 -0
- package/src/fluent/fluent-scene.js +291 -0
- package/src/fluent/index.js +98 -0
- package/src/fluent/sketch.js +380 -0
- package/src/game/game.js +467 -0
- package/src/game/index.js +49 -0
- package/src/game/objects/go.js +220 -0
- package/src/game/objects/imagego.js +30 -0
- package/src/game/objects/index.js +54 -0
- package/src/game/objects/isometric-scene.js +260 -0
- package/src/game/objects/layoutscene.js +549 -0
- package/src/game/objects/scene.js +175 -0
- package/src/game/objects/scene3d.js +118 -0
- package/src/game/objects/text.js +221 -0
- package/src/game/objects/wrapper.js +232 -0
- package/src/game/pipeline.js +243 -0
- package/src/game/ui/button.js +396 -0
- package/src/game/ui/cursor.js +93 -0
- package/src/game/ui/fps.js +91 -0
- package/src/game/ui/index.js +5 -0
- package/src/game/ui/togglebutton.js +93 -0
- package/src/game/ui/tooltip.js +249 -0
- package/src/index.js +25 -0
- package/src/io/events.js +20 -0
- package/src/io/index.js +86 -0
- package/src/io/input.js +70 -0
- package/src/io/keys.js +152 -0
- package/src/io/mouse.js +61 -0
- package/src/io/touch.js +39 -0
- package/src/logger/debugtab.js +138 -0
- package/src/logger/index.js +3 -0
- package/src/logger/loggable.js +47 -0
- package/src/logger/logger.js +113 -0
- package/src/math/complex.js +37 -0
- package/src/math/constants.js +1 -0
- package/src/math/fractal.js +1271 -0
- package/src/math/gr.js +201 -0
- package/src/math/heat.js +202 -0
- package/src/math/index.js +12 -0
- package/src/math/noise.js +433 -0
- package/src/math/orbital.js +191 -0
- package/src/math/patterns.js +1339 -0
- package/src/math/penrose.js +259 -0
- package/src/math/quantum.js +115 -0
- package/src/math/random.js +195 -0
- package/src/math/tensor.js +1009 -0
- package/src/mixins/anchor.js +131 -0
- package/src/mixins/draggable.js +72 -0
- package/src/mixins/index.js +2 -0
- package/src/motion/bezier.js +132 -0
- package/src/motion/bounce.js +58 -0
- package/src/motion/easing.js +349 -0
- package/src/motion/float.js +130 -0
- package/src/motion/follow.js +125 -0
- package/src/motion/hop.js +52 -0
- package/src/motion/index.js +82 -0
- package/src/motion/motion.js +1124 -0
- package/src/motion/orbit.js +49 -0
- package/src/motion/oscillate.js +39 -0
- package/src/motion/parabolic.js +141 -0
- package/src/motion/patrol.js +147 -0
- package/src/motion/pendulum.js +48 -0
- package/src/motion/pulse.js +88 -0
- package/src/motion/shake.js +83 -0
- package/src/motion/spiral.js +144 -0
- package/src/motion/spring.js +150 -0
- package/src/motion/swing.js +47 -0
- package/src/motion/tween.js +92 -0
- package/src/motion/tweenetik.js +139 -0
- package/src/motion/waypoint.js +210 -0
- package/src/painter/index.js +8 -0
- package/src/painter/painter.colors.js +331 -0
- package/src/painter/painter.effects.js +230 -0
- package/src/painter/painter.img.js +229 -0
- package/src/painter/painter.js +295 -0
- package/src/painter/painter.lines.js +189 -0
- package/src/painter/painter.opacity.js +41 -0
- package/src/painter/painter.shapes.js +277 -0
- package/src/painter/painter.text.js +273 -0
- package/src/particle/emitter.js +124 -0
- package/src/particle/index.js +11 -0
- package/src/particle/particle-system.js +322 -0
- package/src/particle/particle.js +71 -0
- package/src/particle/updaters.js +170 -0
- package/src/shapes/arc.js +43 -0
- package/src/shapes/arrow.js +33 -0
- package/src/shapes/bezier.js +42 -0
- package/src/shapes/circle.js +62 -0
- package/src/shapes/clouds.js +56 -0
- package/src/shapes/cone.js +219 -0
- package/src/shapes/cross.js +70 -0
- package/src/shapes/cube.js +244 -0
- package/src/shapes/cylinder.js +254 -0
- package/src/shapes/diamond.js +48 -0
- package/src/shapes/euclidian.js +111 -0
- package/src/shapes/figure.js +115 -0
- package/src/shapes/geometry.js +220 -0
- package/src/shapes/group.js +375 -0
- package/src/shapes/heart.js +42 -0
- package/src/shapes/hexagon.js +26 -0
- package/src/shapes/image.js +192 -0
- package/src/shapes/index.js +111 -0
- package/src/shapes/line.js +29 -0
- package/src/shapes/pattern.js +90 -0
- package/src/shapes/pin.js +44 -0
- package/src/shapes/poly.js +31 -0
- package/src/shapes/prism.js +226 -0
- package/src/shapes/rect.js +35 -0
- package/src/shapes/renderable.js +333 -0
- package/src/shapes/ring.js +26 -0
- package/src/shapes/roundrect.js +95 -0
- package/src/shapes/shape.js +117 -0
- package/src/shapes/slice.js +26 -0
- package/src/shapes/sphere.js +314 -0
- package/src/shapes/sphere3d.js +537 -0
- package/src/shapes/square.js +15 -0
- package/src/shapes/star.js +99 -0
- package/src/shapes/svg.js +408 -0
- package/src/shapes/text.js +553 -0
- package/src/shapes/traceable.js +83 -0
- package/src/shapes/transform.js +357 -0
- package/src/shapes/transformable.js +172 -0
- package/src/shapes/triangle.js +26 -0
- package/src/sound/index.js +17 -0
- package/src/sound/sound.js +473 -0
- package/src/sound/synth.analyzer.js +149 -0
- package/src/sound/synth.effects.js +207 -0
- package/src/sound/synth.envelope.js +59 -0
- package/src/sound/synth.js +229 -0
- package/src/sound/synth.musical.js +160 -0
- package/src/sound/synth.noise.js +85 -0
- package/src/sound/synth.oscillators.js +293 -0
- package/src/state/index.js +10 -0
- package/src/state/state-machine.js +371 -0
- package/src/util/camera3d.js +438 -0
- package/src/util/index.js +6 -0
- package/src/util/isometric-camera.js +235 -0
- package/src/util/layout.js +317 -0
- package/src/util/position.js +147 -0
- package/src/util/tasks.js +47 -0
- package/src/util/zindex.js +287 -0
- package/src/webgl/index.js +9 -0
- package/src/webgl/shaders/sphere-shaders.js +994 -0
- package/src/webgl/webgl-renderer.js +388 -0
- package/tde.png +0 -0
- package/test/math/orbital.test.js +61 -0
- package/test/math/tensor.test.js +114 -0
- package/test/particle/emitter.test.js +204 -0
- package/test/particle/particle-system.test.js +310 -0
- package/test/particle/particle.test.js +116 -0
- package/test/particle/updaters.test.js +386 -0
- package/test/setup.js +120 -0
- package/test/shapes/euclidian.test.js +44 -0
- package/test/shapes/geometry.test.js +86 -0
- package/test/shapes/group.test.js +86 -0
- package/test/shapes/rectangle.test.js +64 -0
- package/test/shapes/transform.test.js +379 -0
- package/test/util/camera3d.test.js +428 -0
- package/test/util/scene3d.test.js +352 -0
- package/types/collision.d.ts +249 -0
- package/types/common.d.ts +155 -0
- package/types/game.d.ts +497 -0
- package/types/index.d.ts +309 -0
- package/types/io.d.ts +188 -0
- package/types/logger.d.ts +127 -0
- package/types/math.d.ts +268 -0
- package/types/mixins.d.ts +92 -0
- package/types/motion.d.ts +678 -0
- package/types/painter.d.ts +378 -0
- package/types/shapes.d.ts +864 -0
- package/types/sound.d.ts +672 -0
- package/types/state.d.ts +251 -0
- package/types/util.d.ts +253 -0
- package/vite.config.js +50 -0
- package/vitest.config.js +13 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Game,
|
|
3
|
+
Scene,
|
|
4
|
+
TileLayout,
|
|
5
|
+
HorizontalLayout,
|
|
6
|
+
Rectangle,
|
|
7
|
+
ShapeGOFactory,
|
|
8
|
+
Button,
|
|
9
|
+
FPSCounter,
|
|
10
|
+
Painter,
|
|
11
|
+
Tween,
|
|
12
|
+
Easing,
|
|
13
|
+
Position,
|
|
14
|
+
} from "../../src/index";
|
|
15
|
+
|
|
16
|
+
// Configuration
|
|
17
|
+
const CONFIG = {
|
|
18
|
+
tileSize: 50,
|
|
19
|
+
tileSpacing: 12,
|
|
20
|
+
tilePadding: 20,
|
|
21
|
+
initialTiles: 50,
|
|
22
|
+
maxColumns: 10,
|
|
23
|
+
uiHeight: 100, // Space reserved for UI at bottom
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class TileDemo extends Scene {
|
|
27
|
+
constructor(game, options = {}) {
|
|
28
|
+
super(game, options);
|
|
29
|
+
this.elapsedTime = this.lastChangeTime = 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isMobile() {
|
|
33
|
+
return this.game.width < 600;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getResponsiveColumns() {
|
|
37
|
+
const availableWidth = this.game.width - CONFIG.tilePadding * 2;
|
|
38
|
+
const tileWithSpacing = CONFIG.tileSize + CONFIG.tileSpacing;
|
|
39
|
+
const columns = Math.floor(availableWidth / tileWithSpacing);
|
|
40
|
+
return Math.max(2, Math.min(CONFIG.maxColumns, columns));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getViewportDimensions() {
|
|
44
|
+
const margin = this.isMobile() ? 20 : 40;
|
|
45
|
+
return {
|
|
46
|
+
width: this.game.width - margin * 2,
|
|
47
|
+
height: this.game.height - CONFIG.uiHeight - margin,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
init() {
|
|
52
|
+
const game = this.game;
|
|
53
|
+
const viewport = this.getViewportDimensions();
|
|
54
|
+
const columns = this.getResponsiveColumns();
|
|
55
|
+
|
|
56
|
+
// 1) Create a scrollable tile grid anchored at center
|
|
57
|
+
this.grid = new TileLayout(game, {
|
|
58
|
+
anchor: Position.CENTER,
|
|
59
|
+
anchorOffsetY: -CONFIG.uiHeight / 2 + 20,
|
|
60
|
+
columns: columns,
|
|
61
|
+
spacing: CONFIG.tileSpacing,
|
|
62
|
+
padding: CONFIG.tilePadding,
|
|
63
|
+
autoSize: true,
|
|
64
|
+
debug: true,
|
|
65
|
+
// Enable scrolling
|
|
66
|
+
scrollable: true,
|
|
67
|
+
viewportWidth: viewport.width,
|
|
68
|
+
viewportHeight: viewport.height,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Add initial tiles
|
|
72
|
+
for (let i = 0; i < CONFIG.initialTiles; i++) {
|
|
73
|
+
this.addTile();
|
|
74
|
+
}
|
|
75
|
+
this.add(this.grid);
|
|
76
|
+
|
|
77
|
+
// 2) Create a HorizontalLayout at bottom-center for UI buttons
|
|
78
|
+
this.createUI();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
createUI() {
|
|
82
|
+
const game = this.game;
|
|
83
|
+
const isMobile = this.isMobile();
|
|
84
|
+
const buttonWidth = isMobile ? 70 : 90;
|
|
85
|
+
|
|
86
|
+
this.bottomUI = new HorizontalLayout(game, {
|
|
87
|
+
anchor: Position.BOTTOM_CENTER,
|
|
88
|
+
anchorOffsetY: -15,
|
|
89
|
+
spacing: isMobile ? 5 : 10,
|
|
90
|
+
padding: 10,
|
|
91
|
+
debug: false,
|
|
92
|
+
align: "center",
|
|
93
|
+
});
|
|
94
|
+
this.add(this.bottomUI);
|
|
95
|
+
|
|
96
|
+
// "Add Tile" button
|
|
97
|
+
this.bottomUI.add(new Button(game, {
|
|
98
|
+
text: isMobile ? "+" : "Add",
|
|
99
|
+
width: isMobile ? 40 : buttonWidth,
|
|
100
|
+
onClick: () => this.addTile(),
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
// "Remove Tile" button
|
|
104
|
+
this.bottomUI.add(new Button(game, {
|
|
105
|
+
text: isMobile ? "-" : "Remove",
|
|
106
|
+
width: isMobile ? 40 : buttonWidth,
|
|
107
|
+
onClick: () => this.removeTile(),
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
// "Add Column" button
|
|
111
|
+
this.bottomUI.add(new Button(game, {
|
|
112
|
+
text: isMobile ? "+Col" : "+ Column",
|
|
113
|
+
width: isMobile ? 50 : buttonWidth,
|
|
114
|
+
onClick: () => {
|
|
115
|
+
const maxColumns = this.getResponsiveColumns();
|
|
116
|
+
if (this.grid.columns < maxColumns) {
|
|
117
|
+
this.grid.columns++;
|
|
118
|
+
this.grid.markBoundsDirty();
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
// "Remove Column" button
|
|
124
|
+
this.bottomUI.add(new Button(game, {
|
|
125
|
+
text: isMobile ? "-Col" : "- Column",
|
|
126
|
+
width: isMobile ? 50 : buttonWidth,
|
|
127
|
+
onClick: () => {
|
|
128
|
+
this.grid.columns = Math.max(1, this.grid.columns - 1);
|
|
129
|
+
this.grid.markBoundsDirty();
|
|
130
|
+
},
|
|
131
|
+
}));
|
|
132
|
+
|
|
133
|
+
// Add 10 tiles button (for quickly testing scroll)
|
|
134
|
+
this.bottomUI.add(new Button(game, {
|
|
135
|
+
text: isMobile ? "+10" : "Add 10",
|
|
136
|
+
width: isMobile ? 45 : buttonWidth,
|
|
137
|
+
onClick: () => {
|
|
138
|
+
for (let i = 0; i < 10; i++) this.addTile();
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
addTile() {
|
|
144
|
+
const rect = new Rectangle({
|
|
145
|
+
width: CONFIG.tileSize,
|
|
146
|
+
height: CONFIG.tileSize,
|
|
147
|
+
color: Painter.colors.randomColorHSL(),
|
|
148
|
+
strokeColor: "white",
|
|
149
|
+
});
|
|
150
|
+
const tileGO = ShapeGOFactory.create(this.game, rect);
|
|
151
|
+
this.grid.add(tileGO);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
removeTile() {
|
|
155
|
+
if (this.grid.children.length > 0) {
|
|
156
|
+
const last = this.grid.children[this.grid.children.length - 1];
|
|
157
|
+
this.grid.remove(last);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
onResize() {
|
|
162
|
+
if (!this.grid) return;
|
|
163
|
+
|
|
164
|
+
// Update columns based on new width
|
|
165
|
+
const newColumns = this.getResponsiveColumns();
|
|
166
|
+
if (this.grid.columns !== newColumns) {
|
|
167
|
+
this.grid.columns = newColumns;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Update viewport for scrolling
|
|
171
|
+
const viewport = this.getViewportDimensions();
|
|
172
|
+
this.grid._viewportWidth = viewport.width;
|
|
173
|
+
this.grid._viewportHeight = viewport.height;
|
|
174
|
+
|
|
175
|
+
this.grid.markBoundsDirty();
|
|
176
|
+
if (this.bottomUI) {
|
|
177
|
+
this.bottomUI.markBoundsDirty();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
update(dt) {
|
|
182
|
+
super.update(dt);
|
|
183
|
+
this.elapsedTime += dt;
|
|
184
|
+
|
|
185
|
+
// Only process tiles every N seconds to reduce frequency
|
|
186
|
+
if (this.elapsedTime - this.lastChangeTime > 0.1) {
|
|
187
|
+
this.lastChangeTime = this.elapsedTime;
|
|
188
|
+
|
|
189
|
+
// Random number of tiles to change (between 1 and 10% of total tiles)
|
|
190
|
+
const tilesToChange = Math.max(
|
|
191
|
+
1,
|
|
192
|
+
Math.floor(this.grid.children.length * (0.1 + Math.random() * 0.1))
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Filter out tiles that are already tweening
|
|
196
|
+
const availableTiles = this.grid.children.filter(
|
|
197
|
+
(tile) => !tile.isTweening
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Shuffle and pick random tiles
|
|
201
|
+
const shuffled = [...availableTiles].sort(() => 0.5 - Math.random());
|
|
202
|
+
const selectedTiles = shuffled.slice(
|
|
203
|
+
0,
|
|
204
|
+
Math.min(tilesToChange, availableTiles.length)
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
// Start tweening on selected tiles
|
|
208
|
+
for (const tile of selectedTiles) {
|
|
209
|
+
tile.isTweening = true;
|
|
210
|
+
|
|
211
|
+
// Store RGB values directly instead of CSS string to avoid parsing issues
|
|
212
|
+
const rgb = tile.shape.color ?
|
|
213
|
+
Painter.colors.parseColorString(tile.shape.color) :
|
|
214
|
+
[255, 255, 255]; // Default to white if color is undefined
|
|
215
|
+
|
|
216
|
+
tile.startRGB = rgb;
|
|
217
|
+
|
|
218
|
+
// Generate vibrant random color in RGB directly
|
|
219
|
+
const hue = Math.floor(Math.random() * 360);
|
|
220
|
+
const saturation = 80 + Math.floor(Math.random() * 20); // 80-100%
|
|
221
|
+
const lightness = 50 + Math.floor(Math.random() * 30); // 50-80%
|
|
222
|
+
const targetRGB = Painter.colors.hslToRgb(hue, saturation, lightness);
|
|
223
|
+
|
|
224
|
+
tile.targetRGB = targetRGB;
|
|
225
|
+
tile.tweenElapsed = 0;
|
|
226
|
+
tile.tweenDuration = 0.5 + Math.random() * 0.5; // Random duration between 0.5-1.0 seconds
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Update all tweening tiles
|
|
231
|
+
for (const tile of this.grid.children) {
|
|
232
|
+
if (tile.isTweening) {
|
|
233
|
+
try {
|
|
234
|
+
// Update elapsed time
|
|
235
|
+
tile.tweenElapsed += dt;
|
|
236
|
+
|
|
237
|
+
// Calculate progress with proper easing
|
|
238
|
+
const progress = Math.min(tile.tweenElapsed / tile.tweenDuration, 1.0);
|
|
239
|
+
const easedProgress = Easing.easeInOutQuad(progress);
|
|
240
|
+
|
|
241
|
+
// Use the stored RGB values directly
|
|
242
|
+
if (tile.startRGB && tile.targetRGB) {
|
|
243
|
+
const newRGB = Tween.tweenColor(
|
|
244
|
+
tile.startRGB,
|
|
245
|
+
tile.targetRGB,
|
|
246
|
+
easedProgress
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Convert interpolated RGB values to CSS color string
|
|
250
|
+
tile.shape.color = Painter.colors.rgbArrayToCSS(newRGB);
|
|
251
|
+
|
|
252
|
+
// Check if tween is complete
|
|
253
|
+
if (progress >= 1) {
|
|
254
|
+
tile.isTweening = false;
|
|
255
|
+
tile.shape.color = Painter.colors.rgbArrayToCSS(tile.targetRGB);
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
// Color missing, reset the tweening state
|
|
259
|
+
console.warn("Missing color values for tweening");
|
|
260
|
+
tile.isTweening = false;
|
|
261
|
+
|
|
262
|
+
// Set a fallback color
|
|
263
|
+
const fallbackRGB = [
|
|
264
|
+
Math.floor(Math.random() * 255),
|
|
265
|
+
Math.floor(Math.random() * 255),
|
|
266
|
+
Math.floor(Math.random() * 255)
|
|
267
|
+
];
|
|
268
|
+
tile.shape.color = Painter.colors.rgbArrayToCSS(fallbackRGB);
|
|
269
|
+
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// Handle any errors in the color transition
|
|
272
|
+
console.warn("Error during color tweening:", error);
|
|
273
|
+
tile.isTweening = false;
|
|
274
|
+
|
|
275
|
+
// Set a fallback color
|
|
276
|
+
const fallbackRGB = [
|
|
277
|
+
Math.floor(Math.random() * 255),
|
|
278
|
+
Math.floor(Math.random() * 255),
|
|
279
|
+
Math.floor(Math.random() * 255)
|
|
280
|
+
];
|
|
281
|
+
tile.shape.color = Painter.colors.rgbArrayToCSS(fallbackRGB);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//
|
|
289
|
+
export class MyGame extends Game {
|
|
290
|
+
constructor(canvas) {
|
|
291
|
+
super(canvas);
|
|
292
|
+
this.backgroundColor = "black";
|
|
293
|
+
this.enableFluidSize();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
init() {
|
|
297
|
+
super.init();
|
|
298
|
+
this.tileDemo = new TileDemo(this);
|
|
299
|
+
this.pipeline.add(this.tileDemo);
|
|
300
|
+
this.pipeline.add(
|
|
301
|
+
new FPSCounter(this, {
|
|
302
|
+
anchor: "bottom-right",
|
|
303
|
+
})
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
onResize() {
|
|
308
|
+
if (this.tileDemo) {
|
|
309
|
+
this.tileDemo.onResize();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Game,
|
|
3
|
+
Rectangle,
|
|
4
|
+
Group,
|
|
5
|
+
Scene,
|
|
6
|
+
ShapeGOFactory,
|
|
7
|
+
TextShape,
|
|
8
|
+
FPSCounter,
|
|
9
|
+
Tween,
|
|
10
|
+
Tweenetik,
|
|
11
|
+
Easing,
|
|
12
|
+
} from "../../src/index";
|
|
13
|
+
export class TweenDemo extends Scene {
|
|
14
|
+
constructor(game, options = {}) {
|
|
15
|
+
super(game, options);
|
|
16
|
+
const bg = new Rectangle({ width: 100, height: 100, color: "#0f0" });
|
|
17
|
+
const frame = new Rectangle({ width: 80, height: 80, color: "#000" });
|
|
18
|
+
this.label = new TextShape("1%", {
|
|
19
|
+
font: "18px monospace",
|
|
20
|
+
color: "#F0F",
|
|
21
|
+
align: "center",
|
|
22
|
+
baseline: "middle",
|
|
23
|
+
});
|
|
24
|
+
const group = new Group();
|
|
25
|
+
group.add(bg);
|
|
26
|
+
group.add(frame);
|
|
27
|
+
group.add(this.label);
|
|
28
|
+
group.scaleX = group.scaleY = 2; // add individual scale to this group to test if the outer group scales it too
|
|
29
|
+
//
|
|
30
|
+
const wrapper = new Group();
|
|
31
|
+
wrapper.add(group);
|
|
32
|
+
//
|
|
33
|
+
this.box = ShapeGOFactory.create(game, wrapper);
|
|
34
|
+
this.box.anchor = "center";
|
|
35
|
+
this.add(this.box);
|
|
36
|
+
this.growing = false;
|
|
37
|
+
this.tween();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
tween() {
|
|
41
|
+
this.growing = !this.growing;
|
|
42
|
+
const scale = this.growing ? 2 : 1;
|
|
43
|
+
const easing = this.growing ? Easing.easeOutElastic : Easing.easeInOutBack;
|
|
44
|
+
// Tweenetik is a simple tweening library that works with any object
|
|
45
|
+
Tweenetik.to(
|
|
46
|
+
this.box, // an object or sprite
|
|
47
|
+
{ scaleX: scale, scaleY: scale }, // the properties & end-values
|
|
48
|
+
2.0, // duration in seconds
|
|
49
|
+
easing, // easing function
|
|
50
|
+
{
|
|
51
|
+
delay: 0.3,
|
|
52
|
+
onComplete: () => this.tween(), // restart the tween
|
|
53
|
+
onUpdate: () => this.updateText(),
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
updateText() {
|
|
59
|
+
this.label.text = `${Math.round(this.box.scaleX * 100)}%`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//
|
|
63
|
+
export class MyGame extends Game {
|
|
64
|
+
constructor(canvas) {
|
|
65
|
+
super(canvas);
|
|
66
|
+
this.backgroundColor = "black";
|
|
67
|
+
this.enableFluidSize();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
init() {
|
|
71
|
+
super.init();
|
|
72
|
+
this.pipeline.add(new TweenDemo(this, {debug: true, anchor: "center"}));
|
|
73
|
+
this.pipeline.add(
|
|
74
|
+
new FPSCounter(this, {
|
|
75
|
+
anchor: "bottom-right",
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Game,
|
|
3
|
+
Scene,
|
|
4
|
+
HorizontalLayout,
|
|
5
|
+
Rectangle,
|
|
6
|
+
ShapeGOFactory,
|
|
7
|
+
Button,
|
|
8
|
+
FPSCounter,
|
|
9
|
+
Square,
|
|
10
|
+
Position,
|
|
11
|
+
} from "../../src/index";
|
|
12
|
+
|
|
13
|
+
export class VisibilityDemo extends Scene {
|
|
14
|
+
constructor(game, options = {}) {
|
|
15
|
+
super(game, options);
|
|
16
|
+
this.MARGIN = 20;
|
|
17
|
+
// 1) A horizontal layout of squares at screen center
|
|
18
|
+
this.squaresLayout = new HorizontalLayout(game, {
|
|
19
|
+
spacing: 1,
|
|
20
|
+
padding: 4,
|
|
21
|
+
});
|
|
22
|
+
this.add(this.squaresLayout);
|
|
23
|
+
// Create a few colored squares and add them to the layout
|
|
24
|
+
const colors = ["#0f0", "#0f0", "#0f0"];
|
|
25
|
+
for (let i = 0; i < colors.length; i++) {
|
|
26
|
+
const rect = new Square(100, {
|
|
27
|
+
color: colors[i],
|
|
28
|
+
});
|
|
29
|
+
const squareGO = ShapeGOFactory.create(game, rect);
|
|
30
|
+
this.squaresLayout.add(squareGO);
|
|
31
|
+
}
|
|
32
|
+
// 2) A UI scene that holds the buttons
|
|
33
|
+
this.uiScene = new Scene(game, {
|
|
34
|
+
name: "UI Scene",
|
|
35
|
+
width: 120,
|
|
36
|
+
height: 40,
|
|
37
|
+
anchor: Position.BOTTOM_CENTER,
|
|
38
|
+
anchorMargin: 20,
|
|
39
|
+
});
|
|
40
|
+
this.uiScene.width = 150;
|
|
41
|
+
this.uiScene.height = 50;
|
|
42
|
+
this.add(this.uiScene);
|
|
43
|
+
// A button that toggles visibility of a random square
|
|
44
|
+
let currentSquare = null;
|
|
45
|
+
const pickOne = () => {
|
|
46
|
+
if (currentSquare) {
|
|
47
|
+
currentSquare.visible = !currentSquare.visible;
|
|
48
|
+
}
|
|
49
|
+
const index = Math.floor(
|
|
50
|
+
Math.random() * this.squaresLayout.children.length
|
|
51
|
+
);
|
|
52
|
+
const square = this.squaresLayout.children[index];
|
|
53
|
+
if (currentSquare == square) {
|
|
54
|
+
currentSquare = null;
|
|
55
|
+
return pickOne();
|
|
56
|
+
}
|
|
57
|
+
currentSquare = square;
|
|
58
|
+
currentSquare.visible = !currentSquare.visible;
|
|
59
|
+
};
|
|
60
|
+
const toggleBtn = new Button(game, {
|
|
61
|
+
text: "Toggle Random",
|
|
62
|
+
width: 120,
|
|
63
|
+
onClick: () => {
|
|
64
|
+
pickOne();
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
this.uiScene.add(toggleBtn);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
update(dt) {
|
|
71
|
+
// Update scene dimensions based on margin
|
|
72
|
+
this.width = this.game.width - this.MARGIN * 2;
|
|
73
|
+
this.height = this.game.height - this.MARGIN * 2;
|
|
74
|
+
// Center the scene in the game
|
|
75
|
+
this.x = this.game.width / 2;
|
|
76
|
+
this.y = this.game.height / 2;
|
|
77
|
+
super.update(dt);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
export class MyGame extends Game {
|
|
83
|
+
constructor(canvas) {
|
|
84
|
+
super(canvas);
|
|
85
|
+
this.backgroundColor = "black";
|
|
86
|
+
this.enableFluidSize();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
init() {
|
|
90
|
+
super.init();
|
|
91
|
+
this.scene = new VisibilityDemo(this, {
|
|
92
|
+
width: this.width,
|
|
93
|
+
height: this.height,
|
|
94
|
+
});
|
|
95
|
+
this.pipeline.add(this.scene);
|
|
96
|
+
this.pipeline.add(
|
|
97
|
+
new FPSCounter(this, {
|
|
98
|
+
anchor: Position.BOTTOM_RIGHT,
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
package/demos/kerr.html
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Math & Physics - Kerr Metric (Rotating Black Hole)</title>
|
|
8
|
+
<link rel="stylesheet" href="demos.css" />
|
|
9
|
+
<script src="./js/info-toggle.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<div id="info">
|
|
14
|
+
<strong>Kerr Metric</strong> — Rotating black hole with frame dragging.<br/>
|
|
15
|
+
<span style="color:#CCC">
|
|
16
|
+
<li><code>Spin</code> — Parameter a controls rotation (0 to M).</li>
|
|
17
|
+
<li><code>g_tφ</code> — Off-diagonal term = frame dragging!</li>
|
|
18
|
+
<li><code>Ergosphere</code> — Orange region where nothing stays still.</li>
|
|
19
|
+
<li><code>Two ISCOs</code> — Prograde vs retrograde orbits differ.</li>
|
|
20
|
+
<li><code>Click</code> — Shuffle mass and spin parameters.</li>
|
|
21
|
+
<li><code>Drag</code> — Rotate the 3D view.</li>
|
|
22
|
+
</span>
|
|
23
|
+
</div>
|
|
24
|
+
<canvas id="game"></canvas>
|
|
25
|
+
<script type="module" src="./js/kerr.js"></script>
|
|
26
|
+
</body>
|
|
27
|
+
|
|
28
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Generative Art - Lava Lamp</title>
|
|
8
|
+
<link rel="stylesheet" href="demos.css" />
|
|
9
|
+
<script src="./js/info-toggle.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<div id="info">
|
|
14
|
+
<strong>Lava Lamp</strong> — Metaball lava lamp with heat dynamics.<br/>
|
|
15
|
+
<span style="color:#CCC">
|
|
16
|
+
<li><code>ON/OFF</code> — Toggle power. Watch the wax cool and rise!</li>
|
|
17
|
+
<li><code>Heat zones</code> — Smooth thermal transitions between hot/cold.</li>
|
|
18
|
+
<li><code>Buoyancy</code> — Hot blobs rise, cold blobs sink.</li>
|
|
19
|
+
<li><code>Heat transfer</code> — Nearby blobs exchange temperature.</li>
|
|
20
|
+
<li><code>Metaballs</code> — Blobs merge and split organically.</li>
|
|
21
|
+
</span>
|
|
22
|
+
</div>
|
|
23
|
+
<canvas id="game"></canvas>
|
|
24
|
+
<script type="module" src="./js/lavalamp.js"></script>
|
|
25
|
+
</body>
|
|
26
|
+
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Layout Demo</title>
|
|
8
|
+
<link rel="stylesheet" href="demos.css" />
|
|
9
|
+
<script src="./js/info-toggle.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<div id="info" class="light">
|
|
14
|
+
<strong>Layout Demo</strong><br>
|
|
15
|
+
<span>Demonstrates dynamic switching between <code>HorizontalLayout</code> and
|
|
16
|
+
<code>VerticalLayout</code>.<br>
|
|
17
|
+
Use the right side buttons to switch layout direction.<br>
|
|
18
|
+
Use the bottom buttons to add or remove random rectangles from the layout group.<br>
|
|
19
|
+
Layout auto-sizes and aligns children with spacing and padding.
|
|
20
|
+
</span>
|
|
21
|
+
</div>
|
|
22
|
+
<canvas id="game"></canvas>
|
|
23
|
+
|
|
24
|
+
<script type="module">
|
|
25
|
+
import { LayoutDemo } from "./js/layout.js";
|
|
26
|
+
window.addEventListener("load", () => {
|
|
27
|
+
const canvas = document.getElementById("game");
|
|
28
|
+
const game = new LayoutDemo(canvas);
|
|
29
|
+
//game.setFPS(1)
|
|
30
|
+
//game.enableLogging(true);
|
|
31
|
+
game.start();
|
|
32
|
+
//setTimeout(game.stop.bind(game), 3000);
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
</body>
|
|
36
|
+
|
|
37
|
+
</html>
|
package/demos/logo.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="32.9 174.743 71.888 63.576" width="71.888px" height="63.576px">
|
|
3
|
+
<path d="M 57.971 224.292 L 57.971 203.374 L 57.971 194.861 L 75.109 194.861 L 75.109 188.769 L 63.16 188.769 L 63.16 174.743 L 57.971 174.743 L 57.971 189.041 L 57.971 194.861 L 32.9 194.861 L 32.9 203.773 L 50.377 203.773 L 50.377 224.292 L 57.971 224.292 Z M 79.717 238.319 L 79.717 224.02 L 79.717 218.2 L 104.788 218.2 L 104.788 209.287 L 87.31 209.287 L 87.31 188.769 L 79.717 188.769 L 79.717 209.686 L 79.717 218.2 L 62.579 218.2 L 62.579 224.293 L 74.526 224.293 L 74.526 238.319 L 79.717 238.319 Z" style="fill: rgb(255, 255, 255); fill-rule: evenodd; stroke-width: 1;" id="path8" transform="matrix(0.9999999999999999, 0, 0, 0.9999999999999999, 0, 0)"/>
|
|
4
|
+
</svg>
|
package/demos/loop.html
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Game Loop Demo</title>
|
|
8
|
+
<link rel="stylesheet" href="demos.css" />
|
|
9
|
+
<script src="./js/info-toggle.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<div id="info">
|
|
14
|
+
<strong>Game Loop Demo</strong> — Demonstrates the <code>update → render</code> cycle using a bouncing ball.
|
|
15
|
+
<br>
|
|
16
|
+
A <strong>Game</strong> runs the loop and delegates updates and rendering to its <strong>Pipeline</strong>. <br>
|
|
17
|
+
A <strong>GameObject</strong> implements <code>update(dt)</code> and <code>render()</code> to animate and draw
|
|
18
|
+
itself. <br>
|
|
19
|
+
This demo shows a ball that moves and bounces off canvas edges on each frame.
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<canvas id="game"></canvas>
|
|
23
|
+
|
|
24
|
+
<script type="module">
|
|
25
|
+
import { Game, Scene, GameObject, FPSCounter, Painter, Circle } from "../src/index";
|
|
26
|
+
class BouncingBall extends GameObject {
|
|
27
|
+
constructor(game) {
|
|
28
|
+
super(game);
|
|
29
|
+
this.radius = 20;
|
|
30
|
+
this.circle = new Circle(this.radius, {
|
|
31
|
+
color: "#0f0",
|
|
32
|
+
debug: false
|
|
33
|
+
});
|
|
34
|
+
this.x = game.width / 2;
|
|
35
|
+
this.y = game.height / 2;
|
|
36
|
+
this.vx = 150;
|
|
37
|
+
this.vy = 100;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
update(dt) {
|
|
41
|
+
this.x += this.vx * dt;
|
|
42
|
+
this.y += this.vy * dt;
|
|
43
|
+
const w = this.game.width;
|
|
44
|
+
const h = this.game.height;
|
|
45
|
+
if (this.x - this.radius < 0 || this.x + this.radius > w) this.vx *= -1;
|
|
46
|
+
if (this.y - this.radius < 0 || this.y + this.radius > h) this.vy *= -1;
|
|
47
|
+
// Clamp and update shape position
|
|
48
|
+
this.x = Math.max(this.radius, Math.min(w - this.radius, this.x));
|
|
49
|
+
this.y = Math.max(this.radius, Math.min(h - this.radius, this.y));
|
|
50
|
+
super.update(dt);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
draw() {
|
|
54
|
+
super.draw();
|
|
55
|
+
this.circle.render();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class LoopGame extends Game {
|
|
60
|
+
constructor(canvas) {
|
|
61
|
+
super(canvas);
|
|
62
|
+
this.enableFluidSize();
|
|
63
|
+
this.backgroundColor = "black";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
init() {
|
|
67
|
+
super.init();
|
|
68
|
+
this.pipeline.add(new BouncingBall(this));
|
|
69
|
+
this.pipeline.add(new FPSCounter(this, { anchor: "bottom-left" }));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
window.addEventListener("load", () => {
|
|
74
|
+
const canvas = document.getElementById("game");
|
|
75
|
+
const game = new LoopGame(canvas);
|
|
76
|
+
//game.enableLogging();
|
|
77
|
+
game.enablePauseOnBlur(true);
|
|
78
|
+
game.setFPS(60);
|
|
79
|
+
game.start();
|
|
80
|
+
});
|
|
81
|
+
</script>
|
|
82
|
+
</body>
|
|
83
|
+
|
|
84
|
+
</html>
|