以下是初始字符的代码:
public class Player extends Mob {
private InputHandler input;
private int colour = Colours.get(-1,111,145,543);
private int scale = 1;
protected boolean isSwimming = false;
private int tickCount = 0;
public Player(Level level,int x,int y,InputHandler input) {
super(level,"Player",x,y,1);
this.input = input;
}
public void tick() {
int xa = 0;
int ya = 0;
if (input.up.ispressed()) {
ya--;
}
if (input.down.ispressed()) {
ya++;
}
if (input.left.ispressed()) {
xa--;
}
if (input.right.ispressed()) {
xa++;
}
if (xa != 0 || ya != 0) {
move(xa,ya);
isMoving = true;
} else {
isMoving = false;
}
if (level.getTile(this.x >> 3,this.y >> 3).getId() == 3) {
isSwimming = true;
}
if (isSwimming && level.getTile(this.x >> 3,this.y >> 3).getId() != 3) {
isSwimming = false;
}
tickCount++;
this.scale = 1;
}
public void render(Screen screen) {
int xTile = 0;
int yTile = 28;
int walkingSpeed = 4;
int flipTop = (numSteps >> walkingSpeed) & 1;
int flipBottom = (numSteps >> walkingSpeed) & 1;
if (movingDir == 1) {
xTile += 2;
} else if (movingDir > 1) {
xTile += 4 + ((numSteps >> walkingSpeed) & 1) * 2;
flipTop = (movingDir - 1) % 2;
}
int modifier = 8 * scale;
int xOffset = x - modifier / 2;
int yOffset = y - modifier / 2 - 4;
if (isSwimming) {
int waterColour = 0;
yOffset += 4;
if (tickCount % 60 < 15) {
waterColour = Colours.get(-1,-1,225,-1);
} else if (15 <= tickCount % 60 && tickCount % 60 < 30) {
yOffset -= 1;
waterColour = Colours.get(-1,115,-1);
} else if (30 <= tickCount % 60 && tickCount % 60 < 45) {
waterColour = Colours.get(-1,225);
} else {
waterColour = Colours.get(-1,-1);
}
screen.render(xOffset,yOffset + 3,0 + 27 * 32,waterColour,0x00,1);
screen.render(xOffset + 8,0x01,1);
}
// upper body
screen.render(xOffset + (modifier * flipTop),yOffset,xTile + yTile * 32,colour,flipTop,scale);
screen.render(xOffset + modifier - (modifier * flipTop),(xTile + 1) + yTile * 32,scale);
if (!isSwimming) {
// lower body
screen.render(xOffset + (modifier * flipBottom),yOffset + modifier,xTile + (yTile + 1) * 32,flipBottom,scale);
screen.render(xOffset + modifier - (modifier * flipBottom),(xTile + 1) + (yTile + 1) * 32,scale);
}
}
public boolean hasCollided(int xa,int ya) {
int xMin = 0;
int xMax = 7;
int yMin = 1;
int yMax = 7;
for (int x = xMin; x < xMax; x++) {
if (isSolidTile(xa,ya,yMin)) {
return true;
}
}
for (int x = xMin; x < xMax; x++) {
if (isSolidTile(xa,yMax)) {
return true;
}
}
for (int y = yMin; y < yMax; y++) {
if (isSolidTile(xa,xMin,y)) {
return true;
}
}
for (int y = yMin; y < yMax; y++) {
if (isSolidTile(xa,xMax,y)) {
return true;
}
}
return false;
}
}
可以在给定位置加载另一个字符;但是,我无法找出一种算法来让它跟随最初的玩家。换句话说,第二个将遵循这些相同的碰撞和命令。感谢您的任何帮助理解,谢谢!