feat: rajout de la gestion des niveaux. création du niveau 1.

This commit is contained in:
Nicolas Hordé 2015-06-16 02:32:31 +02:00
parent bd1e014171
commit 0609d13f92
6 changed files with 297 additions and 79 deletions

View File

@ -13,56 +13,45 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import fr.evolving.assets.AssetLoader;
import fr.evolving.automata.Level;
public class ButtonLevel extends ImageTextButton {
public int level;
public int world;
public boolean Final;
public int[][] Link;
public Level level;
public boolean Activated;
TextureRegion Finalled,Locked;
public String id,shortid;
public int xx,yy;
private Color[] Levelcolors={AssetLoader.Skin_level.getColor("world1"),AssetLoader.Skin_level.getColor("world2"),AssetLoader.Skin_level.getColor("world3"),AssetLoader.Skin_level.getColor("world4"),AssetLoader.Skin_level.getColor("world5")};
Label Thelabel;
public ButtonLevel(String shortid,String id,int world, int level, boolean Final, int[][] Link, boolean Activated,int x, int y) {
super(id, AssetLoader.Skin_level, "world"+String.valueOf(world));
this.xx=x;
this.yy=y;
this.id=id;
this.shortid=shortid;
public ButtonLevel(Level level, boolean Activated) {
super(level.Name, AssetLoader.Skin_level, "world"+String.valueOf(level.aWorld));
this.level=level;
this.world=world;
this.Final=Final;
this.Link=Link;
this.Activated=Activated;
if (Final==true) {
if (level.Special==true) {
Finalled=AssetLoader.Skin_level.getAtlas().findRegion("boss");
}
if (Activated==false) {
this.setDisabled(true);
Locked=AssetLoader.Skin_level.getAtlas().findRegion("locked");
}
this.setColor(1f, 0.47f+(float)x/Gdx.graphics.getWidth()*0.529f,0.607f+(float)x/Gdx.graphics.getWidth()*0.392f, 1f);
this.setBounds(x/1024.0f*Gdx.graphics.getWidth(), y/768.0f*Gdx.graphics.getHeight(), 111, 125);
Thelabel=new Label(this.shortid, AssetLoader.Skin_level,"Levelshort");
Thelabel.setColor(xx/1024f,xx/1024f,xx/1024f,1f);
Thelabel.setPosition(xx/1024.0f*Gdx.graphics.getWidth()+54, yy/768.0f*Gdx.graphics.getHeight()+20, Align.bottom | Align.center);
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);
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);
}
public Color getLevelcolor() {
return Levelcolors[world];
return Levelcolors[level.aWorld];
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (Final) {
batch.draw(Finalled,xx/1024.0f*Gdx.graphics.getWidth(),yy/768.0f*Gdx.graphics.getHeight());
if (level.Special) {
batch.draw(Finalled,level.X,level.Y/768.0f*Gdx.graphics.getHeight());
}
if (!Activated) {
batch.draw(Locked,xx/1024.0f*Gdx.graphics.getWidth()+this.getWidth()-Locked.getRegionWidth(),yy/768.0f*Gdx.graphics.getHeight()+this.getHeight()-Locked.getRegionWidth());
batch.draw(Locked,level.X+this.getWidth()-Locked.getRegionWidth(),level.Y/768.0f*Gdx.graphics.getHeight()+this.getHeight()-Locked.getRegionWidth());
}
Thelabel.draw(batch, 1f);
}

View File

@ -96,15 +96,18 @@ public class SaveObject {
return dbConnection;
}
public Level[] initObject()
public static Level[] initObject()
{
Level[] thelevels=new Level[9];
thelevels[0]=new Level("Introduction",
thelevels[0]=new Level(
0,
0,
"Introduction",
"Prise en main de l'interface de WireChem{#169} et amener l'électron neutre sur le senseur.",
"e0",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
38f,
450f,
-1,
@ -121,7 +124,211 @@ public class SaveObject {
"",
false,
new int[][]{{0, 1}, {0, 8}});
return thelevels;
}
thelevels[1]=new Level(
0,
1,
"Trajectoires",
"Comprendre les trajectoires empruntées par les électrons afin de mieux appréhender la conception de systèmes.",
"e0",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
38f,
200,
-1,
0,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 2}});
thelevels[2]=new Level(
0,
2,
"Pistes",
"Utiliser des pistes afin de réaliser un circuit qui permet l'arrivée d'un électron neutre sur le senseur.",
"e0",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
180f,
300f,
-1,
15,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 3}});
thelevels[3]=new Level(
0,
3,
"Positiveur",
"Comprendre le fonctionnement de l'élément positiveur et générer 8 électrons positifs sur le senseur.",
"e+",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0},
330f,
350f,
0,
16,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 4}});
thelevels[4]=new Level(
0,
4,
"Super-électrons",
"Générer 2 super-électrons negatifs par colision et les amener sur le senseur.",
"E-",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
490f,
380f,
0,
16,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 5}});
thelevels[5]=new Level(
0,
5,
"Activation",
"L'objectif est de générer 6 électrons neutres et de découvrir les liaisons de fibres par lesquelles transitent les photons. Certains modifieurs nécessitent désormais l'activation par des photons.",
"e0",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0},
490f,
200f,
1,
136,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 6}});
thelevels[6]=new Level(
0,
6,
"Fibres",
"A vous de dessiner votre infrastructure à base de fibres et de pistes mais aussi de modifieur activable afin de faire parvenir des éléctrons positifs et neutres sur les senseurs.",
"eX",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0},
640f,
200f,
2,
230,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 7}});
thelevels[7]=new Level(
0,
7,
"Protons",
"Générer deux protons sur le senseur en utilisant un réacteur et un super-positron. Le réacteur est un élément qui nécessite l'activation.",
"p",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2},
800f,
290f,
2,
370,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
false,
new int[][]{{0, 8}});
thelevels[8]=new Level(
0,
8,
"Hydrogène",
"Générer le premier atome complet : l'hydrogène avec un proton et un électron négatif sur la couche K.",
"H",
new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
new int[]{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
900f,
450f,
3,
750,
new Grid(20,20),
0,
0,
0,
0,
99999,
99999,
99999,
99999,
"",
true,
new int[][]{{1, 0},{1, 2}});
return thelevels;
}
}

