Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bin/GUI/Test/TranslatorTester.class
Binary file not shown.
Binary file added bin/GUI/Translator.class
Binary file not shown.
Binary file added bin/Game/ABC/BasicMoveABC.class
Binary file not shown.
Binary file added bin/Game/ABC/GameCharacterABC.class
Binary file not shown.
Binary file added bin/Game/DataPass$AniData.class
Binary file not shown.
Binary file added bin/Game/DataPass$GamePlayerSpeedData.class
Binary file not shown.
Binary file added bin/Game/DataPass$ImageScaleData.class
Binary file not shown.
Binary file added bin/Game/DataPass.class
Binary file not shown.
Binary file removed bin/Game/Factory.class
Binary file not shown.
Binary file modified bin/Game/GameCharacter.class
Binary file not shown.
Binary file added bin/Game/GameElementFactory.class
Binary file not shown.
Binary file added bin/Game/Loader/GameElementLoader.class
Binary file not shown.
Binary file added bin/Game/Loader/ImageLoader.class
Binary file not shown.
Binary file added bin/Game/Loader/ImageNamePath.class
Binary file not shown.
Binary file added bin/Game/PLUG/BasicMoveInterface.class
Binary file not shown.
Binary file added bin/Game/PLUG/GameCharacterInterface.class
Binary file not shown.
Binary file added bin/Game/PLUG/GameRenderInterface.class
Binary file not shown.
Binary file added bin/Game/gameConstant/PlayerState.class
Binary file not shown.
Binary file removed bin/entities/BOOS.class
Binary file not shown.
Binary file removed bin/entities/Methods.class
Binary file not shown.
Binary file removed bin/levels/Level.class
Binary file not shown.
Binary file removed bin/levels/LevelManager.class
Binary file not shown.
Binary file modified bin/logic/input/KeyboardInputs.class
Binary file not shown.
Binary file modified bin/logic/input/MouseInputs.class
Binary file not shown.
Binary file added bin/logic/input/MoveCommand.class
Binary file not shown.
Binary file removed bin/logic/input/MoveCommandConstant.class
Binary file not shown.
Binary file modified bin/main/Game.class
Binary file not shown.
Binary file modified bin/main/GamePanel.class
Binary file not shown.
Binary file added bin/main/Main.class
Binary file not shown.
Binary file removed bin/main/MainClass.class
Binary file not shown.
Binary file removed bin/main/Online.class
Binary file not shown.
Binary file modified bin/main/Translator.class
Binary file not shown.
Binary file added bin/oldVersion/PlayerConstants.class
Binary file not shown.
Binary file added bin/oldVersion/entities/BOOS.class
Binary file not shown.
Binary file not shown.
Binary file added bin/oldVersion/entities/Methods.class
Binary file not shown.
Binary file added bin/oldVersion/entities/Online.class
Binary file not shown.
Binary file not shown.
Binary file removed bin/utilz/Constants$PlayerConstants.class
Binary file not shown.
Binary file removed bin/utilz/Constants.class
Binary file not shown.
Binary file removed bin/utilz/LoadSave.class
Binary file not shown.
53 changes: 53 additions & 0 deletions src/GUI/Test/TranslatorTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package GUI.Test;

import java.awt.Graphics;
import java.util.logging.Logger;

import Game.GameCharacter;
import Game.Loader.GameElementLoader;
import Game.PLUG.GameRenderInterface;
import logic.input.MoveCommand;

public class TranslatorTester implements GameRenderInterface {
private static final Logger LOGGER = Logger.getLogger(TranslatorTester.class.getName());

private GameCharacter player;

public TranslatorTester() {
LOGGER.info("Testing");
player = GameElementLoader.getTestingGameCharacter();

player.init(200, 200);
}

public void updateLogic() {
player.update();
}

public GameCharacter getPlayer() {
return player;
}

public void setPlayMove(MoveCommand moveCmd, boolean move) {
switch (moveCmd) {
case UP -> {
this.player.setUp(move);
}
case LEFT -> {
this.player.setLeft(move);
}
case DOWN -> {
this.player.setDown(move);
}
case RIGHT -> {
this.player.setRight(move);
}
default -> throw new IllegalArgumentException("Unexpected value: " + moveCmd);
}
}

@Override
public void render(Graphics g) {
player.render(g);
}
}
48 changes: 48 additions & 0 deletions src/GUI/Translator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package GUI;

