Final collision fixup.
This commit is contained in:
parent
0d7b99a903
commit
d6283d57e4
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
24
js/module.js
24
js/module.js
|
@ -78,7 +78,7 @@ function MainLoop(timestamp)
|
|||
|
||||
/* Movement left and right */
|
||||
if (KeyLeft.isPressed()) {
|
||||
let lastWallLeft = Math.max(
|
||||
let lastWallLeft = Math.min(
|
||||
architecture.getWallLeft(mrCroc.getPositionHeadLeft()),
|
||||
architecture.getWallLeft(mrCroc.getPositionFootLeft())
|
||||
);
|
||||
|
@ -89,7 +89,7 @@ function MainLoop(timestamp)
|
|||
mrCroc.position.x = lastWallLeft + mrCroc.getWidth() * 0.5 + 1;
|
||||
}
|
||||
} else if (KeyRight.isPressed()) {
|
||||
let lastWallRight = Math.min(
|
||||
let lastWallRight = Math.max(
|
||||
architecture.getWallRight(mrCroc.getPositionHeadRight()),
|
||||
architecture.getWallRight(mrCroc.getPositionFootRight())
|
||||
);
|
||||
|
@ -106,9 +106,10 @@ function MainLoop(timestamp)
|
|||
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
|
||||
architecture.draw(context);
|
||||
mrCroc.draw(context);
|
||||
|
||||
/*
|
||||
context.fillRect(0, lastCeilingHeight, window.innerWidth, 1);
|
||||
context.fillRect(0, lastGroundHeight, window.innerWidth, 1);
|
||||
context.fillRect(0, ceilingHeight, window.innerWidth, 1);
|
||||
context.fillRect(0, groundHeight, window.innerWidth, 1);
|
||||
context.fillStyle = 'black';
|
||||
context.fillRect(lastWallRight, 0, 1, window.innerHeight);
|
||||
context.fillStyle = 'red';
|
||||
|
@ -118,6 +119,7 @@ function MainLoop(timestamp)
|
|||
mrCroc.getPositionHeadLeft().draw(context);
|
||||
mrCroc.getPositionFootLeft().draw(context);
|
||||
*/
|
||||
|
||||
lastRendered = timestamp;
|
||||
}
|
||||
|
||||
|
@ -131,7 +133,7 @@ const FRAME_DURATION = 1000 / FPS;
|
|||
const GAME_SPEED = 1;
|
||||
const GRAVITY = 2;
|
||||
|
||||
let levelJson = new FileLoader('levels/test.json');
|
||||
let levelJson = new FileLoader('levels/level.json');
|
||||
const LEVEL = levelJson.getContent();
|
||||
|
||||
let lastRendered = undefined;
|
||||
|
@ -145,10 +147,6 @@ let KeyJump = new Key('Space');
|
|||
|
||||
let loader = new ImageLoader();
|
||||
|
||||
let image = new Image();
|
||||
image.src = 'graphics/mr-croc-stand.png';
|
||||
loader.addImage(image);
|
||||
|
||||
let imgAnimation = new Image();
|
||||
imgAnimation.src = 'graphics/mr-croc-walk-right.png';
|
||||
loader.addImage(imgAnimation);
|
||||
|
@ -157,10 +155,6 @@ let imgAnimationB = new Image();
|
|||
imgAnimationB.src = 'graphics/mr-croc-walk-left.png';
|
||||
loader.addImage(imgAnimationB);
|
||||
|
||||
let imgBackground = new Image();
|
||||
imgBackground.src = 'graphics/ground.jpg';
|
||||
loader.addImage(imgBackground);
|
||||
|
||||
let imgArch = new Image();
|
||||
imgArch.src = 'graphics/tileset-landscape01.jpg';
|
||||
loader.addImage(imgArch);
|
||||
|
@ -185,8 +179,8 @@ window.addEventListener(
|
|||
architecture = RetroArchitecture.createFromJson(LEVEL);
|
||||
|
||||
mrCroc = new MrCroc();
|
||||
mrCroc.position.x = 300;
|
||||
mrCroc.position.y = 100;
|
||||
mrCroc.position.x = 250;
|
||||
mrCroc.position.y = 0;
|
||||
|
||||
window.requestAnimationFrame(MainLoop);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ export default class RetroArchitecture
|
|||
|
||||
getWallRight(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), 1, -1);
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), 1, 0);
|
||||
|
||||
while (tilePosition !== null && tilePosition.x < this.columns) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
|
@ -127,7 +127,7 @@ export default class RetroArchitecture
|
|||
|
||||
getWallLeft(position)
|
||||
{
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), -1,-1);
|
||||
let tilePosition = this.getTileForPosition(new GeometryPoint(position.x, position.y), -1,0);
|
||||
|
||||
while (tilePosition !== null && tilePosition.x > 0) {
|
||||
if (this.matrix[tilePosition.y][tilePosition.x] !== null) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"tileset": "graphics/tileset-landscape01.jpg",
|
||||
"tiles": 8,
|
||||
"scale": 3,
|
||||
"rows": 10,
|
||||
"columns": 17,
|
||||
"matrix": [
|
||||
[6 ,6 ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,4 ,4 ],
|
||||
[6 ,6 ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,4 ,4 ],
|
||||
[6 ,6 ,null ,null ,null ,null ,null ,null ,0 ,0 ,0 ,0 ,null ,null ,null ,4 ,4 ],
|
||||
[6 ,6 ,2 ,null ,null ,null ,null ,0 ,4 ,4 ,4 ,4 ,0 ,null ,null ,4 ,4 ],
|
||||
[6 ,6 ,6 ,2 ,2 ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,4 ,4 ],
|
||||
[5 ,5 ,5 ,5 ,5 ,1 ,null ,null ,null ,null ,null ,null ,null ,null ,0 ,4 ,4 ],
|
||||
[4 ,4 ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,0 ,4 ,4 ,4 ],
|
||||
[4 ,4 ,null ,null ,null ,null ,0 ,0 ,0 ,null ,null ,null ,0 ,4 ,4 ,4 ,4 ],
|
||||
[4 ,4 ,0 ,0 ,0 ,null ,4 ,4 ,4 ,null ,null ,0 ,4 ,4 ,4 ,4 ,4 ],
|
||||
[4 ,4 ,4 ,4 ,4 ,0 ,4 ,4 ,4 ,0 ,0 ,4 ,4 ,4 ,4 ,4 ,4 ]
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue