stanje 4am
This commit is contained in:
@@ -11,10 +11,7 @@ class DayNightSystem {
|
||||
}
|
||||
|
||||
init() {
|
||||
// Create lighting overlay
|
||||
this.overlay = this.scene.add.graphics();
|
||||
this.overlay.setDepth(4999); // Below weather, above everything else
|
||||
this.overlay.setScrollFactor(0); // Fixed to camera
|
||||
// No local overlay - using UIScene.overlayGraphics
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -32,17 +29,24 @@ class DayNightSystem {
|
||||
}
|
||||
|
||||
getPhase(hour) {
|
||||
if (hour >= 5 && hour < 7) return 'dawn'; // 5-7
|
||||
if (hour >= 7 && hour < 18) return 'day'; // 7-18
|
||||
if (hour >= 18 && hour < 20) return 'dusk'; // 18-20
|
||||
return 'night'; // 20-5
|
||||
if (hour >= 5 && hour < 7) return 'dawn';
|
||||
if (hour >= 7 && hour < 18) return 'day';
|
||||
if (hour >= 18 && hour < 20) return 'dusk';
|
||||
return 'night';
|
||||
}
|
||||
|
||||
updateLighting(hour) {
|
||||
const width = this.scene.cameras.main.width;
|
||||
const height = this.scene.cameras.main.height;
|
||||
// Get Shared Overlay from UI Scene
|
||||
const uiScene = this.scene.scene.get('UIScene');
|
||||
if (!uiScene || !uiScene.overlayGraphics) return;
|
||||
|
||||
this.overlay.clear();
|
||||
const graphics = uiScene.overlayGraphics;
|
||||
|
||||
// IMPORTANT: DayNight is the FIRST system to render to overlay, so it MUST CLEAR it.
|
||||
graphics.clear();
|
||||
|
||||
const width = uiScene.scale.width;
|
||||
const height = uiScene.scale.height;
|
||||
|
||||
let color = 0x000033; // Default night blue
|
||||
let alpha = 0;
|
||||
@@ -72,8 +76,8 @@ class DayNightSystem {
|
||||
}
|
||||
|
||||
if (alpha > 0) {
|
||||
this.overlay.fillStyle(color, alpha);
|
||||
this.overlay.fillRect(0, 0, width, height);
|
||||
graphics.fillStyle(color, alpha);
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ class ParallaxSystem {
|
||||
console.log('🌄 ParallaxSystem: Initialized');
|
||||
|
||||
// Layer 1: Sky/Hills (Distant background)
|
||||
this.createSkyLayer();
|
||||
this.createDistantHills();
|
||||
// Layer 1: Sky/Hills (Disabled by request)
|
||||
// this.createSkyLayer();
|
||||
// this.createDistantHills();
|
||||
|
||||
// Layer 4: Foreground overlay (High grass patches)
|
||||
this.createForegroundGrass();
|
||||
|
||||
@@ -85,24 +85,41 @@ class StatsSystem {
|
||||
|
||||
die() {
|
||||
console.log('💀 Player died!');
|
||||
// Zaenkrat samo respawn / reset
|
||||
this.health = 100;
|
||||
this.hunger = 100;
|
||||
this.thirst = 100;
|
||||
|
||||
// Teleport to spawn
|
||||
const spawnX = this.scene.terrainOffsetX + 500; // Dummy
|
||||
const spawnY = this.scene.terrainOffsetY + 100; // Dummy
|
||||
// Reset player pos...
|
||||
// V pravi implementaciji bi klicali GameScene.respawnPlayer()
|
||||
// Trigger Player Animation
|
||||
if (this.scene.player) {
|
||||
this.scene.player.dieAnimation();
|
||||
}
|
||||
|
||||
// Show notification
|
||||
// Show Notification & Overlay in UI Scene
|
||||
const uiScene = this.scene.scene.get('UIScene');
|
||||
if (uiScene) {
|
||||
const txt = uiScene.add.text(uiScene.width / 2, uiScene.height / 2, 'YOU DIED', {
|
||||
// Full screen overlay using scale dimensions
|
||||
const width = uiScene.scale.width;
|
||||
const height = uiScene.scale.height;
|
||||
|
||||
const bg = uiScene.add.rectangle(width / 2, height / 2, width, height, 0x000000, 0.8);
|
||||
|
||||
const txt = uiScene.add.text(width / 2, height / 2, 'YOU DIED', {
|
||||
fontSize: '64px', color: '#ff0000', fontStyle: 'bold'
|
||||
}).setOrigin(0.5);
|
||||
uiScene.time.delayedCall(2000, () => txt.destroy());
|
||||
|
||||
// Wait and Respawn
|
||||
uiScene.time.delayedCall(3000, () => {
|
||||
if (bg) bg.destroy();
|
||||
if (txt) txt.destroy();
|
||||
|
||||
// Reset Stats
|
||||
this.health = 100;
|
||||
this.hunger = 100;
|
||||
this.thirst = 100;
|
||||
this.updateUI();
|
||||
|
||||
// Reset Player
|
||||
if (this.scene.player) {
|
||||
this.scene.player.respawn();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -350,6 +350,7 @@ class TerrainSystem {
|
||||
if (x > 5 && x < this.width - 5 && y > 5 && y < this.height - 5) {
|
||||
let decorType = null;
|
||||
let maxHp = 1;
|
||||
let scale = 1.0; // Default scale
|
||||
|
||||
if (terrainType.name.includes('grass')) { // Check ANY grass type
|
||||
const rand = Math.random();
|
||||
@@ -361,6 +362,20 @@ class TerrainSystem {
|
||||
} else if (rand < 0.025) { // Reduced to 2.5% trees (optimum balance)
|
||||
decorType = 'tree';
|
||||
maxHp = 5;
|
||||
|
||||
// TREE SIZING LOGIC
|
||||
// 20% Normal (1.0)
|
||||
// 60% Medium (0.6-0.8)
|
||||
// 20% Tiny (0.2)
|
||||
const sizeRand = Math.random();
|
||||
if (sizeRand < 0.2) {
|
||||
scale = 0.25; // 20% Tiny (0.25 visible enough)
|
||||
} else if (sizeRand < 0.8) {
|
||||
scale = 0.6 + Math.random() * 0.2; // 60% Scale 0.6-0.8
|
||||
} else {
|
||||
scale = 1.0; // 20% Full size
|
||||
}
|
||||
|
||||
} else if (rand < 0.03) {
|
||||
decorType = 'gravestone'; // 💀 Nagrobniki
|
||||
maxHp = 10; // Težje uničiti
|
||||
@@ -381,7 +396,8 @@ class TerrainSystem {
|
||||
type: decorType,
|
||||
id: key,
|
||||
maxHp: maxHp,
|
||||
hp: maxHp
|
||||
hp: maxHp,
|
||||
scale: scale // Save scale
|
||||
};
|
||||
|
||||
this.decorations.push(decorData);
|
||||
@@ -608,7 +624,7 @@ class TerrainSystem {
|
||||
));
|
||||
}
|
||||
|
||||
sprite.setDepth(this.iso.getDepth(x, y));
|
||||
sprite.setDepth(this.iso.getDepth(x, y) - 2000); // Tiles always in background
|
||||
|
||||
this.visibleTiles.set(key, sprite);
|
||||
}
|
||||
@@ -630,8 +646,9 @@ class TerrainSystem {
|
||||
cropPos.x + this.offsetX,
|
||||
cropPos.y + this.offsetY + this.iso.tileHeight / 2 + elevationOffset
|
||||
);
|
||||
// Crop depth = Y pos
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
sprite.setDepth(depth + 1); // Just slightly above tile
|
||||
sprite.setDepth(depth);
|
||||
|
||||
this.visibleCrops.set(key, sprite);
|
||||
}
|
||||
@@ -658,8 +675,13 @@ class TerrainSystem {
|
||||
);
|
||||
|
||||
const depth = this.iso.getDepth(x, y);
|
||||
if (decor.type === 'flower') sprite.setDepth(depth + 1);
|
||||
else sprite.setDepth(depth + 1000); // Taller objects update depth
|
||||
// Depth strategy: Base of object sorting.
|
||||
// Add small offset based on type if needed, but mainly use Y
|
||||
sprite.setDepth(depth);
|
||||
|
||||
// Apply scale if present
|
||||
if (decor.scale) sprite.setScale(decor.scale);
|
||||
else sprite.setScale(1);
|
||||
|
||||
sprite.flipX = (x + y) % 2 === 0;
|
||||
|
||||
|
||||
@@ -13,15 +13,18 @@ class WeatherSystem {
|
||||
}
|
||||
|
||||
init() {
|
||||
// Create weather overlay
|
||||
this.overlay = this.scene.add.graphics();
|
||||
this.overlay.setDepth(5000); // Above everything but UI
|
||||
this.overlay.setScrollFactor(0); // Fixed to camera
|
||||
|
||||
// Start with random weather
|
||||
// No local overlay - we use UI Scene
|
||||
this.changeWeather();
|
||||
}
|
||||
|
||||
getOverlay() {
|
||||
const uiScene = this.scene.scene.get('UIScene');
|
||||
if (uiScene && uiScene.weatherGraphics) {
|
||||
return uiScene.weatherGraphics;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
changeWeather() {
|
||||
// Clean up old weather
|
||||
this.clearWeather();
|
||||
@@ -61,10 +64,10 @@ class WeatherSystem {
|
||||
}
|
||||
|
||||
startRain(heavy = false) {
|
||||
const width = this.scene.cameras.main.width;
|
||||
const height = this.scene.cameras.main.height;
|
||||
const width = this.scene.scale.width;
|
||||
const height = this.scene.scale.height;
|
||||
|
||||
// Create rain drops
|
||||
// Create rain drops (keep logic for drops)
|
||||
const dropCount = heavy ? 150 : 100;
|
||||
|
||||
for (let i = 0; i < dropCount; i++) {
|
||||
@@ -77,27 +80,16 @@ class WeatherSystem {
|
||||
this.rainParticles.push(drop);
|
||||
}
|
||||
|
||||
// Darken screen slightly
|
||||
this.overlay.clear();
|
||||
this.overlay.fillStyle(0x000033, heavy ? 0.3 : 0.2);
|
||||
this.overlay.fillRect(0, 0, width, height);
|
||||
// No drawing here - handled in renderWeather
|
||||
}
|
||||
|
||||
applyFog() {
|
||||
const width = this.scene.cameras.main.width;
|
||||
const height = this.scene.cameras.main.height;
|
||||
|
||||
this.overlay.clear();
|
||||
this.overlay.fillStyle(0xcccccc, 0.4);
|
||||
this.overlay.fillRect(0, 0, width, height);
|
||||
// No drawing here - handled in renderWeather
|
||||
}
|
||||
|
||||
clearWeather() {
|
||||
// Remove all weather effects
|
||||
this.rainParticles = [];
|
||||
if (this.overlay) {
|
||||
this.overlay.clear();
|
||||
}
|
||||
// No clearing here - handled by DayNightSystem clearing the frame
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
@@ -108,42 +100,50 @@ class WeatherSystem {
|
||||
this.changeWeather();
|
||||
}
|
||||
|
||||
// Update rain
|
||||
if (this.currentWeather === 'rain' || this.currentWeather === 'storm') {
|
||||
this.updateRain(delta);
|
||||
// Always render active weather
|
||||
if (this.currentWeather !== 'clear') {
|
||||
this.renderWeather(delta);
|
||||
}
|
||||
}
|
||||
|
||||
updateRain(delta) {
|
||||
const height = this.scene.cameras.main.height;
|
||||
const width = this.scene.cameras.main.width;
|
||||
renderWeather(delta) {
|
||||
const overlay = this.getOverlay();
|
||||
if (!overlay) return;
|
||||
|
||||
// Update drop positions
|
||||
for (const drop of this.rainParticles) {
|
||||
drop.y += (drop.speed * delta) / 1000;
|
||||
const height = this.scene.scale.height;
|
||||
const width = this.scene.scale.width;
|
||||
|
||||
// Reset if off screen
|
||||
if (drop.y > height) {
|
||||
drop.y = -10;
|
||||
drop.x = Math.random() * width;
|
||||
}
|
||||
// FOG
|
||||
if (this.currentWeather === 'fog') {
|
||||
overlay.fillStyle(0xcccccc, 0.4);
|
||||
overlay.fillRect(0, 0, width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
// Render rain
|
||||
this.overlay.clear();
|
||||
// RAIN / STORM
|
||||
if (this.currentWeather === 'rain' || this.currentWeather === 'storm') {
|
||||
// Update physics
|
||||
for (const drop of this.rainParticles) {
|
||||
drop.y += (drop.speed * delta) / 1000;
|
||||
if (drop.y > height) {
|
||||
drop.y = -10;
|
||||
drop.x = Math.random() * width;
|
||||
}
|
||||
}
|
||||
|
||||
// Background darkening
|
||||
const isDark = this.currentWeather === 'storm' ? 0.3 : 0.2;
|
||||
this.overlay.fillStyle(0x000033, isDark);
|
||||
this.overlay.fillRect(0, 0, width, height);
|
||||
// Darken background for storm/rain (additive to DayNight)
|
||||
const isDark = this.currentWeather === 'storm' ? 0.3 : 0.2;
|
||||
overlay.fillStyle(0x000033, isDark);
|
||||
overlay.fillRect(0, 0, width, height);
|
||||
|
||||
// Draw drops
|
||||
this.overlay.lineStyle(1, 0x88aaff, 0.5);
|
||||
for (const drop of this.rainParticles) {
|
||||
this.overlay.beginPath();
|
||||
this.overlay.moveTo(drop.x, drop.y);
|
||||
this.overlay.lineTo(drop.x - 2, drop.y + drop.length);
|
||||
this.overlay.strokePath();
|
||||
// Draw drops
|
||||
overlay.lineStyle(1, 0x88aaff, 0.5);
|
||||
for (const drop of this.rainParticles) {
|
||||
overlay.beginPath();
|
||||
overlay.moveTo(drop.x, drop.y);
|
||||
overlay.lineTo(drop.x - 2, drop.y + drop.length);
|
||||
overlay.strokePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user