feat: implement Camera system and component for improved viewport management and player tracking
All checks were successful
Build and Publish Docker Image / Build and Validate (pull_request) Successful in 14s
All checks were successful
Build and Publish Docker Image / Build and Validate (pull_request) Successful in 14s
This commit is contained in:
parent
62e58f77ae
commit
c859e20ffc
13 changed files with 596 additions and 72 deletions
|
|
@ -77,21 +77,42 @@ export class MovementSystem extends System {
|
|||
velocity.vy *= Math.pow(friction, deltaTime * 60);
|
||||
}
|
||||
|
||||
const canvas = this.engine.canvas;
|
||||
if (position.x < 0) {
|
||||
position.x = 0;
|
||||
velocity.vx = 0;
|
||||
} else if (position.x > canvas.width) {
|
||||
position.x = canvas.width;
|
||||
velocity.vx = 0;
|
||||
}
|
||||
if (tileMap) {
|
||||
const mapWidth = tileMap.cols * tileMap.tileSize;
|
||||
const mapHeight = tileMap.rows * tileMap.tileSize;
|
||||
|
||||
if (position.y < 0) {
|
||||
position.y = 0;
|
||||
velocity.vy = 0;
|
||||
} else if (position.y > canvas.height) {
|
||||
position.y = canvas.height;
|
||||
velocity.vy = 0;
|
||||
if (position.x < 0) {
|
||||
position.x = 0;
|
||||
velocity.vx = 0;
|
||||
} else if (position.x > mapWidth) {
|
||||
position.x = mapWidth;
|
||||
velocity.vx = 0;
|
||||
}
|
||||
|
||||
if (position.y < 0) {
|
||||
position.y = 0;
|
||||
velocity.vy = 0;
|
||||
} else if (position.y > mapHeight) {
|
||||
position.y = mapHeight;
|
||||
velocity.vy = 0;
|
||||
}
|
||||
} else {
|
||||
const canvas = this.engine.canvas;
|
||||
if (position.x < 0) {
|
||||
position.x = 0;
|
||||
velocity.vx = 0;
|
||||
} else if (position.x > canvas.width) {
|
||||
position.x = canvas.width;
|
||||
velocity.vx = 0;
|
||||
}
|
||||
|
||||
if (position.y < 0) {
|
||||
position.y = 0;
|
||||
velocity.vy = 0;
|
||||
} else if (position.y > canvas.height) {
|
||||
position.y = canvas.height;
|
||||
velocity.vy = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue