diff --git a/html/images/space.svg b/html/images/space.svg
index 470ce64..4197397 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -178,8 +178,8 @@
- fps
+ - use angular velocity for gun turning?
- bounce from collisions
- - gravity
- fall off screen after crash
- make ship a helicopter
- use paths for walls
@@ -520,7 +520,6 @@ function fireBullet(position, degrees) {
lineEl.addEventListener('transitionend', e => e.target.remove());
const startTime = performance.now()
- // console.time('bulletCollision');
let pt, hit;
for (let i = 0; i <= lineEl.getTotalLength(); i++) {
@@ -530,9 +529,24 @@ function fireBullet(position, degrees) {
}
const endTime = performance.now()
- // console.timeEnd('bulletCollision');
console.log(`Took ${endTime - startTime} milliseconds`)
+ // const screenCTM = svg.getScreenCTM();
+ // const startTime = performance.now()
+ //
+ // let pt, hit;
+ // for (let i = 0; i <= lineEl.getTotalLength(); i++) {
+ // pt = lineEl.getPointAtLength(i);
+ // const domPt = pt.matrixTransform(screenCTM);
+ // const elements = document.elementsFromPoint(domPt.x, domPt.y);
+ // hit = elements.find(el => el.classList.contains('wall'));
+ //
+ // if (hit) break;
+ // }
+ //
+ // const endTime = performance.now()
+ // console.log(`Took ${endTime - startTime} milliseconds`)
+
if (hit) {
lineEl.setAttribute('x2', pt.x);
lineEl.setAttribute('y2', pt.y);
@@ -771,6 +785,8 @@ function lineIntxnPt({ x1, y1, x2, y2 }, { x1: x3, y1: y3, x2: x4, y2: y4 }) {
}
function updateShip(s, elapsed) {
+ const gravity = 0.25;
+
if (rotate > 0) {
s.degrees = (s.degrees + rotationSpeed * elapsed) % 360;
} else if (rotate < 0) {
@@ -781,7 +797,9 @@ function updateShip(s, elapsed) {
const { x: px, y: py } = s.position;
const { x: vx, y: vy } = s.velocity;
- const { x: ax, y: ay } = s.acceleration;
+ // const { x: ax, y: ay } = s.acceleration;
+ let { x: ax, y: ay } = s.acceleration;
+ ay += gravity;
s.velocity = {
x: vx > 0 && vx + ax <= 0 ? 0 : vx + ax,