mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Camera implemented.
This commit is contained in:
12
js/module.js
12
js/module.js
@@ -2,6 +2,7 @@ import Key from "./Key.js";
|
||||
import MrCroc from "./MrCroc.js";
|
||||
import RetroArchitecture from "./retro/RetroArchitecture.js";
|
||||
import FileLoader from "./FileLoader.js";
|
||||
import Camera from "./Camera.js";
|
||||
|
||||
class ImageLoader
|
||||
{
|
||||
@@ -104,8 +105,10 @@ function MainLoop(timestamp)
|
||||
/* Drawing */
|
||||
if (timestamp - lastRendered >= FRAME_DURATION) {
|
||||
context.clearRect(0, 0, window.innerWidth, window.innerHeight);
|
||||
architecture.draw(context);
|
||||
mrCroc.draw(context);
|
||||
|
||||
camera.centerCamera(mrCroc.position.x - mrCroc.getWidth() * 0.5, mrCroc.position.y - mrCroc.getHeight() * 0.5);
|
||||
architecture.draw(context, camera);
|
||||
mrCroc.draw(context, camera);
|
||||
|
||||
/*
|
||||
context.fillRect(0, ceilingHeight, window.innerWidth, 1);
|
||||
@@ -133,7 +136,7 @@ const FRAME_DURATION = 1000 / FPS;
|
||||
const GAME_SPEED = 1;
|
||||
const GRAVITY = 2;
|
||||
|
||||
let levelJson = new FileLoader('levels/test_startpoint.json');
|
||||
let levelJson = new FileLoader('levels/test_depth.json');
|
||||
|
||||
const LEVEL = JSON.parse(levelJson.getContent());
|
||||
|
||||
@@ -141,6 +144,7 @@ let lastRendered = undefined;
|
||||
let lastTimestamp = undefined;
|
||||
let context;
|
||||
let mrCroc, architecture;
|
||||
let camera = new Camera();
|
||||
|
||||
let KeyLeft = new Key('ArrowLeft');
|
||||
let KeyRight = new Key('ArrowRight');
|
||||
@@ -178,6 +182,8 @@ window.addEventListener(
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
architecture = RetroArchitecture.createFromData(LEVEL);
|
||||
camera.borderRight = architecture.columns * architecture.tileWidth;
|
||||
camera.borderBottom = architecture.rows * architecture.tileHeight;
|
||||
|
||||
mrCroc = new MrCroc();
|
||||
mrCroc.position.x = architecture.tileWidth * LEVEL.startX + architecture.tileWidth * 0.5;
|
||||
|
||||
Reference in New Issue
Block a user