feat: ménage dans les sources, suppression de packages inutiles changement des lasers.

This commit is contained in:
Nicolas Hordé 2016-01-12 01:02:29 +01:00
parent 57505ead12
commit 7fe9f6804c
10 changed files with 30 additions and 268 deletions

View File

@ -206,6 +206,7 @@ public class AssetLoader {
Datahandler.Attach(datatype.userdata, "local:test.db"); Datahandler.Attach(datatype.userdata, "local:test.db");
Datahandler.Attach(datatype.statdata, "local:test.db"); Datahandler.Attach(datatype.statdata, "local:test.db");
Datahandler.Attach(datatype.gamedata, "local:test.db"); Datahandler.Attach(datatype.gamedata, "local:test.db");
} }
public static Transmuter getTransmuter(String Name) { public static Transmuter getTransmuter(String Name) {

View File

@ -1,103 +1,13 @@
package fr.evolving.assets; package fr.evolving.assets;
import java.io.ByteArrayInputStream; import com.badlogic.gdx.utils.Array;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
import fr.evolving.automata.Cell; import fr.evolving.automata.Cell;
import fr.evolving.automata.Grid; import fr.evolving.automata.Grid;
import fr.evolving.automata.Level; import fr.evolving.automata.Level;
public class SaveObject { public class InitWorlds {
public static Array<Level> go() {
private static String DB_DRIVER = "";
private static String DB_CONNECTION = "";
private static String DB_USER = "";
private static String DB_PASSWORD = "";
public SaveObject(String DRIVER, String CONNECTION, String USER, String PASSWORD) {
DB_DRIVER=DRIVER;
DB_CONNECTION=CONNECTION;
DB_USER=USER;
DB_PASSWORD=PASSWORD;
}
public void saveObject(Object javaObject) throws Exception
{
try{
Connection conn = getDBConnection();
PreparedStatement ps=null;
String sql=null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(javaObject);
oos.flush();
oos.close();
bos.close();
byte[] data = bos.toByteArray();
sql="insert into worlds (javaObject) values(?)";
ps=conn.prepareStatement(sql);
ps.setObject(1, data);
ps.executeUpdate();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public Object getObject(Object javaObject) throws Exception
{
Connection conn=getDBConnection();
PreparedStatement ps=null;
ResultSet rs=null;
Object mc =null;
String sql="select * from worlds where id=1";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
ByteArrayInputStream bais;
ObjectInputStream ins;
try {
bais = new ByteArrayInputStream(rs.getBytes("javaObject"));
ins = new ObjectInputStream(bais);
mc = ins.readObject();
ins.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
return mc;
}
private static Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
}
catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
dbConnection = DriverManager.getConnection(DB_CONNECTION,DB_USER,DB_PASSWORD);
return dbConnection;
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
return dbConnection;
}
public static Level[] initObject()
{
Level[] thelevels=new Level[35]; Level[] thelevels=new Level[35];
thelevels[0]=new Level( thelevels[0]=new Level(
@ -707,7 +617,7 @@ public class SaveObject {
false, false,
new int[][]{}); new int[][]{});
return thelevels; return new Array<Level>(thelevels);
} }

View File

@ -16,7 +16,6 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.math.Calcul;
public class Laser { public class Laser {
@ -35,17 +34,21 @@ public class Laser {
float y1=yy1+20; float y1=yy1+20;
float x2=xx2+26; float x2=xx2+26;
float y2=yy2+20; float y2=yy2+20;
Vector2 vectorall = new Vector2(x2, y2).sub(new Vector2(x1, y1)); Vector2 vector1=new Vector2(x1, y1);
float length = vectorall.len(); Vector2 vector2=new Vector2(x2, y2);
Vector2 vectoradd = vectorall.scl(10/length); Vector2 vectorall = vector2.sub(vector1);
final int inc=16;
Vector2 vectoradd = vectorall.cpy().setLength(inc);
Vector2 vectoraddit = vectorall.cpy().setLength(64);
Laser.begin(); Laser.begin();
Laser.setColor(colorsrc); Laser.setColor(colorsrc);
Laser.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); Laser.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
Laser.draw(overlaymiddle,x1,y1,32,0,64,length,1f,1f,(float)Math.toDegrees(Calcul.getAngle(x1,y1,x2,y2))); Laser.draw(overlaymiddle,x1,y1,32,0,64,vectorall.len(),1f,1f,vectorall.angle()+270);
Laser.draw(middle,x1,y1,32,0,64,length,1f,1f,(float)Math.toDegrees(Calcul.getAngle(x1,y1,x2,y2))); Laser.draw(middle,x1,y1,32,0,64,vectorall.len(),1f,1f,vectorall.angle()+270);
Laser.setColor(new Color(1f,1f,1f,1f)); Laser.setColor(new Color(1f,1f,1f,1f));
Laser.draw(overlay,x1+i*vectoradd.x,y1+i*vectoradd.y,32,0,64,Calcul.getLen(x1+i*vectoradd.x,y1+i*vectoradd.y,x2,y2),1f,1f,(float)Math.toDegrees(Calcul.getAngle(x1,y1,x2,y2))); for(int j=0;j<(vectorall.len()-vectoradd.cpy().setLength(i*inc).len())/64-1;j++)
Laser.draw(overlay,x1,y1,32,0,64,Calcul.getLen(x1+i*vectoradd.x,y1+i*vectoradd.y,x2,y2),1f,1f,(float)Math.toDegrees(Calcul.getAngle(x1,y1,x2,y2))); Laser.draw(overlay,x1+i*vectoradd.x+j*vectoraddit.x,y1+i*vectoradd.y+j*vectoraddit.y,32,0,64,64,1f,1f,vectorall.angle()+270);
Laser.draw(overlay,x1,y1,32,0,64,i*inc,1f,1f,vectorall.angle()+270);
Laser.end(); Laser.end();
} }

View File

@ -1,74 +0,0 @@
package fr.evolving.inputs;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import fr.evolving.worlds.GameWorld;
public class InputHandler implements InputProcessor {
private GameWorld myWorld;
private float scaleFactorX;
private float scaleFactorY;
public InputHandler(float scaleFactorX, float scaleFactorY) {
this.scaleFactorX = scaleFactorX;
this.scaleFactorY = scaleFactorY;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
screenX = scaleX(screenX);
screenY = scaleY(screenY);
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
screenX = scaleX(screenX);
screenY = scaleY(screenY);
return false;
}
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
private int scaleX(int screenX) {
return (int) (screenX / scaleFactorX);
}
private int scaleY(int screenY) {
return (int) (screenY / scaleFactorY);
}
}

View File

@ -1,23 +0,0 @@
package fr.evolving.math;
import com.badlogic.gdx.math.Vector2;
public class Calcul {
public static double getAngle(float x1,float y1,float x2,float y2) {
double theta = Math.atan2(y2 - y1, x2 - x1);
theta -= Math.PI/2.0f;
if (theta < 0) {
theta += 2.0f*Math.PI;
}
return theta;
}
public static float getLen(float x1,float y1,float x2,float y2) {
Vector2 src=new Vector2(x1,y1);
Vector2 dst=new Vector2(x2,y2);
return dst.sub(src).len();
}
}

View File

@ -1,4 +1,4 @@
package fr.evolving.worlds; package fr.evolving.renderers;
import java.util.List; import java.util.List;
@ -13,11 +13,9 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.inputs.InputHandler;
import fr.evolving.screens.GameScreen; import fr.evolving.screens.GameScreen;
public class GameRenderer { public class GameRenderer {
private GameWorld myWorld;
private ShapeRenderer shapeRenderer; private ShapeRenderer shapeRenderer;
private SpriteBatch batcher; private SpriteBatch batcher;
private GameScreen GameScreen; private GameScreen GameScreen;

View File

@ -1,4 +1,4 @@
package fr.evolving.worlds; package fr.evolving.renderers;
import java.util.List; import java.util.List;
@ -17,7 +17,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import fr.evolving.UI.Objectives; import fr.evolving.UI.Objectives;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.effects.Laser; import fr.evolving.effects.Laser;
import fr.evolving.inputs.InputHandler;
import fr.evolving.screens.LevelScreen; import fr.evolving.screens.LevelScreen;
public class LevelRenderer { public class LevelRenderer {
@ -60,7 +59,7 @@ public class LevelRenderer {
this.dirx = 1; this.dirx = 1;
if (this.scrolly < 0) if (this.scrolly < 0)
this.diry = 1; this.diry = 1;
Laser.i+=1f; Laser.i+=0.3f;
if (Laser.i>10.0f) { if (Laser.i>10.0f) {
Laser.i=0; Laser.i=0;
} }

View File

@ -59,9 +59,8 @@ import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.OrderedMap; import com.badlogic.gdx.utils.OrderedMap;
import fr.evolving.UI.Menu; import fr.evolving.UI.Menu;
import fr.evolving.worlds.GameRenderer; import fr.evolving.renderers.GameRenderer;
import fr.evolving.worlds.GameWorld; import fr.evolving.renderers.LevelRenderer;
import fr.evolving.worlds.LevelRenderer;
import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.ButtonLevel;
import fr.evolving.UI.Objectives; import fr.evolving.UI.Objectives;
import fr.evolving.UI.TouchMaptiles; import fr.evolving.UI.TouchMaptiles;
@ -76,7 +75,6 @@ import fr.evolving.automata.Transmuter.Angular;
import fr.evolving.automata.Transmuter.CaseType; import fr.evolving.automata.Transmuter.CaseType;
import fr.evolving.database.LocalBase; import fr.evolving.database.LocalBase;
import fr.evolving.database.Base.datatype; import fr.evolving.database.Base.datatype;
import fr.evolving.inputs.InputHandler;
public class GameScreen implements Screen { public class GameScreen implements Screen {
private InputMultiplexer multiplexer; private InputMultiplexer multiplexer;
@ -86,7 +84,6 @@ public class GameScreen implements Screen {
private Stage stage,stage_menu,stage_info,stage_tooltip; private Stage stage,stage_menu,stage_info,stage_tooltip;
private HorizontalGroup table; private HorizontalGroup table;
private VerticalGroup table2; private VerticalGroup table2;
private GameWorld world;
private GameRenderer Renderer; private GameRenderer Renderer;
private float runTime; private float runTime;
public Level level; public Level level;
@ -215,9 +212,7 @@ public class GameScreen implements Screen {
oldx=0; oldx=0;
oldy=0; oldy=0;
unroll=false; unroll=false;
world = new GameWorld(level);
Renderer = new GameRenderer(this); Renderer = new GameRenderer(this);
world.setRenderer(Renderer);
Gdx.app.debug(getClass().getSimpleName(),"Mise en place du timer."); Gdx.app.debug(getClass().getSimpleName(),"Mise en place du timer.");
ScrollTimer=new Timer(); ScrollTimer=new Timer();
ScrollTask = new TimerTask() ScrollTask = new TimerTask()
@ -625,7 +620,6 @@ public class GameScreen implements Screen {
public void render(float delta) { public void render(float delta) {
stage.act(); stage.act();
runTime += delta; runTime += delta;
world.update(delta);
if (Preference.prefs.getBoolean("Refresh")) if (Preference.prefs.getBoolean("Refresh"))
fpsLabel.setText(Gdx.graphics.getFramesPerSecond()+"FPS"); fpsLabel.setText(Gdx.graphics.getFramesPerSecond()+"FPS");
Renderer.render(delta, runTime,0); Renderer.render(delta, runTime,0);

View File

@ -26,17 +26,16 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScalingViewport; import com.badlogic.gdx.utils.viewport.ScalingViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport; import com.badlogic.gdx.utils.viewport.StretchViewport;
import fr.evolving.worlds.LevelRenderer; import fr.evolving.renderers.LevelRenderer;
import fr.evolving.UI.ButtonLevel; import fr.evolving.UI.ButtonLevel;
import fr.evolving.UI.Objectives; import fr.evolving.UI.Objectives;
import fr.evolving.UI.ServerList; import fr.evolving.UI.ServerList;
import fr.evolving.game.main; import fr.evolving.game.main;
import fr.evolving.inputs.InputHandler;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import fr.evolving.assets.AssetLoader; import fr.evolving.assets.AssetLoader;
import fr.evolving.assets.SaveObject; import fr.evolving.assets.InitWorlds;
import fr.evolving.automata.Level; import fr.evolving.automata.Level;
import fr.evolving.automata.Transmuter; import fr.evolving.automata.Transmuter;
import fr.evolving.database.Base; import fr.evolving.database.Base;
@ -60,7 +59,7 @@ public class LevelScreen implements Screen {
private TextButton buttonConnect,buttonPlay,buttonStat; private TextButton buttonConnect,buttonPlay,buttonStat;
private ServerList Statdata,Userdata,Gamedata; private ServerList Statdata,Userdata,Gamedata;
private Label Statdatalabel, Userdatalabel, Gamedatalabel; private Label Statdatalabel, Userdatalabel, Gamedatalabel;
private Level[] thelevels; private Array<Level> thelevels;
private TextArea TextDescriptive; private TextArea TextDescriptive;
public int world; public int world;
private Objectives Victory; private Objectives Victory;
@ -267,13 +266,13 @@ public class LevelScreen implements Screen {
Gamedatalabel=new Label("Stockage des données du jeu:", AssetLoader.Skin_ui, "grey"); Gamedatalabel=new Label("Stockage des données du jeu:", AssetLoader.Skin_ui, "grey");
Gamedata.setBounds(1480, AssetLoader.height-900, 420, 200); Gamedata.setBounds(1480, AssetLoader.height-900, 420, 200);
Gamedatalabel.setPosition(1480, AssetLoader.height-700); Gamedatalabel.setPosition(1480, AssetLoader.height-700);
Gdx.app.debug(getClass().getSimpleName(),"Affichage du menu.");
//menu(); //menu();
//Gdx.app.debug(getClass().getSimpleName(),"Création des boutons de niveau.");
//thelevels= SaveObject.initObject();
//thelevels= InitWorlds.go();
thelevels=null; Gdx.app.debug(getClass().getSimpleName(),"Chargement des mondes depuis la base.");
thelevels=AssetLoader.Datahandler.game().getworld("test pour voir").toArray(); thelevels=AssetLoader.Datahandler.game().getworld("test pour voir");
loadWorld(world); loadWorld(world);
} }

View File

@ -1,45 +0,0 @@
package fr.evolving.worlds;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import fr.evolving.assets.SaveObject;
import fr.evolving.assets.AssetLoader;
import fr.evolving.automata.Grid;
import fr.evolving.automata.Level;
public class GameWorld {
private float runTime = 0;
private int midPointY;
private GameRenderer renderer;
private GameState currentState;
private Grid myGrid;
private SaveObject MySaveObject;
public enum GameState {
MENU, READY, RUNNING, GAMEOVER, OPTION
}
public GameWorld(Level level) {
Gdx.app.debug(this.getClass().getSimpleName(),"Initialisation du niveau...");
currentState = GameState.MENU;
//myGrid= new Grid(20,20);
//MySaveObject= new SaveObject("com.mysql.jdbc.Driver","jdbc:mysql://dahut.fr:3306/popfr_games","popfr_games","ef^J,khGMIL~");
//MySaveObject= new SaveObject("com.mysql.jdbc.Driver","jdbc:mysql://192.168.1.252:3306/games","games","WoawGames!!87");
//try {
// MySaveObject.saveObject(myGrid);
//} catch (Exception e) {
// e.printStackTrace();
//}
}
public void update(float delta) {
runTime += delta;
}
public void setRenderer(GameRenderer renderer) {
this.renderer = renderer;
}
}