feat(#15): separate sprite from player
This commit is contained in:
parent
e2cd0ee490
commit
ea9d912e2f
6 changed files with 91 additions and 84 deletions
30
modules/game-objects/sprite.js
Normal file
30
modules/game-objects/sprite.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { GameObject } from "./game-object.js";
|
||||
|
||||
export class Sprite extends GameObject {
|
||||
constructor({ image, x = 0, y = 0, width = 0, height = 0, index = 0 }) {
|
||||
super({ x, y, height, width });
|
||||
this.index = index;
|
||||
this.image = image;
|
||||
this.imageWidth = this.image.width;
|
||||
this.imageHeight = this.image.height;
|
||||
}
|
||||
|
||||
render(ctx, destinationX, destinationY) {
|
||||
ctx.drawImage(
|
||||
this.image,
|
||||
this.x,
|
||||
this.y,
|
||||
this.width,
|
||||
this.height,
|
||||
destinationX,
|
||||
destinationY,
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
if (this.debug) {
|
||||
ctx.fillStyle = "Red";
|
||||
ctx.font = "normal 8pt Pixelify Sans";
|
||||
ctx.fillText(this.index, destinationX, destinationY + 8);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue