WIP: ECS
This commit is contained in:
@@ -1110,16 +1110,11 @@ function updateShip(s, elapsed) {
|
|||||||
const degrees = s.degrees;
|
const degrees = s.degrees;
|
||||||
ay += gravity;
|
ay += gravity;
|
||||||
|
|
||||||
console.log("s.acceleration", ax, ay);
|
|
||||||
|
|
||||||
|
|
||||||
s.velocity = {
|
s.velocity = {
|
||||||
x: vx > 0 && vx + ax <= 0 ? 0 : vx + ax,
|
x: vx > 0 && vx + ax <= 0 ? 0 : vx + ax,
|
||||||
y: vy > 0 && vy + ay <= 0 ? 0 : vy + ay
|
y: vy > 0 && vy + ay <= 0 ? 0 : vy + ay
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("s.v", s.velocity.x, s.velocity.y);
|
|
||||||
|
|
||||||
s.angularVelocity = angularVel + angularAcc;
|
s.angularVelocity = angularVel + angularAcc;
|
||||||
|
|
||||||
const friction = 0.05;
|
const friction = 0.05;
|
||||||
@@ -1154,9 +1149,6 @@ function updateShip(s, elapsed) {
|
|||||||
s.degrees = degrees + dDelta;
|
s.degrees = degrees + dDelta;
|
||||||
current = s.collision;
|
current = s.collision;
|
||||||
|
|
||||||
// const tempRadius = 7;
|
|
||||||
|
|
||||||
// s.collision = detectCollision([px, py], p, s.velocity, tempRadius, map);
|
|
||||||
s.collision = detectCollision([px, py], p, s.velocity, s.radius, map, s.gearDown);
|
s.collision = detectCollision([px, py], p, s.velocity, s.radius, map, s.gearDown);
|
||||||
if (!current && s.collision) console.log("COLLISION", s.collision);
|
if (!current && s.collision) console.log("COLLISION", s.collision);
|
||||||
|
|
||||||
@@ -1173,11 +1165,11 @@ function updateShip(s, elapsed) {
|
|||||||
posP = s.collision.position;
|
posP = s.collision.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// s.velocity = { x: 0, y: 0 };
|
s.velocity = { x: 0, y: 0 };
|
||||||
// s.position = { x: posP.x, y: posP.y }
|
// s.position = { x: posP.x, y: posP.y }
|
||||||
s.position = { x: p.x, y: p.y };
|
s.position = { x: p.x, y: p.y };
|
||||||
|
|
||||||
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
// s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
||||||
// } else if (current && s.collision) {
|
// } else if (current && s.collision) {
|
||||||
// console.log("2222222222222222222222222222222");
|
// console.log("2222222222222222222222222222222");
|
||||||
|
|
||||||
@@ -1193,8 +1185,9 @@ function updateShip(s, elapsed) {
|
|||||||
} else {
|
} else {
|
||||||
// console.log("33333333333333333333333333333");
|
// console.log("33333333333333333333333333333");
|
||||||
s.position = { x: p.x, y: p.y };
|
s.position = { x: p.x, y: p.y };
|
||||||
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
// s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
||||||
}
|
}
|
||||||
|
return s.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateEdges(position) {
|
function updateEdges(position) {
|
||||||
@@ -1289,7 +1282,10 @@ function animate(timestamp) {
|
|||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateShip(s, elapsed);
|
const newPos = updateShip(s, elapsed);
|
||||||
|
|
||||||
|
// s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
|
||||||
|
|
||||||
// Move.update(Ships[0], elapsed);
|
// Move.update(Ships[0], elapsed);
|
||||||
Ships.forEach(({ entity_id }) => {
|
Ships.forEach(({ entity_id }) => {
|
||||||
// Acceleration[entity_id] = zeroP;
|
// Acceleration[entity_id] = zeroP;
|
||||||
@@ -1298,6 +1294,9 @@ function animate(timestamp) {
|
|||||||
Move.update({ entity_id }, elapsed);
|
Move.update({ entity_id }, elapsed);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// s.node.style.transform = `translate(${newPos.x}px, ${newPos.y}px)`;
|
||||||
|
s.node.style.transform = `translate(${Position[Ships[0].entity_id].x}px, ${Position[Ships[0].entity_id].y}px)`;
|
||||||
|
|
||||||
positionEl.innerText = `${Position[Ships[0].entity_id].x.toFixed(1)},${Position[Ships[0].entity_id].y.toFixed(1)}`;
|
positionEl.innerText = `${Position[Ships[0].entity_id].x.toFixed(1)},${Position[Ships[0].entity_id].y.toFixed(1)}`;
|
||||||
|
|
||||||
// updateEdges(position);
|
// updateEdges(position);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 48 KiB |
Reference in New Issue
Block a user