import java.awt.Graphics;

import Game.PLUG.GameRenderInterface;

public class Translator implements GameRenderInterface {

@Override
public void render(Graphics g) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'render'");
}
// private Player player;

// public Translator() {
// player = new Player(200, 200);
// }

// public void updateLogic() {
// player.update();
// }

// public void render(Graphics g) {
// player.render(g);
// }

// public Player getPlayer() {
// return player;
// }

// public void setPlayMove(String moveCmd, boolean move) {
// switch (moveCmd) {
// case MoveCommandConstant.UP -> {
// this.player.setUp(move);
// }
// case MoveCommandConstant.LEFT -> {
// this.player.setLeft(move);
// }
// case MoveCommandConstant.DOWN -> {
// this.player.setDown(move);
// }
// case MoveCommandConstant.RIGHT -> {
// this.player.setRight(move);
// }
// }
// }
}
30 changes: 30 additions & 0 deletions src/Game/ABC/BasicMoveABC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Game.ABC;

import Game.gameConstant.PlayerState;

public abstract class BasicMoveABC {
protected PlayerState playerAction;
protected boolean moving, attacking;
protected float x, y;
protected boolean up, down, right, left;

protected float playerSpeed; // text

public BasicMoveABC() {
this.playerAction = PlayerState.IDLE;
this.moving = false;
this.attacking = false;
}

protected void setPlayerSpeed(float playerSpeed) {
this.playerSpeed = playerSpeed;
}

public BasicMoveABC(PlayerState playerAction, boolean moving, boolean attacking) {
this.playerAction = playerAction;
this.moving = moving;
this.attacking = attacking;
}

public abstract void updatePosition();
}
43 changes: 43 additions & 0 deletions src/Game/ABC/GameCharacterABC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package Game.ABC;

import java.awt.image.BufferedImage;

import Game.DataPass.AniData;
import Game.DataPass.GamePlayerSpeedData;
import Game.DataPass.ImageScaleData;

public abstract class GameCharacterABC extends BasicMoveABC {

protected BufferedImage[][] animations;

protected int aniTick, aniIndex, aniSpeed; // text
protected int imgScaleX, imgScaleY, imageScale; // text

private void setAniThing(AniData aid) {
this.aniTick = aid.aniTick();
this.aniIndex = aid.aniIndex();
this.aniSpeed = aid.aniSpeed();
}

private void setImageScale(ImageScaleData isd) {
this.imgScaleX = isd.imgScaleX();
this.imgScaleY = isd.imgScaleY();
this.imageScale = isd.imageScale();
}

private void setGamePlayerSpeedData(GamePlayerSpeedData gps) {
super.setPlayerSpeed(gps.playSpeed());
}

public GameCharacterABC() {
super();
}

public GameCharacterABC(AniData aid, ImageScaleData isd, GamePlayerSpeedData gps) {
super();

this.setAniThing(aid);
this.setImageScale(isd);
this.setGamePlayerSpeedData(gps);
}
}
17 changes: 17 additions & 0 deletions src/Game/DataPass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Game;

final public class DataPass {

public record AniData(int aniTick, int aniIndex, int aniSpeed) {

}

public record ImageScaleData(int imgScaleX, int imgScaleY, int imageScale) {

}

public record GamePlayerSpeedData(float playSpeed) {

}

}
132 changes: 128 additions & 4 deletions src/Game/GameCharacter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,136 @@
package Game;

import java.awt.Point;
import java.awt.Graphics;
import java.io.IOException;

