Atari ipe游戏克隆javafx

时间:2018-11-28 03:39:14

标签: java user-interface javafx arraylist

因此,我正在努力制作Atari cent游戏的简单克隆。这是一个视频,带有游戏性。 https://www.youtube.com/watch?v=VkxJu250AO8。 我想做的是能够在其上添加播放器/弹丸。目前,我对如何启动它存在疑问,我正在考虑创建画布并将其添加到区域中,并设置自定义背景。

我的问题是如何添加可以左右移动并能够发射导弹的玩家/精灵?

public class MyCentipede extends Application {

private Object root;
private Label mStatus, mScore;
private Canvas mCanvas = new Canvas(350, 350);
private Sprite player = new Sprite(300, 750, 40, 40, "player", Color.RED);

@Override
public void start(Stage primaryStage) {
    Pane sPane= new Pane();
    sPane.setPrefSize(400, 400);
    sPane.getChildren().add(player);

    BorderPane root = new BorderPane();
    //root.setCenter(sPane);
    Game newGame = new Game();


    // add the menus
    root.setCenter(newGame);
    root.setTop(buildMenuBar()) ;
    this.mStatus = new Label("Lives = 3");
    mScore = new Label("High Score");
    ToolBar toolBar = new ToolBar(mStatus, mScore) ;
    //root.getChildren().add(player);
    root.setBottom(toolBar) ; 

    Scene scene = new Scene(root, 550, 550);

    primaryStage.setTitle("My Centipede!");
    primaryStage.setScene(scene);
    //primaryStage.setResizable(false);
    primaryStage.show();
}
    public void setStatus(String status){
         this.mStatus.setText(status);
}

到目前为止,我的自定义游戏课程是

public class Game extends Region {
private final Canvas mCanvas;
private Image bGround= new Image("/images/mars.jpg");

public Game(){

    mCanvas = new Canvas();
    mCanvas.prefHeight(400);
    mCanvas.prefWidth(400);
    BackgroundImage baGround = new BackgroundImage(bGround, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT);
    setBackground(new Background(new BackgroundImage[] { baGround }));
    getChildren().add(mCanvas);
}

} //游戏结束

0 个答案:

没有答案