Compare commits
2 Commits
c52b91c007
...
b43b67ecac
Author | SHA1 | Date | |
---|---|---|---|
b43b67ecac | |||
e5b1498955 |
@ -1,5 +1,6 @@
|
|||||||
**/.git
|
**/.git
|
||||||
**/node_modules
|
**/node_modules
|
||||||
|
**/dist
|
||||||
|
|
||||||
*.html
|
*.html
|
||||||
*.css
|
*.css
|
||||||
|
@ -104,26 +104,62 @@ export class TiledSprite extends Sprite {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw single image
|
||||||
context.drawImage(this.image(), this.x, this.y);
|
context.drawImage(this.image(), this.x, this.y);
|
||||||
|
|
||||||
let copyUpByY = Math.ceil(this.y / this.image().height);
|
let copyUpByY = Math.ceil(this.y / this.image().height);
|
||||||
|
let copyUpByX = Math.ceil(this.y / this.image().width);
|
||||||
let copyDownByY = Math.ceil(
|
let copyDownByY = Math.ceil(
|
||||||
(context.canvas.height - this.y - this.image().height) / this.image().height
|
(context.canvas.height - this.y - this.image().height) / this.image().height
|
||||||
);
|
);
|
||||||
|
let copyDownByX = Math.ceil(
|
||||||
|
(context.canvas.width - this.y - this.image().width) / this.image().width
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i <= copyUpByY; i++) {
|
for (let iy = 0; iy <= copyUpByY; iy++) {
|
||||||
if (copyUpByY === Infinity) {
|
if (copyUpByY === Infinity) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.drawImage(this.image(), this.x, this.y - this.image().height * i);
|
for (let ix = 0; ix <= copyUpByX + 1; ix++) {
|
||||||
|
if (copyUpByX === Infinity) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.drawImage(
|
||||||
|
this.image(),
|
||||||
|
this.x - this.image().width * ix,
|
||||||
|
this.y - this.image().height * iy
|
||||||
|
);
|
||||||
|
context.drawImage(
|
||||||
|
this.image(),
|
||||||
|
this.x + this.image().width * ix,
|
||||||
|
this.y - this.image().height * iy
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i <= copyDownByY; i++) {
|
for (let iy = 0; iy <= copyDownByY; iy++) {
|
||||||
if (copyDownByY === Infinity) {
|
if (copyDownByY === Infinity) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.drawImage(this.image(), this.x, this.y + this.image().height * i);
|
for (let ix = 0; ix <= copyUpByX + 1; ix++) {
|
||||||
|
if (copyUpByX === Infinity) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.drawImage(
|
||||||
|
this.image(),
|
||||||
|
this.x - this.image().width * ix,
|
||||||
|
this.y + this.image().height * iy
|
||||||
|
);
|
||||||
|
context.drawImage(
|
||||||
|
this.image(),
|
||||||
|
this.x + this.image().width * ix,
|
||||||
|
this.y + this.image().height * iy
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { App } from './app.js';
|
import { App, Scene, SceneLayer, Rect, StrokeRect, Sprite } from './engine.js';
|
||||||
import { Scene, SceneLayer } from './scene.js';
|
|
||||||
import { Rect, StrokeRect, Sprite } from './objects.js';
|
|
||||||
|
|
||||||
// init player
|
// init player
|
||||||
let Player = {
|
let Player = {
|
||||||
@ -21,14 +19,14 @@ let layerBg = new SceneLayer('background', [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
let layerHud = new SceneLayer('hud', [
|
let layerHud = new SceneLayer('hud', [
|
||||||
new Sprite('compass.png', 15, 15),
|
new Sprite('/assets/compass.png', 15, 15),
|
||||||
new Sprite('compass-arrow.png', 27, 21),
|
new Sprite('/assets/compass-arrow.png', 27, 21),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let layerInstances = new SceneLayer('Instances', [Player.rect], { debug: true });
|
let layerInstances = new SceneLayer('Instances', [Player.rect], { debug: true });
|
||||||
|
|
||||||
// init app
|
// init app
|
||||||
let app = new App(document.querySelector('canvas'), 400, 400);
|
let app = new App(400, 400);
|
||||||
|
|
||||||
// init scene
|
// init scene
|
||||||
let firstScene = new Scene(app.canvas, app.context, 400, 400);
|
let firstScene = new Scene(app.canvas, app.context, 400, 400);
|
||||||
|
Loading…
Reference in New Issue
Block a user