Float around
This commit is contained in:
@@ -29,6 +29,10 @@
|
|||||||
transform: translate(-7.5px, -5px);
|
transform: translate(-7.5px, -5px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tank circle {
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
#crosshair {
|
#crosshair {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
@@ -48,14 +52,15 @@
|
|||||||
<rect id="bg" x="-200" y="-150" width="400" height="300"/>
|
<rect id="bg" x="-200" y="-150" width="400" height="300"/>
|
||||||
<g class="hitbox">
|
<g class="hitbox">
|
||||||
<g class="tank">
|
<g class="tank">
|
||||||
<line x1="0" y1="0" x2="0" y2="10" stroke="black"/>
|
<!-- <line x1="0" y1="0" x2="0" y2="10" stroke="black"/> -->
|
||||||
<rect width="15" height="10"/>
|
<!-- <rect width="15" height="10"/> -->
|
||||||
|
<circle cx="0" cy="0" r="5"/>
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
<g id="crosshair">
|
<!-- <g id="crosshair"> -->
|
||||||
<line x1="-2" y1="0" x2="2" y2="0" stroke="red"/>
|
<!-- <line x1="-2" y1="0" x2="2" y2="0" stroke="red"/> -->
|
||||||
<line x1="0" y1="-2" x2="0" y2="2" stroke="red"/>
|
<!-- <line x1="0" y1="-2" x2="0" y2="2" stroke="red"/> -->
|
||||||
</g>
|
<!-- </g> -->
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<foreignObject x="-200" y="-150" width="100%" height="100%">
|
<foreignObject x="-200" y="-150" width="100%" height="100%">
|
||||||
@@ -78,8 +83,8 @@
|
|||||||
const reverseMoveButton = document.querySelector("#move-backward");
|
const reverseMoveButton = document.querySelector("#move-backward");
|
||||||
const forwardMoveButton = document.querySelector("#move-forward");
|
const forwardMoveButton = document.querySelector("#move-forward");
|
||||||
const fps = document.querySelector("#fps");
|
const fps = document.querySelector("#fps");
|
||||||
const velocity = [-100, -50]; // meters per second
|
let velocity = [0, 0]; // meters per second
|
||||||
|
let acceleration = [0, 0]; // meters per second per second
|
||||||
let previous, zero, frameCount = 0;
|
let previous, zero, frameCount = 0;
|
||||||
|
|
||||||
requestAnimationFrame(firstFrame);
|
requestAnimationFrame(firstFrame);
|
||||||
@@ -103,7 +108,12 @@
|
|||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [velocityX, velocityY] = velocity;
|
let [velocityX, velocityY] = velocity;
|
||||||
|
|
||||||
|
const [accelerationX, accelerationY] = acceleration;
|
||||||
|
|
||||||
|
velocity = [velocityX + accelerationX, velocityY + accelerationY];
|
||||||
|
|
||||||
const changeX = 0.001 * elapsed * velocityX;
|
const changeX = 0.001 * elapsed * velocityX;
|
||||||
const changeY = 0.001 * elapsed * velocityY;
|
const changeY = 0.001 * elapsed * velocityY;
|
||||||
|
|
||||||
@@ -121,8 +131,8 @@
|
|||||||
let positionX = changeX + +x;
|
let positionX = changeX + +x;
|
||||||
let positionY = changeY + +y;
|
let positionY = changeY + +y;
|
||||||
|
|
||||||
if (positionY > 150) positionY = positionY - 150 - 150;
|
if (positionY > 150) positionY += -300;
|
||||||
else if (positionY < -150) positionY = -1 * positionY - 150 + 150;
|
else if (positionY < -150) positionY += 300;
|
||||||
|
|
||||||
if (positionX > 200) positionX += -400;
|
if (positionX > 200) positionX += -400;
|
||||||
else if (positionX < -200) positionX += 400;
|
else if (positionX < -200) positionX += 400;
|
||||||
@@ -131,7 +141,10 @@
|
|||||||
// console.log(hitbox.style.transform);
|
// console.log(hitbox.style.transform);
|
||||||
// hitbox.style.transform = `translate(0px, ${position}px)`;
|
// hitbox.style.transform = `translate(0px, ${position}px)`;
|
||||||
// if (+y < 200)
|
// if (+y < 200)
|
||||||
if (timestamp < 10000) requestAnimationFrame(t => animate(t));
|
// if (timestamp < 10000)
|
||||||
|
requestAnimationFrame(t => animate(t));
|
||||||
|
|
||||||
|
// if (velocity[1] < 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveTank(el) {
|
function moveTank(el) {
|
||||||
@@ -300,43 +313,56 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
leftTurnButton.addEventListener("mousedown", function (e) {
|
leftTurnButton.addEventListener("mousedown", function (e) {
|
||||||
tankTurn.playbackRate = 1;
|
acceleration[0] = -1;
|
||||||
tankTurn.play();
|
// tankTurn.playbackRate = 1;
|
||||||
|
// tankTurn.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
leftTurnButton.addEventListener("mouseup", function (e) {
|
leftTurnButton.addEventListener("mouseup", function (e) {
|
||||||
tankTurn.pause();
|
acceleration[0] = 0;
|
||||||
afterTurn();
|
|
||||||
|
// tankTurn.pause();
|
||||||
|
// afterTurn();
|
||||||
});
|
});
|
||||||
|
|
||||||
rightTurnButton.addEventListener("mousedown", function (e) {
|
rightTurnButton.addEventListener("mousedown", function (e) {
|
||||||
tankTurn.playbackRate = -1;
|
acceleration[0] = 1;
|
||||||
tankTurn.play();
|
|
||||||
|
// tankTurn.playbackRate = -1;
|
||||||
|
// tankTurn.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
rightTurnButton.addEventListener("mouseup", function (e) {
|
rightTurnButton.addEventListener("mouseup", function (e) {
|
||||||
tankTurn.pause();
|
acceleration[0] = 0;
|
||||||
afterTurn();
|
|
||||||
|
// tankTurn.pause();
|
||||||
|
// afterTurn();
|
||||||
});
|
});
|
||||||
|
|
||||||
reverseMoveButton.addEventListener("mousedown", function (e) {
|
reverseMoveButton.addEventListener("mousedown", function (e) {
|
||||||
tankMove.playbackRate = -1;
|
acceleration[1] = -1; // meters per second per second
|
||||||
tankMove.play();
|
|
||||||
|
// tankMove.playbackRate = -1;
|
||||||
|
// tankMove.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
reverseMoveButton.addEventListener("mouseup", function (e) {
|
reverseMoveButton.addEventListener("mouseup", function (e) {
|
||||||
tankMove.pause();
|
acceleration[1] = 0; // meters per second per second
|
||||||
afterMove();
|
|
||||||
|
// tankMove.pause();
|
||||||
|
// afterMove();
|
||||||
});
|
});
|
||||||
|
|
||||||
forwardMoveButton.addEventListener("mousedown", function (e) {
|
forwardMoveButton.addEventListener("mousedown", function (e) {
|
||||||
tankMove.playbackRate = 1;
|
// tankMove.playbackRate = 1;
|
||||||
tankMove.play();
|
// tankMove.play();
|
||||||
|
acceleration[1] = 1; // meters per second per second
|
||||||
});
|
});
|
||||||
|
|
||||||
forwardMoveButton.addEventListener("mouseup", function (e) {
|
forwardMoveButton.addEventListener("mouseup", function (e) {
|
||||||
tankMove.pause();
|
// tankMove.pause();
|
||||||
afterMove();
|
// afterMove();
|
||||||
|
acceleration[1] = 0; // meters per second per second
|
||||||
});
|
});
|
||||||
|
|
||||||
// tankTurn.addEventListener("finish", function (e) {
|
// tankTurn.addEventListener("finish", function (e) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
Reference in New Issue
Block a user