← Back to home
Tutorial series

Step 9. Player

Creating Tower Defense game with PIXI Step 9 of 12 2 min read

The player class will store information about the available number of coins and the remaining number of lives:

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

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

We will write the initial values ​​in the config:

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

Let’s create a player in the Game class:

import { Player } from './Player';

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

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