Skip to content

Commit

Permalink
Added flockdemo
Browse files Browse the repository at this point in the history
  • Loading branch information
tracygardner committed Jan 16, 2025
1 parent ea43bc2 commit 900d71d
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ define(['./workbox-d9a5ed57'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.e3d7gq7qrfo"
"revision": "0.029nmjdg088"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
6 changes: 3 additions & 3 deletions flock.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export const flock = {
onIntersect,
getProperty,
exportMesh,
abortSceneExecution
abortSceneExecution,
setPhysicsShape,
} = flock;
${code}
Expand Down Expand Up @@ -3199,7 +3200,6 @@ export const flock = {
mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs, true);
},
createPlane(planeId, color, width, height, position) {

const newPlane = flock.BABYLON.MeshBuilder.CreatePlane(
planeId,
{ width, height, sideOrientation: flock.BABYLON.Mesh.DOUBLESIDE },
Expand Down Expand Up @@ -3239,7 +3239,7 @@ export const flock = {
});

newPlane.physics = planeBody;

//flock.setSizeBasedPlaneUVs(newPlane, width, height);

const material = new flock.BABYLON.StandardMaterial(
Expand Down
151 changes: 151 additions & 0 deletions flockdemo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Flock standalone example</title>

<style>
body {
font-family: "Asap", Helvetica, Arial, Lucida, sans-serif !important;
}
</style>
</head>
<body>
<h1>Flock!</h1>

<canvas id="renderCanvas" touch-action="none" style="width: 640px; height: 360px;" tabindex="0"></canvas>
</div>

<script id="flock" type="application/flock">
// Made with Flock XR
var player = 'player'; var cylinder5 = 'cylinder5'; var box2 = 'box2'; var box1 = 'box1'; var jumping = 'jumping'; var cylinder3 = 'cylinder3'; var sound1 = 'sound1'; var object1 = 'object1'; var cylinder4 = 'cylinder4'; var cylinder6 = 'cylinder6';

(async () => {
printText('🌈 Welcome to Flock XR', 30, "#000080");
printText('Use WASD to walk around', 30, "#000080");
box2 = createBox("box2", "#333333", 2, 1, 0.5, [(-1.2), 0.6, (-2.2)]);

cylinder6 = createCylinder("cylinder6", "#666666", 0.1, 0.6, 0.6, 24, [(-0.6), 0.6, (-1.9)]);
await rotateTo(cylinder6, 90, 180, 180);

cylinder6 = createCylinder("cylinder6", "#666666", 0.1, 0.6, 0.6, 24, [(-1.8), 0.6, (-1.9)]);
await rotateTo(cylinder6, 90, 180, 180);

})();

(async () => {
box1 = createBox("box1", "#cc9933", 10, 0.1, 10, [0, 0.05, 0]);

object1 = newObject({
modelName: 'hut.glb',
modelId: 'hut.glb__7',
color: ["#2a9d8f", "#e9c46a", "#e76f51"],
scale: 1,
position: { x: 0, y: 0, z: 0 },
callback: async function() {
await positionAt(object1, 0, 4.5, 0, true);
await scaleMesh(object1, 10, 6, 10, 'CENTRE', 'BASE', 'CENTRE');
await rotateTo(object1, 0, (-90), 0);
await setPhysicsShape(object1, "MESH");

}
});
})();

(async () => {
cylinder3 = createCylinder("cylinder3", "#666666", 0.2, 1, 1, 24, [2, 0.1, (-1)]);

cylinder4 = createCylinder("cylinder4", "#666666", 2.4, 0.1, 0.1, 24, [2, 1.5, (-1)]);

cylinder5 = createCylinder("cylinder5", "#ffcc00", 1, 1, 2, 24, [2, 2.2, (-1)]);

})();

(async () => {
setSky("#6495ed");
createGround("#71bc78", "ground");
buttonControls("BOTH", false, "#ffffff");
})();

(async () => {
jumping = false;
player = newCharacter({
modelName: 'Character1.glb',
modelId: 'Character1.glb__8',
scale: 0.75,
position: { x: 0.3, y: 0.3, z: 10 },
colors: {
hair: "#000000",
skin: "#a15c33",
eyes: "#000000",
sleeves: "#008b8b",
shorts: "#00008b",
tshirt: "#ff8f60"
}
});
await setPhysics(player, "DYNAMIC");
await attachCamera(player, 5);
})();

onIntersect(player, cylinder5, "OnIntersectionEnterTrigger", async function() {

await glow(cylinder5);

});

onIntersect(player, box1, "OnIntersectionExitTrigger", async function() {

await clearEffects(cylinder5);

});

onTrigger(box2, "OnPickTrigger", [
async function() {
flock.playSound(box2, "theme-electronic.ogg", {"playbackRate":1,"volume":1,"loop":false});
}
], { mode: "wait" });

forever(async () => {
if (jumping && (isTouchingSurface(player))) {
jumping = false;
broadcastEvent('landed');
}
if ((keyPressed(" ")) && !jumping) {
applyForce(player, 0, 5, 0);
jumping = true;
broadcastEvent('jumped');
}
if (keyPressed("w")) {
moveForward(player, 8);
} else if (keyPressed("s")) {
moveForward(player, (-8));
} else if (keyPressed("a")) {
moveSideways(player, 5);
} else if (keyPressed("d")) {
moveSideways(player, (-5));
}
if (!jumping) {
if ((keyPressed("w")) || (keyPressed("s")) || (keyPressed("a")) || (keyPressed("d"))) {
await switchAnimation(player, "Walk");
} else {
await switchAnimation(player, "Idle");
}
}
});

onEvent('jumped', async function() {
await playAnimation(player, "Jump");
await switchAnimation(player, "Jump_Idle");
});

onEvent('landed', async function() {
await playAnimation(player, "Jump_Land");
});
</script>

<script type="module">
import "https://flipcomputing.github.io/flock/flock.js";
</script>
</body>
</html>

0 comments on commit 900d71d

Please sign in to comment.