From 2f8b8c87fb2062313afea7b625ccb20d1bea95b9 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 24 May 2022 18:25:43 +0200 Subject: Initial commit --- src/drawables/Background.ts | 26 ++++++++++++++++++++++++++ src/drawables/Bullet.ts | 27 +++++++++++++++++++++++++++ src/drawables/Selector.ts | 15 +++++++++++++++ src/drawables/TopBar.ts | 17 +++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 src/drawables/Background.ts create mode 100644 src/drawables/Bullet.ts create mode 100644 src/drawables/Selector.ts create mode 100644 src/drawables/TopBar.ts (limited to 'src/drawables') diff --git a/src/drawables/Background.ts b/src/drawables/Background.ts new file mode 100644 index 0000000..1eef6c4 --- /dev/null +++ b/src/drawables/Background.ts @@ -0,0 +1,26 @@ +import { canvas, ctx } from "../consts"; +import Drawable from "../Drawable"; +import { IMGS } from "../Images"; + +export class Background extends Drawable { + sprite = IMGS.bg; + width = canvas.width + height = canvas.height - 24 + constructor() { + super(0, 0) + } + // delta = -1751 + 24 + 2693; + delta = 0 + move(): boolean { + this.delta += 1; + return true; + } + draw() { + if (this.sprite.src == null) this.sprite = IMGS.bg; + ctx.drawImage(this.sprite, 0, 2693 - this.delta + 24, 320, 200 - 24, 0, 24, this.width, this.height) + } + getImageData() { + ctx.drawImage(this.sprite, 0, 2693 - this.delta + 24, 320, 200 - 24, 0, 24, this.width, this.height) + return ctx.getImageData(0, 24, this.width, this.height); + } +} diff --git a/src/drawables/Bullet.ts b/src/drawables/Bullet.ts new file mode 100644 index 0000000..68f55e8 --- /dev/null +++ b/src/drawables/Bullet.ts @@ -0,0 +1,27 @@ +import { canvas } from "../consts"; +import Drawable from "../Drawable"; + +export default class Bullet extends Drawable { + static width = 2; + static height = 5; + static color = "black"; + color = "black"; + sprite = "black"; + + squares = [this] + + constructor(x: number, y: number, public xvel: number, public yvel: number, public players: boolean) { + super(x, y); + this.width = Bullet.width; + this.height = Bullet.height; + } + + move(): boolean { + this.x += this.xvel; + this.y += this.yvel; + + return ( + this.x + this.width < 0 || this.y + this.height < 0 || this.x > canvas.width || this.y > canvas.height + ); + } +} diff --git a/src/drawables/Selector.ts b/src/drawables/Selector.ts new file mode 100644 index 0000000..b72d839 --- /dev/null +++ b/src/drawables/Selector.ts @@ -0,0 +1,15 @@ +import { canvas, ctx } from "../consts"; +import Drawable from "../Drawable"; +import { IMGS } from "../Images"; + +export class Selector extends Drawable { + sprite = IMGS.selector + width = canvas.width + height = 24 + draw() { + if (this.sprite.src == null) this.sprite = IMGS.selector; + ctx.drawImage(this.sprite, this.x, this.y) + } +} + + diff --git a/src/drawables/TopBar.ts b/src/drawables/TopBar.ts new file mode 100644 index 0000000..f021f77 --- /dev/null +++ b/src/drawables/TopBar.ts @@ -0,0 +1,17 @@ +import { canvas, ctx } from "../consts"; +import Drawable from "../Drawable"; +import { IMGS } from "../Images"; + +export class TopBar extends Drawable { + sprite = IMGS.topbar; + width = canvas.width + height = 24 + constructor() { + super(0, 0) + } + draw() { + if (this.sprite.src == null) this.sprite = IMGS.topbar; + ctx.drawImage(this.sprite, 0, 0) + } +} + -- cgit v1.3.1