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);
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.setBounds(level.X, level.Y/768.0f*Gdx.graphics.getHeight(), 111, 125);
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, 111, 125);
Thelabel=new Label(level.Element, AssetLoader.Skin_level,"Levelshort");
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() {
@ -48,10 +48,10 @@ public class ButtonLevel extends ImageTextButton {
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (level.Special) {
batch.draw(Finalled,level.X,level.Y/768.0f*Gdx.graphics.getHeight());
batch.draw(Finalled,level.X,level.Y);
}
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);
}

View File

@ -18,11 +18,15 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
public class AssetLoader {
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_fond2;
public static Texture Texture_logo;
public static Sound intro;
public static int width=1440;
public static int height=960;
public static boolean stretch=false;
private static Preferences prefs;
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.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
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++)
addstyle(Atlas_level,"leveler"+String.valueOf(i));
addstyle(Atlas_level,"arrows");

View File

@ -29,9 +29,7 @@ public class Laser {
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) {
float y1=yy1/768.0f*Gdx.graphics.getHeight();
float y2=yy2/768.0f*Gdx.graphics.getHeight();
public void draw(float x1,float y1,float x2,float y2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
Vector2 vectorall = new Vector2(x2, y2).sub(new Vector2(x1, y1));
float length = vectorall.len();
Vector2 vectoradd = vectorall.scl(10/length);
@ -48,9 +46,7 @@ public class Laser {
Laser.dispose();
}
public void drawnotsoold(float x1,float yy1,float x2,float yy2,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();
public void drawnotsoold(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);
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) {
float y1=yy1/768.0f*Gdx.graphics.getHeight();
float y2=yy2/768.0f*Gdx.graphics.getHeight();
public static 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;

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.utils.ClickListener;
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.UI.ButtonLevel;
@ -39,14 +43,16 @@ public class LevelScreen implements Screen {
private ImageButton Previous,Next,Exit;
private TextButton buttonPlay,buttonExit;
private Level[] thelevels=new Level[9];
private float spaces,sizes;
private TextArea TextDescriptive;
// This is the constructor, not the class declaration
private ScalingViewport viewport;
public LevelScreen() {
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
Renderer=new LevelRenderer((int)screenWidth,(int)screenHeight,this);
if (AssetLoader.stretch)
viewport = new StretchViewport(AssetLoader.width,AssetLoader.height);
else
viewport = new FitViewport(AssetLoader.width,AssetLoader.height);
viewport.apply();
Renderer=new LevelRenderer(this);
buttonLevels = new ButtonLevel[10];
thelevels= SaveObject.initObject();
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.setBounds(15, 15, 1009, 130);
buttonPlay = new TextButton("Jouer", AssetLoader.Skin_level,"Bouton");
buttonPlay.setPosition(120, 170);
buttonExit = new TextButton("Quitter", AssetLoader.Skin_level,"Bouton");
buttonExit.setPosition(220, 170);
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(){
@Override
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.setPosition(840, 170);
Next.setPosition(940, 170);
Previous=new ImageButton(AssetLoader.Skin_level,"Previous");
Previous.setPosition(920, 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;
Previous.setPosition(1020, 170);
}
@Override
@ -102,13 +105,12 @@ public class LevelScreen implements Screen {
@Override
public void resize(int width, int height) {
viewport.update(width,height);
}
@Override
public void show() {
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++) {
if (buttonLevels[i]!=null) {
stage.addActor(buttonLevels[i]);
@ -116,9 +118,10 @@ public class LevelScreen implements Screen {
}
table.setFillParent(true);
stage.addActor(TextDescriptive);
stage.addActor(table);
stage.addActor(Exit);
stage.addActor(Next);
stage.addActor(buttonPlay);
stage.addActor(buttonExit);
stage.addActor(Previous);
Gdx.input.setInputProcessor(stage);
}

View File

@ -21,8 +21,6 @@ import fr.evolving.screens.LevelScreen;
public class LevelRenderer {
private ShapeRenderer shapeRenderer;
private SpriteBatch batcher;
int gameWidth;
int gameHeight;
int scrollx;
int scrolly;
int dirx;
@ -32,14 +30,12 @@ public class LevelRenderer {
TextureRegion Texture_logobig;
TextureRegion Texture_logosmall;
public LevelRenderer(int gameWidth, int gameHeight,LevelScreen LevelScreen) {
public LevelRenderer(LevelScreen LevelScreen) {
this.LevelScreen=LevelScreen;
this.scrollx=0;
this.scrolly=0;
this.dirx=1;
this.diry=1;
this.gameHeight=gameHeight;
this.gameWidth=gameWidth;
batcher = new SpriteBatch();
shapeRenderer = new ShapeRenderer();
Laser=new Laser();
@ -67,23 +63,34 @@ 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);
batcher.begin();
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.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);
Texture_logobig=AssetLoader.Skin_level.getRegion("logo3");
Texture_logosmall=AssetLoader.Skin_level.getRegion("logo2");
batcher.draw(Texture_logosmall,20, this.gameHeight-Texture_logobig.getRegionHeight()+Texture_logosmall.getRegionHeight()/2);
batcher.draw(Texture_logobig,120, this.gameHeight-Texture_logobig.getRegionHeight());
batcher.draw(Texture_logosmall,20, AssetLoader.height-Texture_logobig.getRegionHeight()+Texture_logosmall.getRegionHeight()/2);
batcher.draw(Texture_logobig,120, AssetLoader.height-Texture_logobig.getRegionHeight());
batcher.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeType.Filled);
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();
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++) {
if (LevelScreen.buttonLevels[i]!=null) {
for (int[] item : LevelScreen.buttonLevels[i].level.Link)