diff --git a/core/src/fr/evolving/assets/AssetLoader.java b/core/src/fr/evolving/assets/AssetLoader.java index 8415145..f9c963e 100644 --- a/core/src/fr/evolving/assets/AssetLoader.java +++ b/core/src/fr/evolving/assets/AssetLoader.java @@ -3,7 +3,10 @@ package fr.evolving.assets; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.PerspectiveCamera; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; @@ -15,6 +18,9 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.Texture.TextureWrap; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.utils.viewport.FitViewport; +import com.badlogic.gdx.utils.viewport.ScalingViewport; +import com.badlogic.gdx.utils.viewport.StretchViewport; public class AssetLoader { public static Skin Skin_level; @@ -24,10 +30,12 @@ public class AssetLoader { public static Texture Texture_fond2; public static Texture Texture_logo; public static Sound intro; - public static int width=1440; - public static int height=960; + public static int width; + public static int height; + public static float ratio; public static boolean stretch=false; - private static Preferences prefs; + public static Preferences prefs; + public static ScalingViewport viewport; public static void addstyle(TextureAtlas Atlas_level,String Name) { AtlasRegion AnAtlasRegion = Atlas_level.findRegion(Name); @@ -53,7 +61,7 @@ public class AssetLoader { } public static void loadall() { - Gdx.app.log("Chargements des éléments multimédia","ok"); + Gdx.app.debug("AssetLoader","Chargements de tout les éléments multimédia"); Texture_fond = new Texture(Gdx.files.internal("pictures/fond.png")); Texture_fond.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png")); @@ -66,29 +74,50 @@ public class AssetLoader { addstyle(Atlas_level,"arrows2"); addstyle(Atlas_level,"exit2"); Skin_level = new Skin(Gdx.files.internal("textures/level.json"),Atlas_level); - prefs = Gdx.app.getPreferences("WireWorld"); - - if (!prefs.contains("resolutionx")) { - prefs.putInteger("resolutionx", 0); + } + + public static int setpref() { + prefs = Gdx.app.getPreferences("WireWorld - Evolving Games"); + if (prefs.contains("log")) + return prefs.getInteger("log"); + else + return Gdx.app.LOG_INFO; + } + + public static void init() { + Gdx.app.debug("AssetLoader","Initialisation de la résolution virtuelle..."); + int realWidth=Gdx.graphics.getWidth(); + int realHeight=Gdx.graphics.getHeight(); + float realRatio=realWidth/(float)realHeight; + Gdx.app.debug("AssetLoader","Résolution de "+realWidth+"x"+realHeight+" ratio de "+String.format("%.2f", realRatio)+"."); + ratio=1; + width=1920; + height=1080; + if (Math.abs(16f/9f-realRatio)>Math.abs(4f/3f-realRatio)) { + ratio=4/3; + Gdx.app.debug("AssetLoader","Ratio 4/3, résolution virtuelle : 1920x1440."); + height=1440; } + else + Gdx.app.debug("AssetLoader","Ratio 16/9, résolution virtuelle : 1920x1080."); + if (stretch) { + viewport = new StretchViewport(realWidth,realHeight); + Gdx.app.debug("AssetLoader","Adaptation d'écran maximale, 'Aspect-Ratio' non conservé."); + } + else { + viewport = new FitViewport(realWidth,realHeight); + Gdx.app.debug("AssetLoader","Adaptation d'écran totale, 'Aspect-Ratio' conservé."); + } + viewport.apply(); } public static void load() { - Gdx.app.log("Chargements des éléments minimalistes","ok"); + Gdx.app.debug("AssetLoader","Chargements des éléments minimalistes"); Texture_logo = new Texture(Gdx.files.internal("pictures/logo.png")); Texture_logo.setFilter(TextureFilter.Linear,TextureFilter.Linear); intro = Gdx.audio.newSound(Gdx.files.internal("musics/intro.mp3")); } - public static void setHighScore(int val) { - prefs.putInteger("highScore", val); - prefs.flush(); - } - - public static int getHighScore() { - return prefs.getInteger("highScore"); - } - public static void dispose() { Texture_logo.dispose(); Texture_fond.dispose(); diff --git a/core/src/fr/evolving/effects/Laser.java b/core/src/fr/evolving/effects/Laser.java index caa7746..02535cc 100644 --- a/core/src/fr/evolving/effects/Laser.java +++ b/core/src/fr/evolving/effects/Laser.java @@ -82,7 +82,7 @@ public class Laser { } - public static void drawold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) { + public void drawold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) { ShapeRenderer Laser=new ShapeRenderer(); //Laser.begin(ShapeType.Line); float adding=0; diff --git a/core/src/fr/evolving/game/main.java b/core/src/fr/evolving/game/main.java index 57f258d..3c5aab8 100644 --- a/core/src/fr/evolving/game/main.java +++ b/core/src/fr/evolving/game/main.java @@ -11,8 +11,51 @@ public class main extends Game { @Override public void create() { + Gdx.app.setLogLevel(AssetLoader.setpref()); + //debug(); + test(); + Gdx.app.debug(getClass().getSimpleName(), "Récupération de la résolution des préférences."); + if (AssetLoader.prefs.contains("ResolutionX") && AssetLoader.prefs.contains("ResolutionX")) { + try { + int ResolutionX=AssetLoader.prefs.getInteger("ResolutionX"); + int ResolutionY=AssetLoader.prefs.getInteger("ResolutionY"); + boolean Fullscreen=AssetLoader.prefs.getBoolean("Fullscreen"); + boolean VSync=AssetLoader.prefs.getBoolean("VSync"); + Gdx.graphics.setDisplayMode(ResolutionX, ResolutionY, Fullscreen); + Gdx.graphics.setVSync(VSync); + } catch (ClassCastException e) { + Gdx.app.error("****","Impossible d'appliquer les préférences graphiques"); + Gdx.app.debug(getClass().getSimpleName(),e.getMessage()); + } finally { + Gdx.app.log("****","Changement de résolution selon préférences graphiques"); + } + } + else + Gdx.app.debug(getClass().getSimpleName(), "...Aucune préférence !"); + AssetLoader.init(); + Gdx.app.debug(getClass().getSimpleName(), "Creation de l'objet SplashScreen."); setScreen(new SplashScreen(this)); } + + public void debug() { + AssetLoader.prefs.putInteger("ResolutionX", 1280); + AssetLoader.prefs.putInteger("ResolutionY", 1024); + AssetLoader.prefs.putBoolean("Fullscreen", false); + AssetLoader.prefs.putBoolean("VSync", false); + AssetLoader.prefs.putInteger("log", Gdx.app.LOG_DEBUG); + Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG); + AssetLoader.prefs.flush(); + } + + public void test() { + AssetLoader.prefs.putInteger("ResolutionX", 1280); + AssetLoader.prefs.putInteger("ResolutionY", 1024); + AssetLoader.prefs.putBoolean("Fullscreen", true); + AssetLoader.prefs.putBoolean("VSync", true); + AssetLoader.prefs.putInteger("log", Gdx.app.LOG_INFO); + Gdx.app.setLogLevel(Gdx.app.LOG_INFO); + AssetLoader.prefs.flush(); + } @Override public void dispose() { diff --git a/core/src/fr/evolving/screens/LevelScreen.java b/core/src/fr/evolving/screens/LevelScreen.java index 6385306..0ed5a51 100644 --- a/core/src/fr/evolving/screens/LevelScreen.java +++ b/core/src/fr/evolving/screens/LevelScreen.java @@ -32,26 +32,22 @@ import fr.evolving.effects.Laser; public class LevelScreen implements Screen { - protected static final Class ButtonLevel = null; public ButtonLevel[] buttonLevels; private LevelRenderer Renderer; private float runTime; private Timer ScrollTimer; private TimerTask ScrollTask; - private Stage stage = new Stage(); - private Table table = new Table(); + private Stage stage; + private Table table; private ImageButton Previous,Next,Exit; private TextButton buttonPlay,buttonExit; - private Level[] thelevels=new Level[9]; + private Level[] thelevels; private TextArea TextDescriptive; - private ScalingViewport viewport; public LevelScreen() { - if (AssetLoader.stretch) - viewport = new StretchViewport(AssetLoader.width,AssetLoader.height); - else - viewport = new FitViewport(AssetLoader.width,AssetLoader.height); - viewport.apply(); + Gdx.app.debug(getClass().getSimpleName(),"Création des boutons."); + stage = new Stage(AssetLoader.viewport); + table = new Table(); Renderer=new LevelRenderer(this); buttonLevels = new ButtonLevel[10]; thelevels= SaveObject.initObject(); @@ -105,12 +101,12 @@ public class LevelScreen implements Screen { @Override public void resize(int width, int height) { - viewport.update(width,height); + AssetLoader.viewport.update(width,height); } @Override public void show() { - Gdx.app.log("Affichage du LevelScreen","ok"); + Gdx.app.log("*****","Affichage du choix des mondes & niveaux."); for (int i=0;i<10;i++) { if (buttonLevels[i]!=null) { stage.addActor(buttonLevels[i]); diff --git a/core/src/fr/evolving/screens/SplashScreen.java b/core/src/fr/evolving/screens/SplashScreen.java index 6eae2df..07a1b35 100644 --- a/core/src/fr/evolving/screens/SplashScreen.java +++ b/core/src/fr/evolving/screens/SplashScreen.java @@ -17,23 +17,23 @@ import fr.evolving.game.main; public class SplashScreen implements Screen { private main game; - private Stage stage = new Stage(); + private Stage stage; private Image splashImage; + private float scale; public SplashScreen(main game) { this.game = game; AssetLoader.load(); + stage = new Stage(); splashImage = new Image(AssetLoader.Texture_logo); } @Override public void show() { - float width = Gdx.graphics.getWidth(); - float height = Gdx.graphics.getHeight(); - float desiredWidth = width * .7f; - float scale = desiredWidth / splashImage.getWidth(); - splashImage.setSize(splashImage.getWidth() * scale, splashImage.getHeight() * scale); - splashImage.setPosition((width / 2) - (splashImage.getWidth() / 2), (height / 2) - (splashImage.getHeight() / 2)); + Gdx.app.log("****","Affichage du SplashScreen"); + scale=2; + splashImage.setScale(scale); + splashImage.setPosition((AssetLoader.width / 2) - (scale * splashImage.getWidth() / 2), (AssetLoader.height / 2) - (scale * splashImage.getHeight() / 2)); stage.addActor(splashImage); splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.fadeIn(0.5f),Actions.run(new Runnable() { //splashImage.addAction(Actions.sequence(Actions.alpha(0),Actions.run(new Runnable() { @@ -48,10 +48,9 @@ public class SplashScreen implements Screen { ((Game)Gdx.app.getApplicationListener()).setScreen(new LevelScreen()); } }))); - + Gdx.app.debug("AssetLoader","Début dans la bande son \'intro\'"); AssetLoader.intro.setLooping(0, true); AssetLoader.intro.play(); - Gdx.app.log("Affichage du SplashScreen","ok"); } @Override @@ -64,6 +63,7 @@ public class SplashScreen implements Screen { @Override public void resize(int width, int height) { + AssetLoader.viewport.update(width,height); } @Override diff --git a/core/src/fr/evolving/worlds/LevelRenderer.java b/core/src/fr/evolving/worlds/LevelRenderer.java index 49f86b5..bc195f9 100644 --- a/core/src/fr/evolving/worlds/LevelRenderer.java +++ b/core/src/fr/evolving/worlds/LevelRenderer.java @@ -21,6 +21,7 @@ import fr.evolving.screens.LevelScreen; public class LevelRenderer { private ShapeRenderer shapeRenderer; private SpriteBatch batcher; + private SpriteBatch batcher2; int scrollx; int scrolly; int dirx; @@ -37,6 +38,7 @@ public class LevelRenderer { this.dirx=1; this.diry=1; batcher = new SpriteBatch(); + batcher2 = new SpriteBatch(); shapeRenderer = new ShapeRenderer(); Laser=new Laser(); } @@ -63,6 +65,7 @@ public class LevelRenderer { public void render(float delta, float runTime) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + //Gdx.gl.glViewport(0, 0, AssetLoader.width, AssetLoader.height); batcher.begin(); batcher.setColor(0.25f,0.25f,0.25f,1); @@ -85,11 +88,12 @@ public class LevelRenderer { shapeRenderer.rect(1134, 310, AssetLoader.width-1144, 300); shapeRenderer.rect(1134, 620, AssetLoader.width-1144, AssetLoader.height-620); shapeRenderer.end(); - - batcher.begin(); - batcher.draw(AssetLoader.Atlas_game.findRegion("cout"),1150,40); - batcher.draw(AssetLoader.Atlas_game.findRegion("tech"),1280,40); - batcher.end(); + + batcher2.begin(); + batcher2.setColor(1f,1f,1f,1f); + batcher2.draw(AssetLoader.Atlas_game.findRegion("cout"),1150,40); + batcher2.draw(AssetLoader.Atlas_game.findRegion("tech"),1280,40); + batcher2.end(); for (int i=0;i