diff --git a/graphics/mr-croc-walk-left.png b/graphics/mr-croc-walk-left.png new file mode 100644 index 0000000..db0f6bc Binary files /dev/null and b/graphics/mr-croc-walk-left.png differ diff --git a/graphics/mr-croc-walk-right.png b/graphics/mr-croc-walk-right.png new file mode 100644 index 0000000..8d9c7f4 Binary files /dev/null and b/graphics/mr-croc-walk-right.png differ diff --git a/graphics/tileset-landscape01.jpg b/graphics/tileset-landscape01.jpg new file mode 100644 index 0000000..497f6a8 Binary files /dev/null and b/graphics/tileset-landscape01.jpg differ diff --git a/js/module.js b/js/module.js index 5ed278c..d408b92 100644 --- a/js/module.js +++ b/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); } diff --git a/js/retro/RetroArchitecture.js b/js/retro/RetroArchitecture.js index 9a0de0a..6ae730e 100644 --- a/js/retro/RetroArchitecture.js +++ b/js/retro/RetroArchitecture.js @@ -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) { diff --git a/levels/level.json b/levels/level.json new file mode 100644 index 0000000..7246516 --- /dev/null +++ b/levels/level.json @@ -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 ] + ] +} \ No newline at end of file