diff --git a/res/Chicknight/ChicknightLeft.png b/res/Chicknight/ChicknightLeft.png index 1a3374b..a477c1f 100644 Binary files a/res/Chicknight/ChicknightLeft.png and b/res/Chicknight/ChicknightLeft.png differ diff --git a/res/Chicknight/ChicknightLeftAtk.png b/res/Chicknight/ChicknightLeftAtk.png index 42af6fe..5599828 100644 Binary files a/res/Chicknight/ChicknightLeftAtk.png and b/res/Chicknight/ChicknightLeftAtk.png differ diff --git a/res/Chicknight/ChicknightLeftWalk1.png b/res/Chicknight/ChicknightLeftWalk1.png index b7fc04e..83d54c8 100644 Binary files a/res/Chicknight/ChicknightLeftWalk1.png and b/res/Chicknight/ChicknightLeftWalk1.png differ diff --git a/res/Chicknight/ChicknightRight.png b/res/Chicknight/ChicknightRight.png index 33d340a..dd2db6f 100644 Binary files a/res/Chicknight/ChicknightRight.png and b/res/Chicknight/ChicknightRight.png differ diff --git a/res/Chicknight/ChicknightRightAtk.png b/res/Chicknight/ChicknightRightAtk.png index 141d847..fe6208b 100644 Binary files a/res/Chicknight/ChicknightRightAtk.png and b/res/Chicknight/ChicknightRightAtk.png differ diff --git a/res/Chicknight/ChicknightRightWalk1.png b/res/Chicknight/ChicknightRightWalk1.png index 143ebba..ba21419 100644 Binary files a/res/Chicknight/ChicknightRightWalk1.png and b/res/Chicknight/ChicknightRightWalk1.png differ diff --git a/res/IngameSong.wav b/res/IngameSong.wav new file mode 100644 index 0000000..0665c9a Binary files /dev/null and b/res/IngameSong.wav differ diff --git a/res/John.png b/res/John.png deleted file mode 100644 index 4a84953..0000000 Binary files a/res/John.png and /dev/null differ diff --git a/res/MoleDerKaiser/moleDerKaiser.png b/res/MoleDerKaiser/moleDerKaiser.png new file mode 100644 index 0000000..5b3838e Binary files /dev/null and b/res/MoleDerKaiser/moleDerKaiser.png differ diff --git a/res/MoleDerKaiser/normalMole.png b/res/MoleDerKaiser/normalMole.png new file mode 100644 index 0000000..cae6bb8 Binary files /dev/null and b/res/MoleDerKaiser/normalMole.png differ diff --git a/res/mapTile/BottomLeftMap.png b/res/mapTile/BottomLeftMap.png new file mode 100644 index 0000000..6b84c3f Binary files /dev/null and b/res/mapTile/BottomLeftMap.png differ diff --git a/res/mapTile/BottomMap.png b/res/mapTile/BottomMap.png new file mode 100644 index 0000000..9dd8c2b Binary files /dev/null and b/res/mapTile/BottomMap.png differ diff --git a/res/mapTile/BottomRightMap.png b/res/mapTile/BottomRightMap.png new file mode 100644 index 0000000..a8445da Binary files /dev/null and b/res/mapTile/BottomRightMap.png differ diff --git a/res/mapTile/LeftMap.png b/res/mapTile/LeftMap.png new file mode 100644 index 0000000..2da9b53 Binary files /dev/null and b/res/mapTile/LeftMap.png differ diff --git a/res/mapTile/RightMap.png b/res/mapTile/RightMap.png new file mode 100644 index 0000000..a19d867 Binary files /dev/null and b/res/mapTile/RightMap.png differ diff --git a/res/mapTile/Tomb.png b/res/mapTile/Tomb.png new file mode 100644 index 0000000..46c1534 Binary files /dev/null and b/res/mapTile/Tomb.png differ diff --git a/res/mapTile/TopLeftMap.png b/res/mapTile/TopLeftMap.png new file mode 100644 index 0000000..9ddb3fa Binary files /dev/null and b/res/mapTile/TopLeftMap.png differ diff --git a/res/mapTile/TopMap.png b/res/mapTile/TopMap.png new file mode 100644 index 0000000..bf7b76f Binary files /dev/null and b/res/mapTile/TopMap.png differ diff --git a/res/mapTile/TopRightMap.png b/res/mapTile/TopRightMap.png new file mode 100644 index 0000000..a4ad7f0 Binary files /dev/null and b/res/mapTile/TopRightMap.png differ diff --git a/res/mapTile/ground1.png b/res/mapTile/ground1.png new file mode 100644 index 0000000..6887e8a Binary files /dev/null and b/res/mapTile/ground1.png differ diff --git a/res/mapTile/ground2.png b/res/mapTile/ground2.png new file mode 100644 index 0000000..209988d Binary files /dev/null and b/res/mapTile/ground2.png differ diff --git a/res/mapTile/ground3.png b/res/mapTile/ground3.png new file mode 100644 index 0000000..9f6f55f Binary files /dev/null and b/res/mapTile/ground3.png differ diff --git a/res/mapTile/spawn1.png b/res/mapTile/spawn1.png new file mode 100644 index 0000000..af94da0 Binary files /dev/null and b/res/mapTile/spawn1.png differ diff --git a/res/mapTile/spawn2.png b/res/mapTile/spawn2.png new file mode 100644 index 0000000..4ca2ebf Binary files /dev/null and b/res/mapTile/spawn2.png differ diff --git a/res/mapTile/water1.png b/res/mapTile/water1.png new file mode 100644 index 0000000..1d6a828 Binary files /dev/null and b/res/mapTile/water1.png differ diff --git a/res/mapTile/water2.png b/res/mapTile/water2.png new file mode 100644 index 0000000..14b4d20 Binary files /dev/null and b/res/mapTile/water2.png differ diff --git a/src/MainMenu/GameMenu.java b/src/MainMenu/GameMenu.java index e1ddd4a..efb697c 100644 --- a/src/MainMenu/GameMenu.java +++ b/src/MainMenu/GameMenu.java @@ -1,6 +1,6 @@ package MainMenu; -import application.GameStart; +import application.Main; import javafx.animation.FadeTransition; import javafx.animation.TranslateTransition; import javafx.scene.Parent; @@ -54,9 +54,12 @@ public GameMenu() { ft.setToValue(0); ft.setOnFinished(evt-> setVisible(false)); ft.play(); + Main.isStart = true; + Main.GameStart(); - GameStart.start(); - + gameMenu.getChildren().remove(playMenu); + gameMenu.getChildren().addAll(mainMenu); + transition(playMenu,mainMenu,640); }); MenuButton ContBtn = new MenuButton("CONTINUE"); diff --git a/src/MainMenu/GameOverButton.java b/src/MainMenu/GameOverButton.java index 0c2287c..f2ff783 100644 --- a/src/MainMenu/GameOverButton.java +++ b/src/MainMenu/GameOverButton.java @@ -29,7 +29,7 @@ public void draw(GraphicsContext gc) { gc.strokeRect(x,y,width,height); gc.setFill(Color.BLACK); gc.setFont(Font.font("Times New Roman", FontWeight.BOLD, 32)); - gc.fillText(text.getText(), (x+width/2-55), (y+height/1.3)); + gc.fillText(text.getText(), (x+width/2-75), (y+height/1.3)); } public int getX() { diff --git a/src/application/GameStart.java b/src/application/GameStart.java deleted file mode 100644 index c5fb7f8..0000000 --- a/src/application/GameStart.java +++ /dev/null @@ -1,71 +0,0 @@ -package application; - -import drawing.GameScreen; -import input.InputUtility; -import javafx.animation.AnimationTimer; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.ProgressBar; -import javafx.scene.control.ProgressIndicator; -import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; -import javafx.stage.Modality; -import javafx.stage.Stage; -import logic.game.GameLogic; -import logic.entity.Player; -import sharedObject.RenderableHolder; - -public class GameStart{ - - - public static void start(){ - final int width = 1280; - final int height = 720; -// VBox statBar = new VBox(); - ProgressBar hpBar = new ProgressBar(); - hpBar.setStyle("-fx-accent: Green; \n -fx-background-color: White; \n"); - hpBar.setMaxWidth(width); - hpBar.setProgress(1); - ProgressBar manaBar = new ProgressBar(); - manaBar.setStyle("-fx-accent: Blue; \n -fx-background-color: White; \n"); - manaBar.setMaxWidth(width); - manaBar.setProgress(1); - - Stage gameWindow = new Stage(); - gameWindow.initModality(Modality.APPLICATION_MODAL); - VBox root = new VBox(); - Scene gameScene = new Scene(root); - gameWindow.setScene(gameScene); - gameWindow.setTitle("Test"); - - GameScreen gameScreen = new GameScreen(width, height); - GameLogic logic = new GameLogic(gameScreen); - root.getChildren().addAll(gameScreen,hpBar,manaBar); - gameScreen.requestFocus(); - - - AnimationTimer animation = new AnimationTimer() { - long previousTime = 0; - double drawInterval = 1e9/30; - double delta = 0; - - public void handle(long now) { - delta += (now-previousTime)/drawInterval; - previousTime = now; - - if (delta >= 1) { - - gameScreen.paintComponent(); - logic.logicUpdate(); - RenderableHolder.getInstance().update(); - InputUtility.updateInputState(); - delta--; - } - } - }; - animation.start(); - gameWindow.show(); -} -} diff --git a/src/application/Main.java b/src/application/Main.java index 1fe2038..9fcc5c5 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -1,62 +1,123 @@ package application; +import MainMenu.GameMenu; import drawing.GameScreen; import input.InputUtility; import javafx.animation.AnimationTimer; +import javafx.animation.FadeTransition; import javafx.application.Application; import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; +import javafx.util.Duration; import logic.game.GameLogic; import logic.entity.Player; import sharedObject.RenderableHolder; -public class Main extends Application{ +public class Main extends Application { + + Scene gameScene, mainScene; public static void main(String[] args) { // TODO Auto-generated method stub Application.launch(args); } - @Override - public void start(Stage stage) throws Exception { - final int width = 1280; - final int height = 720; - // TODO Auto-generated method stub - StackPane root = new StackPane(); - Scene scene = new Scene(root); - stage.setScene(scene); - stage.setTitle("2D Game"); - - - GameScreen gameScreen = new GameScreen(width, height); - GameLogic logic = new GameLogic(gameScreen); + public static boolean isStart = false; + private static GameMenu gameMenu; + public static Stage stage; + private static StackPane root; + private static ImageView bg; + private static GameScreen gameScreen; + private static GameLogic logic; + private static AnimationTimer animation; + + final static int width = 1280; + final static int height = 720; + + public Stage getStage() { + return stage; + } + + public boolean isStart() { + return isStart; + } + + public static void GameStart() { + + System.out.println(isStart); + root.getChildren().removeAll(bg, gameMenu); + gameScreen = new GameScreen(width, height); + logic = new GameLogic(gameScreen); root.getChildren().add(gameScreen); gameScreen.requestFocus(); - - stage.show(); - - AnimationTimer animation = new AnimationTimer() { - long previousTime = 0; - double drawInterval = 1e9/60; - double delta = 0; - - public void handle(long now) { - delta += (now-previousTime)/drawInterval; - previousTime = now; - logic.checkGameState(); - if (delta >= 1) { - logic.count(); -// logic.logicUpdate(); -// gameScreen.paintComponent(); - logic.update(); - RenderableHolder.getInstance().update(); - InputUtility.updateInputState(); - delta--; +// +// + animation = new AnimationTimer() { + long previousTime = 0; + double drawInterval = 1e9 / 60; + double delta = 0; + + public void handle(long now) { + delta += (now - previousTime) / drawInterval; + previousTime = now; + logic.checkGameState(); + if (delta >= 1) { + logic.count(); + logic.update(); + RenderableHolder.getInstance().update(); + InputUtility.updateInputState(); + delta--; + } } - } - }; - animation.start(); + }; + animation.start(); + } + + public static void GoToMenu() { + animation.stop(); + root.getChildren().remove(gameScreen); + root.getChildren().addAll(bg,gameMenu); } + @Override + public void start(Stage stage) { + + Main.stage = stage; + Main.root = new StackPane(); + root.setPrefSize(width, height); + + gameMenu = new GameMenu(); + + Image img = new Image(ClassLoader.getSystemResource("Elysia.jpeg").toString()); + bg = new ImageView(img); + bg.setFitWidth(width); + bg.setFitHeight(height); + + root.getChildren().addAll(bg, gameMenu); + gameMenu.setVisible(false); + + Scene scene = new Scene(root); + + scene.setOnKeyPressed(e -> { + if (!gameMenu.isVisible()) { + FadeTransition ft = new FadeTransition(Duration.seconds(1), gameMenu); + ft.setFromValue(0); + ft.setToValue(1); + gameMenu.setVisible(true); + ft.play(); + } + }); + + stage.setTitle("2D Game"); + stage.setScene(scene); + stage.show(); + // TODO Auto-generated method stub + +// +// + } } diff --git a/src/drawing/GameScreen.java b/src/drawing/GameScreen.java index 2d0bc6f..7263ec8 100644 --- a/src/drawing/GameScreen.java +++ b/src/drawing/GameScreen.java @@ -17,72 +17,72 @@ import sharedObject.RenderableHolder; public class GameScreen extends Canvas { - private boolean paused = false; - - public GameScreen(double width, double height) { - super(width, height); - this.setVisible(true); - addListerner(); - } - - public void addListerner() { - this.setOnKeyPressed((KeyEvent event) -> { - InputUtility.setKeyPressed(event.getCode(), true); - }); - - this.setOnKeyReleased((KeyEvent event) -> { - InputUtility.setKeyPressed(event.getCode(), false); - }); - - this.setOnMousePressed((MouseEvent event) -> { - if (event.getButton() == MouseButton.PRIMARY) - InputUtility.mouseLeftDown(); - }); - - this.setOnMouseReleased((MouseEvent event) -> { - if (event.getButton() == MouseButton.PRIMARY) - InputUtility.mouseLeftRelease(); - }); - - this.setOnMouseEntered((MouseEvent event) -> { - InputUtility.mouseOnScreen = true; - }); - - this.setOnMouseExited((MouseEvent event) -> { - InputUtility.mouseOnScreen = false; - }); - - this.setOnMouseMoved((MouseEvent event) -> { - if (InputUtility.mouseOnScreen) { - InputUtility.mouseX = event.getX(); - InputUtility.mouseY = event.getY(); - } - }); - - this.setOnMouseDragged((MouseEvent event) -> { - if (InputUtility.mouseOnScreen) { - InputUtility.mouseX = event.getX(); - InputUtility.mouseY = event.getY(); - } - }); - - } - - public void paintComponent() { - GraphicsContext gc = this.getGraphicsContext2D(); - gc.setFill(Color.BLACK); - gc.fillRect(0, 0, getWidth(), getHeight()); - for (IRenderable entity : RenderableHolder.getInstance().getEntities()) { - // System.out.println(entity.getZ()); - if (entity.isVisible() && !entity.isDestroyed()) { - entity.draw(gc); - - } - } - } - - - public GameScreen getGameScreen() { - return this; - } -} + private boolean paused = false; + + public GameScreen(double width, double height) { + super(width, height); + this.setVisible(true); + addListerner(); + } + + public void addListerner() { + this.setOnKeyPressed((KeyEvent event) -> { + InputUtility.setKeyPressed(event.getCode(), true); + }); + + this.setOnKeyReleased((KeyEvent event) -> { + InputUtility.setKeyPressed(event.getCode(), false); + }); + + this.setOnMousePressed((MouseEvent event) -> { + if (event.getButton() == MouseButton.PRIMARY) + InputUtility.mouseLeftDown(); + }); + + this.setOnMouseReleased((MouseEvent event) -> { + if (event.getButton() == MouseButton.PRIMARY) + InputUtility.mouseLeftRelease(); + }); + + this.setOnMouseEntered((MouseEvent event) -> { + InputUtility.mouseOnScreen = true; + }); + + this.setOnMouseExited((MouseEvent event) -> { + InputUtility.mouseOnScreen = false; + }); + + this.setOnMouseMoved((MouseEvent event) -> { + if (InputUtility.mouseOnScreen) { + InputUtility.mouseX = event.getX(); + InputUtility.mouseY = event.getY(); + } + }); + + this.setOnMouseDragged((MouseEvent event) -> { + if (InputUtility.mouseOnScreen) { + InputUtility.mouseX = event.getX(); + InputUtility.mouseY = event.getY(); + } + }); + + } + + public void paintComponent() { + GraphicsContext gc = this.getGraphicsContext2D(); + gc.setFill(Color.BLACK); + gc.fillRect(0, 0, getWidth(), getHeight()); + for (IRenderable entity : RenderableHolder.getInstance().getEntities()) { + // System.out.println(entity.getZ()); + if (entity.isVisible() && !entity.isDestroyed()) { + entity.draw(gc); + + } + } + } + + + public GameScreen getGameScreen() { + return this; + } +} \ No newline at end of file diff --git a/src/input/InputUtility.java b/src/input/InputUtility.java index 81f638f..60523cb 100644 --- a/src/input/InputUtility.java +++ b/src/input/InputUtility.java @@ -2,7 +2,9 @@ import java.util.ArrayList; +import MainMenu.GameOverButton; import javafx.scene.input.KeyCode; +import javafx.scene.input.MouseEvent; public class InputUtility { public static double mouseX,mouseY; @@ -45,4 +47,7 @@ public static ArrayList getKeyPressed() { return keyPressed; } + public boolean isIn(GameOverButton b,MouseEvent e) { + return b.getBounds().contains(e.getX(),e.getY()); + } } diff --git a/src/logic/entity/Chicknight.java b/src/logic/entity/Chicknight.java index c3d3dfa..a8b224e 100644 --- a/src/logic/entity/Chicknight.java +++ b/src/logic/entity/Chicknight.java @@ -8,18 +8,16 @@ import sharedObject.RenderableHolder; public class Chicknight extends Enemy { - private Image image = RenderableHolder.CKRight; - private String currentState = "default"; - public Chicknight(int x, int y, GameLogic gameLogic) { + + public Chicknight(double x, double y, GameLogic gameLogic) { super(x,y,gameLogic); this.maxHp = 10; this.currentHealth = maxHp; this.dmg = 5; this.z = -100; this.speed = 1; - initSolidArea(); - initAttackBlock(); + image = RenderableHolder.CKRight; } @Override @@ -28,41 +26,40 @@ public void draw(GraphicsContext gc) { // System.out.println(c); switch (direction) { case "right": - if (currentState == "attack") + if (currentState == "attacking") if (gameLogic.getCounter() / 10 % 2 == 1) { image = RenderableHolder.CKRight; } else { - image = RenderableHolder.CKRightAtk; + if(canAttack) + image = RenderableHolder.CKRightAtk; + else + image =RenderableHolder.CKRightWalk1; } else { - if (gameLogic.getCounter() / 10 % 2 == 1) { - image = RenderableHolder.CKRightWalk1; - } else image = RenderableHolder.CKRight; } break; case "left": - if (currentState == "attack") + if (currentState == "attacking") if (gameLogic.getCounter() / 10 % 2 == 1) { image = RenderableHolder.CKLeft; } else { - image = RenderableHolder.CKLeftAtk; + if(canAttack) + image = RenderableHolder.CKLeftAtk; + else + image =RenderableHolder.CKLeftWalk1; } else { - if (gameLogic.getCounter() / 10 % 2 == 1) { - image = RenderableHolder.CKLeftWalk1; - } else image = RenderableHolder.CKLeft; } break; } - if (!playerfound()) image = RenderableHolder.CKRight; + gc.drawImage(image, screenX, screenY); - // debugging -// gc.drawImage(RenderableHolder.pauseMenu,screenX,screenY); + drawHitbox(gc); drawAttackBlock(gc); } @@ -73,58 +70,62 @@ public void draw(GraphicsContext gc) { public void update() { // TODO Auto-generated method stub super.update(); - - + if (playerfound(500)) + currentState = "attacking"; + else + currentState = "default"; Player player = gameLogic.getPlayer(); - if (!canAttack(player.worldX, player.worldY, worldX, worldY, (int)(attackBlock.getWidth()+solidArea.getWidth()))) { - angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); - double xspeed = Math.cos(angle) * speed; - double yspeed = Math.sin(angle) * speed; - currentState = "walking"; - - if(yspeed<0) - direction = "up"; - else - direction = "down"; - setCollisionOn(false); - gameLogic.checkTile(this); - if (collisionOn == false) { - worldY += yspeed; + canAttack = canAttack(player.solidScreen.getX()+solidScreen.getWidth()/2, player.solidScreen.getY()+solidScreen.getHeight()/2, solidScreen.getX()+solidScreen.getWidth()/2, solidScreen.getY()+solidScreen.getHeight()/2, + (int) (32)); + if (currentState == "attacking") { + if(canAttack) { + attack(gameLogic.getPlayer()); + } + else { + double xspeed = Math.cos(angle) * speed; + double yspeed = Math.sin(angle) * speed; + + + if (yspeed < 0) + direction = "up"; + else + direction = "down"; + setCollisionOn(false); + gameLogic.checkTile(this); + if (collisionOn == false) { + worldY += yspeed; } - - if (xspeed<0) - direction = "left"; - else direction = "right"; - - setCollisionOn(false); - gameLogic.checkTile(this); - if (collisionOn == false) { - worldX += xspeed; + + if (xspeed < 0) + direction = "left"; + else + direction = "right"; + + setCollisionOn(false); + gameLogic.checkTile(this); + if (collisionOn == false) { + worldX += xspeed; + } } - } - else { - currentState = "attack"; - attack(gameLogic.getPlayer()); + } - if (playerfound()) speed = 1; - else speed = 0; updateAttackBlock(); } public void initSolidArea() { - solidArea = new Rectangle(0, 0, 32, 64); + solidArea = new Rectangle(20, 0, 24, 64); } public void initAttackBlock() { - attackBlock = new Rectangle(screenX+solidArea.getWidth(), screenY, 10 * 2, 7 * 2); + attackBlock = new Rectangle(screenX+solidArea.getWidth(), screenY, solidArea.getWidth()+10 * 2, 64); } // Debug Chick public void drawAttackBlock(GraphicsContext gc) { gc.setFill(Color.BLACK); - gc.strokeRect(attackBlock.getX()+solidArea.getWidth(), attackBlock.getY(), attackBlock.getWidth(), + gc.strokeRect(attackBlock.getX(), attackBlock.getY(), attackBlock.getWidth(), attackBlock.getHeight()); } diff --git a/src/logic/entity/Enemy.java b/src/logic/entity/Enemy.java index 35a3d7d..7fb5dfb 100644 --- a/src/logic/entity/Enemy.java +++ b/src/logic/entity/Enemy.java @@ -6,13 +6,16 @@ import logic.game.GameLogic; public abstract class Enemy extends Entity{ - protected double angle = 0; - protected String currentState; + protected String currentState = "default"; protected double delay = 0; + protected boolean canAttack; + protected double xspeed,yspeed; - public Enemy(int x, int y, GameLogic gameLogic) { + public Enemy(double x, double y, GameLogic gameLogic) { super(x, y, gameLogic); + initSolidArea(); + initAttackBlock(); // TODO Auto-generated constructor stub } @@ -26,7 +29,7 @@ else if (health<=0) { } else { currentHealth = health; -// System.out.println("Plathong" + currentHealth); + } } public boolean checkEnemyHit() { @@ -35,29 +38,28 @@ public boolean checkEnemyHit() { int y = (int) p.getScreenY(); int width = (int) p.getSolidArea().getWidth(); int height = (int) p.getSolidArea().getHeight(); - boolean overlap = solidScreen.intersects(x,y,width,height); -// System.out.println("Overlap = " + overlap); -// System.out.println("X = " + x + " Y = " + y); - return overlap; + return solidScreen.intersects(x,y,width,height) || attackBlock.intersects(x,y,width,height); } - + public int getCurrentHealth() { return currentHealth; } public void attack(Entity p) { // TODO Auto-generated method stub - System.out.println(this.getClass().getSimpleName()+"Attack"); - if (checkEnemyHit()) ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); +// System.out.println(this.getClass().getSimpleName()+"Attack"); + if (checkEnemyHit()) { + ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); + } } //Debugger public void drawHitbox(GraphicsContext gc) { gc.setLineWidth(2); - gc.setFill(Color.BLACK); + gc.setFill(Color.PINK); gc.strokeRect(solidScreen.getX(), solidScreen.getY(), solidScreen.getWidth(), solidScreen.getHeight()); - } + } public void drawAttackBlock(GraphicsContext gc) { gc.setFill(Color.BLACK); @@ -66,14 +68,43 @@ public void drawAttackBlock(GraphicsContext gc) { } public void updateAttackBlock() { - attackBlock.setX(screenX); + if (direction == "right") + attackBlock.setX(solidScreen.getX()); + else if (direction == "left") + attackBlock.setX(solidScreen.getX()+solidScreen.getWidth()-attackBlock.getWidth()); attackBlock.setY(screenY); + } public void update() { super.update(); -// System.out.println(getClass().getSimpleName()+playerfound()); solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight()); + Player player = gameLogic.getPlayer(); + angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); + } + + public void move() { + if (yspeed < 0) + direction = "up"; + else + direction = "down"; + setCollisionOn(false); + gameLogic.checkTile(this); + if (collisionOn == false) { + worldY += yspeed; + + } + + if (xspeed < 0) + direction = "left"; + else + direction = "right"; + + setCollisionOn(false); + gameLogic.checkTile(this); + if (collisionOn == false) { + worldX += xspeed; + } } public void reset() { @@ -85,17 +116,13 @@ public void reset() { this.direction = "right"; } - public boolean playerfound() { + public boolean playerfound(int range) { int rangeX = (int) Math.abs(worldX-gameLogic.getPlayer().getWorldX()); int rangeY = (int) Math.abs(worldY-gameLogic.getPlayer().getWorldY()); - int range = (int) Math.sqrt(Math.pow(rangeX, 2) + Math.pow(rangeY, 2)); - if (this instanceof Chicknight) { -// System.out.println("X = " + worldX +" Y = " + worldY); -// System.out.println("X = " + gameLogic.getPlayer().getWorldX() +" Y = " + gameLogic.getPlayer().getWorldY() + "Range =" +range); - } - return range<300; + return (int) Math.sqrt(Math.pow(rangeX, 2) + Math.pow(rangeY, 2)) < range; } - + + public abstract void initSolidArea(); public abstract void initAttackBlock(); } diff --git a/src/logic/entity/Entity.java b/src/logic/entity/Entity.java index 8fa9dbb..b488b8c 100644 --- a/src/logic/entity/Entity.java +++ b/src/logic/entity/Entity.java @@ -25,26 +25,27 @@ public abstract class Entity implements IRenderable { // AttackBlock protected Rectangle attackBlock; - public Entity(int x, int y, GameLogic gameLogic) { + public Entity(double x, double y, GameLogic gameLogic) { visible = true; destroyed = false; worldX = x; worldY = y; this.gameLogic = gameLogic; this.direction = "right"; + radius =32; } public abstract void attack(Entity t); + public abstract void move(); public void update() { screenX = worldX - gameLogic.getPlayer().worldX + gameLogic.getPlayer().screenX; screenY = worldY - gameLogic.getPlayer().worldY + gameLogic.getPlayer().screenY; + } - public boolean canAttack(double x1, double y1, double x2, double y2, int attackRange) { return (Math.abs(x1 - x2) < attackRange && Math.abs(y1 - y2) < attackRange); } - @Override public int getZ() { diff --git a/src/logic/entity/EyeOfQwifot.java b/src/logic/entity/EyeOfQwifot.java index 3e68468..ddd4043 100644 --- a/src/logic/entity/EyeOfQwifot.java +++ b/src/logic/entity/EyeOfQwifot.java @@ -5,38 +5,33 @@ import logic.game.GameLogic; import sharedObject.RenderableHolder; -public class EyeOfQwifot extends MiniBoss{ +public class EyeOfQwifot extends Enemy{ - public EyeOfQwifot(int x, int y, GameLogic gameLogic) { + public EyeOfQwifot(double x, double y, GameLogic gameLogic) { super(x, y, gameLogic); maxHp = 100; currentHealth = maxHp; - z = -100; + z = 100; image = RenderableHolder.EQ1; - currentState = "alive"; -// initAttackBlock(); - initSolidArea(); // TODO Auto-generated constructor stub } @Override public void draw(GraphicsContext gc) { // TODO Auto-generated method stub - switch(currentState) { - case "alive": + if(currentState == "dead") { + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.EQDead1; + + else + image = RenderableHolder.EQDead2; + } else { if (gameLogic.getCounter()/10%2==1) image = RenderableHolder.EQ1; else image = RenderableHolder.EQ2; - break; - case "dead": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.EQDead1; - else - image = RenderableHolder.EQDead2; - break; } gc.drawImage(image,screenX,screenY); // TODO Auto-generated method stub @@ -54,6 +49,25 @@ public void attack(Entity t) { public void update() { // TODO Auto-generated method stub super.update(); + if(currentState != "dead") { + if (playerfound(768)) + currentState = "attacking"; + else + currentState = "default"; + + + if(currentState =="attacking") { + if(delay == 0) + delay = 300; + if(delay == 60) { + gameLogic.addNewObject(new GriszlyEye(worldX, worldY, gameLogic)); + gameLogic.addNewObject(new GriszlyEye(worldX+20, worldY, gameLogic)); + } + delay--; + } + } + + } @Override @@ -65,7 +79,7 @@ public void initSolidArea() { @Override public void initAttackBlock() { // TODO Auto-generated method stub -// attackBlock = new Rectangle(0,0,256,256); + attackBlock = new Rectangle(0,0,0,0); } public void changeHealthTo(int health) { @@ -78,7 +92,6 @@ else if (health<=0) { } else { currentHealth = health; -// System.out.println("Plathong" + currentHealth); } } diff --git a/src/logic/entity/GriszlyEye.java b/src/logic/entity/GriszlyEye.java index a5f13ec..f819300 100644 --- a/src/logic/entity/GriszlyEye.java +++ b/src/logic/entity/GriszlyEye.java @@ -8,20 +8,17 @@ import sharedObject.RenderableHolder; public class GriszlyEye extends Enemy { - private double angle = 0; - public String currentState = "default"; - public GriszlyEye(int x, int y, GameLogic gameLogic) { + private int normalSpeed = 3; + public GriszlyEye(double x, double y, GameLogic gameLogic) { super(x, y, gameLogic); this.maxHp = 10; this.currentHealth = maxHp; this.dmg = 3; this.z = -100; - this.speed = 3; + this.speed = normalSpeed; this.dmg = 3; this.image = RenderableHolder.GERight; - initSolidArea(); - initAttackBlock(); } @@ -38,6 +35,7 @@ public void draw(GraphicsContext gc) { if (gameLogic.getCounter() / 10 % 2 == 1) { image = RenderableHolder.GERightWalk; } else + image = RenderableHolder.GERightWalk2; } break; @@ -52,92 +50,58 @@ public void draw(GraphicsContext gc) { } break; } - if (!playerfound()) image = RenderableHolder.GERight; gc.drawImage(image, screenX, screenY); drawHitbox(gc); -// drawAttackBlock(gc); } -// @Override -// public void attack(Entity p) { -// // TODO Auto-generated method stub -// System.out.println("GrsizlyEye Attack"); -// -// ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); -// } - public void attack(Entity p) { - super.attack(p); - if (delay==0) { - if (direction == "right") worldX+=40; - else if (direction == "left") worldX-=60; - - delay =60; - } - - } - @Override public void update() { // TODO Auto-generated method stub super.update(); + if (playerfound(500)) + currentState = "attacking"; + else + currentState = "default"; Player player = gameLogic.getPlayer(); - if (!canAttack(player.worldX, player.worldY, worldX, worldY, 24)) { - angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); - double xspeed = Math.cos(angle) * speed; - double yspeed = Math.sin(angle) * speed; - currentState = "walking"; - - if (yspeed < 0) - direction = "up"; - else - direction = "down"; - setCollisionOn(false); - gameLogic.checkTile(this); - if (collisionOn == false) { - worldY += yspeed; - + canAttack = canAttack(player.worldX, player.worldY, worldX+radius, worldY+radius, + 128); + if (currentState=="attacking") { + if (delay==0) { + speed = normalSpeed; + delay =120; } - - if (xspeed < 0) - direction = "left"; - else - direction = "right"; - - setCollisionOn(false); - gameLogic.checkTile(this); - if (collisionOn == false) { - worldX += xspeed; + if (delay ==30) { + speed = normalSpeed*3; + xspeed = Math.cos(angle) * speed; + yspeed = Math.sin(angle) * speed; } - + + if(delay>30) { + xspeed = Math.cos(angle) * speed; + yspeed = Math.sin(angle) * speed; + move(); } - - else { - currentState = "default"; + else { + worldX += xspeed; + worldY += yspeed; + } + attack(gameLogic.getPlayer()); - } - if (delay<=0) { - delay =0; - } - else { delay--; -// speed-=(5/60); } - if (playerfound()) speed=3; - else speed = 0; - + updateAttackBlock(); } public void initSolidArea() { solidArea = new Rectangle(20, 0, 24, 32); - solidScreen = new Rectangle(screenX,screenY,8,8); } public void initAttackBlock() { - attackBlock = new Rectangle(20, 0, 24, 32); + attackBlock = new Rectangle(0,0,0,0); } diff --git a/src/logic/entity/MagicalTortoise.java b/src/logic/entity/MagicalTortoise.java index d9b2491..ef47482 100644 --- a/src/logic/entity/MagicalTortoise.java +++ b/src/logic/entity/MagicalTortoise.java @@ -8,78 +8,83 @@ import sharedObject.RenderableHolder; public class MagicalTortoise extends Entity{ - private Image image = RenderableHolder.MTRight1; - protected ArrayList dialogues; - - public MagicalTortoise(int x, int y, GameLogic gameLogic) { - super(x, y, gameLogic); - this.dialogues = new ArrayList(); - // TODO Auto-generated constructor stub - setDialogues(); - } + private Image image = RenderableHolder.MTRight1; + protected ArrayList dialogues; - @Override - public void draw(GraphicsContext gc) { - // TODO Auto-generated method stub - switch(direction) { - case "right": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.MTRight1; - - else - image = RenderableHolder.MTRight2; - break; - case "left": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.MTLeft1; - - else - image = RenderableHolder.MTLeft2; - - break; - } - gc.drawImage(image, screenX, screenY); + public MagicalTortoise(double x, double y, GameLogic gameLogic) { + super(x, y, gameLogic); + this.dialogues = new ArrayList(); + // TODO Auto-generated constructor stub + setDialogues(); + } - } + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + switch(direction) { + case "right": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.MTRight1; - @Override - public void attack(Entity p) { - // TODO Auto-generated method stub - } + else + image = RenderableHolder.MTRight2; + break; + case "left": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.MTLeft1; + + else + image = RenderableHolder.MTLeft2; + + break; + } + gc.drawImage(image, screenX, screenY); + + } + + @Override + public void attack(Entity p) { + // TODO Auto-generated method stub + } + + @Override + public void update() { + // TODO Auto-generated method stub + super.update(); + Player player = gameLogic.getPlayer(); + double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); + if(xDirection<0) + direction = "left"; + else + direction = "right"; + } + + public void setDialogues() { + dialogues.add("Hi , I'm GAY"); + dialogues.add("This is GayZone So u r Gay"); + } + + public boolean playerfound(){ + int rangeX = (int) Math.abs(worldX-gameLogic.getPlayer().getWorldX()); + int rangeY = (int) Math.abs(worldY-gameLogic.getPlayer().getWorldY()); + int range = (int) Math.sqrt(Math.pow(rangeX, 2) + Math.pow(rangeY, 2)); + return range<30; + } + public String getDialogues(int i) { + return dialogues.get(i); + } + + public int getDialoguesSize() { + return dialogues.size(); + } + + public void speak() { + + } @Override - public void update() { + public void move() { // TODO Auto-generated method stub - screenX = worldX-gameLogic.getPlayer().worldX+gameLogic.getPlayer().screenX; - screenY = worldY-gameLogic.getPlayer().worldY+gameLogic.getPlayer().screenY; - Player player = gameLogic.getPlayer(); - double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); - if(xDirection<0) - direction = "left"; - else - direction = "right"; - } - - public void setDialogues() { - dialogues.add("Hi , I'm GAY"); - dialogues.add("This is GayZone So u r Gay"); - } - - public boolean playerfound(){ - int rangeX = (int) Math.abs(worldX-gameLogic.getPlayer().getWorldX()); - int rangeY = (int) Math.abs(worldY-gameLogic.getPlayer().getWorldY()); - int range = (int) Math.sqrt(Math.pow(rangeX, 2) + Math.pow(rangeY, 2)); - return range<30; - } - public String getDialogues(int i) { - return dialogues.get(i); - } - - public int getDialoguesSize() { - return dialogues.size(); - } - - public void speak() { } } diff --git a/src/logic/entity/Mole.java b/src/logic/entity/Mole.java new file mode 100644 index 0000000..c1f8043 --- /dev/null +++ b/src/logic/entity/Mole.java @@ -0,0 +1,62 @@ +package logic.entity; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.shape.Rectangle; +import logic.game.GameLogic; +import sharedObject.RenderableHolder; + +public class Mole extends Enemy{ + protected String rank; + public Mole(double x, double y, GameLogic gameLogic,String rank) { + super(x, y, gameLogic); + this.maxHp = 100; + this.currentHealth = maxHp; + this.z = -100; + this.rank = rank; + if(rank=="DerKaiser") + image = RenderableHolder.moleDerKaiser; + else + image = RenderableHolder.mole; + } + + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + gc.drawImage(image, screenX, screenX); + } + + @Override + public void update() { + // TODO Auto-generated method stub + super.update(); + if (playerfound(1000)) + currentState = "attacking"; + else + currentState = "default"; + if(currentState == "attacking") { + Player player = gameLogic.getPlayer(); + angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); + double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); + if(xDirection<0) + direction = "left"; + else + direction = "right"; + + if(delay==0) { + attack(gameLogic.getPlayer()); + delay = 1*60; + } + delay--; + } + } + @Override + public void initSolidArea() { + solidArea = new Rectangle(16, 8, 32, 48); + } + + @Override + public void initAttackBlock() { + attackBlock = new Rectangle(0,0,0,0); + } + +} diff --git a/src/logic/entity/MoleDerKaiser.java b/src/logic/entity/MoleDerKaiser.java new file mode 100644 index 0000000..445e5f7 --- /dev/null +++ b/src/logic/entity/MoleDerKaiser.java @@ -0,0 +1,43 @@ +package logic.entity; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.shape.Rectangle; +import logic.game.GameLogic; +import sharedObject.RenderableHolder; + +public class MoleDerKaiser extends Enemy{ + private int width = 7; + private int height = 7; + public MoleDerKaiser(double x, double y, GameLogic gameLogic) { + super(x, y, gameLogic); + this.maxHp = 100; + this.currentHealth = maxHp; + this.z = -100; + image = RenderableHolder.CKRight; + + // TODO Auto-generated constructor stub + } + + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + + } + + @Override + public void update() { + + } + @Override + public void initSolidArea() { + // TODO Auto-generated method stub + solidArea = new Rectangle(16, 8, 32, 48); + } + + @Override + public void initAttackBlock() { + attackBlock = new Rectangle(0,0,0,0); + + } + +} diff --git a/src/logic/entity/Player.java b/src/logic/entity/Player.java index 0360583..5254704 100644 --- a/src/logic/entity/Player.java +++ b/src/logic/entity/Player.java @@ -28,52 +28,51 @@ public class Player extends Entity{ private int healthBarY = (int) (11*1.5); //Status - protected int maxHp = 100; + protected int maxHp = 50; protected int currentHealth = maxHp; protected float healthWidth = healthBarWidth; - protected int dmg = 5; + protected int dmg = 10; protected int iframe = 0; //AttackBlock private Rectangle attackBlock; int counter; - public Player(int x, int y,GameLogic gameLogic) { + public Player(double x, double y,GameLogic gameLogic) { super(x,y,gameLogic); this.speed = 5; - this.radius = 32; screenX = gameLogic.getGameScreen().getWidth()/2-radius; screenY = gameLogic.getGameScreen().getHeight()/2-radius; + image = RenderableHolder.playerRight; initSolidArea(); initAttackBlock(); } @Override public void draw(GraphicsContext gc) { - int count = 0; - Image playerImage = RenderableHolder.playerRight; + image = RenderableHolder.playerRight; // TODO Auto-generated method stub switch(direction) { case "left": - playerImage = (RenderableHolder.playerLeft); + image = (RenderableHolder.playerLeft); break; case "right": - playerImage = RenderableHolder.playerRight; + image = RenderableHolder.playerRight; break; } - gc.drawImage(playerImage , screenX, screenY); + gc.drawImage(image , screenX, screenY); drawUI(gc); //Debugging - drawHitbox(gc, 44, 64); + drawHitbox(gc); drawAttackBlock(gc); } - public void drawHitbox(GraphicsContext gc,int width , int height) { + public void drawHitbox(GraphicsContext gc) { gc.setLineWidth(2); gc.setFill(Color.PINK); - gc.strokeRect(screenX,screenY,width,height); + gc.strokeRect(solidScreen.getX(),solidScreen.getY(),solidScreen.getWidth(),solidScreen.getHeight()); } public void drawUI(GraphicsContext gc) { @@ -88,68 +87,33 @@ public void drawAttackBlock(GraphicsContext gc){ } public void attack(Entity e) { - + attackState = "yes"; + Enemy enemy = (Enemy)e; System.out.println("Player Attack "+e.getClass().getSimpleName()); - ((Enemy)e).changeHealthTo(((Enemy)e).getCurrentHealth()-dmg); + enemy.changeHealthTo(enemy.getCurrentHealth()-dmg); + } @Override public void update() { // TODO Auto-generated method stub - direction = ""; - if (InputUtility.getKeyPressed(KeyCode.W)) { - direction = "up"; - } - if (InputUtility.getKeyPressed(KeyCode.S)) { - direction = "down"; - } - - - setCollisionOn(false); - gameLogic.checkTile(this); - - if (collisionOn == false) { - switch(direction) { - case "up": - worldY -= speed; - break; - case "down": - worldY += speed; - break; - - } - } - - if (InputUtility.getKeyPressed(KeyCode.D)) { - direction = "right"; - } - if (InputUtility.getKeyPressed(KeyCode.A)) { - direction = "left"; - } - - setCollisionOn(false); - gameLogic.checkTile(this); - if (collisionOn == false) { - switch(direction) { - case "left": - worldX -= speed; - break; - case "right": - worldX += speed; - break; - } - } + solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight()); + move(); if (InputUtility.isLeftClickTriggered()) { for (Entity entity: gameLogic.getGameObjectContainer()) { if ((entity instanceof Enemy)) { Enemy enemy = ((Enemy)entity); - boolean canAtk = canAttack(worldX,worldY,enemy.getWorldX(),enemy.getWorldY(),(int) (solidArea.getWidth()+attackBlock.getWidth())); - if (canAtk) { + int x = (int) enemy.solidScreen.getX(); + int y = (int) enemy.solidScreen.getY(); + int width = (int) enemy.getSolidArea().getWidth(); + int height = (int) enemy.getSolidArea().getHeight(); + attackBlock.intersects(x,y,width,height); + if (attackBlock.intersects(x,y,width,height)) { attack(entity); } if(enemy instanceof EyeOfQwifot) { - System.out.println(enemy.solidScreen.getWidth()+" "+enemy.solidScreen.getHeight()); +// System.out.println(enemy.solidScreen.getWidth()+" "+enemy.solidScreen.getHeight()); } } @@ -164,8 +128,6 @@ public void update() { public void updateHealthBar() { healthWidth = (float) (currentHealth/(float) maxHp) * healthBarWidth; -// healthWidth = (int) (0.5 * healthBarWidth); -// System.out.println(healthWidth); } public void changeHealthTo(int health) { @@ -186,22 +148,64 @@ else if (health<=0) { } + public void move() { + direction = ""; + if (InputUtility.getKeyPressed(KeyCode.W)) { + direction = "up"; + } + if (InputUtility.getKeyPressed(KeyCode.S)) { + direction = "down"; + } + + setCollisionOn(false); + gameLogic.checkTile(this); + + if (collisionOn == false) { + switch(direction) { + case "up": + worldY -= speed; + break; + case "down": + worldY += speed; + break; + } + } + + if (InputUtility.getKeyPressed(KeyCode.D)) { + direction = "right"; + } + if (InputUtility.getKeyPressed(KeyCode.A)) { + direction = "left"; + } + + setCollisionOn(false); + gameLogic.checkTile(this); + if (collisionOn == false) { + switch(direction) { + case "left": + worldX -= speed; + break; + case "right": + worldX += speed; + break; + } + } + } public void initSolidArea() { - solidArea = new Rectangle(0,0,32,64); + solidArea = new Rectangle(16,0,32,64); + } public void initAttackBlock() { - attackBlock = new Rectangle(worldX,worldY,20*2,20*2); + attackBlock = new Rectangle(screenX,screenY,solidArea.getWidth()+20*2,96); } public void updateAttackBlock() { - if (direction=="right") { - attackBlock.setX(screenX+(int)solidArea.getWidth()); -// attackBlock.setLayoutX(0); - }else if(direction=="left") { - attackBlock.setX(screenX+(int)solidArea.getWidth()-(int)(30*2)); - } - attackBlock.setY(screenY+(int)(10*2)); + if (direction == "right") + attackBlock.setX(solidScreen.getX()); + else if (direction == "left") + attackBlock.setX(solidScreen.getX()+solidScreen.getWidth()-attackBlock.getWidth()); + attackBlock.setY(screenY-16); } public void GameOver() { diff --git a/src/logic/entity/ShadowPot.java b/src/logic/entity/ShadowPot.java index bfe56bd..4097692 100644 --- a/src/logic/entity/ShadowPot.java +++ b/src/logic/entity/ShadowPot.java @@ -7,16 +7,13 @@ import sharedObject.RenderableHolder; public class ShadowPot extends Enemy{ - - private int cooldown; - public ShadowPot(int x, int y, GameLogic gameLogic) { + + public ShadowPot(double x, double y, GameLogic gameLogic) { super(x, y, gameLogic); image = RenderableHolder.SPRight1; maxHp = 10; currentHealth = maxHp; - cooldown = 1*60; - initSolidArea(); - initAttackBlock(); + delay = 1*60; } @Override @@ -24,15 +21,21 @@ public void draw(GraphicsContext gc) { // TODO Auto-generated method stub switch(direction) { case "right": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.SPRight1; + if (gameLogic.getCounter()<20) + if(currentState == "attacking") + image = RenderableHolder.SPRightAtk; + else + image = RenderableHolder.SPRight1; else image = RenderableHolder.SPRight2; break; case "left": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.SPLeft1; + if (gameLogic.getCounter()<20) + if(currentState == "attacking") + image = RenderableHolder.SPLeftAtk; + else + image = RenderableHolder.SPLeft1; else image = RenderableHolder.SPLeft2; @@ -47,6 +50,7 @@ public void draw(GraphicsContext gc) { @Override public void attack(Entity t) { // TODO Auto-generated method stub + Projectile projectile = new Projectile(worldX+solidArea.getX(), worldY+solidArea.getY(), angle,gameLogic); gameLogic.addNewProjectile(projectile); } @@ -55,6 +59,11 @@ public void attack(Entity t) { public void update() { // TODO Auto-generated method stub super.update(); + if (playerfound(1000)) + currentState = "attacking"; + else + currentState = "default"; + if(currentState == "attacking") { Player player = gameLogic.getPlayer(); angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); @@ -63,24 +72,25 @@ public void update() { else direction = "right"; - if(cooldown==0) { + if(delay==0) { + attack(gameLogic.getPlayer()); - cooldown = 1*60; + delay = 1*60; } - cooldown--; + delay--; + } } @Override public void initSolidArea() { // TODO Auto-generated method stub solidArea = new Rectangle(16,24,32,40); - solidScreen = new Rectangle(screenX,screenY,8,8); } @Override public void initAttackBlock() { // TODO Auto-generated method stub - attackBlock = new Rectangle(16,24,32,40); + attackBlock = new Rectangle(0,0,0,0); } } \ No newline at end of file diff --git a/src/logic/field/Map1.java b/src/logic/field/Map1.java index 119339e..fd62266 100644 --- a/src/logic/field/Map1.java +++ b/src/logic/field/Map1.java @@ -11,33 +11,77 @@ public class Map1 implements IRenderable{ public GameLogic gL; // private WritableImage[] croppedImage = new WritableImage[4]; - private Tile [] tiles = new Tile[5]; + private Tile [] tiles = new Tile[20]; public Map1(GameLogic gameLogic) { this.gL = gameLogic; - tiles[0] = new Tile(RenderableHolder.whiteTile,false); - tiles[1] = new Tile(RenderableHolder.grayTile,true); - tiles[2] = new Tile(RenderableHolder.pathTile,false); - tiles[3] = new Tile(RenderableHolder.blackStarTile,true); - tiles[4] = new Tile(RenderableHolder.blackTile,true); + tiles[0] = new Tile( RenderableHolder.ground1Tile,false); + tiles[1] = new Tile( RenderableHolder.ground2Tile,false); + tiles[2] = new Tile( RenderableHolder.ground3Tile,false); + tiles[3] = new Tile(RenderableHolder.ground1Tile,true); + tiles[4] = new Tile(RenderableHolder.water1Tile,false); + tiles[5] = new Tile( RenderableHolder.water2Tile,false); + tiles[6] = new Tile( RenderableHolder.topLeftMapTile,true); + tiles[7] = new Tile( RenderableHolder.topMapTile,true); + tiles[8] = new Tile( RenderableHolder.topRightMapTile,true); + tiles[9] = new Tile( RenderableHolder.rightMapTile,true); + tiles[10] = new Tile( RenderableHolder.bottomRightMapTile,true); + tiles[11] = new Tile( RenderableHolder.bottomMapTile,true); + tiles[12] = new Tile( RenderableHolder.bottomLeftMapTile,true); + tiles[13] = new Tile( RenderableHolder.leftMapTile,true); + tiles[14] = new Tile( RenderableHolder.tombTile,true); + tiles[15] = new Tile( RenderableHolder.spawn1Tile,false); + tiles[16] = new Tile(RenderableHolder.spawn2Tile,false); } int tileSize = 64; - public int[][] field = {{3,3,3,3,3,3,4,3,4,4,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0}, - {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0}, - {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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,9}, + {13,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}, + {13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}, + {13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}, + {12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10}}; public int getTerrain(int x, int y) { if (x < 0 || x >= field[0].length || y < 0 || y >= field.length) @@ -50,7 +94,7 @@ public int getTileIndex(int x, int y) { if (terrain >= 0) return terrain; else - return 1; + return 3; } @Override diff --git a/src/logic/game/GameLogic.java b/src/logic/game/GameLogic.java index 2cd3c22..314a9b2 100644 --- a/src/logic/game/GameLogic.java +++ b/src/logic/game/GameLogic.java @@ -5,8 +5,11 @@ import MainMenu.GameOverButton; import Object.Projectile; +import application.Main; import drawing.GameScreen; import input.InputUtility; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.scene.canvas.GraphicsContext; import javafx.scene.input.KeyCode; import javafx.scene.paint.Color; @@ -31,12 +34,9 @@ public class GameLogic { private GameScreen gameScreen; private Player player; - private Chicknight ck1; - private GriszlyEye GE1; - private MagicalTortoise MG; - private EyeOfQwifot EQ; - private ShadowPot SP; + private EyeOfQwifot eQ; private Map1 map; + private MagicalTortoise mT; // GameState public int gameState = 1; @@ -46,32 +46,16 @@ public class GameLogic { public final int gameOverState = 4; public GameLogic(GameScreen gameScreen) { - this.gameObjectContainer = new ArrayList(); - this.projectilesContainer = new ArrayList(); this.gameScreen = gameScreen; - player = new Player(384, 288, this); - - map = new Map1(this); - RenderableHolder.getInstance().add(map); + startNewGame(); - ck1 = new Chicknight(200, 0, this); - MG = new MagicalTortoise(200, 200, this); - GE1 = new GriszlyEye(200, 200, this); - EQ = new EyeOfQwifot(780, 780, this); - SP = new ShadowPot(300, 500, this); - addNewObject(player); - addNewObject(ck1); - addNewObject(MG); - addNewObject(GE1); - addNewObject(EQ); - addNewObject(SP); } public GameScreen getGameScreen() { return gameScreen; } - protected void addNewObject(Entity entity) { + public void addNewObject(Entity entity) { gameObjectContainer.add(entity); RenderableHolder.getInstance().add(entity); } @@ -81,6 +65,28 @@ public void addNewProjectile(Projectile p) { RenderableHolder.getInstance().add(p); } + public void startNewGame() { + RenderableHolder.inGameSong.play(); + this.gameObjectContainer = new ArrayList(); + this.projectilesContainer = new ArrayList(); + RenderableHolder.getInstance().getEntities().clear(); + + map = new Map1(this); + RenderableHolder.getInstance().add(map); + + player = new Player(384, 288, this); + eQ = new EyeOfQwifot(3456, 512, this); + mT = new MagicalTortoise(200, 200, this); + addNewObject(player); + addNewObject(new Chicknight(200, 200, this)); + addNewObject(mT); + addNewObject(new GriszlyEye(200, 200, this)); + addNewObject(eQ); + addNewObject(new ShadowPot(300, 500, this)); + + gameState = playState; + System.out.println("New Game"); + } public void checkTile(Entity entity) { int entityLeftWorldX = (int) (entity.getWorldX() + entity.solidArea.getX()); int entityRightWorldX = (int) (entity.getWorldX() + entity.solidArea.getX() + entity.solidArea.getWidth()); @@ -142,7 +148,10 @@ public void checkTile(Entity entity) { } public void update() { -// System.out.println(gameState); + System.out.println(gameState); + if (!RenderableHolder.inGameSong.isPlaying()) { + RenderableHolder.inGameSong.play(); + } if(gameState == playState) { logicUpdate(); gameScreen.paintComponent(); @@ -152,9 +161,14 @@ else if (gameState == pauseState) { // System.out.println(500); }else if (gameState == gameOverState) { drawGameOverOverlay(); + RenderableHolder.inGameSong.stop(); if (InputUtility.getKeyPressed(KeyCode.R)) { - gameState = playState; - reset(); + startNewGame(); +// reset(); + } + else if ( InputUtility.getKeyPressed(KeyCode.M)) { + InputUtility.getKeyPressed().remove(KeyCode.M); + Main.GoToMenu(); } } else if (gameState == npcState) { @@ -164,11 +178,6 @@ else if (gameState == npcState) { } } - private void reset() { - // TODO Auto-generated method stub - getPlayer().reset(); - - } public void logicUpdate() { if (counter == 60) { @@ -190,7 +199,7 @@ public void logicUpdate() { } public MagicalTortoise getMagicalTortoise() { - return MG; + return mT; } public void drawDialogueScreen(int i) { @@ -212,12 +221,8 @@ public void drawGamePauseOverlay() { } public void drawGameOverOverlay() { - GameOverButton retry = new GameOverButton((int) (1280 / 3.5), (int) (720 / 1.5), 200, 40, "RETRY"); - retry.getBounds().setOnMouseClicked(e -> { -// gameLogic.reset(); - }); - - GameOverButton mainMenu = new GameOverButton((int) (1280 / 3.5) + 320, (int) (720 / 1.5), 200, 40, " Menu"); + GameOverButton retry = new GameOverButton((int) (1280 / 3.5), (int) (720 / 1.5), 200, 40, "RETRY(R)"); + GameOverButton mainMenu = new GameOverButton((int) (1280 / 3.5) + 320, (int) (720 / 1.5), 200, 40, " Menu(M)"); GraphicsContext gc = getGameScreen().getGraphicsContext2D(); gc.drawImage(RenderableHolder.gameOverOverlay, 0, 0); retry.draw(gc); @@ -235,7 +240,7 @@ public int getCounter() { public void count() { counter++; if (counter % 10 == 0) { - System.out.println(counter); +// System.out.println(counter); } } diff --git a/src/sharedObject/RenderableHolder.java b/src/sharedObject/RenderableHolder.java index eba6b87..87d9cae 100644 --- a/src/sharedObject/RenderableHolder.java +++ b/src/sharedObject/RenderableHolder.java @@ -25,49 +25,91 @@ public class RenderableHolder { public static Image blackStarTile; public static Image blackTile; public static Image CKLeft, CKLeftWalk1, CKLeftWalk2, CKLeftAtk, CKRight, CKRightWalk1, CKRightWalk2, CKRightAtk; - public static Image gameOverOverlay,pauseOverlay,pauseMenu, soundButton, urm, volumeButton; + public static Image gameOverOverlay, pauseOverlay, pauseMenu, soundButton, urm, volumeButton; public static Image GELeft, GELeftWalk, GELeftWalk2, GERight, GERightWalk, GERightWalk2; + // Magical Tortoise Sprite public static Image MTLeft1, MTLeft2, MTRight1, MTRight2; - public static Image SPLeft1,SPLeft2,SPRight2,SPRight1,SPLeftAtk,SPRightAtk,ball; - public static Image EQ1,EQ2,EQDead1,EQDead2; + // ShadowPot Sprite + public static Image SPLeft1, SPLeft2, SPRight2, SPRight1, SPLeftAtk, SPRightAtk, ball; + // EyeOfQwifot Sprite + public static Image EQ1, EQ2, EQDead1, EQDead2; + //MoleDerKaiser + public static Image mole,moleDerKaiser; public static Image moonSprite; public static Image healthBar; - + //Song + public static AudioClip inGameSong; + // Map Tile + public static Image ground1Tile,ground2Tile,ground3Tile,water1Tile,water2Tile,topLeftMapTile,topMapTile,topRightMapTile, + rightMapTile,bottomRightMapTile,bottomMapTile,bottomLeftMapTile,leftMapTile,tombTile,spawn1Tile,spawn2Tile; static { loadResource(); } public RenderableHolder() { - entities = new ArrayList(); - comparator = (IRenderable o1, IRenderable o2) -> { - if (o1.getZ() > o2.getZ()) - return 1; - else if (o1.getZ() == o2.getZ()) { - if(o1 instanceof Entity && o2 instanceof Entity){ - if (((Entity) o1).getWorldY()>((Entity) o2).getWorldY()) { - return 1; - } - } - } - return -1; - }; - } + entities = new ArrayList(); + comparator = (IRenderable o1, IRenderable o2) -> { + if (o1.getZ() > o2.getZ()) + return 1; + else if (o1.getZ() == o2.getZ()) { + if (o1 instanceof Entity && o2 instanceof Entity) { + if (((Entity) o1).getWorldY() > ((Entity) o2).getWorldY()) { + return 1; + } + } + } + return -1; + }; + } public static RenderableHolder getInstance() { return instance; } public static void loadResource() { + //player Sprite + loadPlayer(); + loadMapTile(); + loadChicknight(); + loadGriszlyEye(); + loadMagicalTortoise(); + loadShadowPot(); + loadEyeOfQwifot(); + loadMoleDerKaiser(); + // + //Game State + pauseOverlay = new Image(ClassLoader.getSystemResource("pause/PauseOverlay.png").toString()); + gameOverOverlay = new Image(ClassLoader.getSystemResource("pause/GameOver.png").toString()); + inGameSong = new AudioClip(ClassLoader.getSystemResource("IngameSong.wav").toString()); + // StatusBar + healthBar = new Image(ClassLoader.getSystemResource("health_power_bar.png").toString()); + + } + + public static void loadPlayer() { playerLeft = new Image(ClassLoader.getSystemResource("player/RabbiLeft.png").toString()); playerRight = new Image(ClassLoader.getSystemResource("player/Rabbi.png").toString()); playerRightAtk = new Image(ClassLoader.getSystemResource("player/RabbiRightAtk.png").toString()); - whiteTile = new Image(ClassLoader.getSystemResource("Tiles/WhiteTile.png").toString()); - grayTile = new Image(ClassLoader.getSystemResource("Tiles/GrayTile.png").toString()); - pathTile = new Image(ClassLoader.getSystemResource("Tiles/pathTile.png").toString()); - blackStarTile = new Image(ClassLoader.getSystemResource("Tiles/blackStarTile.png").toString()); - blackTile = new Image(ClassLoader.getSystemResource("Tiles/blackTile.png").toString()); - - // Chicknight's Resource + } + public static void loadMapTile() { + ground1Tile = new Image(ClassLoader.getSystemResource("mapTile/ground1.png").toString()); + ground2Tile = new Image(ClassLoader.getSystemResource("mapTile/ground2.png").toString()); + ground3Tile = new Image(ClassLoader.getSystemResource("mapTile/ground3.png").toString()); + water1Tile = new Image(ClassLoader.getSystemResource("mapTile/water1.png").toString()); + water2Tile = new Image(ClassLoader.getSystemResource("mapTile/water2.png").toString()); + topLeftMapTile = new Image(ClassLoader.getSystemResource("mapTile/TopLeftMap.png").toString()); + topMapTile = new Image(ClassLoader.getSystemResource("mapTile/TopMap.png").toString()); + topRightMapTile = new Image(ClassLoader.getSystemResource("mapTile/TopRightMap.png").toString()); + rightMapTile = new Image(ClassLoader.getSystemResource("mapTile/RightMap.png").toString()); + bottomRightMapTile = new Image(ClassLoader.getSystemResource("mapTile/BottomRightMap.png").toString()); + bottomMapTile = new Image(ClassLoader.getSystemResource("mapTile/BottomMap.png").toString()); + bottomLeftMapTile = new Image(ClassLoader.getSystemResource("mapTile/BottomLeftMap.png").toString()); + leftMapTile = new Image(ClassLoader.getSystemResource("mapTile/LeftMap.png").toString()); + tombTile = new Image(ClassLoader.getSystemResource("mapTile/Tomb.png").toString()); + spawn1Tile = new Image(ClassLoader.getSystemResource("mapTile/spawn1.png").toString()); + spawn2Tile = new Image(ClassLoader.getSystemResource("mapTile/spawn2.png").toString()); + } + public static void loadChicknight() { CKLeft = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightLeft.png").toString()); CKLeftWalk1 = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightLeftWalk1.png").toString()); CKLeftWalk2 = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightLeftWalk2.png").toString()); @@ -76,19 +118,28 @@ public static void loadResource() { CKRightWalk1 = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightRightWalk1.png").toString()); CKRightWalk2 = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightRightWalk2.png").toString()); CKRightAtk = new Image(ClassLoader.getSystemResource("Chicknight/ChicknightRightAtk.png").toString()); - // GriszlyEye's Resource + } + public static void loadGriszlyEye() { GELeft = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeLeft.png").toString()); GELeftWalk = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeLeftWalk.png").toString()); GELeftWalk2 = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeLeftWalk2.png").toString()); GERight = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeRight.png").toString()); GERightWalk = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeRightWalk.png").toString()); GERightWalk2 = new Image(ClassLoader.getSystemResource("GriszlyEye/GriszlyEyeRightWalk2.png").toString()); - // MagicalTortoise + } + public static void loadMagicalTortoise() { MTLeft1 = new Image(ClassLoader.getSystemResource("MagicalTortoise/MagicalTortoiseLeft1.png").toString()); MTLeft2 = new Image(ClassLoader.getSystemResource("MagicalTortoise/MagicalTortoiseLeft2.png").toString()); MTRight1 = new Image(ClassLoader.getSystemResource("MagicalTortoise/MagicalTortoiseRight1.png").toString()); MTRight2 = new Image(ClassLoader.getSystemResource("MagicalTortoise/MagicalTortoiseRight2.png").toString()); - // ShadowPot + } + public static void loadEyeOfQwifot() { + EQ1 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot1.png").toString()); + EQ2 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot2.png").toString()); + EQDead1 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifotDead1.png").toString()); + EQDead2 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifotDead2.png").toString()); + } + public static void loadShadowPot() { SPLeft1 = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotLeft1.png").toString()); SPLeft2 = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotLeft2.png").toString()); SPLeftAtk = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotLeftAtk.png").toString()); @@ -96,24 +147,11 @@ public static void loadResource() { SPRight2 = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotRight2.png").toString()); SPRightAtk = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotRightAtk.png").toString()); ball = new Image(ClassLoader.getSystemResource("ShadowPot/ball.png").toString()); - //Eye of Qwifot - EQ1 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot1.png").toString()); - EQ2 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot2.png").toString()); - EQDead1 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifotDead1.png").toString()); - EQDead2 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifotDead2.png").toString()); - //Game State - pauseOverlay = new Image(ClassLoader.getSystemResource("pause/PauseOverlay.png").toString()); - gameOverOverlay = new Image(ClassLoader.getSystemResource("pause/GameOver.png").toString()); -// pauseMenu = new Image(ClassLoader.getSystemResource("pause/.png").toString()); -// soundButton = new Image(ClassLoader.getSystemResource("pause/sound_button.png").toString()); -// urm = new Image(ClassLoader.getSystemResource("pause/urm_buttons.png").toString()); -// volumeButton = new Image(ClassLoader.getSystemResource("pause/volume_buttons.png").toString()); - - // StatusBar - healthBar = new Image(ClassLoader.getSystemResource("health_power_bar.png").toString()); - } - + public static void loadMoleDerKaiser() { + mole = new Image(ClassLoader.getSystemResource("MoleDerKaiser/normalMole.png").toString()); + moleDerKaiser = new Image(ClassLoader.getSystemResource("MoleDerKaiser/moleDerKaiser.png").toString()); + } public void add(IRenderable entity) { System.out.println("add"); entities.add(entity);