Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUC...
If you think the Android project Station42 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.station42.world;
/*fromwww.java2s.com*/import java.util.HashMap;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.math.Rectangle;
import com.station42.base.Entity;
import com.station42.faction.EntityFaction;
import com.station42.game.Station40Game;
publicclass World {
publicstaticfinal World orangeWorld = new World("Orange", Color.ORANGE, 0);
publicstaticfinal World greenWorld = new World("Green", Color.GREEN, 1);
Color theme;
String name;
TextureRegion region;
TextureRegion wallRegion;
publicint worldId;
private World(String name, Color theme, int worldId) {
this.name = name;
this.theme = theme;
this.worldId = worldId;
}
public Color getColor() {
return theme;
}
publicstaticboolean visible(Entity viewer, Entity viewed) {
World entityWorld = viewed.getComponent(World.class);
if (viewer == null) {
return true;
} elseif (viewer.getComponent(World.class) == null) {
return true;
} elseif (entityWorld == null) {
return true;
} elseif (entityWorld == viewer.getComponent(World.class)) {
return true;
} else {
return false;
}
}
publicstatic Color getColor(Entity viewed) {
World entityWorld = viewed.getComponent(World.class);
if (entityWorld == null) {
return Color.WHITE;
} else {
return entityWorld.theme;
}
}
public World nextWorld() {
if (this == orangeWorld)
return greenWorld;
elseif (this == greenWorld)
return orangeWorld;
return null;
}
public TextureRegion getBackground() {
if (region == null) {
if (this == orangeWorld)
region = new TextureRegion(Station40Game.manager.get("sprites.png", Texture.class), 64, 32, 32, 32);
elseif (this == greenWorld)
region = new TextureRegion(Station40Game.manager.get("sprites.png", Texture.class), 96, 64, 32, 32);
}
return region;
}
public EntityFaction getHomeFaction() {
if (this == orangeWorld)
return EntityFaction.red;
elseif (this == greenWorld)
return EntityFaction.blue;
return null;
}
HashMap<Rectangle, Texture> optimizedRegions = new HashMap<Rectangle, Texture>();
public Texture getBackground(SpriteBatch batch, Rectangle bounds) {
Rectangle normalBounds = new Rectangle(bounds).setPosition(0, 0);
if (!optimizedRegions.containsKey(bounds))
{
TextureRegion tileRegion = getBackground();
tileRegion.getTexture().getTextureData().prepare();
Texture newTexture = new Texture((int)bounds.x, (int)bounds.y, tileRegion.getTexture().getTextureData().getFormat());
Pixmap newPixmap = newTexture.getTextureData().consumePixmap();
Pixmap tilePixmap = tileRegion.getTexture().getTextureData().consumePixmap();
for (int x = 0;x < bounds.width;x+=tileRegion.getRegionWidth()) {
for (int y = 0;y < bounds.width;y+= tileRegion.getRegionHeight()) {
newPixmap.drawPixmap(tilePixmap, x, y,
tileRegion.getRegionX(), tileRegion.getRegionY(),
tileRegion.getRegionWidth(), tileRegion.getRegionHeight());
}
}
optimizedRegions.put(normalBounds, newTexture);
}
return optimizedRegions.get(normalBounds);
}
}