diff options
author | elioat <{ID}+{username}@users.noreply.github.com> | 2024-12-27 10:51:53 -0500 |
---|---|---|
committer | elioat <{ID}+{username}@users.noreply.github.com> | 2024-12-27 10:51:53 -0500 |
commit | 93af36423b2a1415c89ab7adb92ee458d4ae5a46 (patch) | |
tree | c1ccd887ec6d28a8f8dd293868a29652ef33566d /html/rogue/js/items.js | |
parent | 558906f2349403e781c78e0385b70a08d320a21e (diff) | |
download | tour-93af36423b2a1415c89ab7adb92ee458d4ae5a46.tar.gz |
*
Diffstat (limited to 'html/rogue/js/items.js')
-rw-r--r-- | html/rogue/js/items.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/html/rogue/js/items.js b/html/rogue/js/items.js new file mode 100644 index 0000000..dc6dc1e --- /dev/null +++ b/html/rogue/js/items.js @@ -0,0 +1,63 @@ +const Items = { + items: new Map(), // Map of items on the grid, key is "q,r" + + // Item types + TYPES: { + COIN: { + name: 'Coin', + color: '#FFD700', + size: 0.2 // Size relative to hex + }, + GEM: { + name: 'Gem', + color: '#50C878', + size: 0.25 + } + }, + + // Initialize items on the map + init() { + this.items.clear(); + + // Add some random items + for (let i = 0; i < 10; i++) { + const q = Math.floor(Math.random() * HexGrid.GRID_SIZE - HexGrid.GRID_SIZE/2); + const r = Math.floor(Math.random() * HexGrid.GRID_SIZE - HexGrid.GRID_SIZE/2); + + // Don't place items at player start position + if (q !== 0 || r !== 0) { + const type = Math.random() < 0.5 ? this.TYPES.COIN : this.TYPES.GEM; + this.addItem(q, r, type); + } + } + }, + + // Add an item to the map + addItem(q, r, type) { + this.items.set(`${q},${r}`, { type, q, r }); + }, + + // Remove an item from the map + removeItem(q, r) { + return this.items.delete(`${q},${r}`); + }, + + // Get item at position + getItem(q, r) { + return this.items.get(`${q},${r}`); + }, + + // Draw all items + draw(ctx, hexToPixel, camera, HEX_SIZE) { + this.items.forEach(item => { + const pixelPos = hexToPixel({ q: item.q, r: item.r }); + const screenX = pixelPos.x - camera.x; + const screenY = pixelPos.y - camera.y; + + ctx.fillStyle = item.type.color; + ctx.beginPath(); + ctx.arc(screenX, screenY, HEX_SIZE * item.type.size, 0, Math.PI * 2); + ctx.fill(); + }); + } +}; \ No newline at end of file |