8.2.1 • Published 2 days ago

emath.js v8.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

Header

NOTE: THIS PACKAGE IS IN DEVELOPMENT AND IS SUBJECT TO MAJOR CHANGES

Abstract

This project started when I was trying to create my first incremental game. I found it difficult to implement certain systems like upgrades and saving. When I eventually made those systems, I wanted to make a package so I could streamline those tools. After a few months of development, I have finally developed it into a presentable state (I should have started it with v0.1.0 instead of v1.0.0 . . .).

Example Usage

import { E } from "emath.js";
import { Game } from "emath.js/game";

// For CDN usage:
// const { E, Game } = eMath; 

// Initialize game
const coinGame = new Game();

// Create a new currency
const coins = coinGame.addCurrency("coins");

// Create upgrades
coins.static.addUpgrade({
    id: "upg1Coins", // Unique ID
    cost: level => level.mul(10), // Cost of 10 times the level
    maxLevel: E(1000),
    effect: (level) => {
        coins.static.boost.setBoost({
            id: "boostUpg1Coins",
            effect: n => n.plus(level.mul(11)).sub(1),
        });
    },
});

// Initialize / Load game
coinGame.init();
coinGame.dataManager.loadData();

// Gain coins
coins.static.gain();

// Buy (max) upgrades
coins.static.buyUpgrade("upg1Coins");

// Hotkeys
coinGame.keyManager.addKey([
    {
        id: "gainCoins",
        name: "Gain Coins",
        key: "g",
        onDownContinuous: () => coins.static.gain(),
    },
    {
        id: "buyUpgrades",
        name: "Buy Upgrades",
        key: "b",
        onDownContinuous: () => coins.static.buyUpgrade("upg1Coins"),
    },
]);

// Saving and Loading
window.addEventListener("beforeunload", () => {
    coinGame.dataManager.saveData();
});
coinGame.eventManager.setEvent("autoSave", "interval", 30000, () => {
    coinGame.dataManager.saveData();
    console.log("Auto Saved!");
});

Installation

Install via npm (recommended)

npm install emath.js

Include using CDN

Note: There is no development build for CDN, as it is used for nodejs.

emath.js

<script src="https://cdn.jsdelivr.net/gh/xShadowBlade/emath.js/dist/main/eMath.min.js"></script>

emath.js/game

<script src="https://cdn.jsdelivr.net/gh/xShadowBlade/emath.js/dist/game/eMath.game.min.js"></script>

emath.js/pixiGame

CDN usage for this module is not yet available.


Check out the documentation!

8.2.1

2 days ago

8.2.0

7 days ago

8.1.0

11 days ago

8.0.0

15 days ago

8.0.0-rc.2

16 days ago

8.0.0-rc.1

19 days ago

8.0.0-rc.0

27 days ago

7.1.0

2 months ago

7.0.0

2 months ago

6.0.0

3 months ago

5.0.0

3 months ago

3.0.0

6 months ago

1.2.3

7 months ago

2.3.0

6 months ago

2.2.0

6 months ago

4.0.0

5 months ago

2.1.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.0

7 months ago

1.0.0

7 months ago