diff --git a/.gitignore b/.gitignore index 7170400..9facc3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules ._* -.DS_Store \ No newline at end of file +.DS_Store +dist \ No newline at end of file diff --git a/README.md b/README.md index 198f009..8fb5883 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# caa-game \ No newline at end of file +# caa-game +Welcome to the official repository of caa-game. Here one can track the progress of this wonderful game, and find the installation instructions. + +### 🏗️ Installation +To install, clone this repo, and run npm install. +```bash +git clone https://gitea.arnweb.nl/Hecc-inc./caa-game.git && cd caa-game +npm install +``` + +If you want to run this game, enter `npm start` in your terminal. + +### 🛠️ Building +To build this game into a distributable format, + - run `npm run build:win` on windows. + - run `npm run build:mac` on macOS. + - run `npm run build:linux` on linux. \ No newline at end of file diff --git a/main.js b/main.js index 5bd6946..d541e63 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,11 @@ const { app, BrowserWindow, ipcMain } = require("electron"); const path = require("path"); -require("electron-reload")(__dirname, { - electron: path.join(__dirname, "node_modules", ".bin", "electron") -}); +if (process.env.NODE_ENV === "dev") { + require("electron-reload")(__dirname, { + electron: path.join(__dirname, "node_modules", ".bin", "electron") + }); +} function createWindow () { // Create the browser window. diff --git a/package-lock.json b/package-lock.json index abd4bd9..da887ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -471,6 +471,58 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "cross-env": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.2.tgz", + "integrity": "sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + }, + "dependencies": { + "cross-spawn": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz", + "integrity": "sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", diff --git a/package.json b/package.json index 0b1b056..d57fffe 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,11 @@ "description": "", "main": "main.js", "scripts": { - "start": "npm run lint && electron .", - "lint": "eslint ." + "start": "npm run lint && cross-env NODE_ENV=dev electron .", + "lint": "eslint .", + "build:win": "electron-packager . --platform=win32 --out=dist --overwrite", + "build:mac": "electron-packager . --platform=darwin --out=dist --overwrite", + "build:linux": "electron-packager . --platform=linux --out=dist --overwrite" }, "author": "McArn", "license": "ISC", @@ -13,6 +16,7 @@ "asdf-games": "^1.0.12" }, "devDependencies": { + "cross-env": "^7.0.2", "electron": "^8.0.2", "electron-packager": "^14.2.1", "electron-reload": "^1.5.0", diff --git a/src/game.js b/src/game.js index fe241c2..9a81cb9 100644 --- a/src/game.js +++ b/src/game.js @@ -14,6 +14,7 @@ const { scene } = game; const mouseAim = new MouseControls(document.getElementById("board")); const keys = new KeyControls(); +const Stats = require("./src/helpers/stats.js"); var Player = require("./src/entities/player.js"); var Level = require("./src/helpers/level.js"); @@ -26,10 +27,12 @@ player.pos.y = level.startPos[0].y / 1; player.level = level; const camera = new Camera(player, window, { w: level.w * 2, h: level.h * 2 }); +const stats = new Stats(player); scene.add(camera); camera.add(level); camera.add(player); +scene.add(stats); function switchLevel(module, pos = 0) { camera.map(function(e) { @@ -55,15 +58,15 @@ game.run(() => { // Debugging tools if (mouseAim.isDown) { console.log("cliccccccccccc"); - console.log(player.items); + console.log(player); console.log(level); } // Switch to another level if (level.switch) { + console.log("Switching level!", level); switchLevel(require(level.switch.module), level.switch.pos); level.switch = undefined; - console.log(player); } // Refocus camera to player when player is moved by a portal diff --git a/src/helpers/stats.js b/src/helpers/stats.js new file mode 100644 index 0000000..25f1429 --- /dev/null +++ b/src/helpers/stats.js @@ -0,0 +1,60 @@ +const { Container, TileSprite, Rect, Texture, Text } = require("asdf-games"); +const tilemapFrames = require("../../res/tilemap.js"); + +const tilemap = new Texture("res/tilemap.png"); +const tileSize = 32; +const fillStyle = {fill: "#ffffff", font: "24px Arial"}; + +class Stats extends Container { + constructor(player) { + super(); + + this.player = player; + + const background = new Rect(640, 42, {fill: "rgba(0,0,0, 0.5)"}); + background.pos = {x: 0, y: 280}; + + const livesText = new Text("LIVES:", fillStyle); + livesText.pos = {x: 10, y: 310}; + + const livesCounter = new Text(player.lives, fillStyle); + livesCounter.pos = {x: 90, y: 310}; + + const heart = new TileSprite(tilemap, tileSize, tileSize); + heart.frame = {x: tilemapFrames[42].x / tileSize, y: tilemapFrames[42].y / tileSize}; + heart.pos = {x: 104, y: 284}; + + const staminaText = new Text("| STAMINA:", fillStyle); + staminaText.pos = {x: 140, y: 310}; + + this.children = [ + background, + livesText, + livesCounter, + heart, + staminaText + // Stamina is added afterward + ]; + + Array(5).fill().forEach((_val, index) => { + const sprite = new TileSprite(tilemap, tileSize, tileSize); + sprite.frame = {x: tilemapFrames[44].x / tileSize, y: tilemapFrames[44].y / tileSize}; + sprite.pos = {x: index * 26 + 270, y: 286}; + this.children.push(sprite); + }); + } + + update() { + this.children[2].text = this.player.lives; + + Array(5).fill().forEach((_val, index) => { + //console.log(Math.round(this.player.stamina.current) - 1, index); + this.children[index + 5].frame = + (Math.round(this.player.stamina.current)) <= index + ? {x: tilemapFrames[45].x / tileSize, y: tilemapFrames[45].y / tileSize} + : {x: tilemapFrames[44].x / tileSize, y: tilemapFrames[44].y / tileSize}; + }); + } +} + +module.exports = Stats; \ No newline at end of file