本文整理汇总了Java中com.badlogic.gdx.math.GridPoint2类的典型用法代码示例。如果您正苦于以下问题:Java GridPoint2类的具体用法?Java GridPoint2怎么用?Java GridPoint2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GridPoint2类属于com.badlogic.gdx.math包,在下文中一共展示了GridPoint2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: laserTarget
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
protected Tile laserTarget(Tile tile, int rotation){
rotation = Mathf.mod(rotation, 4);
GridPoint2 point = Geometry.getD4Points()[rotation];
int i = 0;
for(i = 1; i < laserRange; i++){
Tile other = Vars.world.tile(tile.x + i * point.x, tile.y + i * point.y);
if(other != null && other.block() instanceof PowerAcceptor){
Tile linked = other.getLinked();
if(linked == null || linked instanceof PowerAcceptor){
return other;
}
}
}
return null;
}
示例2: isFreeTetriminoPosition
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private boolean isFreeTetriminoPosition(GridPoint2 position, int direction) {
boolean turn = true;
for(GridPoint2 p : currentTetrimino.position[direction]) {
if(p.x + position.x >= 0 && p.x + position.x < PLAYFIELD_WIDTH && p.y + position.y >= 0 && p.y + position.y < PLAYFIELD_HEIGHT) {
Color color = cells[p.x + position.x][p.y + position.y];
if(color != null) {
turn = false;
break;
}
}
else {
turn = false;
break;
}
}
return turn;
}
示例3: checkDpadDown
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
boolean checkDpadDown(int keyCode){
GridPoint2 position = player.getPosition();
if(keyCode == Input.Keys.W || keyCode == Input.Keys.UP){
position.y++;
}
else if(keyCode == Input.Keys.S || keyCode == Input.Keys.DOWN){
position.y--;
}
else if(keyCode == Input.Keys.D || keyCode == Input.Keys.RIGHT){
position.x++;
}
else if(keyCode == Input.Keys.A || keyCode == Input.Keys.LEFT){
position.x--;
}
if (position.equals(player.getPosition())){
return false;
} else {
player.moveTo(position);
return true;
}
}
示例4: getNextPointTowardsEndPoint
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private static GridPoint2 getNextPointTowardsEndPoint(GridPoint2 startPoint, GridPoint2 endPoint){
int x = startPoint.x;
int y = startPoint.y;
if (startPoint.x < endPoint.x){
x++;
} else if(startPoint.x > endPoint.x){
x--;
}
if (startPoint.y < endPoint.y){
y++;
} else if(startPoint.y > endPoint.y){
y--;
}
return new GridPoint2(x, y);
}
示例5: placeBoundingWalls
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
void placeBoundingWalls(Dungeon dungeon, int x, int y, int width, int height){
for(int i = x+1; i < x + width-1; i++){
for(int j = y+1; j < y + height-1; j++) {
dungeon.setTile(new FloorDungeonTile(new GridPoint2(i, j), dungeon));
}
}
for (int j = x; j < width+x; j++) {
dungeon.setTile(new WallDungeonTile(new GridPoint2(j, y), dungeon, false));
dungeon.setTile(new WallDungeonTile(new GridPoint2(j, height + y - 1), dungeon, false));
}
for (int i = y; i < height+y; i++) {
dungeon.setTile(new WallDungeonTile(new GridPoint2(x, i), dungeon, false));
dungeon.setTile(new WallDungeonTile(new GridPoint2(x + width - 1, i), dungeon, false));
}
}
示例6: Dungeon
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
public Dungeon(int mapWidth, int mapHeight){
this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
renderer = new DungeonRenderer(this);
map = new DungeonTile[mapWidth+2][mapHeight+2];
for(int i = 0; i < mapWidth+2; i++){
for (int j = 0; j < mapHeight+2; j++){
map[i][j] = new EmptyDungeonTile(new GridPoint2(i-1, j-1), this);
}
}
dungeonRooms = new Array<>();
monsters = new Array<>();
level = 1;
}
示例7: getAstarGraph
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
Array<Array<AstarNode>> getAstarGraph(){
Array<Array<AstarNode>> astarGraph = new Array<>();
for(int i = 0; i < getMapWidth(); i++){
astarGraph.add(new Array<>());
}
for (int i = 0; i < getMapWidth(); i++){
for(int j = 0; j < getMapHeight(); j++){
AstarNode node = new AstarNode();
node.passingCost = getDungeonTile(new GridPoint2(i, j)).getPassingCost();
node.x = i;
node.y = j;
astarGraph.get(i).add(node);
}
}
return astarGraph;
}
示例8: placeStartAndEndStairs
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private void placeStartAndEndStairs(Dungeon dungeon) {
GridPoint2 stairsUpPos;
GridPoint2 stairsDownPos;
Room startRoom = dungeon.startRoom;
Room endRoom = DungeonUtils.getRandomNotStartDungeonRoom(dungeon);
stairsUpPos = startRoom.getRandomFloorTile();
stairsDownPos = endRoom.getRandomFloorTile();
StairsUpDungeonTile stairsUpDungeonTile = new StairsUpDungeonTile(stairsUpPos, dungeon);
StairsDownDungeonTile stairsDownDungeonTile = new StairsDownDungeonTile(stairsDownPos, dungeon);
dungeon.setTile(stairsUpDungeonTile);
dungeon.setTile(stairsDownDungeonTile);
dungeon.stairsDownDungeonTile = stairsDownDungeonTile;
dungeon.stairsUpDungeonTile = stairsUpDungeonTile;
}
示例9: getDungeonAsAstarNodeGraph
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private Array<Array<AstarNode>> getDungeonAsAstarNodeGraph(Dungeon dungeon) {
Array<Array<AstarNode>> graph = new Array<>();
for(int i = 0; i < dungeon.getMapWidth(); i++){
graph.add(new Array<>());
}
for (int i = 0; i < dungeon.getMapWidth(); i++){
for(int j = 0; j < dungeon.getMapHeight(); j++){
AstarNode node = new AstarNode();
node.passingCost = dungeon.getDungeonTile(new GridPoint2(i, j)).getCorridorPlacingCost();
node.x = i;
node.y = j;
graph.get(i).add(node);
}
}
return graph;
}
示例10: addCorridorTile
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private void addCorridorTile(Dungeon dungeon, GridPoint2 pos, Direction direction){
DungeonTile tile = dungeon.getDungeonTile(pos);
// Set wall tiles this corridor passes through to doors
if(tile instanceof WallDungeonTile){
if (direction == Direction.VERTICAL ){
// Place a perpendicular door across the corridor
dungeon.setTile(new DoorDungeonTile(pos, dungeon, true));
} else {
dungeon.setTile(new DoorDungeonTile(pos, dungeon, false));
}
}
// Otherwise set the tile to a floor tiles with walls either side
else if(tile instanceof EmptyDungeonTile || tile instanceof CorridorWallDungeonTile) {
dungeon.setTile(new CorridorFloorDungeonTile(pos, dungeon));
if(direction == Direction.VERTICAL){
addCorridorWall(dungeon, new GridPoint2(pos.x+1, pos.y));
addCorridorWall(dungeon, new GridPoint2(pos.x-1, pos.y));
} else {
addCorridorWall(dungeon, new GridPoint2(pos.x, pos.y+1));
addCorridorWall(dungeon, new GridPoint2(pos.x, pos.y-1));
}
}
}
示例11: getNewPath
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private boolean getNewPath(){
Dungeon dungeon = Dungeon.getActiveDungeon();
int tries = 0;
GridPoint2 potentialTarget = DungeonUtils.getRandomTileInAnyRoom(dungeon);
Array<AstarNode> potentialPath = DungeonUtils.generateNewPathBetween(character.getPosition(), potentialTarget, character.getDungeon());
//Loop trying to find a path to a random room. Give up after 3 tries.
//TODO build the fScore limit into the algo to avoid unnecessary path generation
float pathCostThreshold = 50000;
while (potentialPath.size == 0 || potentialPath.get(0).fScore > pathCostThreshold){
potentialTarget = DungeonUtils.getRandomTileInAnyRoom(dungeon);
potentialPath = DungeonUtils.generateNewPathBetween(character.getPosition(), potentialTarget, character.getDungeon());
tries++;
if (tries >= 3){
return false;
}
}
pathTarget.set(potentialTarget);
path = potentialPath;
return true;
}
示例12: project
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
private GridPoint2 project(float x, float y){
float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight());
float size = Math.min(width, height);
float sclwidth = size * zoom;
float sclheight = size * zoom * ratio;
x = (x - getWidth()/2 + sclwidth/2 - offsetx*zoom) / sclwidth * editor.texture().getWidth();
y = (y - getHeight()/2 + sclheight/2 - offsety*zoom) / sclheight * editor.texture().getHeight();
return Tmp.g1.set((int)x, editor.texture().getHeight() - 1 - (int)y);
}
示例13: raycast
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
/**
* Input is in block coordinates, not world coordinates.
* @return null if no collisions found, block position otherwise.
*/
public GridPoint2 raycast(int x0f, int y0f, int x1, int y1){
int x0 = x0f;
int y0 = y0f;
int dx = Math.abs(x1 - x0);
int dy = Math.abs(y1 - y0);
int sx = x0 < x1 ? 1 : -1;
int sy = y0 < y1 ? 1 : -1;
int err = dx - dy;
int e2;
while(true){
if(!passable(x0, y0)){
return Tmp.g1.set(x0, y0);
}
if(x0 == x1 && y0 == y1) break;
e2 = 2 * err;
if(e2 > -dy){
err = err - dy;
x0 = x0 + sx;
}
if(e2 < dx){
err = err + dx;
y0 = y0 + sy;
}
}
return null;
}
示例14: testRemovedPixmapField
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
public void testRemovedPixmapField(){
GraphHeader.currentReadWriteVersion = 0;
TestClass object = new TestClass();
object.someInt = randInt();
object.someFloat = randFloat();
object.point = new GridPoint2(randInt(), randInt());
object.color = new Color(Color.CYAN);
object.smallTestClass = new SmallTestClass();
object.smallTestClass.someValue = randInt();
Pixmap pixmap = new Pixmap(20, 24, Pixmap.Format.RGBA8888);
for (int i = 0; i < pixmap.getWidth(); i++) {
for (int j = 0; j < pixmap.getHeight(); j++) {
pixmap.drawPixel(i, j, randInt());
}
}
object.smallTestClass.somePixmap = pixmap;
kryo.register(SmallTestClass.class);
kryo.register(TestClass.class);
GraphHeader<TestClass> graphHeader = new GraphHeader<TestClass>();
graphHeader.data = object;
GraphHeader.currentReadWriteVersion = 0;
byte[] written = write(graphHeader);
GraphHeader.currentReadWriteVersion = 1;
GraphHeader<TestClass> returned = read(written, GraphHeader.class);
assertTrue(equals(graphHeader, returned));
assertTrue(returned.data.smallTestClass.somePixmap == null);
}
示例15: receiveMessage
import com.badlogic.gdx.math.GridPoint2; //导入依赖的package包/类
@Override
public void receiveMessage(MessageType type, Object... args) {
switch (type) {
case LOAD_ANIMATIONS:
EntityConfig config = (EntityConfig) args[0];
Array<AnimationConfig> animationConfigs = config.getAnimationConfig();
int animationWidth = config.getAnimationWidth();
int animationHeight = config.getAnimationHeight();
String charAtlasID = config.getCharAtlasID();
for (AnimationConfig animationConfig : animationConfigs) {
Array<GridPoint2> gridPoints = animationConfig.getGridPoints();
AnimationType animationType = animationConfig.getAnimationType();
float frameDuration = animationConfig.getFrameDuration();
animations.put(animationType, loadAnimation(charAtlasID, gridPoints, animationWidth, animationHeight, frameDuration));
}
break;
case SET_SIZE:
origin.set((Float) args[0] * 0.5f, (Float) args[1] * 0.5f);
break;
case SET_STATE:
this.state = (State) args[0];
updateCurrentAnimation();
break;
case SET_DIRECTION:
this.direction = (Direction) args[0];
updateCurrentAnimation();
break;
default:
break;
}
}