View File

@ -3,29 +3,33 @@ package fr.evolving.automata;
import java.io.Serializable;
public class Level implements Serializable{
String Name;
String Description;
String Element;
int[] Current;
int[] Victory;
float X;
float Y;
int Tech;
int Cout;
Grid Grid;
int Cycle;
int Temp;
int Rayon;
int Nrj;
int Maxcycle;
int Maxtemp;
int Maxrayon;
int Maxnrj;
boolean Special;
String Tuto;
int[][] Link;
public String Name;
public String Description;
public String Element;
public int[] Current;
public int[] Victory;
public int aWorld;
public int aLevel;
public float X;
public float Y;
public int Tech;
public int Cout;
public Grid Grid;
public int Cycle;
public int Temp;
public int Rayon;
public int Nrj;
public int Maxcycle;
public int Maxtemp;
public int Maxrayon;
public int Maxnrj;
public boolean Special;
public String Tuto;
public int[][] Link;
public Level(String Name,String Description,String Element,int[] Current,int[] Victory,float X,float Y,int Tech,int Cout,Grid World,int Cycle,int Temp,int Rayon,int Nrj,int Maxcycle,int Maxtemp,int Maxrayon,int Maxnrj,String Tuto,boolean Special, int[][] Link){
public Level(int aWorld, int aLevel,String Name,String Description,String Element,int[] Current,int[] Victory,float X,float Y,int Tech,int Cout,Grid World,int Cycle,int Temp,int Rayon,int Nrj,int Maxcycle,int Maxtemp,int Maxrayon,int Maxnrj,String Tuto,boolean Special, int[][] Link){
this.aWorld=aWorld;
this.aLevel=aLevel;
this.Name=Name;
this.Description=Description;
this.Element=Element;

View File

@ -29,9 +29,7 @@ public class Laser {
overlay=AssetLoader.Skin_level.getAtlas().findRegion("overlay");
}
public void draw(float xx1,float yy1,float xx2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float x1=xx1/1024.0f*Gdx.graphics.getWidth();
float x2=xx2/1024.0f*Gdx.graphics.getWidth();
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();
Vector2 vectorall = new Vector2(x2, y2).sub(new Vector2(x1, y1));
@ -50,9 +48,7 @@ public class Laser {
Laser.dispose();
}
public void drawnotsoold(float xx1,float yy1,float xx2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float x1=xx1/1024.0f*Gdx.graphics.getWidth();
float x2=xx2/1024.0f*Gdx.graphics.getWidth();
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();
ShapeRenderer Laser=new ShapeRenderer();
@ -91,9 +87,7 @@ public class Laser {
}
public static void drawold(float xx1,float yy1,float xx2,float yy2,float maxwidth,float power,boolean active,Color colorsrc,Color colordst) {
float x1=xx1/1024.0f*Gdx.graphics.getWidth();
float x2=xx2/1024.0f*Gdx.graphics.getWidth();
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();
ShapeRenderer Laser=new ShapeRenderer();

View File

@ -9,9 +9,12 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextArea;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
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 fr.evolving.worlds.LevelRenderer;
import fr.evolving.UI.ButtonLevel;
@ -19,10 +22,13 @@ import fr.evolving.inputs.InputHandler;
import java.util.Timer;
import java.util.TimerTask;
import fr.evolving.assets.AssetLoader;
import fr.evolving.assets.SaveObject;
import fr.evolving.automata.Level;
import fr.evolving.effects.Laser;
public class LevelScreen implements Screen {
protected static final Class<? extends Actor> ButtonLevel = null;
public ButtonLevel[] buttonLevels;
private LevelRenderer Renderer;
private float runTime;
@ -32,6 +38,9 @@ public class LevelScreen implements Screen {
private Table table = new Table();
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
public LevelScreen() {
@ -39,14 +48,17 @@ public class LevelScreen implements Screen {
float screenHeight = Gdx.graphics.getHeight();
Renderer=new LevelRenderer((int)screenWidth,(int)screenHeight,this);
buttonLevels = new ButtonLevel[10];
int[][] integer=new int[][] {{0,2},{0,3},{0,1}};
buttonLevels[0]= new ButtonLevel("H","Hydrogene en test",0,0,true, integer, true,120,120);
buttonLevels[1]= new ButtonLevel("Li","Lithium a voir",0,1,false, new int[0][0], false,820,520);
buttonLevels[2]= new ButtonLevel("Ne","Neon",0,2,true, new int[0][0], true,420,420);
buttonLevels[3]= new ButtonLevel("Mg","Magnesium 23",0,3,false, new int[0][0], false,420,220);
buttonLevels[4]= new ButtonLevel("Pr","prout 21",1,3,true, integer, true,520,520);
int[][] integer2=new int[][] {{0,1},{1,3},{0,2}};
buttonLevels[5]= new ButtonLevel("Pr","prout",4,5,true, integer2, true,900,40);
thelevels= SaveObject.initObject();
for (int i = 0;i<thelevels.length;i++) {
if (thelevels[i] != null)
buttonLevels[i]=new ButtonLevel(thelevels[i],true);
buttonLevels[i].addListener(new ClickListener(){
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
TextDescriptive.setText(((ButtonLevel)event.getListenerActor()).level.Description);
}
});
}
ScrollTimer=new Timer();
ScrollTask = new TimerTask()
{
@ -57,8 +69,10 @@ public class LevelScreen implements Screen {
}
};
ScrollTimer.scheduleAtFixedRate(ScrollTask, 0, 30);
buttonPlay = new TextButton("Play", AssetLoader.Skin_level);
buttonExit = new TextButton("Exit", AssetLoader.Skin_level);
TextDescriptive = new TextArea("Descriptif", AssetLoader.Skin_level,"Descriptif");
TextDescriptive.setBounds(15, 15, 1009, 130);
buttonPlay = new TextButton("Jouer", AssetLoader.Skin_level,"Bouton");
buttonExit = new TextButton("Quitter", AssetLoader.Skin_level,"Bouton");
Exit=new ImageButton(AssetLoader.Skin_level,"Exit");
Exit.setPosition(900, Gdx.graphics.getHeight()-Exit.getHeight());
Exit.addListener(new ClickListener(){
@ -68,9 +82,14 @@ public class LevelScreen implements Screen {
}
});
Next=new ImageButton(AssetLoader.Skin_level,"Next");
Next.setPosition(800, 100);
Next.setPosition(840, 170);
Previous=new ImageButton(AssetLoader.Skin_level,"Previous");
Previous.setPosition(900, 100);
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;
}
@Override
@ -88,14 +107,15 @@ public class LevelScreen implements Screen {
@Override
public void show() {
Gdx.app.log("Affichage du LevelScreen","ok");
table.add(buttonPlay).size(150,60).padBottom(20).row();
table.add(buttonExit).size(150,60).padBottom(20).row();
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]);
}
}
table.setFillParent(true);
stage.addActor(TextDescriptive);
stage.addActor(table);
stage.addActor(Exit);
stage.addActor(Next);

View File

@ -78,23 +78,27 @@ public class LevelRenderer {
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.end();
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.end();
for (int i=0;i<LevelScreen.buttonLevels.length;i++) {
if (LevelScreen.buttonLevels[i]!=null) {
for (int[] item : LevelScreen.buttonLevels[i].Link)
for (int[] item : LevelScreen.buttonLevels[i].level.Link)
{
int found=-1;
for (int j=0;j<LevelScreen.buttonLevels.length;j++)
{
if ((LevelScreen.buttonLevels[j]!=null) && (LevelScreen.buttonLevels[j].world==item[0]) && (LevelScreen.buttonLevels[j].level==item[1])) {
if ((LevelScreen.buttonLevels[j]!=null) && (LevelScreen.buttonLevels[j].level.aWorld==item[0]) && (LevelScreen.buttonLevels[j].level.aLevel==item[1])) {
found=j;
break;
}
}
if (found!=-1)
{
Laser.draw(LevelScreen.buttonLevels[i].xx+20,LevelScreen.buttonLevels[i].yy+20,LevelScreen.buttonLevels[found].xx+20,LevelScreen.buttonLevels[found].yy+20,10,0.5f,LevelScreen.buttonLevels[found].Activated,LevelScreen.buttonLevels[i].getLevelcolor(),LevelScreen.buttonLevels[found].getLevelcolor());
Laser.draw(LevelScreen.buttonLevels[i].level.X+20,LevelScreen.buttonLevels[i].level.Y+20,LevelScreen.buttonLevels[found].level.X+20,LevelScreen.buttonLevels[found].level.Y+20,10,0.5f,LevelScreen.buttonLevels[found].Activated,LevelScreen.buttonLevels[i].getLevelcolor(),LevelScreen.buttonLevels[found].getLevelcolor());
}
}
}