feat: ajout de la gestion des viewports ajout des moyens de victoire

This commit is contained in:
Nicolas Hordé 2015-06-17 01:13:15 +02:00
parent 0609d13f92
commit b921df2cb8
5 changed files with 53 additions and 44 deletions

View File

@ -33,11 +33,11 @@ public class ButtonLevel extends ImageTextButton {
this.setDisabled(true); this.setDisabled(true);
Locked=AssetLoader.Skin_level.getAtlas().findRegion("locked"); Locked=AssetLoader.Skin_level.getAtlas().findRegion("locked");
} }
this.setColor(1f, 0.47f+(float)level.X/Gdx.graphics.getWidth()*0.529f,0.607f+(float)level.X/Gdx.graphics.getWidth()*0.392f, 1f); this.setColor(1f, 0.47f+(float)level.X/1024f*0.529f,0.607f+(float)level.X/768f*0.392f, 1f);
this.setBounds(level.X, level.Y/768.0f*Gdx.graphics.getHeight(), 111, 125); this.setBounds(level.X, level.Y, 111, 125);
Thelabel=new Label(level.Element, AssetLoader.Skin_level,"Levelshort"); Thelabel=new Label(level.Element, AssetLoader.Skin_level,"Levelshort");
Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f); Thelabel.setColor(level.X/1024f,level.X/1024f,level.X/1024f,1f);
Thelabel.setPosition(level.X+54, level.Y/768.0f*Gdx.graphics.getHeight()+20, Align.bottom | Align.center); Thelabel.setPosition(level.X+54, level.Y+20, Align.bottom | Align.center);
} }
public Color getLevelcolor() { public Color getLevelcolor() {
@ -48,10 +48,10 @@ public class ButtonLevel extends ImageTextButton {
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
if (level.Special) { if (level.Special) {
batch.draw(Finalled,level.X,level.Y/768.0f*Gdx.graphics.getHeight()); batch.draw(Finalled,level.X,level.Y);
} }
if (!Activated) { if (!Activated) {
batch.draw(Locked,level.X+this.getWidth()-Locked.getRegionWidth(),level.Y/768.0f*Gdx.graphics.getHeight()+this.getHeight()-Locked.getRegionWidth()); batch.draw(Locked,level.X+this.getWidth()-Locked.getRegionWidth(),level.Y+this.getHeight()-Locked.getRegionWidth());
} }
Thelabel.draw(batch, 1f); Thelabel.draw(batch, 1f);
} }

View File

@ -19,10 +19,14 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
public class AssetLoader { public class AssetLoader {
public static Skin Skin_level; public static Skin Skin_level;
public static TextureAtlas Atlas_level; public static TextureAtlas Atlas_level;
public static TextureAtlas Atlas_game;
public static Texture Texture_fond; public static Texture Texture_fond;
public static Texture Texture_fond2; public static Texture Texture_fond2;
public static Texture Texture_logo; public static Texture Texture_logo;
public static Sound intro; public static Sound intro;
public static int width=1440;
public static int height=960;
public static boolean stretch=false;
private static Preferences prefs; private static Preferences prefs;
public static void addstyle(TextureAtlas Atlas_level,String Name) { public static void addstyle(TextureAtlas Atlas_level,String Name) {
@ -55,6 +59,7 @@ public class AssetLoader {
Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png")); Texture_fond2 = new Texture(Gdx.files.internal("pictures/fond2.png"));
Texture_fond2.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); Texture_fond2.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
Atlas_level= new TextureAtlas(Gdx.files.internal("textures/level.pack")); Atlas_level= new TextureAtlas(Gdx.files.internal("textures/level.pack"));
Atlas_game = new TextureAtlas(Gdx.files.internal("textures/game.pack"));
for(int i=0; i < 5; i++) for(int i=0; i < 5; i++)
addstyle(Atlas_level,"leveler"+String.valueOf(i)); addstyle(Atlas_level,"leveler"+String.valueOf(i));
addstyle(Atlas_level,"arrows"); addstyle(Atlas_level,"arrows");

View File

@ -29,9 +29,7 @@ public class Laser {
overlay=AssetLoader.Skin_level.getAtlas().findRegion("overlay"); overlay=AssetLoader.Skin_level.getAtlas().findRegion("overlay");
} }
public void draw(float x1,float yy1,float x2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) { public void draw(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float y1=yy1/768.0f*Gdx.graphics.getHeight();
float y2=yy2/768.0f*Gdx.graphics.getHeight();
Vector2 vectorall = new Vector2(x2, y2).sub(new Vector2(x1, y1)); Vector2 vectorall = new Vector2(x2, y2).sub(new Vector2(x1, y1));
float length = vectorall.len(); float length = vectorall.len();
Vector2 vectoradd = vectorall.scl(10/length); Vector2 vectoradd = vectorall.scl(10/length);
@ -48,9 +46,7 @@ public class Laser {
Laser.dispose(); Laser.dispose();
} }
public void drawnotsoold(float x1,float yy1,float x2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) { public void drawnotsoold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float y1=yy1/768.0f*Gdx.graphics.getHeight();
float y2=yy2/768.0f*Gdx.graphics.getHeight();
ShapeRenderer Laser=new ShapeRenderer(); ShapeRenderer Laser=new ShapeRenderer();
//Laser.begin(ShapeType.Line); //Laser.begin(ShapeType.Line);
Laser.begin(ShapeType.Filled); Laser.begin(ShapeType.Filled);
@ -87,9 +83,7 @@ public class Laser {
} }
public static void drawold(float x1,float yy1,float x2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) { public static void drawold(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float y1=yy1/768.0f*Gdx.graphics.getHeight();
float y2=yy2/768.0f*Gdx.graphics.getHeight();
ShapeRenderer Laser=new ShapeRenderer(); ShapeRenderer Laser=new ShapeRenderer();
//Laser.begin(ShapeType.Line); //Laser.begin(ShapeType.Line);
float adding=0; float adding=0;

View File

@ -15,6 +15,10 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScalingViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import fr.evolving.worlds.LevelRenderer; import fr.evolving.worlds.LevelRenderer;
import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.ButtonLevel;
@ -39,14 +43,16 @@ public class LevelScreen implements Screen {
private ImageButton Previous,Next,Exit; private ImageButton Previous,Next,Exit;
private TextButton buttonPlay,buttonExit; private TextButton buttonPlay,buttonExit;
private Level[] thelevels=new Level[9]; private Level[] thelevels=new Level[9];
private float spaces,sizes;
private TextArea TextDescriptive; private TextArea TextDescriptive;
private ScalingViewport viewport;
// This is the constructor, not the class declaration
public LevelScreen() { public LevelScreen() {
float screenWidth = Gdx.graphics.getWidth(); if (AssetLoader.stretch)
float screenHeight = Gdx.graphics.getHeight(); viewport = new StretchViewport(AssetLoader.width,AssetLoader.height);
Renderer=new LevelRenderer((int)screenWidth,(int)screenHeight,this); else
viewport = new FitViewport(AssetLoader.width,AssetLoader.height);
viewport.apply();
Renderer=new LevelRenderer(this);
buttonLevels = new ButtonLevel[10]; buttonLevels = new ButtonLevel[10];
thelevels= SaveObject.initObject(); thelevels= SaveObject.initObject();
for (int i = 0;i<thelevels.length;i++) { for (int i = 0;i<thelevels.length;i++) {
@ -72,9 +78,11 @@ public class LevelScreen implements Screen {
TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,"Descriptif"); TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,"Descriptif");
TextDescriptive.setBounds(15, 15, 1009, 130); TextDescriptive.setBounds(15, 15, 1009, 130);
buttonPlay = new TextButton("Jouer", AssetLoader.Skin_level,"Bouton"); buttonPlay = new TextButton("Jouer", AssetLoader.Skin_level,"Bouton");
buttonPlay.setPosition(120, 170);
buttonExit = new TextButton("Quitter", AssetLoader.Skin_level,"Bouton"); buttonExit = new TextButton("Quitter", AssetLoader.Skin_level,"Bouton");
buttonExit.setPosition(220, 170);
Exit=new ImageButton(AssetLoader.Skin_level,"Exit"); Exit=new ImageButton(AssetLoader.Skin_level,"Exit");
Exit.setPosition(900, Gdx.graphics.getHeight()-Exit.getHeight()); Exit.setPosition(1000, AssetLoader.height-Exit.getHeight());
Exit.addListener(new ClickListener(){ Exit.addListener(new ClickListener(){
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
@ -82,14 +90,9 @@ public class LevelScreen implements Screen {
} }
}); });
Next=new ImageButton(AssetLoader.Skin_level,"Next"); Next=new ImageButton(AssetLoader.Skin_level,"Next");
Next.setPosition(840, 170); Next.setPosition(940, 170);
Previous=new ImageButton(AssetLoader.Skin_level,"Previous"); Previous=new ImageButton(AssetLoader.Skin_level,"Previous");
Previous.setPosition(920, 170); Previous.setPosition(1020, 170);
table.right().top().padTop(100);
sizes=(screenWidth-1024.0f)*0.7f;
if (sizes>250.0f)
sizes=250.0f;
spaces=(screenWidth-1024.0f-sizes)/2;
} }
@Override @Override
@ -102,13 +105,12 @@ public class LevelScreen implements Screen {
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
viewport.update(width,height);
} }
@Override @Override
public void show() { public void show() {
Gdx.app.log("Affichage du LevelScreen","ok"); Gdx.app.log("Affichage du LevelScreen","ok");
table.add(buttonPlay).size(sizes,60).padRight(spaces).padBottom(20).row();
table.add(buttonExit).size(sizes,60).padRight(spaces).padBottom(20).row();
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
if (buttonLevels[i]!=null) { if (buttonLevels[i]!=null) {
stage.addActor(buttonLevels[i]); stage.addActor(buttonLevels[i]);
@ -116,9 +118,10 @@ public class LevelScreen implements Screen {
} }
table.setFillParent(true); table.setFillParent(true);
stage.addActor(TextDescriptive); stage.addActor(TextDescriptive);
stage.addActor(table);
stage.addActor(Exit); stage.addActor(Exit);
stage.addActor(Next); stage.addActor(Next);
stage.addActor(buttonPlay);
stage.addActor(buttonExit);
stage.addActor(Previous); stage.addActor(Previous);
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
} }

View File

@ -21,8 +21,6 @@ import fr.evolving.screens.LevelScreen;
public class LevelRenderer { public class LevelRenderer {
private ShapeRenderer shapeRenderer; private ShapeRenderer shapeRenderer;
private SpriteBatch batcher; private SpriteBatch batcher;
int gameWidth;
int gameHeight;
int scrollx; int scrollx;
int scrolly; int scrolly;
int dirx; int dirx;
@ -32,14 +30,12 @@ public class LevelRenderer {
TextureRegion Texture_logobig; TextureRegion Texture_logobig;
TextureRegion Texture_logosmall; TextureRegion Texture_logosmall;
public LevelRenderer(int gameWidth, int gameHeight,LevelScreen LevelScreen) { public LevelRenderer(LevelScreen LevelScreen) {
this.LevelScreen=LevelScreen; this.LevelScreen=LevelScreen;
this.scrollx=0; this.scrollx=0;
this.scrolly=0; this.scrolly=0;
this.dirx=1; this.dirx=1;
this.diry=1; this.diry=1;
this.gameHeight=gameHeight;
this.gameWidth=gameWidth;
batcher = new SpriteBatch(); batcher = new SpriteBatch();
shapeRenderer = new ShapeRenderer(); shapeRenderer = new ShapeRenderer();
Laser=new Laser(); Laser=new Laser();
@ -67,23 +63,34 @@ public class LevelRenderer {
public void render(float delta, float runTime) { public void render(float delta, float runTime) {
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
batcher.begin(); batcher.begin();
batcher.setColor(0.25f,0.25f,0.25f,1); batcher.setColor(0.25f,0.25f,0.25f,1);
batcher.draw(AssetLoader.Texture_fond2, 0, 0, this.scrollx/2, this.scrolly/2, this.gameWidth, this.gameHeight); batcher.draw(AssetLoader.Texture_fond2, 0, 0, this.scrollx/2, this.scrolly/2, AssetLoader.width, AssetLoader.height);
batcher.setColor(0.7f,0.7f,0.7f,1); batcher.setColor(0.7f,0.7f,0.7f,1);
batcher.draw(AssetLoader.Texture_fond, 0, 0, this.scrollx, this.scrolly, this.gameWidth, this.gameHeight); batcher.draw(AssetLoader.Texture_fond, 0, 0, this.scrollx, this.scrolly, AssetLoader.width, AssetLoader.height);
batcher.setColor(1,1,1,1); batcher.setColor(1,1,1,1);
Texture_logobig=AssetLoader.Skin_level.getRegion("logo3"); Texture_logobig=AssetLoader.Skin_level.getRegion("logo3");
Texture_logosmall=AssetLoader.Skin_level.getRegion("logo2"); Texture_logosmall=AssetLoader.Skin_level.getRegion("logo2");
batcher.draw(Texture_logosmall,20, this.gameHeight-Texture_logobig.getRegionHeight()+Texture_logosmall.getRegionHeight()/2); batcher.draw(Texture_logosmall,20, AssetLoader.height-Texture_logobig.getRegionHeight()+Texture_logosmall.getRegionHeight()/2);
batcher.draw(Texture_logobig,120, this.gameHeight-Texture_logobig.getRegionHeight()); batcher.draw(Texture_logobig,120, AssetLoader.height-Texture_logobig.getRegionHeight());
batcher.end(); batcher.end();
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeType.Filled); shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.5f); shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.5f);
shapeRenderer.rect(10, 10, 1014, 140); shapeRenderer.rect(10, 10, 1114, 140);
shapeRenderer.rect(1134, 10, AssetLoader.width-1144, 140);
shapeRenderer.rect(1134, 160, AssetLoader.width-1144, 140);
shapeRenderer.rect(1134, 310, AssetLoader.width-1144, 300);
shapeRenderer.rect(1134, 620, AssetLoader.width-1144, AssetLoader.height-620);
shapeRenderer.end(); shapeRenderer.end();
batcher.begin();
batcher.draw(AssetLoader.Atlas_game.findRegion("cout"),1150,40);
batcher.draw(AssetLoader.Atlas_game.findRegion("tech"),1280,40);
batcher.end();
for (int i=0;i<LevelScreen.buttonLevels.length;i++) { for (int i=0;i<LevelScreen.buttonLevels.length;i++) {
if (LevelScreen.buttonLevels[i]!=null) { if (LevelScreen.buttonLevels[i]!=null) {
for (int[] item : LevelScreen.buttonLevels[i].level.Link) for (int[] item : LevelScreen.buttonLevels[i].level.Link)