mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Final collision fixup.
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user