gpt4 book ai didi

Javaplayer_width和player_height错误

转载 作者:行者123 更新时间:2023-12-02 12:47:22 25 4
gpt4 key购买 nike

我正在尝试制作这个游戏,现在我有一个可以移动的角色,但我想有效地改变角色的宽度和高度。因此,角色上下移动的尺寸与角色左右移动的尺寸不同,所以我做了这个 if 语句,如果玩家向上移动,那么宽度就是这个,如果玩家向右移动,那么 with 就是这样。但是当我写完代码时,它给了我两个错误:

Syntax error on token ";", { expected after this token
Syntax error, insert "}" to complete Block

有人可以告诉我出了什么问题吗?

代码如下:

public class player extends creature {
// other code

private static int player_width;
private static int player_height = 70; // error 1 here

if(currentimage == assets.player_up) {
player_width = 50;
} else if(currentimage == assets.player_down) {
player_width = 50;
} else if(currentimage == assets.player_right) {
player_width = 60;
} else if(currentimage == assets.player_left) {
player_width = 60;
} // error 2 here

public player(game game, float x, float y) {
super(x, y,player_width,player_height);
this.game = game;

}

这是生物构造函数:

public abstract class creature extends entity {

public static final int DEFAULT_HEALTH = 10;
public static final float DEFAULT_SPEED = 3.0f;
public static final int DEFAULT_CREATURE_WIDTH = 64,
DEFAULT_CREATURE_HEIGHT = 64;

protected int health;
protected float speed;
protected float xMove, yMove;

public creature(float x, float y, int width, int height) {
super(x, y, width, height);
health = DEFAULT_HEALTH;
speed = DEFAULT_SPEED;
xMove = 0;
yMove = 0;

}

最佳答案

嗯,你应该将这些 if 语句放在你的构造函数中。如果它们位于类内而不是方法内,则它们不会运行。只需将它们放入您的

public player(game game, float x, float y)

方法,你应该是金子。

注意:只是一个旁注,类名应该大写,这样更容易阅读代码。

关于Javaplayer_width和player_height错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com