package engine.world.weather; import engine.api.AFTRuntime; import engine.utils.AFTRandomUtils; import engine.world.AFTTime; import javax.microedition.lcdui.Graphics; /** * * @author DominaN */ public class AFTWeather { //Night & Day private int[] atmosphere; //Weather public static AFTWeatherType currentWeather; private AFTWeatherType weatherClear; private Rain weatherRain; private AcidRain weatherAcidRain; private Snow weatherSnow; //Enviroiment public static int temperature; private long lastTemperatureCalculate = AFTTime.time; public void addWeather(int particle_type, int intensity) { createParticles(particle_type, intensity); } public void createAtmosphere() { atmosphere = new int[AFTRuntime.SCREEN_WIDTH * AFTRuntime.SCREEN_HEIGHT]; //Set (initial) transparency & color of atmosphere switch (AFTTime.hours) { case 16: setAtmosphereColor(0x08, 0x08, 0x20, 0.05f); break; case 17: setAtmosphereColor(0x08, 0x08, 0x20, 0.1f); break; case 18: setAtmosphereColor(0x08, 0x08, 0x20, 0.15f); break; case 19: setAtmosphereColor(0x08, 0x08, 0x20, 0.2f); break; case 20: setAtmosphereColor(0x08, 0x08, 0x20, 0.25f); break; case 21: setAtmosphereColor(0x08, 0x08, 0x20, 0.3f); break; case 22: setAtmosphereColor(0x08, 0x08, 0x20, 0.35f); break; case 23: setAtmosphereColor(0x08, 0x08, 0x20, 0.4f); break; case 0: case 1: case 2: setAtmosphereColor(0x08, 0x08, 0x20, 0.45f); break; case 3: setAtmosphereColor(0x08, 0x08, 0x20, 0.4f); break; case 4: setAtmosphereColor(0x08, 0x08, 0x20, 0.35f); break; case 5: setAtmosphereColor(0x08, 0x08, 0x20, 0.3f); break; case 6: setAtmosphereColor(0x08, 0x08, 0x20, 0.25f); break; case 7: setAtmosphereColor(0x08, 0x08, 0x20, 0.2f); break; case 8: setAtmosphereColor(0x08, 0x08, 0x20, 0.15f); break; case 9: setAtmosphereColor(0x08, 0x08, 0x20, 0.1f); break; case 10: setAtmosphereColor(0x08, 0x08, 0x20, 0.05f); break; case 11: case 12: case 13: case 14: case 15: setAtmosphereColor(0x08, 0x08, 0x20, 0.0f); break; } //Initial weather currentWeather = new AFTWeatherType(); weatherClear = new AFTWeatherType(); setWeather(weatherClear, AFTRandomUtils.getLong(450, 1800)); } //Fake particles, yes, it's sad =( private void createParticles(int particle_type, int intensity) { switch (particle_type) { case AFTWeatherType.RAIN: weatherRain = new Rain(intensity); break; case AFTWeatherType.ACID_RAIN: weatherAcidRain = new AcidRain(intensity); break; case AFTWeatherType.SNOW: weatherSnow = new Snow(intensity); break; } } public void calculateEnviroiment() { //Random weather if (AFTTime.time > currentWeather.precStartTime + currentWeather.precDuration) { //Clear if (currentWeather.type != AFTWeatherType.CLEAR && AFTRandomUtils.getInt(0, 5000) <= 2) { setWeather(weatherClear, AFTRandomUtils.getLong(450, 1800)); } else //Rain if (weatherRain != null && AFTRandomUtils.getInt(0, 5000) <= 2) { setWeather(weatherRain, AFTRandomUtils.getLong(900, 2700)); } else //Acid rain if (weatherAcidRain != null && AFTRandomUtils.getInt(0, 10000) <= 2) { setWeather(weatherAcidRain, AFTRandomUtils.getLong(600, 1800)); } else //Snow if (weatherSnow != null) { setWeather(weatherSnow, AFTRandomUtils.getLong(900, 2700)); } } //Calculate temperature if (AFTTime.time - lastTemperatureCalculate > 300) { temperature = (AFTTime.hours < 20) ? AFTRandomUtils.getInt(5, 10) : AFTRandomUtils.getInt(-5, 5); if (currentWeather.type == AFTWeatherType.RAIN || currentWeather.type == AFTWeatherType.ACID_RAIN) { temperature -= AFTRandomUtils.getInt(0, 2); } lastTemperatureCalculate = AFTTime.time; } } public void draw(Graphics g) { //Draw weather currentWeather.processWeather(g); //So, you already know, what this code doing if (AFTTime.minutes == 0 && AFTTime.seconds == 0) { switch (AFTTime.hours) { case 16: setAtmosphereColor(0x08, 0x08, 0x20, 0.05f); break; case 17: setAtmosphereColor(0x08, 0x08, 0x20, 0.10f); break; case 18: setAtmosphereColor(0x08, 0x08, 0x20, 0.15f); break; case 19: setAtmosphereColor(0x08, 0x08, 0x20, 0.20f); break; case 20: setAtmosphereColor(0x08, 0x08, 0x20, 0.25f); break; case 21: setAtmosphereColor(0x08, 0x08, 0x20, 0.30f); break; case 22: setAtmosphereColor(0x08, 0x08, 0x20, 0.35f); break; case 23: setAtmosphereColor(0x08, 0x08, 0x20, 0.40f); break; case 0: case 1: case 2: setAtmosphereColor(0x08, 0x08, 0x20, 0.45f); break; case 3: setAtmosphereColor(0x08, 0x08, 0x20, 0.40f); break; case 4: setAtmosphereColor(0x08, 0x08, 0x20, 0.35f); break; case 5: setAtmosphereColor(0x08, 0x08, 0x20, 0.30f); break; case 6: setAtmosphereColor(0x08, 0x08, 0x20, 0.25f); break; case 7: setAtmosphereColor(0x08, 0x08, 0x20, 0.20f); break; case 8: setAtmosphereColor(0x08, 0x08, 0x20, 0.15f); break; case 9: setAtmosphereColor(0x08, 0x08, 0x20, 0.10f); break; case 10: setAtmosphereColor(0x08, 0x08, 0x20, 0.05f); break; case 11: case 12: case 13: case 14: case 15: setAtmosphereColor(0x08, 0x08, 0x20, 0.0f); break; } } //Draw atmosphere upper layer on virtual screen g.drawRGB(atmosphere, 0, AFTRuntime.SCREEN_WIDTH, 0, 0, AFTRuntime.SCREEN_WIDTH, AFTRuntime.SCREEN_HEIGHT, true); } private void setWeather(AFTWeatherType t, long duration) { currentWeather = t; currentWeather.precStartTime = AFTTime.time; currentWeather.precDuration = duration; } private void setAtmosphereColor(int r, int g, int b, float transparency) { for (int i = 0; i < atmosphere.length; i += 4) { atmosphere[i] = atmosphere[i + 1] = atmosphere[i + 2] = atmosphere[i + 3] = (b | g << 8 | r << 16 | (int) (0xff * transparency) << 24); } } }