Skip to content

Commit

Permalink
90% completed
Browse files Browse the repository at this point in the history
  • Loading branch information
PacharaphonP committed May 20, 2023
1 parent 1a07332 commit 279b537
Show file tree
Hide file tree
Showing 73 changed files with 614 additions and 304 deletions.
Binary file modified bin/MainMenu/GameOverButton.class
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/Object/Ball.class
Binary file not shown.
Binary file modified bin/Object/Projectile.class
Binary file not shown.
Binary file added bin/Object/SwordBeam.class
Binary file not shown.
Binary file modified bin/application/Main$1.class
Binary file not shown.
Binary file modified bin/application/Main.class
Binary file not shown.
Binary file added bin/darkSoul4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightLeft1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightLeft2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightLeftAtk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightRight1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightRight2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/llaristicKnight/llaristicKnightRightAtk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bin/logic/entity/Chicknight.class
Binary file not shown.
Binary file modified bin/logic/entity/Enemy.class
Binary file not shown.
Binary file modified bin/logic/entity/Entity.class
Binary file not shown.
Binary file modified bin/logic/entity/EyeOfQwifot.class
Binary file not shown.
Binary file modified bin/logic/entity/GriszlyEye.class
Binary file not shown.
Binary file modified bin/logic/entity/LlaristicKnight.class
Binary file not shown.
Binary file modified bin/logic/entity/MagicalTortoise.class
Binary file not shown.
Binary file modified bin/logic/entity/Mole.class
Binary file not shown.
Binary file modified bin/logic/entity/Player.class
Binary file not shown.
Binary file modified bin/logic/entity/ShadowPot.class
Binary file not shown.
Binary file modified bin/logic/game/GameLogic.class
Binary file not shown.
Binary file added bin/pause/Victory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bin/sharedObject/RenderableHolder.class
Binary file not shown.
Binary file added bin/sound/monsterdie.wav
Binary file not shown.
Binary file added bin/sound/skill1.wav
Binary file not shown.
Binary file added bin/swordBeam/beamBottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/swordBeam/beamLeft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/swordBeam/beamRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/swordBeam/beamtop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/test3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/MoleDerKaiser/moleDerKaiser1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/MoleDerKaiser/normalMole1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/darkSoul4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightLeft1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightLeft2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightLeftAtk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightRight1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightRight2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/llaristicKnight/llaristicKnightRightAtk.png
Binary file added res/pause/Victory.png
Binary file added res/sound/monsterdie.wav
Binary file not shown.
Binary file added res/sound/skill1.wav
Binary file not shown.
Binary file added res/swordBeam/beamBottom.png
Binary file added res/swordBeam/beamLeft.png
Binary file added res/swordBeam/beamRight.png
Binary file added res/swordBeam/beamtop.png
Binary file added res/test1.png
Binary file added res/test2.png
Binary file added res/test3.png
5 changes: 3 additions & 2 deletions src/MainMenu/GameOverButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public GameOverButton(int x, int y, int width, int height,String text) {

}

public void draw(GraphicsContext gc) {
public void draw(GraphicsContext gc,Color colorStrokeRect,Color colorFillText) {
//(1280/2.5,720/1.5,200,40)
gc.strokeRect(x,y,width,height);
gc.setFill(Color.BLACK);
gc.setFill(colorStrokeRect);
gc.setFont(Font.font("Times New Roman", FontWeight.BOLD, 32));
gc.setFill(colorFillText);
gc.fillText(text.getText(), (x+width/2-75), (y+height/1.3));
}

Expand Down
29 changes: 29 additions & 0 deletions src/Object/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Object;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.shape.Rectangle;
import logic.game.GameLogic;
import sharedObject.RenderableHolder;

public class Ball extends Projectile{

public Ball(double worldX, double worldY, double angle, GameLogic gameLogic) {
super(worldX, worldY, angle, gameLogic);
speed = 3;
xspeed = Math.cos(angle) * speed;
yspeed = Math.sin(angle) * speed;
dmg = 10;
solidArea = new Rectangle(0, 0, 8, 8);
solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight());
RenderableHolder.shootSound.play(0.1);
image = RenderableHolder.ball;
}

@Override
public void draw(GraphicsContext gc) {
// TODO Auto-generated method stub
gc.drawImage(image, screenX, screenY);
// drawHitbox(gc);
}

}
45 changes: 13 additions & 32 deletions src/Object/Projectile.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,46 @@
package Object;

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import logic.entity.Player;
import logic.game.GameLogic;
import sharedObject.IRenderable;
import sharedObject.RenderableHolder;

