mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Level class created and gravity editable.
This commit is contained in:
57
js/module.js
57
js/module.js
@@ -3,45 +3,13 @@
|
||||
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";
|
||||
import Gisela from "./Gisela.js";
|
||||
import Setting from "./Setting.js";
|
||||
import FrameRateMeasurer from "./FrameRateMeasurer.js";
|
||||
import GraphicSet from "./GraphicSet.js";
|
||||
|
||||
class ImageLoader
|
||||
{
|
||||
images = [];
|
||||
numberImagesLoaded = 0;
|
||||
|
||||
update()
|
||||
{
|
||||
this.numberImagesLoaded++;
|
||||
|
||||
if (this.numberImagesLoaded === this.images.length) {
|
||||
window.dispatchEvent(new Event('imagesloaded'));
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentProgress()
|
||||
{
|
||||
return this.numberImagesLoaded / this.images.length;
|
||||
}
|
||||
|
||||
addImage(imagePath)
|
||||
{
|
||||
let image = new Image();
|
||||
image.src = imagePath;
|
||||
image.addEventListener(
|
||||
'load', () => {
|
||||
this.update();
|
||||
}
|
||||
);
|
||||
|
||||
this.images.push(image);
|
||||
}
|
||||
}
|
||||
import ImageLoader from "./ImageLoader.js";
|
||||
import Level from "./Level.js";
|
||||
|
||||
function MainLoop(timestamp)
|
||||
{
|
||||
@@ -155,15 +123,12 @@ function MainLoop(timestamp)
|
||||
window.requestAnimationFrame(MainLoop);
|
||||
}
|
||||
|
||||
let level = Level.createFromFile('levels/test(2).json');
|
||||
|
||||
const GAME_SPEED = 1;
|
||||
const GRAVITY = 2;
|
||||
const GRAVITY = level.gravity;
|
||||
let fps;
|
||||
let frameDuration;
|
||||
|
||||
let levelJson = new FileLoader('levels/level01.json');
|
||||
|
||||
const LEVEL = JSON.parse(levelJson.getContent());
|
||||
|
||||
let lastRendered = undefined;
|
||||
let lastTimestamp = undefined;
|
||||
let context;
|
||||
@@ -180,7 +145,7 @@ let loader = new ImageLoader();
|
||||
|
||||
loader.addImage(Setting.GRAPHICS_LOCATION + 'mr-croc-walk-right.png');
|
||||
loader.addImage(Setting.GRAPHICS_LOCATION + 'mr-croc-walk-left.png');
|
||||
loader.addImage(Setting.TILESET_LOCATION + GraphicSet[LEVEL.tileset].tileset);
|
||||
loader.addImage(Setting.TILESET_LOCATION + GraphicSet[level.getTilesetId()].tileset);
|
||||
loader.addImage(Setting.GRAPHICS_LOCATION + 'gisela-right.png');
|
||||
|
||||
new FrameRateMeasurer();
|
||||
@@ -195,11 +160,11 @@ window.addEventListener(
|
||||
canvas.style.backgroundSize = 'cover';
|
||||
canvas.style.backgroundPosition = 'center center';
|
||||
|
||||
if (GraphicSet[LEVEL.tileset].backgroundImage !== null) {
|
||||
canvas.style.backgroundImage = 'url("' + Setting.GRAPHICS_LOCATION + GraphicSet[LEVEL.tileset].backgroundImage +'")';
|
||||
if (GraphicSet[level.getTilesetId()].backgroundImage !== null) {
|
||||
canvas.style.backgroundImage = 'url("' + Setting.GRAPHICS_LOCATION + GraphicSet[level.getTilesetId()].backgroundImage +'")';
|
||||
}
|
||||
|
||||
canvas.style.backgroundColor = LEVEL.backgroundColor;
|
||||
canvas.style.backgroundColor = level.getBackgroundColor();
|
||||
|
||||
window.addEventListener(
|
||||
'resize',
|
||||
@@ -211,7 +176,7 @@ window.addEventListener(
|
||||
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
architecture = RetroArchitecture.createFromData(LEVEL);
|
||||
architecture = RetroArchitecture.createFromData(level);
|
||||
camera.borderRight = architecture.columns * architecture.tileWidth;
|
||||
camera.borderBottom = architecture.rows * architecture.tileHeight;
|
||||
|
||||
@@ -221,7 +186,7 @@ window.addEventListener(
|
||||
gisela = new Gisela();
|
||||
architecture.setMovableToTargetPosition(gisela);
|
||||
|
||||
fps = 120;
|
||||
fps = 60;
|
||||
frameDuration = 1000 / fps;
|
||||
window.requestAnimationFrame(MainLoop);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user