code/component-patrol.js
// custom component controlling enemy patrol movement
custom component controlling enemy patrol movement
custom component controlling enemy patrol movement
function patrol(speed = 60, dir = 1) {
	return {
		id: "patrol",
		require: [ "pos", "area", ],
		add() {
			this.on("collide", (obj, side) => {
				if (side === "left" || side === "right") {
					dir = -dir;
				}
			});
		},
		update() {
			this.move(speed * dir, 0);
		},
	};
}
function patrol ( speed = 60 , dir = 1 ) { return { id : "patrol" , require : [ "pos" , "area" , ] , add ( ) { this . on ( "collide" , ( obj , side ) => { if ( side === "left" || side === "right" ) { dir = - dir ; } } ) ; } , update ( ) { this . move ( speed * dir , 0 ) ; } , } ; }
custom component controlling enemy patrol movement
custom component controlling enemy patrol movement