fix camera
This commit is contained in:
parent
abe1e2ca54
commit
344569edee
@ -140,11 +140,7 @@ class GameEngine {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.canvas.addEventListener('wheel', (e) => {
|
// Zoom controls disabled for fixed camera view
|
||||||
e.preventDefault();
|
|
||||||
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
|
||||||
this.renderer.setZoom(this.renderer.camera.zoom * zoomFactor);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
@ -184,7 +180,6 @@ class GameEngine {
|
|||||||
if (this.puckActive) {
|
if (this.puckActive) {
|
||||||
this.puck.update(deltaTime, this.gameState, this.players);
|
this.puck.update(deltaTime, this.gameState, this.players);
|
||||||
this.updateCollisions();
|
this.updateCollisions();
|
||||||
this.renderer.updateCamera(this.puck.position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateEffects(deltaTime);
|
this.updateEffects(deltaTime);
|
||||||
|
|||||||
@ -2,15 +2,9 @@ class Renderer {
|
|||||||
constructor(canvas) {
|
constructor(canvas) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.ctx = canvas.getContext('2d');
|
this.ctx = canvas.getContext('2d');
|
||||||
this.camera = {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
zoom: 1,
|
|
||||||
target: null,
|
|
||||||
smoothing: 0.1
|
|
||||||
};
|
|
||||||
|
|
||||||
this.setupCanvas();
|
this.setupCanvas();
|
||||||
|
this.setupFixedCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupCanvas() {
|
setupCanvas() {
|
||||||
@ -18,6 +12,27 @@ class Renderer {
|
|||||||
this.ctx.imageSmoothingEnabled = false;
|
this.ctx.imageSmoothingEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupFixedCamera() {
|
||||||
|
const rinkWidth = 1000;
|
||||||
|
const rinkHeight = 600;
|
||||||
|
const padding = 50;
|
||||||
|
|
||||||
|
const scaleX = this.canvas.width / (rinkWidth + padding * 2);
|
||||||
|
const scaleY = this.canvas.height / (rinkHeight + padding * 2);
|
||||||
|
const zoom = Math.min(scaleX, scaleY);
|
||||||
|
|
||||||
|
const x = (this.canvas.width - rinkWidth * zoom) / 2;
|
||||||
|
const y = (this.canvas.height - rinkHeight * zoom) / 2;
|
||||||
|
|
||||||
|
this.camera = {
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
zoom: zoom,
|
||||||
|
target: null,
|
||||||
|
smoothing: 0.1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
}
|
}
|
||||||
@ -242,17 +257,7 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateCamera(target) {
|
updateCamera(target) {
|
||||||
if (target) {
|
// Camera is now fixed - no updates needed
|
||||||
this.camera.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.camera.target) {
|
|
||||||
const targetX = this.canvas.width / 2 - this.camera.target.x * this.camera.zoom;
|
|
||||||
const targetY = this.canvas.height / 2 - this.camera.target.y * this.camera.zoom;
|
|
||||||
|
|
||||||
this.camera.x += (targetX - this.camera.x) * this.camera.smoothing;
|
|
||||||
this.camera.y += (targetY - this.camera.y) * this.camera.smoothing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyCamera() {
|
applyCamera() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user