// for put the game character skin
public class GameCharacter {
Point stayPoint;
import Game.ABC.GameCharacterABC;
import Game.DataPass.AniData;
import Game.DataPass.GamePlayerSpeedData;
import Game.DataPass.ImageScaleData;
import Game.Loader.ImageLoader;
import Game.Loader.ImageNamePath;
import Game.PLUG.GameCharacterInterface;
import Game.PLUG.GameRenderInterface;
import Game.gameConstant.PlayerState;

// for put the game character skin
public class GameCharacter extends GameCharacterABC implements GameCharacterInterface, GameRenderInterface {
public GameCharacter() {
super(null, null, null);
}

public GameCharacter(AniData aid, ImageScaleData isd, GamePlayerSpeedData gps) {
super(aid, isd, gps);
}

public void init(float x, float y) {
this.x = x;
this.y = y;

try {
this.setAnimationImage();
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public void updatePosition() {
this.moving = false;

if (this.left && !this.right) {
this.x -= this.playerSpeed;
moving = true;
} else if (this.right && !this.left) {
this.x += this.playerSpeed;
this.moving = true;
}

if (this.up && !this.down) {
this.y -= this.playerSpeed;
this.moving = true;
} else if (this.down && !this.up) {
this.y += this.playerSpeed;
this.moving = true;
}
}

@Override
public void setUp(boolean up) {
this.up = up;
}

@Override
public void setDown(boolean down) {
this.down = down;
}

@Override
public void setLeft(boolean left) {
this.left = left;
}

@Override
public void setRight(boolean right) {
this.right = right;
}

@Override
public void render(Graphics g) {
this.imgScaleX = animations[this.playerAction.num][this.aniIndex].getWidth() / this.imageScale;
this.imgScaleY = animations[this.playerAction.num][this.aniIndex].getHeight() / this.imageScale;
g.drawImage(animations[this.playerAction.num][this.aniIndex],
(int) this.x, (int) this.y,
this.imgScaleX, this.imgScaleY,
null);
}

@Override
public void setAnimationImage() throws IOException {
this.animations = ImageLoader.loadCharacter(ImageNamePath.PLAYER_MAIN_CHARACTER, 5, 6);
}

@Override
public void setAttacking(boolean attacking) {
this.attacking = attacking;
}

@Override
public void setAnimationState() {

PlayerState startAni = playerAction;

playerAction = (moving ? PlayerState.MOVING : PlayerState.IDLE);

if (attacking) {
aniSpeed = 20;
playerAction = PlayerState.ATTACKING;
}

if (startAni != playerAction) {
aniTick = 0;
aniIndex = 0;
}
}

@Override
public void updateAnimationTick() {
aniTick++;
if (aniTick >= aniSpeed) {
aniTick = 0;
aniIndex++;
if (aniIndex >= playerAction.getAnimationFrameNumbs()) {
aniIndex = 0;
attacking = false;
aniSpeed = 35;
}
}
}

public void update() {
this.updatePosition();
this.updateAnimationTick();
this.setAnimationState();
}

}
4 changes: 2 additions & 2 deletions src/Game/Factory.java → src/Game/GameElementFactory.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Game;

public class Factory {
public Factory() {
public class GameElementFactory {
public GameElementFactory() {

}

Expand Down
22 changes: 22 additions & 0 deletions src/Game/Loader/GameElementLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Game.Loader;

// import Game.GameElementFactory;
import Game.GameCharacter;
import Game.DataPass.AniData;
import Game.DataPass.GamePlayerSpeedData;
import Game.DataPass.ImageScaleData;

// Factory
public class GameElementLoader {

public GameCharacter gameCharacter() {
return null;
}

public static GameCharacter getTestingGameCharacter() {
return new GameCharacter(
new AniData(0, 0, 35),
new ImageScaleData(0, 0, 10),
new GamePlayerSpeedData(5.0f));
}
}
Loading