← На главную
Серия руководств

Шаг 9. Игрок

Создание Tower Defense с PIXI • Шаг 9 из 12

Класс игрока хранит доступное число монет и оставшиеся жизни:

import { App } from "../system/App";

export class Player {
    constructor() {
        this.coins = App.config.player.coins;
        this.lives = App.config.player.lives;
    }
}

Начальные значения запишем в конфигурацию:

export const Config = {
    // ...
    player: {
        coins: 200,
        lives: 5
    }
};

Создадим игрока в классе Game:

import { Player } from './Player';

export class GameScene extends Scene {
    create() {
        this.createPlayer();
        // ...
    }

    createPlayer() {
        this.player = new Player();
    }
    // ...
}