Commit fb1a77e1 authored by Yuhan Chen's avatar Yuhan Chen
Browse files

New update

parent 043fd95d
......@@ -131,11 +131,10 @@ public class DemoRule {
while (!nearObjectUp(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == HEIGHT) {
return false;
} else {
boundaryObj = nearObjectDown(boundaryObj);
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
return true;
case UP:
while (!nearObjectDown(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == 0) {
......@@ -143,7 +142,7 @@ public class DemoRule {
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
return true;
case RIGHT:
while (!nearObjectLeft(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == WIDTH) {
......@@ -151,7 +150,7 @@ public class DemoRule {
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
return true;
case LEFT:
while (!nearObjectRight(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == 0) {
......@@ -159,7 +158,7 @@ public class DemoRule {
}
boundaryObj = nearObjectDown(boundaryObj);
}
break;
return true;
}
return true;
}
......
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.awt.*;
import java.util.ArrayList;
import static javafx.application.Platform.exit;
public class TestGUI extends Application {
/** The width of the board */
private static final int WIDTH = 800;
/** The height of the board */
private static final int HEIGHT = 800;
/** The number of rows of the board */
private static final int ROWS = 40;
/** The number of columns of the board */
private static final int COLUMNS = 40;
/** The size of a square */
private static final int SQUARE_SIZE = WIDTH/ROWS;
/** Graphics for game */
private GraphicsContext gc;
/** For character movement */
private int moveUp = 1;
private int moveDown = 1;
private int moveRight = 1;
private int moveLeft = 1;
/** Character color */
protected static javafx.scene.paint.Color currentColor = defaultColor();
/** The root */
private static Group root;
/** The in-game layout */
private static javafx.scene.canvas.Canvas canvas;
/** The in-game scene */
protected static Scene scene;
/** The stage */
protected static Stage stage;
/** The in-game menu */
private InGameMenu inGameMenu;
private KeyCode code;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
//The stage
stage = primaryStage;
//Setting up the screen...
root = new Group();
canvas = new Canvas(WIDTH, HEIGHT);
root.getChildren().add(canvas);
scene = new Scene(root);
//Initiate the graphic context gc
gc = canvas.getGraphicsContext2D();
//Initiate the character to Baba
DemoRule.player = DemoRule.babaObj;
//Initiate the objects list
DemoRule.setObjs(DemoRule.objs);
//Changing the characters coordinate based on key press
keyboardInput();
//Setting the scene
stage.setScene(scene);
stage.setTitle("Baba Is You");
stage.show();
//Timeline for character animation
Timeline timeline = new Timeline(new KeyFrame(new Duration(10), e -> run()));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
private void keyboardInput() {
scene.setOnKeyPressed(event -> {
code = event.getCode();
DemoRule.moveCharacter(code);
});
}
private void run(){
colorBackground();
drawBabaObj();
drawIsObj();
drawRockObj();
drawWinObj();
DemoRule.changeCharacter();
DemoRule.ruleChange();
if (DemoRule.isWin()){exit();};
}
/**
* Go to in-game menu by calling In-Game Menu methods
*/
private void goToInGameMenu(){
InGameMenu.generateInGameMenu();
InGameMenu.generateHint();
InGameMenu.generateCustomizeTheme();
stage.setScene(InGameMenu.getMenuScene());
}
private void drawBabaObj(){
gc.drawImage(DemoRule.babaObj.getImage(),DemoRule.babaObj.getX(),DemoRule.babaObj.getY());
}
private void drawIsObj(){
gc.drawImage(DemoRule.isObj.getImage(), DemoRule.isObj.getX(), DemoRule.isObj.getY());
}
private void drawRockObj(){
gc.drawImage(DemoRule.rockObj.getImage(), DemoRule.rockObj.getX(), DemoRule.rockObj.getY());
}
private void drawWinObj(){
gc.drawImage(DemoRule.winObj.addImage(), DemoRule.winObj.getX(), DemoRule.winObj.getY());
}
/**
* colors the background
*/
private void colorBackground(){
gc.setFill(javafx.scene.paint.Color.BLACK);
gc.fillRect(0, 0, 800,800);
}
/**
* Default color
*/
private static javafx.scene.paint.Color defaultColor(){
return Color.WHITE;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment