From dd831a0a97e1cb75e581347e0ee6459bf26aa212 Mon Sep 17 00:00:00 2001 From: Nikita Iryupin Date: Wed, 28 Apr 2021 13:16:32 +0200 Subject: [PATCH] Reformat --- src/Blocks/block.js | 21 +++++++++++++-------- src/Graphics/Tileset/tile.js | 1 - src/{ => Graphics}/gameField.js | 6 +++--- src/KeyAdapters/tankKeyAdapter.js | 2 +- src/{ => Tanks}/directionEnum.js | 0 src/{ => Tanks}/playerTank.js | 0 src/canvas.js | 10 ---------- src/game.js | 11 ++++++++++- src/main.js | 4 ++-- 9 files changed, 29 insertions(+), 26 deletions(-) rename src/{ => Graphics}/gameField.js (94%) rename src/{ => Tanks}/directionEnum.js (100%) rename src/{ => Tanks}/playerTank.js (100%) delete mode 100644 src/canvas.js diff --git a/src/Blocks/block.js b/src/Blocks/block.js index 78e0633..fcba516 100644 --- a/src/Blocks/block.js +++ b/src/Blocks/block.js @@ -1,15 +1,9 @@ class Block { - constructor(width, height, xBox, yBox, wBox, hBox, tile) { - this._width = width; - this._height = height; - this._xBox = xBox; - this._yBox = yBox; - this._wBox = wBox; - this._hBox = hBox; + constructor(xBox, yBox, wBox, hBox, tile) { + this._box = new Box(xBox, yBox, wBox, hBox); this._tile = tile; } - draw(ctx, x, y){ ctx.drawImage(tile, x, y); } @@ -17,4 +11,15 @@ class Block { resolveAttack(){ return; } + + +} + +class Box { + constructor(xBox, yBox, wBox, hBox) { + this._xBox = xBox; + this._yBox = yBox; + this._wBox = wBox; + this._hBox = hBox; + } } \ No newline at end of file diff --git a/src/Graphics/Tileset/tile.js b/src/Graphics/Tileset/tile.js index ae64868..ef2be0e 100644 --- a/src/Graphics/Tileset/tile.js +++ b/src/Graphics/Tileset/tile.js @@ -6,7 +6,6 @@ export class Tile { this.height = height; this.id = id; - this.isTransperent = false; this.img = null; } diff --git a/src/gameField.js b/src/Graphics/gameField.js similarity index 94% rename from src/gameField.js rename to src/Graphics/gameField.js index 0274bd1..db43e96 100644 --- a/src/gameField.js +++ b/src/Graphics/gameField.js @@ -1,6 +1,6 @@ -import { Tileset } from "./Graphics/Tileset/tileset" -import { Map } from "./Graphics/map"; -import { PlayerTank } from "./playerTank"; +import { Tileset } from "./Tileset/tileset" +import { Map } from "./map"; +import { PlayerTank } from "../Tanks/playerTank"; export class GameField { TILE_SIZE = 32; diff --git a/src/KeyAdapters/tankKeyAdapter.js b/src/KeyAdapters/tankKeyAdapter.js index 1c3fb53..c264342 100644 --- a/src/KeyAdapters/tankKeyAdapter.js +++ b/src/KeyAdapters/tankKeyAdapter.js @@ -1,5 +1,5 @@ import { GameKeyAdapterInterface } from "./gameKeyAdapterInterface"; -import {DirectionEnum} from "./../directionEnum"; +import {DirectionEnum} from "../Tanks/directionEnum"; export class TankKeyAdapter extends GameKeyAdapterInterface{ diff --git a/src/directionEnum.js b/src/Tanks/directionEnum.js similarity index 100% rename from src/directionEnum.js rename to src/Tanks/directionEnum.js diff --git a/src/playerTank.js b/src/Tanks/playerTank.js similarity index 100% rename from src/playerTank.js rename to src/Tanks/playerTank.js diff --git a/src/canvas.js b/src/canvas.js deleted file mode 100644 index 1128219..0000000 --- a/src/canvas.js +++ /dev/null @@ -1,10 +0,0 @@ -import { Game } from "./game"; - -export function init() { - const canvas = document.getElementById("canvas"); - const ctx = canvas.getContext("2d"); - if (ctx) { - const game = new Game(500, 500, ctx, canvas); - game.start(); - } -} \ No newline at end of file diff --git a/src/game.js b/src/game.js index e8072ad..d0c99fe 100644 --- a/src/game.js +++ b/src/game.js @@ -1,6 +1,15 @@ -import { GameField } from "./gameField"; +import { GameField } from "./Graphics/gameField"; import { TankKeyAdapter } from "./KeyAdapters/tankKeyAdapter"; +export function init() { + const canvas = document.getElementById("canvas"); + const ctx = canvas.getContext("2d"); + if (ctx) { + const game = new Game(500, 500, ctx, canvas); + game.start(); + } +} + export class Game { constructor(width = 500, height = 500, ctx) { this.gameField = new GameField(width, height, ctx, canvas); diff --git a/src/main.js b/src/main.js index 9d2376e..c0bd8bc 100644 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,3 @@ -import * as canvas from "./canvas"; +import {init} from "./game"; -addEventListener("load", () => canvas.init()); \ No newline at end of file +addEventListener("load", () => init()); \ No newline at end of file