commit 31c7eaefb6deb1e81ecc4d24ff856d302d085608 Author: Brian Fertig Date: Sat Aug 23 12:49:48 2025 -0600 first commit diff --git a/.continue/rules/framework.md b/.continue/rules/framework.md new file mode 100644 index 0000000..19857b0 --- /dev/null +++ b/.continue/rules/framework.md @@ -0,0 +1,8 @@ +--- +name: Phaser 3.90 Framework +--- + +- Follow best practices for Phaser 3.90 +- Follow best ES6 practices +- Write class imports using full .js paths, NPM package manager or any other web packager is not installed +- Break things out into classes when it makes sense \ No newline at end of file diff --git a/assets/jewels.png b/assets/jewels.png new file mode 100644 index 0000000..d913801 Binary files /dev/null and b/assets/jewels.png differ diff --git a/assets/jewels.psd b/assets/jewels.psd new file mode 100644 index 0000000..778017d Binary files /dev/null and b/assets/jewels.psd differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..552763c --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + + The Jewel Weaver + + + +
+ + + + \ No newline at end of file diff --git a/src/GameScene.js b/src/GameScene.js new file mode 100644 index 0000000..a7e14ac --- /dev/null +++ b/src/GameScene.js @@ -0,0 +1,122 @@ +export class GameScene extends Phaser.Scene { + constructor() { + super({ key: 'GameScene' }); + + this.gridConfig = { + allPadding: 50, + leftPadding: 700, + rows: 8, + cols: 8, + jewelWidth: 100, + jewelHeight: 100, + }; + + this.numberOfJewels = 5; + this.startRows = 2; + this.level = 1; + this.levelTime = 60; + } + + preload() { + this.load.spritesheet('jewels', 'assets/jewels.png', { + frameWidth: 100, + frameHeight: 100 + }); + } + + create() { + this.makeGrid(); + this.physics.world.setBounds(this.grid.getBounds().x, this.grid.getBounds().y, this.grid.getBounds().width, this.grid.getBounds().height); + this.jewels = this.physics.add.group({ + collideWorldBounds: true, + }); + this.physics.add.collider(this.jewels, this.jewels); + this.createStart(); + this.createJewel(this.getJewelAtPosition(1, 7), 3, 3); + } + + update(time, delta) { + + } + + selectJewel(x, y) { + + } + + makeGrid() { + this.grid = this.add.rectangle( + this.gridConfig.leftPadding + this.gridConfig.allPadding, + 0 + this.gridConfig.allPadding, + this.gridConfig.cols * this.gridConfig.jewelWidth, + this.gridConfig.rows*this.gridConfig.jewelHeight, + 0x000000, + .5 + ).setOrigin(0); + } + + createJewel(type, col, row) { + // Create a jewel sprite from the spritesheet using the type as frame index + const jewel = this.physics.add.sprite( + col * this.gridConfig.jewelWidth + this.gridConfig.leftPadding, + row * this.gridConfig.jewelHeight, + 'jewels', + type + ); + jewel.setDisplaySize(this.gridConfig.jewelWidth, this.gridConfig.jewelHeight); + jewel.jewelType = type; + this.jewels.add(jewel); + } + + createStart() { + // Create jewels at the bottom of the grid + let createWait = 0; + const startRow = this.gridConfig.rows - this.startRows; + + for (let row = this.startRows; row > 0; row--) { + for (let col = 1; col <= this.gridConfig.cols; col++) { + let type = null; + let match = false; + + do { + type = Phaser.Math.Between(0, this.numberOfJewels - 1) + match = false; + + if (this.getJewelAtPosition(col-1, startRow + row) === type && + this.getJewelAtPosition(col-2, startRow + row) === type) { + match = true; + } + + if (this.getJewelAtPosition(col, startRow + row + 1) === type && + this.getJewelAtPosition(col, startRow + row + 2) === type) { + match = true; + } + } while (match === true); + + // Create the jewel at the correct position + this.createJewel(type, col, startRow + row); + } + } + } + + getJewelAtPosition(col, row) { + // Convert grid coordinates to world coordinates + const x = col * this.gridConfig.jewelWidth + this.gridConfig.leftPadding; + const y = row * this.gridConfig.jewelHeight; + + // Find the jewel at that position + let jewelAtPosition = null; + + // Iterate through all jewels to find one near the specified position + this.jewels.children.iterate((jewel) => { + if (jewel && + Math.abs(jewel.x - x) < this.gridConfig.jewelWidth / 2 && + Math.abs(jewel.y - y) < this.gridConfig.jewelHeight / 2) { + jewelAtPosition = jewel; + return false; // Stop iteration + } + }); + + // Return the jewel type or null if not found + return jewelAtPosition ? jewelAtPosition.jewelType : null; + } +} \ No newline at end of file diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..8163c13 --- /dev/null +++ b/src/config.js @@ -0,0 +1,6 @@ +export const GRID_CONFIG = { + rows: 8, + cols: 8, + jewelWidth: 100, + jewelHeight: 100, +}; diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..8e4dd62 --- /dev/null +++ b/src/main.js @@ -0,0 +1,29 @@ +import { GameScene } from './GameScene.js'; + +const GAME_CONFIG = { + type: Phaser.AUTO, + scale: { + mode: Phaser.Scale.FIT, + autoCenter: Phaser.Scale.CENTER_BOTH, + width: 1600, + height: 900, + parent: 'game-container' + }, + parent: 'game-container', + backgroundColor: '#2c3e50', + scene: [ + GameScene + ], + physics: { + default: 'arcade', + arcade: { + gravity: { y: 100 }, + debug: false + } + } +}; + +// Create the game instance +const game = new Phaser.Game(GAME_CONFIG); + +console.log('The Jewel Weaver game initialized successfully!'); diff --git a/start_web.bat b/start_web.bat new file mode 100644 index 0000000..f266b01 --- /dev/null +++ b/start_web.bat @@ -0,0 +1 @@ +python -m http.server 8000 \ No newline at end of file