Hello all so I m Creat a brief 2Dmmer, and so standard, I ve had a bit of a hamaretries to access each other. 到目前为止,我拥有一个主要的菜单、游戏网和显示网上的形象。 我现在要处理这一运动,但我似乎不能让它发挥作用。
<编码>应用。
http://www.un.org/Depts/DGACM/index_french.htm
package application;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.image.Image;
public class Level {
// private static Array[] level1;
// private WarehouseKeeper warehouse;
private static ImageView image1 = ImageLoader.showWareHouseImage();
private static final int KEYBOARD_MOVEMENT_DELTA = 2;
public static void runLevel1(Stage theStage) {
// ImageView image = new ImageView((Element)
// ImageLoader.wareHouseImage);
// WarehouseKeeper warehouse = new
// WarehouseKeeper(ImageLoader.wareHouseImage);
Group root = new Group();
int columnAmount = 12;
int rowAmount = 12;
GridPane gameGrid = new GridPane();
for (int i = 0; i < columnAmount; i++) {
ColumnConstraints columnn = new ColumnConstraints(45);
gameGrid.getColumnConstraints().add(columnn);
}
for (int i = 0; i < rowAmount; i++) {
RowConstraints row = new RowConstraints(45);
gameGrid.getRowConstraints().add(row);
}
gameGrid.setStyle("-fx-background-color: white; -fx-grid-lines-visible:true");
Scene scene = new Scene(root, (columnAmount * 40) + 66, (rowAmount * 40) + 66, Color.WHITE);
image(root, gameGrid);
moveWareHouse(scene, createKeeper());
theStage.setScene(scene);
theStage.show();
}
private static void image(Group root, GridPane gameGrid) {
// ImageLoader.wareHouseImage;
/*
* ImageView wareHouse = new ImageView(); wareHouse.setFitHeight(45);
* wareHouse.setFitWidth(45);
*
* Image image1 = ImageLoader.showWareHouseImage();
* wareHouse.setImage(image1);
*/
ImageView image1 = ImageLoader.showWareHouseImage();
final HBox picture = new HBox();
picture.getChildren().add(image1);
gameGrid.setAlignment(Pos.CENTER);
// gameGrid.getChildren().add(wareHouse);
gameGrid.add(picture, 7, 9);
root.getChildren().add(gameGrid);
}
private static WarehouseKeeper createKeeper() {
final WarehouseKeeper keeper = new WarehouseKeeper(image1);
return keeper;
}
private static void moveWareHouse(Scene scene, final WarehouseKeeper keeper) {
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
switch (event.getCode()) {
case W:
keeper.setyPosition(keeper.getyPosition() - KEYBOARD_MOVEMENT_DELTA);
break;
case D:
keeper.setxPosition(keeper.getxPosition() + KEYBOARD_MOVEMENT_DELTA);
break;
case A:
keeper.setyPosition(keeper.getyPosition() + KEYBOARD_MOVEMENT_DELTA);
break;
case S:
keeper.setxPosition(keeper.getxPosition() - KEYBOARD_MOVEMENT_DELTA);
break;
}
}
});
}
}
http://www.un.org/Depts/DGACM/index_french.htm 扩展图像。
package application;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
public class WarehouseKeeper extends ImageLoader {
private Image playerImage;
private ImageView image;
private int speed;
private double xPosition;
private double yPosition;
public WarehouseKeeper(ImageView wareHouseImage) {
super(wareHouseImage);
this.speed = speed;
this.xPosition = xPosition;
this.yPosition = yPosition;
this.wareHouseImage.relocate(xPosition, yPosition);
}
public void updateUI() {
wareHouseImage.relocate(xPosition, yPosition);
}
public double getCenterX() {
return xPosition * 0.5;
}
public double getCenterY() {
return yPosition * 0.5;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public double getxPosition() {
return xPosition;
}
// one of the ideas i had
public void setxPosition(double xPosition) {
this.xPosition = xPosition.setTranslateX(1.0);
}
public double getyPosition() {
return yPosition;
}
public void setyPosition(double d) {
this.yPosition = d + 1.0;
}
public void setTranslateY(double yPosition) {
// TODO Auto-generated method stub
yPosition = yPosition + 2.0;
}
}
http://www.un.org/Depts/DGACM/index_french.htm
package application;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class ImageLoader {
protected ImageView wareHouseImage;
private Object diamondImage;
private Object wallImage;
private Object mapImage;
private Object crateImage;
public ImageLoader(ImageView wareHouseImage) {
this.wareHouseImage = showWareHouseImage();
}
public ImageView getWareHouseImage() {
return wareHouseImage;
}
public void setWareHouseImage(Image wareHouseImage) {
this.wareHouseImage = showWareHouseImage();
}
public static ImageView showWareHouseImage() {
ImageView wareHouse = new ImageView();
wareHouse.setFitHeight(45);
wareHouse.setFitWidth(45);
Image wareHouseImage = new Image("application/warehouse.png");
wareHouse.setImage(wareHouseImage);
return wareHouse;
}
public Object getDiamondImage() {
return diamondImage;
}
public void setDiamondImage(Object diamondImage) {
this.diamondImage = diamondImage;
}
public Object getWallImage() {
return wallImage;
}
public void setWallImage(Object wallImage) {
this.wallImage = wallImage;
}
public Object getMapImage() {
return mapImage;
}
public void setMapImage(Object mapImage) {
this.mapImage = mapImage;
}
public Object getCrateImage() {
return crateImage;
}
public void setCrateImage(Object crateImage) {
this.crateImage = crateImage;
}
}