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:
@@ -10,15 +10,15 @@ export default class RetroArchitecture
|
||||
{
|
||||
constructor(tilesetSprite, tiles, columns, rows)
|
||||
{
|
||||
this.tileset = tilesetSprite;
|
||||
this.tilesetSprite = tilesetSprite;
|
||||
this.tiles = tiles;
|
||||
this.backgroundColor = null;
|
||||
this.backgroundImage = null;
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.matrix = [];
|
||||
this.tileWidth = this.tileset.getWidth() / this.tiles;
|
||||
this.tileHeight = this.tileset.getHeight();
|
||||
this.tileWidth = this.tilesetSprite.getWidth() / this.tiles;
|
||||
this.tileHeight = this.tilesetSprite.getHeight();
|
||||
this.startX = 0;
|
||||
this.startY = 0;
|
||||
this.targetX = 0;
|
||||
@@ -202,7 +202,7 @@ export default class RetroArchitecture
|
||||
tileRect.isContainingPoint(movable.getPositionFootRight());
|
||||
}
|
||||
|
||||
draw(context, camera = null)
|
||||
draw(context, camera = new Camera())
|
||||
{
|
||||
let viewX = parseInt(Math.floor(Math.max(0, camera.position.x) / this.tileWidth));
|
||||
let viewWidth = parseInt(Math.min(Math.ceil(camera.width), this.columns));
|
||||
@@ -213,7 +213,7 @@ export default class RetroArchitecture
|
||||
for (let x = viewX; x < viewWidth; x++) {
|
||||
let field = this.matrix[y][x];
|
||||
|
||||
if (field !== null && field !== undefined) {
|
||||
if (field !== null) {
|
||||
this.drawField(context, x, y, camera, field);
|
||||
}
|
||||
}
|
||||
@@ -223,8 +223,8 @@ export default class RetroArchitecture
|
||||
drawField(context, x, y, camera, field)
|
||||
{
|
||||
context.drawImage(
|
||||
this.tileset.canvas,
|
||||
field.tile * this.tileWidth,
|
||||
this.tilesetSprite.canvas,
|
||||
field.tile.index * this.tileWidth,
|
||||
0,
|
||||
this.tileWidth,
|
||||
this.tileHeight,
|
||||
@@ -235,10 +235,10 @@ export default class RetroArchitecture
|
||||
);
|
||||
}
|
||||
|
||||
static createFromData(data)
|
||||
static createFromData(level)
|
||||
{
|
||||
let graphicSet = GraphicSet[data.tileset];
|
||||
console.log(data);
|
||||
let graphicSet = GraphicSet[level.getTilesetId()];
|
||||
|
||||
let tileset = new RetroSprite(
|
||||
Setting.TILESET_LOCATION + graphicSet.tileset,
|
||||
graphicSet.scale
|
||||
@@ -247,29 +247,29 @@ export default class RetroArchitecture
|
||||
let architecture = new RetroArchitecture(
|
||||
tileset,
|
||||
graphicSet.tiles,
|
||||
data.columns,
|
||||
data.rows
|
||||
level.getColumns(),
|
||||
level.getRows()
|
||||
);
|
||||
|
||||
architecture.setBackgroundColor(graphicSet.backgroundColor);
|
||||
architecture.setBackgroundImage(graphicSet.backgroundImage);
|
||||
|
||||
architecture.startX = data.startX;
|
||||
architecture.startY = data.startY;
|
||||
architecture.targetX = data.targetX;
|
||||
architecture.targetY = data.targetY;
|
||||
architecture.targetPosition = new GeometryPoint(data.targetX, data.targetY);
|
||||
architecture.startX = level.getStartX();
|
||||
architecture.startY = level.getStartY();
|
||||
architecture.targetX = level.getTargetX();
|
||||
architecture.targetY = level.getTargetY();
|
||||
architecture.targetPosition = new GeometryPoint(level.getTargetX(), level.getTargetY());
|
||||
|
||||
for (let y = 0; y < data.rows; y++) {
|
||||
for (let x = 0; x < data.columns; x++) {
|
||||
if (data.matrix[y][x] > -1) {
|
||||
for (let y = 0; y < level.getRows(); y++) {
|
||||
for (let x = 0; x < level.getColumns(); x++) {
|
||||
if (level.getTilesetMatrix()[y][x].index > -1) {
|
||||
architecture.matrix[y][x] = new RetroArchitectureTile(
|
||||
data.matrix[y][x],
|
||||
level.getTilesetMatrix()[y][x],
|
||||
x * architecture.tileWidth,
|
||||
y * architecture.tileHeight,
|
||||
architecture.tileWidth,
|
||||
architecture.tileHeight
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user