List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2(float x, float y)
From source file:com.mygdx.environments.EnvironmentManager.java
public static void init(int index) { switch (index) { default:/*from www . j av a 2s .c o m*/ currentEnv = new EnvRoom(0, 1); } FULL_ENV_MAP.put(currentEnv.getId(), currentEnv); //player //NOTE: player declaration needs to proceed Env initialization for b2d purposes player = new Player_Test(new Vector2(0, 0), 10, 10); currentEnv.begin(); }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
public EnvNull(int id, int linkid, int difficulty) { super(id);/*from w w w.jav a 2 s.c om*/ this.linkid = linkid; this.width = MainGame.WIDTH; this.height = MainGame.HEIGHT; this.DIFFICULTY = difficulty; introDescription = "The Null"; playTexture = MainGame.am.get(ResourceManager.DEFAULT_SQUARE); introTexture = MainGame.am.get(ResourceManager.DEFAULT_SQUARE); outroTexture = MainGame.am.get(ResourceManager.DEFAULT_SQUARE); fgx = 0; fgy = 0; fgw = width; fgh = height; //todo: dont need 7 render layers renderLayers = 7; cameraZoom = 1.0f; //todo: adjust position - coordinate with first section startPos = new Vector2(MainGame.WIDTH * 0.55f / PPM, MainGame.HEIGHT * 0.65f / PPM); this.setPlayerToStart(); playerDiveSprite = EnvironmentManager.player.getDiveSprite(); playerDiveSprite.sprite.setPosition(width * 0.5f, height * 0.15f); PLAYER_DIVE_POS = new Vector2(playerDiveSprite.sprite.getX(), playerDiveSprite.sprite.getY()); PLAYER_DIVE_SCALE = playerDiveSprite.sprite.getScaleX(); diveTime = (long) (2000 * 0.6); impactSprite = new EntitySprite(new Vector2(playerPos.x * PPM, playerPos.y * PPM), 185f, 390f, "player-impact", 1.0f, true, false); //todo: change pos impactSprite.setPosition(new Vector2(playerPos.x * PPM - impactSprite.getWidth() / 2, playerPos.y * PPM - impactSprite.getHeight() * 0.175f)); //end endFC.setTime(4.0f); }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
public void fallingUpdate() { if (diveFC.complete) { /************************ COMPLETE THE DIVE/*from w w w. ja va 2 s. com*/ ************************/ //set player to center of section EnvironmentManager.player.getBody() .setTransform(new Vector2((currentSection.getPos().x + currentSection.getWidth() / 2) / PPM, (currentSection.getPos().y + currentSection.getHeight() / 2) / PPM), 0); EnvironmentManager.player.getBody().setLinearVelocity(new Vector2(0, 0)); //zoom out to normal if (fallDown) { currentPlayerZoom = currentPlayerZoom >= PLAYER_LAYER_ZOOM ? PLAYER_LAYER_ZOOM : currentPlayerZoom + 0.065f; } else { //fallUp currentPlayerZoom = currentPlayerZoom <= PLAYER_LAYER_ZOOM ? PLAYER_LAYER_ZOOM : currentPlayerZoom + 0.065f; } //complete current fall, resume play if (currentPlayerZoom == PLAYER_LAYER_ZOOM) { //BUG FIX (4/22/16) Player body movement on dive complete EnvironmentManager.player.getBody().setLinearVelocity(new Vector2(0, 0)); sm.setState(1); currentTopZoom = TOP_LAYER_ZOOM; currentPlayerZoom = PLAYER_LAYER_ZOOM; diveIn = false; diveMovement = 0.1f; } } else { /*************************************** FALL ZOOM INTO CURRENT SECTION ***************************************/ for (LayerManager lm : layerManagers) { lm.updatePitZoom(fallDown); } //move player towards center of pit section Vector2 sectionPos = new Vector2((currentSection.getPos().x + currentSection.getWidth() / 2) / PPM, (currentSection.getPos().y + currentSection.getHeight() / 2) / PPM); //prevSection Vector2 dir = sectionPos.cpy().sub(prevSectionPosition).nor(); float dist = sectionPos.dst(EnvironmentManager.player.getBody().getPosition()); //move player to center of currentSection EnvironmentManager.player.getBody().setTransform(prevSectionPosition.add(dir.scl(diveMovement * dist)), 0); diveMovement = diveMovement >= 1 ? 1 : diveMovement / 0.99f; if (fallDown) { //zoom for sections falling FROM currentTopZoom = currentTopZoom <= 0.03f ? 0.03f : currentTopZoom - 0.055f; //needed for player sprite going out of view at end of dive if (!diveIn) { currentPlayerZoom = currentPlayerZoom <= 0.80f ? 0.80f : currentPlayerZoom - 0.0075f; if (currentPlayerZoom == 0.8f) { diveIn = true; } } else { currentPlayerZoom = currentPlayerZoom >= 1.0f ? 1.0f : currentPlayerZoom + 0.016f; } } else { //fallUp currentTopZoom = currentTopZoom >= 0.03f ? 0.03f : currentTopZoom + 0.055f; //needed for player sprite going out of view at end of dive if (!diveIn) { currentPlayerZoom = currentPlayerZoom >= 0.80f ? 0.80f : currentPlayerZoom + 0.0075f; if (currentPlayerZoom == 0.8f) { diveIn = true; } } else { currentPlayerZoom = currentPlayerZoom <= 1.0f ? 1.0f : currentPlayerZoom - 0.016f; } } } }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
public void fall(NullSection section, boolean fallDown) { this.fallDown = fallDown; currentSection = section;/*from w w w .java 2s. c om*/ if (fallDown) { prevSectionPosition = new Vector2( (currentSection.parentSection.getPos().x + currentSection.parentSection.getWidth() / 2) / PPM, (currentSection.parentSection.getPos().y + currentSection.parentSection.getHeight() / 2) / PPM); } else { prevSectionPosition = new Vector2( (currentSection.childSection.getPos().x + currentSection.childSection.getWidth() / 2) / PPM, (currentSection.childSection.getPos().y + currentSection.childSection.getHeight() / 2) / PPM); } int tempDepth = currentDepth - section.LAYER_DEPTH; currentDepth = section.LAYER_DEPTH; for (LayerManager lm : layerManagers) { lm.adjustZoom(tempDepth); } //add player to new section layerManager int tdepth = 0; for (LayerManager lm : layerManagers) { for (Entity e : lm.layerEntities) { if (e.equals(EnvironmentManager.player)) { lm.layerEntToRemove.add(e); tdepth = lm.depth; } } } tdepth = fallDown ? tdepth + 1 : tdepth - 1; layerManagers.get(tdepth).layerEntities.add(EnvironmentManager.player); diveFC.start(fm); sm.setState(4); }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
/******************************* GENERATE FIRST LAYER/* ww w . j a va2s .co m*/ *******************************/ private void generateLayer0(int scount, boolean reset) { sectionCount = scount; if (layerManagers.size == 0) { layerManagers.add(new LayerManager(0)); } LayerManager mainLayer = layerManagers.peek(); for (int i = 0; i < sectionCount; i++) { //create first null section if (mainLayer.layerSections.size == 0) { mainLayer.layerSections.add(new NullSection(new Vector2(200 * RATIO, 100 * RATIO), sectionWidth, sectionHeight, this, nullCoord, mainLayer.depth)); gridCoords.add(nullCoord); } else { //create ajoined null sections NullSection prevSection = reset ? mainLayer.layerSections.random() : mainLayer.layerSections.peek(); boolean[] prevSides = prevSection.getAvailableSides(); int index; Vector2 secPosition; Array<Boolean> sideCheck = new Array<Boolean>(); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); boolean occupied; int count; do { index = rng.nextInt(prevSides.length); switch (index) { case 0: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() + 1); secPosition = new Vector2(0, sectionHeight); break; case 1: nullCoord = new Coordinate(prevSection.getCoord().getX() + 1, prevSection.getCoord().getY()); secPosition = new Vector2(sectionWidth, 0); break; case 2: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() - 1); secPosition = new Vector2(0, -sectionHeight); break; default: //3 nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); secPosition = new Vector2(-sectionWidth, 0); break; } //if coord is already taken occupied = false; try { for (Coordinate coord : gridCoords) { if (coord.compareTo(nullCoord)) { sideCheck.set(index, true); occupied = true; } } } catch (IndexOutOfBoundsException ex) { ex.printStackTrace(); } //todo: fix the "spiral problem" w/ section generation //perhaps just choose random coord?? //use array[s,s,s,s] to check all four sides //if(count == 4) return; count = 0; for (Boolean s : sideCheck) { if (s) count++; } if (count >= 4) { generateLayer0(sectionCount - i, true); return; } } while (occupied); prevSection.setSide(index, false, NullSection.WallType.CONNECTED); gridCoords.add(nullCoord); //create section at specifies coord(x,y) mainLayer.layerSections.add(new NullSection(prevSection.getPos().cpy().add(secPosition), sectionWidth, sectionHeight, this, nullCoord, mainLayer.depth)); //layerDepth switch (index) { case 0: mainLayer.layerSections.peek().setSide(2, false, NullSection.WallType.CONNECTED); break; case 1: mainLayer.layerSections.peek().setSide(3, false, NullSection.WallType.CONNECTED); break; case 2: mainLayer.layerSections.peek().setSide(0, false, NullSection.WallType.CONNECTED); break; case 3: mainLayer.layerSections.peek().setSide(1, false, NullSection.WallType.CONNECTED); break; default: break; } } } }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
/********************************************************************************* CREATES AN INITIAL PIT SECTION AND NEW LAYERMANAGER, based on piChance *********************************************************************************/ private int generateLayer(int layers, int scount) { //recursive termination if (layers <= 0) return 0; int depth = layerManagers.size; System.out.println("@EnvNull generate layer : depth:" + depth); LayerManager prevLayer = layerManagers.get(depth - 1); layerManagers.add(new LayerManager(depth)); LayerManager currentLayer = layerManagers.peek(); /**//from w w w . j a v a 2 s. co m * ***************************************** * * PIT SECTION GENERATION * ****************************************** */ //go through sections of prevLayer NullSection prevSection = prevLayer.layerSections.peek(); //check section for available adjecent sections boolean[] sides = prevSection.getAvailableSides(); int index; Array<Boolean> sideCheck = new Array<Boolean>(); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); int count; boolean occupied; do { index = rng.nextInt(sides.length); switch (index) { case 0: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() + 1); break; case 1: nullCoord = new Coordinate(prevSection.getCoord().getX() + 1, prevSection.getCoord().getY()); break; case 2: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() - 1); break; case 3: nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); break; default: nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); break; } //if coord is already taken occupied = false; try { for (Coordinate coord : gridCoords) { if (coord.compareTo(nullCoord)) { sideCheck.set(index, true); occupied = true; } } } catch (IndexOutOfBoundsException ex) { ex.printStackTrace(); } count = 0; for (Boolean s : sideCheck) { if (s) { count++; } } if (count >= 4) { layerManagers.pop(); return generateLayer(layers, scount); } } while (occupied); prevSection.setSide(index, false, NullSection.WallType.PIT_HIGHER); gridCoords.add(nullCoord); switch (index) { case 0: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(0, sectionHeight)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(2, false, NullSection.WallType.PIT_LOWER); break; case 1: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(sectionWidth, 0)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(3, false, NullSection.WallType.PIT_LOWER); break; case 2: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(0, -sectionHeight)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(0, false, NullSection.WallType.PIT_LOWER); break; case 3: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(-sectionWidth, 0)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(1, false, NullSection.WallType.PIT_LOWER); break; default: break; } //set pit section child of higher pit section prevSection.childSection = currentLayer.layerSections.peek(); currentLayer.layerSections.peek().parentSection = prevSection; fillLayer(currentLayer, scount, false); return generateLayer(layers - 1, scount - 1); }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
/*********************************************************************** FILL IN NEW PIT SECTION/LAYER WITH MORE SECTIONS ***********************************************************************/ private void fillLayer(LayerManager lm, int scount, boolean reset) { for (int i = 0; i < scount; i++) { //create ajoined null sections NullSection prevSection = !reset ? lm.layerSections.peek() : lm.layerSections.random(); boolean[] prevSides = prevSection.getAvailableSides(); int index; Vector2 secPosition;//w w w. j av a 2 s. c om Array<Boolean> sideCheck = new Array<Boolean>(); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); boolean occupied; int count; do { index = rng.nextInt(prevSides.length); switch (index) { case 0: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() + 1); secPosition = new Vector2(0, sectionHeight); break; case 1: nullCoord = new Coordinate(prevSection.getCoord().getX() + 1, prevSection.getCoord().getY()); secPosition = new Vector2(sectionWidth, 0); break; case 2: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() - 1); secPosition = new Vector2(0, -sectionHeight); break; default: //3 nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); secPosition = new Vector2(-sectionWidth, 0); break; } //if coord is already taken occupied = false; try { for (Coordinate coord : gridCoords) { if (coord.compareTo(nullCoord)) { sideCheck.set(index, true); occupied = true; } } } catch (IndexOutOfBoundsException ex) { ex.printStackTrace(); } //todo: fix the "spiral problem" w/ section generation //perhaps just choose random coord?? //use array[s,s,s,s] to check all four sides //if(count == 4) return; count = 0; for (Boolean s : sideCheck) { if (s) { count++; } } if (count >= 4) { fillLayer(lm, scount - i, true); return; } } while (occupied); prevSection.setSide(index, false, NullSection.WallType.CONNECTED); gridCoords.add(nullCoord); //create section at specifies coord(x,y) lm.layerSections.add(new NullSection(prevSection.getPos().cpy().add(secPosition), sectionWidth, sectionHeight, this, nullCoord, lm.depth)); //layerDepth switch (index) { case 0: lm.layerSections.peek().setSide(2, false, NullSection.WallType.CONNECTED); break; case 1: lm.layerSections.peek().setSide(3, false, NullSection.WallType.CONNECTED); break; case 2: lm.layerSections.peek().setSide(0, false, NullSection.WallType.CONNECTED); break; case 3: lm.layerSections.peek().setSide(1, false, NullSection.WallType.CONNECTED); break; default: break; } } }
From source file:com.mygdx.environments.EnvNull.NullSection.java
public void init() { //north wall// w w w .j ava 2 s . c om switch (sideTypes[0]) { case WALL: env.toAddEntity(new BlankWall(new Vector2(pos.x + width / 2, pos.y + height - height * 0.035f), width / 2, height * 0.035f)); break; case PIT_HIGHER: fallSensor = new FallSensor(new Vector2(pos.x + width / 2, pos.y + height), width / 2, 15f * RATIO, childSection, this); env.toAddEntity(fallSensor); break; case PIT_LOWER: //spawn SectionPad env.toAddEntity( new SectionPad(new Vector2(pos.x + width / 2, pos.y + height - height * 0.15f), parentSection)); env.toAddEntity(new BlankWall(new Vector2(pos.x + width / 2, pos.y + height - height * 0.035f), width / 2, height * 0.035f)); sideTypes[0] = WallType.WALL; break; default: break; } switch (sideTypes[1]) { case WALL: env.toAddEntity(new BlankWall(new Vector2(pos.x + width - width * 0.05f, pos.y + height / 2), width * 0.05f, height / 2)); break; case PIT_HIGHER: fallSensor = new FallSensor(new Vector2(pos.x + width, pos.y + height / 2), 15f * RATIO, height / 2, childSection, this); env.toAddEntity(fallSensor); break; case PIT_LOWER: //spawn SectionPad //spawn SectionPad env.toAddEntity(new SectionPad(new Vector2(pos.x + width - width * 0.2f, pos.y + height * 0.55f), parentSection)); env.toAddEntity(new BlankWall(new Vector2(pos.x + width - width * 0.05f, pos.y + height / 2), width * 0.05f, height / 2)); sideTypes[1] = WallType.WALL; break; default: break; } switch (sideTypes[2]) { case WALL: env.toAddEntity( new BlankWall(new Vector2(pos.x + width / 2, pos.y + height * 0.1f), width / 2, height * 0.1f)); break; case PIT_HIGHER: fallSensor = new FallSensor(new Vector2(pos.x + width / 2, pos.y + height * 0.085f), width * 0.425f, 25f * RATIO, childSection, this); env.toAddEntity(fallSensor); break; case PIT_LOWER: //spawn SectionPad env.toAddEntity(new SectionPad(new Vector2(pos.x + width / 2, pos.y + height * 0.25f), parentSection)); //env.spawnEntity(new NullWall(new Vector2(pos.x + width / 2, pos.y + height * 0.1f), width / 2, height * 0.1f)); env.toAddEntity( new BlankWall(new Vector2(pos.x + width / 2, pos.y + height * 0.1f), width / 2, height * 0.1f)); sideTypes[2] = WallType.WALL; break; default: break; } switch (sideTypes[3]) { case WALL: env.toAddEntity(new BlankWall(new Vector2(pos.x + width * 0.05f, pos.y + height / 2), width * 0.05f, height / 2)); break; case PIT_HIGHER: fallSensor = new FallSensor(new Vector2(pos.x, pos.y + height / 2), 15f * RATIO, height / 2, childSection, this); env.toAddEntity(fallSensor); break; case PIT_LOWER: //spawn SectionPad env.toAddEntity( new SectionPad(new Vector2(pos.x + width * 0.2f, pos.y + height * 0.55f), parentSection)); env.toAddEntity(new BlankWall(new Vector2(pos.x + width * 0.05f, pos.y + height / 2), width * 0.05f, height / 2)); sideTypes[3] = WallType.WALL; break; default: break; } setSideNumber(); setTexture(); }
From source file:com.mygdx.environments.EnvRoom.EnvRoom.java
public EnvRoom(int id, int linkid) { super(id);/*from w w w. j a v a 2 s . c om*/ this.linkid = linkid; fg = MainGame.am.get(ResourceManager.DEFAULT_SQCOLOR); beginFC.setTime(0); /* Initial room settings */ width = 5000 * RATIO; height = 5000 * RATIO; fgx = 0; fgy = 0; fgw = width; fgh = height; startPos = new Vector2(width * 0.5f / PPM, height * 0.2f / PPM); this.setPlayerToStart(); //Fill possible spawn locations for this Environment spawns.add(new Vector2(1000 * RATIO, 1000 * RATIO)); spawns.add(new Vector2(1100 * RATIO, 1000 * RATIO)); spawns.add(new Vector2(2400 * RATIO, 1300 * RATIO)); spawns.add(new Vector2(3400 * RATIO, 4300 * RATIO)); spawns.add(new Vector2(700 * RATIO, 3400 * RATIO)); spawns.add(new Vector2(4100 * RATIO, 2300 * RATIO)); spawns.add(new Vector2(3100 * RATIO, 800 * RATIO)); spawns.add(new Vector2(1000 * RATIO, 1800 * RATIO)); spawns.add(new Vector2(4000 * RATIO, 2200 * RATIO)); spawns.add(new Vector2(4300 * RATIO, 2800 * RATIO)); spawns.add(new Vector2(3400 * RATIO, 3400 * RATIO)); spawns.add(new Vector2(2000 * RATIO, 3400 * RATIO)); spawns.add(new Vector2(4500 * RATIO, 1800 * RATIO)); }
From source file:com.mygdx.environments.EnvRoom.EnvRoom.java
@Override public void init() { super.init(); /***************************************************** * INITIAL WALLS / ENVIRONMENT BOUNDARIES **************************************************/ float border = 25f; spawnEntity(new BlankWall(new Vector2((fgx) + width / 2, height * 0.1f), width / 2, border));//south spawnEntity(new BlankWall(new Vector2((fgx) + width / 2, height * 0.95f), width / 2, border));//north spawnEntity(new BlankWall(new Vector2((fgx) + width * 0.92f, height / 2), border, height / 2));//east spawnEntity(new BlankWall(new Vector2((fgx) + width * 0.08f, height / 2), border, height / 2));//west try {//from w w w. java 2 s.co m for (int i = 0; i < 10; i++) { Vector2 v = spawns.random(); spawns.removeValue(v, false); spawnEntity(EnemyManager.createRandom(v)); } } catch (NullPointerException ex) { ex.printStackTrace(); } }