List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.dongbat.invasion.enemy.tasks.NormalFindTargetTask.java
@Override public void run(Entity enemy) { Enemy enemyComponent = EntityUtil.getComponent(enemy, Enemy.class); Vector2 position = PhysicsUtil.getPosition(enemy); Vector2 target = new Vector2(0, position.y); if (enemyComponent.hasPickedUpAds()) { target.x = enemyComponent.isAirUnit() ? Constants.ENEMY.AIR_START_X : Constants.ENEMY.GROUND_START_X; } else {//from w ww .j av a2 s. c o m target.x = Constants.ENEMY.PICK_UP_POINT_X; } MovementUtil.setTarget(enemy, target); success(); }
From source file:com.dongbat.invasion.registry.EnemyRegistry.java
public static Entity createEnemy(String enemyType, Float positionX) { EnemyInfo enemyInfo = get(enemyType); EnemyType enemyTypeAI = createEnemyType(enemyInfo); Enemy enemyComponent = new Enemy(); enemyComponent.setType(enemyTypeAI); enemyComponent.setAirUnit(enemyInfo.isAirUnit()); enemyComponent.setBoss(enemyInfo.isBoss()); enemyComponent.setInfinitePickup(enemyInfo.isInfinitePickup()); enemyComponent.setCanPickAds(enemyInfo.canPickAds()); enemyComponent.setAdsPickingDelay(enemyInfo.getAdsPickingDelay()); enemyComponent.setTributeDelay(enemyInfo.getTributeDelay()); enemyComponent.setBounty(enemyInfo.getBounty()); Vector2 position;/*from ww w . j a v a2 s . co m*/ if (enemyInfo.isAirUnit()) { position = new Vector2(Constants.ENEMY.AIR_START_X, Constants.ENEMY.AIR_START_Y); } else { float startY = Constants.PHYSICS.GROUND_Y + enemyInfo.getRadius(); position = new Vector2(Constants.ENEMY.GROUND_START_X, startY); } if (positionX != null) { position.x = positionX; } Body body = PhysicsUtil.createBody(position, enemyInfo.getRadius()); body.setGravityScale(0); MassData massData = new MassData(); massData.mass = 1; body.setMassData(massData); Physics physicsComponent = new Physics(); physicsComponent.setBody(body); physicsComponent.setMaxSpeed(enemyInfo.getMaxSpeed()); physicsComponent.setRadius(enemyInfo.getRadius()); Health healthComponent = new Health(enemyInfo.getMaxHealth(), enemyInfo.getMaxHealth()); Collision collision = new Collision(); Buff buffComponent = new Buff(); Delay delayComponent = new Delay(); Ability abilityComponent = new Ability(); String abilities = enemyInfo.getAbilities(); if (abilities != null && !abilities.isEmpty()) { String[] names = enemyInfo.getAbilities().split(","); for (String name : names) { AbilityInfo ability = AbilityRegistry.getAbility(name); abilityComponent.addAbility(name, ability); } } EnemyMovement movementComponent = new EnemyMovement(); DisplayPosition displayPosition = new DisplayPosition(position); Ads ads = new Ads(); ads.setOffline(true); ads.setPosition(new Vector2(Constants.ADS.DEFAULT_OFFSET_X, Constants.ADS.DEFAULT_OFFSET_Y)); Spine spineComponent = new Spine(enemyInfo.getSpineName()); Entity enemy = ECSUtil.getWorld().createEntity().edit().add(enemyComponent).add(physicsComponent) .add(healthComponent).add(collision).add(buffComponent).add(abilityComponent).add(movementComponent) .add(ads).add(displayPosition).add(spineComponent).add(delayComponent).getEntity(); physicsComponent.getBody().setUserData(enemy); // Add enemy to a group ECSUtil.getWorld().getManager(GroupManager.class).add(enemy, Constants.ENEMY.GROUP_NAME); return enemy; }
From source file:com.dongbat.invasion.system.AdsDeliverySystem.java
@Override protected void process(Entity entity) { Vector2 position = PhysicsUtil.getPosition(entity); Enemy enemy = enemyMapper.get(entity); if (!enemy.canPickAds()) { return;/*from ww w . j a v a2 s . c om*/ } Ads ads = adsMapper.get(entity); Delay delay = delayMapper.get(entity); if (!enemy.hasPickedUpAds() && position.x >= Constants.ENEMY.PICK_UP_POINT_X) { // TODO pick up ads animation if (delay.getDuration() == 0) { // set delay delay.setDelay(TimeUtil.getGameTime(), enemy.getAdsPickingDelay()); } else { long timePassed = TimeUtil.getGameTimeSince(delay.getStartTime()); if (timePassed >= delay.getDuration()) { enemy.setPickedUpAds(true); if (ads.isOffline()) { String spriteName = MathUtils.random(10) + ".jpg"; Texture texture = AssetUtil.getTexture(spriteName); Sprite sprite = new Sprite(texture); ads.setSprite(sprite); ads.setSize(new Vector2(texture.getWidth(), texture.getHeight())); } } } } int leftLimit = enemy.isAirUnit() ? Constants.ENEMY.AIR_START_X : Constants.ENEMY.GROUND_START_X; if (enemy.hasPickedUpAds() && position.x <= leftLimit) { // TODO tribute animation if (delay.getDuration() == 0) { delay.setDelay(TimeUtil.getGameTime(), enemy.getTributeDelay()); } else { long timePassed = TimeUtil.getGameTimeSince(delay.getStartTime()); if (timePassed >= delay.getDuration()) { enemy.setPickedUpAds(false); if (!enemy.isInfinitePickup()) { entity.deleteFromWorld(); } } } } }
From source file:com.dongbat.invasion.system.AdsRenderSystem.java
@Override protected void inserted(Entity e) { Ads ads = adsMapper.get(e);/* www .ja v a2 s .com*/ Vector2 position = ads.getPosition(); if (ads.isOffline()) { //set sprite String spriteName = MathUtils.random(10) + ".jpg"; Texture texture = AssetUtil.getTexture(spriteName); Sprite sprite = new Sprite(texture); ads.setSprite(sprite); //set size by texture width, height ads.setSize(new Vector2(texture.getWidth(), texture.getHeight())); } Vector2 size = ads.getSize(); if (size == null) { size = new Vector2(0, 0); } int id = AdsUtil.add(position.x, position.y, size.x, size.y); if (!ads.isOffline()) { ads.setId(id); } }
From source file:com.dongbat.invasion.util.PhysicsUtil.java
public static World getWorld() { if (physicsWorld == null) { physicsWorld = new World(new Vector2(0, Constants.PHYSICS.DEFAULT_GRAVITY), false); }// w w w . j av a 2s. c om return physicsWorld; }
From source file:com.esotericsoftware.spine.Box2DExample.java
License:Open Source License
private void createWorld() { world = new World(new Vector2(0, -10), true); float[] vertices = { -0.07421887f, -0.16276085f, -0.12109375f, -0.22786504f, -0.157552f, -0.7122401f, 0.04296875f, -0.7122401f, 0.110677004f, -0.6419276f, 0.13151026f, -0.49869835f, 0.08984375f, -0.3190109f };/*from www .j av a 2s. c o m*/ PolygonShape shape = new PolygonShape(); shape.set(vertices); // next we create a static ground platform. This platform // is not moveable and will not react to any influences from // outside. It will however influence other bodies. First we // create a PolygonShape that holds the form of the platform. // it will be 100 meters wide and 2 meters high, centered // around the origin PolygonShape groundPoly = new PolygonShape(); groundPoly.setAsBox(50, 1); // next we create the body for the ground platform. It's // simply a static body. BodyDef groundBodyDef = new BodyDef(); groundBodyDef.type = BodyType.StaticBody; groundBody = world.createBody(groundBodyDef); // finally we add a fixture to the body using the polygon // defined above. Note that we have to dispose PolygonShapes // and CircleShapes once they are no longer used. This is the // only time you have to care explicitely for memomry managment. FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = groundPoly; fixtureDef.filter.groupIndex = 0; groundBody.createFixture(fixtureDef); groundPoly.dispose(); PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(1, 1); // Next we create the 50 box bodies using the PolygonShape we just // defined. This process is similar to the one we used for the ground // body. Note that we reuse the polygon for each body fixture. for (int i = 0; i < 45; i++) { // Create the BodyDef, set a random position above the // ground and create a new body BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = -24 + (float) (Math.random() * 48); boxBodyDef.position.y = 10 + (float) (Math.random() * 100); Body boxBody = world.createBody(boxBodyDef); boxBody.createFixture(boxPoly, 1); } // we are done, all that's left is disposing the boxPoly boxPoly.dispose(); }
From source file:com.evoluzion.Mundo.java
License:Open Source License
public Mundo(Evoluzion ev, String ruta, String nombre, String poblacion, int numOrg, int numSen, int numQen, int Senergia, int Qbiomasa, boolean cargarPoblacion, boolean moverMasa, String genesPedidos, int ingles) { this.ev = ev; this.numOrg = numOrg; this.numSen = numSen; this.numQen = numQen; this.Senergia = Senergia; this.Qbiomasa = Qbiomasa; this.cargarPoblacion = cargarPoblacion; this.moverMasa = moverMasa; this.nombre = nombre; this.ruta = ruta; this.poblacion = poblacion; this.ingles = ingles; tx = new Texto(); if (ingles == 1) { tx.setIngles();/*from ww w. j ava2 s . co m*/ } if (ingles == -1) { tx.setEspanol(); } orgNombre = new StringBuffer("a"); //quaddtree // quad = new Quadtree(0, new Rectangle(0,0,ancho,alto)); // tamao de la pantalla ancho = Gdx.graphics.getWidth(); alto = Gdx.graphics.getHeight(); //listas ase = new Array<Senergia>(); aqe = new Array<Qenergia>(); aorg = new Array<Organismo>(); aEspesies = new Array<Organismo>(); aEspesiesTotales = new Array<Organismo>(); quad = new Quadtree(0, new Rectangle(0, 0, ancho, alto)); // set time to 0 setDelta(); setDelta2(); setDelta3(); setTiempo(); linea = new StringBuffer();// used to write text in files textuRA_ENER = new TextureAtlas("data/energia.pack"); textura_ORG = new TextureAtlas("data/objetos.pack"); textura_organismos = new TextureAtlas("data/organ.pack"); auraATB = new Texture("data/auraATB.png"); transferido = new Texture("data/Transferido.png"); //agregar cuantos de energia solar float x = 0; float y = alto; for (int i = 0; i < this.numSen; i++) { Vector2 pos = new Vector2((float) Math.random() * ancho, (float) Math.random() * alto); x = x + 20; if (x >= ancho) { x = 0; y = y - 20; } ase.add(new Senergia(pos, this)); } //agregar materia for (int i = 0; i < numQen; i++) { Vector2 pos = new Vector2((float) (Math.random() * (ancho - 5 + 1)) + 5, (float) Math.random() * alto); aqe.add(new Qenergia(pos, moverMasa, this)); } //agregar materia invisible para usarla en el balanse de masa for (int i = 0; i < numQen / 3; i++) { Vector2 pos = new Vector2((float) (Math.random() * (ancho - 5 + 1)) + 5, (float) Math.random() * alto); Qenergia qe = new Qenergia(pos, moverMasa, this); qe.visible = false; aqe.add(qe); } //colecta la primera especie en la lista for (Organismo or : aorg) { boolean igual = false; String id = or.identificador; for (Organismo or2 : aEspesies) { if (id.equals(or2.nombre)) { igual = true; } } if (igual == false) { aEspesies.add(or); } } for (Organismo or : aorg) { boolean igual = false; String id = or.identificador; for (Organismo or2 : aEspesiesTotales) { if (id.equals(or2.nombre)) { igual = true; } } if (igual == false) { aEspesiesTotales.add(or); } } //manejamos los archivos f_datos = new Archivar(); f_genes = new Archivar(); f_proteoma = new Archivar(); f_arbol = new Archivar(); f_poblacion = new Archivar(); f_mutantes = new Archivar(); }
From source file:com.evoluzion.Mundo.java
License:Open Source License
public void agregarPrimerosOrg(int num) { for (int i = 0; i < num; i++) { Vector2 pos = new Vector2((float) Math.random() * ancho, (float) Math.random() * alto); Vector2 dir = new Vector2((float) Math.random() * 20, (float) Math.random() * 20); if (dir.x < 10) { dir.x = dir.x * (-1);// ww w . ja v a 2s . c o m } if (dir.x > 10) { dir.x = dir.x - 10; } if (dir.y < 10) { dir.y = dir.y * (-1); } if (dir.y > 10) { dir.y = dir.y - 10; } aorg.add(new Organismo(new Genoma(), pos, orgNombre, this)); aorg.get(i).direccion = dir; } int o = BiomasaTotal() / Qbiomasa; //System.out.println(BiomasaTotal()); for (int i = 0; i < o; i++) { Qenergia qe = aqe.get(i); qe.visible = false; } Masatotal = MateriaLibre() + BiomasaTotal(); }
From source file:com.evoluzion.Mundo.java
License:Open Source License
public void leerArchivoPoblacion() { for (Organismo or : aorg) { aorg.removeValue(or, true);//w ww.java 2 s.co m } ; for (Organismo or : aEspesiesTotales) { aEspesiesTotales.removeValue(or, true); } try { FileReader fr = new FileReader(poblacion); BufferedReader br = new BufferedReader(fr); String linea = null; while ((linea = br.readLine()) != null) { Genoma gen = new Genoma(); gen.color = new StringBuffer( linea.substring(linea.indexOf("<color>") + 7, linea.indexOf("<ancho>"))); gen.ancho = new StringBuffer( linea.substring(linea.indexOf("<ancho>") + 7, linea.indexOf("<alto>"))); gen.alto = new StringBuffer(linea.substring(linea.indexOf("<alto>") + 6, linea.indexOf("<speed>"))); gen.speed = new StringBuffer( linea.substring(linea.indexOf("<speed>") + 7, linea.indexOf("<temp>"))); gen.toleranciaTemp = new StringBuffer( linea.substring(linea.indexOf("<temp>") + 6, linea.indexOf("<sentir>"))); gen.sentir = new StringBuffer( linea.substring(linea.indexOf("<sentir>") + 8, linea.indexOf("<alcance>"))); gen.radioConsiente = new StringBuffer( linea.substring(linea.indexOf("<alcance>") + 9, linea.indexOf("<cazar>"))); gen.cazar = new StringBuffer( linea.substring(linea.indexOf("<cazar>") + 7, linea.indexOf("<escapar>"))); gen.escapar = new StringBuffer( linea.substring(linea.indexOf("<escapar>") + 9, linea.indexOf("<predador>"))); gen.predador = new StringBuffer( linea.substring(linea.indexOf("<predador>") + 10, linea.indexOf("<longevidad>"))); gen.longevidad = new StringBuffer( linea.substring(linea.indexOf("<longevidad>") + 12, linea.indexOf("<tasamut>"))); gen.tasaMutacion = new StringBuffer( linea.substring(linea.indexOf("<tasamut>") + 9, linea.indexOf("<atb>"))); gen.resistenciaATB = new StringBuffer(linea.substring(linea.indexOf("<atb>") + 5, linea.length())); Vector2 pos = new Vector2( Float.parseFloat(linea.substring(linea.indexOf("dX") + 2, linea.indexOf("dY"))), Float.parseFloat(linea.substring(linea.indexOf("dY") + 2, linea.indexOf("<color>")))); StringBuffer nombre = new StringBuffer( linea.substring(linea.indexOf("<h>") + 3, linea.indexOf("dX"))); Organismo or = new Organismo(gen, pos, nombre, this); or.direccion.x = (float) (Math.random() * 10); or.direccion.y = (float) (Math.random() * 10); aorg.add(or); } int o = BiomasaTotal() / Qbiomasa; //System.out.println(BiomasaTotal()); for (int i = 0; i < o; i++) { Qenergia qe = aqe.get(i); qe.visible = false; } Masatotal = MateriaLibre() + BiomasaTotal(); br.close(); fr.close(); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "no se puede leer este archivo"); for (int i = 0; i < numOrg; i++) { Vector2 pos = new Vector2((float) Math.random() * ancho, (float) Math.random() * alto); Vector2 dir = new Vector2((float) Math.random() * 20, (float) Math.random() * 20); if (dir.x < 10) { dir.x = dir.x * (-1); } if (dir.x > 10) { dir.x = dir.x - 10; } if (dir.y < 10) { dir.y = dir.y * (-1); } if (dir.y > 10) { dir.y = dir.y - 10; } // System.out.println("x "+ dir.x +" y "+dir.y); aorg.add(new Organismo(new Genoma(), pos, orgNombre, this)); } ex.printStackTrace(); } }
From source file:com.evoluzion.Mundo.java
License:Open Source License
public void detectarColiciones() { //organismo toca la energia verde for (int i = 0; i < aorg.size; i++) { Organismo or = aorg.get(i);//from ww w. j a va 2 s. co m Rectangle er = or.borde; if (or.carnivoro == false) { for (int a = 0; a < ase.size; a++) { Senergia se = ase.get(a); Rectangle tr = se.borde; if (se.visible == true) { if (er.overlaps(tr)) { or.energia = or.energia + se.energia; //se.setEnergia(0); se.energia = se.energia - (or.capacidad - or.energia); if (se.energia <= 0) { se.visible = false; } if (or.energia > or.capacidad) { or.energia = or.capacidad; } ; // // // // } } } } } //organismo toca la biomasa for (int i = 0; i < aorg.size; i++) { Organismo or = aorg.get(i); Rectangle er = or.borde; if (or.carnivoro == false) { for (int a = 0; a < aqe.size; a++) { Qenergia qe = aqe.get(a); Rectangle tr = qe.borde; if (qe.visible == true) { if (er.overlaps(tr)) { if (or.biomasa < or.capacidad) { or.biomasa = or.biomasa + qe.masa; qe.posicion = new Vector2(-100, -100); qe.visible = false; // qe.setMasa(0); } } } } } } quad.clear(); for (int i = 0; i < aorg.size; i++) { quad.insert(aorg.get(i)); } Array<Organismo> returnObjects = new Array<Organismo>(); for (int i = 0; i < quad.objects.size; i++) { returnObjects.clear(); quad.retrieve(returnObjects, quad.objects.get(i)); //Organismo toca organismo for (int x = 0; x < returnObjects.size; x++) { Organismo or = returnObjects.get(i); Rectangle er = or.borde; for (int a = 0; a < returnObjects.size; a++) { Organismo or2 = returnObjects.get(a); Rectangle er2 = or2.borde; if (er.overlaps(er2)) { if (a != i) { horizontalTransfer(or, or2);//horizontal transfer of genes // System.out.println("Colision"); } if (or.carnivoro == true) { if (!or.identificador.equals(or2.identificador) && or.capacidad >= or2.capacidad) { EnRe = (int) (or.capacidad - or.energia); BioRe = (int) (or.capacidad - or.biomasa); if (EnRe >= or2.energia && EnRe > 0) { or.energia = or.energia + or2.energia; or2.energia = 0; } if (EnRe < or2.energia && EnRe > 0) { or.energia = or.energia + EnRe; or2.energia = or2.energia - EnRe; } if (BioRe >= or2.biomasa && BioRe > 0) { or.biomasa = or.biomasa + or2.biomasa; or2.biomasa = 0; } if (BioRe < or2.biomasa && BioRe > 0) { or.biomasa = or.biomasa + BioRe; or2.biomasa = or2.biomasa - BioRe; } if (or2.energia <= 0) { or2.morir(); } } } } } } } }