public class Projectile implements IRenderable {

public abstract class Projectile implements IRenderable {
protected Image image;
protected double worldX, worldY;
public double screenX, screenY;
private Rectangle solidArea,solidScreen;
private double angle;
private int dmg, speed;
protected Rectangle solidArea,solidScreen;
protected double angle;
protected int dmg, speed;
protected int z, radius;
protected boolean visible, destroyed;
public GameLogic gameLogic;
private double xspeed, yspeed;
protected double xspeed, yspeed;

public Projectile(double worldX, double worldY, double angle, GameLogic gameLogic) {
this.worldX = worldX;
this.worldY = worldY;
this.gameLogic = gameLogic;
this.angle = angle;
this.speed = 3;
this.z = 10;
this.visible = true;
this.destroyed = false;
this.xspeed = Math.cos(angle) * speed;
this.yspeed = Math.sin(angle) * speed;
this.dmg = 10;
solidArea = new Rectangle(0, 0, 8, 8);
solidScreen = new Rectangle(screenX,screenY,8,8);
RenderableHolder.shootSound.play(0.1);
}

public void update() {
worldX += xspeed;
worldY += yspeed;
screenX = worldX - gameLogic.getPlayer().getWorldX() + gameLogic.getPlayer().screenX;
screenY = worldY - gameLogic.getPlayer().getWorldY() + gameLogic.getPlayer().screenY;
solidArea.setX(screenX);
solidArea.setY(screenY);
// System.out.println("X =" + xspeed + " Y = " + yspeed);
boolean isOut = screenX < 0 || screenX > 1280 || screenY < 0 || screenY > 720;
if (isOut) {
destroyed = true;
}
solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight());
checkEnemyHit();
}

Expand All @@ -58,15 +50,10 @@ public void checkEnemyHit() {
int y = (int) p.getScreenY();
int width = (int) p.getSolidArea().getWidth();
int height = (int) p.getSolidArea().getHeight();
boolean overlap = solidArea.intersects(x,y,width,height);
// System.out.println("Overlap = " + overlap);
// System.out.println("X = " + x + " Y = " + y);
if (overlap) {
if (solidScreen.intersects(x,y,width,height)) {
p.changeHealthTo(p.getCurrentHealth() - dmg);
destroyed = true;
}
solidArea.setX(screenX);
solidArea.setY(screenY);
}

public Rectangle getSolidArea() {
Expand All @@ -79,13 +66,7 @@ public int getZ() {
return 0;
}

@Override
public void draw(GraphicsContext gc) {
// TODO Auto-generated method stub
gc.drawImage(RenderableHolder.ball, screenX, screenY);
drawHitbox(gc);
}

public abstract void draw(GraphicsContext gc);
@Override
public boolean isDestroyed() {
// TODO Auto-generated method stub
Expand All @@ -103,7 +84,7 @@ public boolean isVisible() {
public void drawHitbox(GraphicsContext gc) {
gc.setLineWidth(2);
gc.setFill(Color.RED);
gc.strokeRect(solidArea.getX(), solidArea.getY(), solidArea.getWidth(),
solidArea.getHeight());
gc.strokeRect(solidScreen.getX(), solidScreen.getY(), solidScreen.getWidth(),
solidScreen.getHeight());
}
}
}
43 changes: 43 additions & 0 deletions src/Object/SwordBeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package Object;

import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import logic.game.GameLogic;
import sharedObject.RenderableHolder;

public class SwordBeam extends Projectile{
ImageView rotatedImage;
SnapshotParameters params;
public SwordBeam(double worldX, double worldY, double angle, GameLogic gameLogic) {
super(worldX, worldY, angle, gameLogic);
speed = 5;
xspeed = Math.cos(angle) * speed;
yspeed = Math.sin(angle) * speed;
dmg = 20;
image = RenderableHolder.beamRight;
rotatedImage = new ImageView(image);
rotatedImage.setRotate(angle*180/Math.PI);
params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
if(Math.abs(xspeed)>Math.abs(yspeed)) {
solidArea = new Rectangle(0, -32, 32, 128);
}
else {
solidArea = new Rectangle(-32,0,128,32);
}
solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight());
RenderableHolder.shootSound.play(0.1);
}

@Override
public void draw(GraphicsContext gc) {
// TODO Auto-generated method stub
gc.drawImage(rotatedImage.snapshot(params, null), screenX, screenY);

// drawHitbox(gc);
}

}
63 changes: 39 additions & 24 deletions src/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static void main(String[] args) {
Application.launch(args);
}

public static int second;
public static long lastTimeTriggered = -1;

public static boolean isStart = false;
private static GameMenu gameMenu;
public static Stage stage;
Expand Down Expand Up @@ -56,31 +59,40 @@ public static void GameStart() {
gameScreen.requestFocus();
//
//
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--;
}
second = 0 ;
animation = new AnimationTimer() {
long previousTime = 0;
double drawInterval = 1e9 / 60;
double delta = 0;

public void handle(long now) {
// timer
lastTimeTriggered = (lastTimeTriggered < 0 ? now : lastTimeTriggered);
if (now - lastTimeTriggered >= 1000000000) {
second++;
lastTimeTriggered = now;
}
};
animation.start();
}

delta += (now - previousTime) / drawInterval;
previousTime = now;
logic.checkGameState();
if (delta >= 1) {
logic.count();
logic.update();
RenderableHolder.getInstance().update();
InputUtility.updateInputState();
delta--;
}
// System.out.println(second);
}
};
animation.start();
}

