This commit is contained in:
Nikita Iryupin 2021-04-28 13:16:32 +02:00
parent e1a909b728
commit dd831a0a97
9 changed files with 29 additions and 26 deletions

View File

@ -1,15 +1,9 @@
class Block { class Block {
constructor(width, height, xBox, yBox, wBox, hBox, tile) { constructor(xBox, yBox, wBox, hBox, tile) {
this._width = width; this._box = new Box(xBox, yBox, wBox, hBox);
this._height = height;
this._xBox = xBox;
this._yBox = yBox;
this._wBox = wBox;
this._hBox = hBox;
this._tile = tile; this._tile = tile;
} }
draw(ctx, x, y){ draw(ctx, x, y){
ctx.drawImage(tile, x, y); ctx.drawImage(tile, x, y);
} }
@ -17,4 +11,15 @@ class Block {
resolveAttack(){ resolveAttack(){
return; return;
} }
}
class Box {
constructor(xBox, yBox, wBox, hBox) {
this._xBox = xBox;
this._yBox = yBox;
this._wBox = wBox;
this._hBox = hBox;
}
} }

View File

@ -6,7 +6,6 @@ export class Tile {
this.height = height; this.height = height;
this.id = id; this.id = id;
this.isTransperent = false;
this.img = null; this.img = null;
} }

View File

@ -1,6 +1,6 @@
import { Tileset } from "./Graphics/Tileset/tileset" import { Tileset } from "./Tileset/tileset"
import { Map } from "./Graphics/map"; import { Map } from "./map";
import { PlayerTank } from "./playerTank"; import { PlayerTank } from "../Tanks/playerTank";
export class GameField { export class GameField {
TILE_SIZE = 32; TILE_SIZE = 32;

View File

@ -1,5 +1,5 @@
import { GameKeyAdapterInterface } from "./gameKeyAdapterInterface"; import { GameKeyAdapterInterface } from "./gameKeyAdapterInterface";
import {DirectionEnum} from "./../directionEnum"; import {DirectionEnum} from "../Tanks/directionEnum";
export class TankKeyAdapter extends GameKeyAdapterInterface{ export class TankKeyAdapter extends GameKeyAdapterInterface{

View File

@ -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();
}
}

View File

@ -1,6 +1,15 @@
import { GameField } from "./gameField"; import { GameField } from "./Graphics/gameField";
import { TankKeyAdapter } from "./KeyAdapters/tankKeyAdapter"; 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 { export class Game {
constructor(width = 500, height = 500, ctx) { constructor(width = 500, height = 500, ctx) {
this.gameField = new GameField(width, height, ctx, canvas); this.gameField = new GameField(width, height, ctx, canvas);

View File

@ -1,3 +1,3 @@
import * as canvas from "./canvas"; import {init} from "./game";
addEventListener("load", () => canvas.init()); addEventListener("load", () => init());