A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
import {
defineSystem, Query, Mut, Transform,
} from 'esengine';
import { Mover, Bouncer } from '../components';
const HALF_WIDTH = 400;
const HALF_HEIGHT = 300;
export const bounceSystem = defineSystem(
[Query(Transform, Mut(Mover), Bouncer)],
(query) => {
for (const [_entity, transform, mover] of query) {
if (transform.position.x > HALF_WIDTH || transform.position.x < -HALF_WIDTH) {
mover.directionX *= -1;
}
if (transform.position.y > HALF_HEIGHT || transform.position.y < -HALF_HEIGHT) {
mover.directionY *= -1;
}
}
},
{ name: 'BounceSystem' }
);