public static void GoToMenu() {
animation.stop();
root.getChildren().remove(gameScreen);
root.getChildren().addAll(bg,gameMenu);
root.getChildren().addAll(bg, gameMenu);
}

@Override
Expand All @@ -92,7 +104,7 @@ public void start(Stage stage) {

gameMenu = new GameMenu();

Image img = new Image(ClassLoader.getSystemResource("Elysia.jpeg").toString());
Image img = new Image(ClassLoader.getSystemResource("darkSoul4.png").toString());
bg = new ImageView(img);
bg.setFitWidth(width);
bg.setFitHeight(height);
Expand All @@ -101,16 +113,18 @@ public void start(Stage stage) {
gameMenu.setVisible(false);

Scene scene = new Scene(root);

if (!gameMenu.isVisible()) {
scene.setOnKeyPressed(e -> {
if (!gameMenu.isVisible()) {
System.out.println("attempt");

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);
Expand All @@ -120,4 +134,5 @@ public void start(Stage stage) {
//
//
}

}
18 changes: 9 additions & 9 deletions src/logic/entity/Chicknight.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Chicknight(double x, double y, GameLogic gameLogic) {
this.dmg = 5;
this.z = -100;
this.speed = 1;
image = RenderableHolder.CKRight;
image = RenderableHolder.cKRight;
}

@Override
Expand All @@ -27,23 +27,23 @@ public void draw(GraphicsContext gc) {
switch (direction) {
case "right":
if (attackState)
image = RenderableHolder.CKRightAtk;
image = RenderableHolder.cKRightAtk;
else {
image = RenderableHolder.CKRight;
image = RenderableHolder.cKRight;
if (currentState == "attacking") {
if (gameLogic.getCounter() / 10 % 2 == 1)
image = RenderableHolder.CKRightWalk1;
image = RenderableHolder.cKRightWalk1;
}
}
break;
case "left":
if (attackState)
image = RenderableHolder.CKLeftAtk;
image = RenderableHolder.cKLeftAtk;
else {
image = RenderableHolder.CKLeft;
image = RenderableHolder.cKLeft;
if (currentState == "attacking") {
if (gameLogic.getCounter() / 10 % 2 == 1)
image = RenderableHolder.CKLeftWalk1;
image = RenderableHolder.cKLeftWalk1;
}
}
break;
Expand All @@ -52,8 +52,8 @@ public void draw(GraphicsContext gc) {

gc.drawImage(image, screenX, screenY);

drawHitbox(gc);
drawAttackBlock(gc);
// drawHitbox(gc);
// drawAttackBlock(gc);
}


Expand Down
Loading

0 comments on commit 279b537

Please sign in to comment.