summaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-10-31 03:24:28 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-10-31 03:24:28 +0000
commit15be06b415c693dfe6a10750e619d3128b0b59de (patch)
tree6612c79573216026c5b1601fbb33ad37e10112ff /src/index.js
parentbcb38594492aec4f1116b3fdf0e9821d4016903a (diff)
downloadthrow_simulation-15be06b415c693dfe6a10750e619d3128b0b59de.tar
throw_simulation-15be06b415c693dfe6a10750e619d3128b0b59de.tar.gz
throw_simulation-15be06b415c693dfe6a10750e619d3128b0b59de.zip
Add image support, page title; fix sleep issue
Passing the ?image query param will use that as the background-image for the throwable div. I also had to add a `true` to the applyImpulse call to stop the ball from going unresponsive (this is because it can go to "sleep", the extra parameter ensures it's woken up.)
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/index.js b/src/index.js
index 1275360..e07ac8a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,5 +1,13 @@
import RAPIER from "./rapier.es.js";
+const objElement = document.querySelector("div#throwable");
+
+const queryParams = new URLSearchParams(window.location.search);
+const image = queryParams.get("image");
+if (image !== null) {
+ objElement.style.backgroundImage = `url(${decodeURI(image)})`;
+}
+
RAPIER.init().then(() => {
const CLICK_IMPULSE_MULTIPLIER = 300_000;
const GRAVITY = { x: 0.0, y: 2000 };
@@ -36,7 +44,6 @@ RAPIER.init().then(() => {
obj,
);
- const objElement = document.querySelector("div#throwable");
const objSize = {
x: OBJ_BASE_SIZE.x,
y: OBJ_BASE_SIZE.y,
@@ -81,12 +88,15 @@ RAPIER.init().then(() => {
y: clickPosition.y - objPosition.y,
};
const distance = Math.sqrt(direction.x ** 2 + direction.y ** 2);
- obj.setLinvel({x: 0, y: 0});
+ obj.setLinvel({ x: 0, y: 0 });
if (distance > 0) {
- obj.applyImpulse({
- x: (direction.x * CLICK_IMPULSE_MULTIPLIER) / distance,
- y: (direction.y * CLICK_IMPULSE_MULTIPLIER) / distance,
- });
+ obj.applyImpulse(
+ {
+ x: (direction.x * CLICK_IMPULSE_MULTIPLIER) / distance,
+ y: (direction.y * CLICK_IMPULSE_MULTIPLIER) / distance,
+ },
+ true,
+ );
}
});