FAZA 1: Terrain generation with Perlin noise and isometric view - Ready for testing
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
class GameScene extends Phaser.Scene {
|
||||
constructor() {
|
||||
super({ key: 'GameScene' });
|
||||
this.terrainSystem = null;
|
||||
this.terrainContainer = null;
|
||||
}
|
||||
|
||||
create() {
|
||||
@@ -11,23 +13,31 @@ class GameScene extends Phaser.Scene {
|
||||
const width = this.cameras.main.width;
|
||||
const height = this.cameras.main.height;
|
||||
|
||||
// Testno besedilo - potrditev da scena deluje
|
||||
const testText = this.add.text(width / 2, height / 2, 'FAZA 0: Setup Complete!\n\nGame Scene Active', {
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '32px',
|
||||
fill: '#00ff41',
|
||||
align: 'center'
|
||||
});
|
||||
testText.setOrigin(0.5);
|
||||
// Setup kamere
|
||||
this.cameras.main.setBackgroundColor('#1a1a2e');
|
||||
|
||||
// Inicializiraj terrain sistem - 100x100 mapa
|
||||
console.log('🌍 Initializing terrain...');
|
||||
this.terrainSystem = new TerrainSystem(this, 100, 100);
|
||||
this.terrainSystem.generate();
|
||||
this.terrainContainer = this.terrainSystem.render(width / 2, 100);
|
||||
|
||||
// Kamera kontrole
|
||||
this.setupCamera();
|
||||
|
||||
// UI elementi
|
||||
this.createUI();
|
||||
|
||||
// Debug info
|
||||
const debugText = this.add.text(10, 10, 'FAZA 0 TEST\nElectron + Phaser OK', {
|
||||
this.debugText = this.add.text(10, 10, '', {
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '14px',
|
||||
fontSize: '12px',
|
||||
fill: '#ffffff',
|
||||
backgroundColor: '#000000',
|
||||
padding: { x: 10, y: 5 }
|
||||
padding: { x: 5, y: 3 }
|
||||
});
|
||||
this.debugText.setScrollFactor(0);
|
||||
this.debugText.setDepth(1000);
|
||||
|
||||
// FPS counter
|
||||
this.fpsText = this.add.text(10, height - 30, 'FPS: 60', {
|
||||
@@ -35,14 +45,125 @@ class GameScene extends Phaser.Scene {
|
||||
fontSize: '14px',
|
||||
fill: '#00ff41'
|
||||
});
|
||||
this.fpsText.setScrollFactor(0);
|
||||
this.fpsText.setDepth(1000);
|
||||
|
||||
console.log('✅ Faza 0 setup complete - ready for manual testing!');
|
||||
console.log('✅ GameScene ready - FAZA 1!');
|
||||
}
|
||||
|
||||
update() {
|
||||
setupCamera() {
|
||||
const cam = this.cameras.main;
|
||||
|
||||
// Zoom kontrole (Mouse Wheel)
|
||||
this.input.on('wheel', (pointer, gameObjects, deltaX, deltaY, deltaZ) => {
|
||||
const zoomSpeed = 0.001;
|
||||
const newZoom = Phaser.Math.Clamp(
|
||||
cam.zoom - deltaY * zoomSpeed,
|
||||
0.3,
|
||||
2.0
|
||||
);
|
||||
cam.setZoom(newZoom);
|
||||
});
|
||||
|
||||
// Pan kontrole (Right click + drag)
|
||||
this.input.on('pointermove', (pointer) => {
|
||||
if (pointer.rightButtonDown()) {
|
||||
cam.scrollX -= (pointer.x - pointer.prevPosition.x) / cam.zoom;
|
||||
cam.scrollY -= (pointer.y - pointer.prevPosition.y) / cam.zoom;
|
||||
}
|
||||
});
|
||||
|
||||
// WASD za kamera kontrolo (alternativa)
|
||||
this.cursors = this.input.keyboard.addKeys({
|
||||
up: Phaser.Input.Keyboard.KeyCodes.W,
|
||||
down: Phaser.Input.Keyboard.KeyCodes.S,
|
||||
left: Phaser.Input.Keyboard.KeyCodes.A,
|
||||
right: Phaser.Input.Keyboard.KeyCodes.D,
|
||||
zoomIn: Phaser.Input.Keyboard.KeyCodes.Q,
|
||||
zoomOut: Phaser.Input.Keyboard.KeyCodes.E
|
||||
});
|
||||
}
|
||||
|
||||
createUI() {
|
||||
const width = this.cameras.main.width;
|
||||
|
||||
// Naslov
|
||||
const title = this.add.text(width / 2, 20, 'FAZA 1: Generacija Terena', {
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '20px',
|
||||
fill: '#00ff41',
|
||||
fontStyle: 'bold'
|
||||
});
|
||||
title.setOrigin(0.5, 0);
|
||||
title.setScrollFactor(0);
|
||||
title.setDepth(1000);
|
||||
|
||||
// Kontrole info
|
||||
const controlsText = this.add.text(width - 10, 10,
|
||||
'Kontrole:\n' +
|
||||
'WASD - Pan\n' +
|
||||
'Q/E - Zoom\n' +
|
||||
'Mouse Wheel - Zoom\n' +
|
||||
'Right Click - Pan',
|
||||
{
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '11px',
|
||||
fill: '#888888',
|
||||
backgroundColor: '#000000',
|
||||
padding: { x: 5, y: 3 },
|
||||
align: 'right'
|
||||
}
|
||||
);
|
||||
controlsText.setOrigin(1, 0);
|
||||
controlsText.setScrollFactor(0);
|
||||
controlsText.setDepth(1000);
|
||||
}
|
||||
|
||||
update(time, delta) {
|
||||
// Update FPS
|
||||
if (this.fpsText) {
|
||||
this.fpsText.setText(`FPS: ${Math.round(this.game.loop.actualFps)}`);
|
||||
}
|
||||
|
||||
// Kamera movement (WASD)
|
||||
const cam = this.cameras.main;
|
||||
const panSpeed = 5;
|
||||
|
||||
if (this.cursors) {
|
||||
if (this.cursors.up.isDown) {
|
||||
cam.scrollY -= panSpeed;
|
||||
}
|
||||
if (this.cursors.down.isDown) {
|
||||
cam.scrollY += panSpeed;
|
||||
}
|
||||
if (this.cursors.left.isDown) {
|
||||
cam.scrollX -= panSpeed;
|
||||
}
|
||||
if (this.cursors.right.isDown) {
|
||||
cam.scrollX += panSpeed;
|
||||
}
|
||||
|
||||
// Zoom
|
||||
if (this.cursors.zoomIn.isDown) {
|
||||
cam.setZoom(Phaser.Math.Clamp(cam.zoom + 0.01, 0.3, 2.0));
|
||||
}
|
||||
if (this.cursors.zoomOut.isDown) {
|
||||
cam.setZoom(Phaser.Math.Clamp(cam.zoom - 0.01, 0.3, 2.0));
|
||||
}
|
||||
}
|
||||
|
||||
// Debug info update
|
||||
if (this.debugText) {
|
||||
const pointer = this.input.activePointer;
|
||||
const worldX = Math.round(pointer.worldX);
|
||||
const worldY = Math.round(pointer.worldY);
|
||||
|
||||
this.debugText.setText(
|
||||
`FAZA 1 - Terrain System\n` +
|
||||
`Zoom: ${cam.zoom.toFixed(2)}\n` +
|
||||
`Camera: (${Math.round(cam.scrollX)}, ${Math.round(cam.scrollY)})\n` +
|
||||
`Mouse: (${worldX}, ${worldY})`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user