FAZA 2: Player entity with WASD movement, walking animation, and camera follow - Ready for testing
This commit is contained in:
@@ -4,6 +4,7 @@ class GameScene extends Phaser.Scene {
|
||||
super({ key: 'GameScene' });
|
||||
this.terrainSystem = null;
|
||||
this.terrainContainer = null;
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
create() {
|
||||
@@ -22,6 +23,13 @@ class GameScene extends Phaser.Scene {
|
||||
this.terrainSystem.generate();
|
||||
this.terrainContainer = this.terrainSystem.render(width / 2, 100);
|
||||
|
||||
// Dodaj igralca - spawn na sredini mape
|
||||
console.log('👤 Initializing player...');
|
||||
this.player = new Player(this, 50, 50);
|
||||
|
||||
// Kamera sledi igralcu
|
||||
this.cameras.main.startFollow(this.player.sprite, true, 0.1, 0.1);
|
||||
|
||||
// Kamera kontrole
|
||||
this.setupCamera();
|
||||
|
||||
@@ -48,7 +56,7 @@ class GameScene extends Phaser.Scene {
|
||||
this.fpsText.setScrollFactor(0);
|
||||
this.fpsText.setDepth(1000);
|
||||
|
||||
console.log('✅ GameScene ready - FAZA 1!');
|
||||
console.log('✅ GameScene ready - FAZA 2!');
|
||||
}
|
||||
|
||||
setupCamera() {
|
||||
@@ -65,20 +73,11 @@ class GameScene extends Phaser.Scene {
|
||||
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;
|
||||
}
|
||||
});
|
||||
// Pan kontrole (Right click + drag) - DISABLED za FAZA 2
|
||||
// Player movement sedaj uporablja WASD
|
||||
|
||||
// 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,
|
||||
// Q/E za zoom
|
||||
this.zoomKeys = this.input.keyboard.addKeys({
|
||||
zoomIn: Phaser.Input.Keyboard.KeyCodes.Q,
|
||||
zoomOut: Phaser.Input.Keyboard.KeyCodes.E
|
||||
});
|
||||
@@ -88,7 +87,7 @@ class GameScene extends Phaser.Scene {
|
||||
const width = this.cameras.main.width;
|
||||
|
||||
// Naslov
|
||||
const title = this.add.text(width / 2, 20, 'FAZA 1: Generacija Terena', {
|
||||
const title = this.add.text(width / 2, 20, 'FAZA 2: Igralec in Gibanje', {
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '20px',
|
||||
fill: '#00ff41',
|
||||
@@ -101,10 +100,9 @@ class GameScene extends Phaser.Scene {
|
||||
// Kontrole info
|
||||
const controlsText = this.add.text(width - 10, 10,
|
||||
'Kontrole:\n' +
|
||||
'WASD - Pan\n' +
|
||||
'WASD - Gibanje igralca\n' +
|
||||
'Q/E - Zoom\n' +
|
||||
'Mouse Wheel - Zoom\n' +
|
||||
'Right Click - Pan',
|
||||
'Mouse Wheel - Zoom',
|
||||
{
|
||||
fontFamily: 'Courier New',
|
||||
fontSize: '11px',
|
||||
@@ -120,49 +118,37 @@ class GameScene extends Phaser.Scene {
|
||||
}
|
||||
|
||||
update(time, delta) {
|
||||
// Update player
|
||||
if (this.player) {
|
||||
this.player.update(delta);
|
||||
}
|
||||
|
||||
// Update FPS
|
||||
if (this.fpsText) {
|
||||
this.fpsText.setText(`FPS: ${Math.round(this.game.loop.actualFps)}`);
|
||||
}
|
||||
|
||||
// Kamera movement (WASD)
|
||||
// Zoom controls
|
||||
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) {
|
||||
if (this.zoomKeys) {
|
||||
if (this.zoomKeys.zoomIn.isDown) {
|
||||
cam.setZoom(Phaser.Math.Clamp(cam.zoom + 0.01, 0.3, 2.0));
|
||||
}
|
||||
if (this.cursors.zoomOut.isDown) {
|
||||
if (this.zoomKeys.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);
|
||||
if (this.debugText && this.player) {
|
||||
const playerPos = this.player.getPosition();
|
||||
const screenPos = this.player.getScreenPosition();
|
||||
|
||||
this.debugText.setText(
|
||||
`FAZA 1 - Terrain System\n` +
|
||||
`FAZA 2 - Player Movement\n` +
|
||||
`Zoom: ${cam.zoom.toFixed(2)}\n` +
|
||||
`Camera: (${Math.round(cam.scrollX)}, ${Math.round(cam.scrollY)})\n` +
|
||||
`Mouse: (${worldX}, ${worldY})`
|
||||
`Player Grid: (${playerPos.x}, ${playerPos.y})\n` +
|
||||
`Player Screen: (${Math.round(screenPos.x)}, ${Math.round(screenPos.y)})`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user