arranged large classes
This commit is contained in:
@@ -50,21 +50,7 @@ public class Entity {
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
public void setAction() {}
|
||||
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
dialogueIndex++;
|
||||
|
||||
switch(panel.player.direction) {
|
||||
case UP -> direction = Direction.DOWN;
|
||||
case DOWN -> direction = Direction.UP;
|
||||
case LEFT -> direction = Direction.RIGHT;
|
||||
case RIGHT -> direction = Direction.LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
// DEFAULT
|
||||
public void update() {
|
||||
setAction();
|
||||
collisionOn = false;
|
||||
@@ -97,7 +83,6 @@ public class Entity {
|
||||
spriteCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||
@@ -111,6 +96,22 @@ public class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
// INTERACTION
|
||||
public void speak() {
|
||||
if(dialogue[dialogueIndex] == null) dialogueIndex = 0;
|
||||
panel.ui.currentDialogue = dialogue[dialogueIndex];
|
||||
dialogueIndex++;
|
||||
|
||||
switch(panel.player.direction) {
|
||||
case UP -> direction = Direction.DOWN;
|
||||
case DOWN -> direction = Direction.UP;
|
||||
case LEFT -> direction = Direction.RIGHT;
|
||||
case RIGHT -> direction = Direction.LEFT;
|
||||
}
|
||||
}
|
||||
public void setAction() {}
|
||||
|
||||
// SETTING THINGS UP
|
||||
BufferedImage parseSprite() {
|
||||
return switch (direction) {
|
||||
case UP -> (spriteNum == 1) ? up1 : up2;
|
||||
@@ -119,7 +120,6 @@ public class Entity {
|
||||
case RIGHT -> (spriteNum == 1) ? right1 : right2;
|
||||
};
|
||||
}
|
||||
|
||||
BufferedImage parseSpriteATK() {
|
||||
return switch (direction) {
|
||||
case UP -> (spriteNum == 1) ? attackUp1 : attackUp2;
|
||||
@@ -128,7 +128,6 @@ public class Entity {
|
||||
case RIGHT -> (spriteNum == 1) ? attackRight1 : attackRight2;
|
||||
};
|
||||
}
|
||||
|
||||
public BufferedImage initEntitySprites(String name) {
|
||||
try {
|
||||
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), panel.tileSize, panel.tileSize);
|
||||
@@ -137,7 +136,6 @@ public class Entity {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BufferedImage initEntitySprites(String name, int width, int height) {
|
||||
try {
|
||||
return Utility.scaleImage(ImageIO.read(new FileInputStream("assets/" + name + ".png")), width, height);
|
||||
|
||||
@@ -38,17 +38,7 @@ public class Player extends Entity {
|
||||
getPlayerAttackImage();
|
||||
}
|
||||
|
||||
public void setDefaultValues() {
|
||||
worldX = panel.tileSize * 23;
|
||||
worldY = panel.tileSize * 21;
|
||||
speed = 4;
|
||||
direction = Direction.DOWN;
|
||||
|
||||
// PLAYER STATUS (1 heart = 2 lives)
|
||||
maxLife = 6;
|
||||
life = maxLife;
|
||||
}
|
||||
|
||||
// DEFAULT
|
||||
public void update() {
|
||||
if(attacking) {
|
||||
attacking();
|
||||
@@ -108,7 +98,33 @@ public class Player extends Entity {
|
||||
invincibleCount = 0;
|
||||
}
|
||||
}
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||
|
||||
if(invincible) {
|
||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
|
||||
}
|
||||
|
||||
if(attacking) graphics2d.drawImage(parseSpriteATK(),
|
||||
(direction == Direction.LEFT) ? screenX - panel.tileSize : screenX,
|
||||
(direction == Direction.UP) ? screenY - panel.tileSize : screenY, null);
|
||||
else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
|
||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
|
||||
}
|
||||
|
||||
// INTERACTION
|
||||
public void pickObject(int index) {
|
||||
if(index == 999) return;
|
||||
}
|
||||
|
||||
public void interactMonster(int index) {
|
||||
if(index == 999) return;
|
||||
if(invincible) return;
|
||||
life -= 1;
|
||||
invincible = true;
|
||||
}
|
||||
public void attacking() {
|
||||
spriteCounter++;
|
||||
if(spriteCounter <= 5) spriteNum = 1;
|
||||
@@ -143,31 +159,10 @@ public class Player extends Entity {
|
||||
attacking = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void damageMonster(int index) {
|
||||
if(index == 999) return;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphics2d) {
|
||||
int screenX = worldX - panel.player.worldX + panel.player.screenX;
|
||||
int screenY = worldY - panel.player.worldY + panel.player.screenY;
|
||||
|
||||
if(invincible) {
|
||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
|
||||
}
|
||||
|
||||
if(attacking) graphics2d.drawImage(parseSpriteATK(),
|
||||
(direction == Direction.LEFT) ? screenX - panel.tileSize : screenX,
|
||||
(direction == Direction.UP) ? screenY - panel.tileSize : screenY, null);
|
||||
else graphics2d.drawImage(parseSprite(), screenX, screenY, null);
|
||||
|
||||
graphics2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
|
||||
}
|
||||
|
||||
public void pickObject(int index) {
|
||||
if(index == 999) return;
|
||||
}
|
||||
|
||||
public void interactNPC(int index) {
|
||||
if(index == 999) {
|
||||
if(panel.keyH.spacePressed) attacking = true;
|
||||
@@ -177,19 +172,22 @@ public class Player extends Entity {
|
||||
panel.gameState = GameState.DIALOGUE;
|
||||
panel.npc[index].speak();
|
||||
}
|
||||
|
||||
public void interactMonster(int index) {
|
||||
if(index == 999) return;
|
||||
if(invincible) return;
|
||||
life -= 1;
|
||||
invincible = true;
|
||||
}
|
||||
|
||||
public void speak() {
|
||||
//This method only exists for character specific things later...
|
||||
super.speak();
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
public void setDefaultValues() {
|
||||
worldX = panel.tileSize * 23;
|
||||
worldY = panel.tileSize * 21;
|
||||
speed = 4;
|
||||
direction = Direction.DOWN;
|
||||
|
||||
// PLAYER STATUS (1 heart = 2 lives)
|
||||
maxLife = 6;
|
||||
life = maxLife;
|
||||
}
|
||||
public void getPlayerImage() {
|
||||
up1 = initEntitySprites("player/boy_up_1");
|
||||
up2 = initEntitySprites("player/boy_up_2");
|
||||
@@ -200,7 +198,6 @@ public class Player extends Entity {
|
||||
right1 = initEntitySprites("player/boy_right_1");
|
||||
right2 = initEntitySprites("player/boy_right_2");
|
||||
}
|
||||
|
||||
public void getPlayerAttackImage() {
|
||||
attackUp1 = initEntitySprites("player/attack/boy_attack_up_1", panel.tileSize, panel.tileSize*2);
|
||||
attackUp2 = initEntitySprites("player/attack/boy_attack_up_2", panel.tileSize, panel.tileSize*2);
|
||||
|
||||
@@ -27,17 +27,7 @@ public class GreenSlimeMON extends Entity {
|
||||
getImage();
|
||||
}
|
||||
|
||||
public void getImage() {
|
||||
up1 = initEntitySprites("monster/greenslime_down_1");
|
||||
up2 = initEntitySprites("monster/greenslime_down_2");
|
||||
down1 = initEntitySprites("monster/greenslime_down_1");
|
||||
down2 = initEntitySprites("monster/greenslime_down_2");
|
||||
left1 = initEntitySprites("monster/greenslime_down_1");
|
||||
left2 = initEntitySprites("monster/greenslime_down_2");
|
||||
right1 = initEntitySprites("monster/greenslime_down_1");
|
||||
right2 = initEntitySprites("monster/greenslime_down_2");
|
||||
}
|
||||
|
||||
// INTERACTION
|
||||
public void setAction() {
|
||||
actionLock++;
|
||||
if(actionLock != 120) return; //lock action for x frames
|
||||
@@ -50,4 +40,16 @@ public class GreenSlimeMON extends Entity {
|
||||
actionLock = 0;
|
||||
}
|
||||
|
||||
// SETTING THINGS UP
|
||||
public void getImage() {
|
||||
up1 = initEntitySprites("monster/greenslime_down_1");
|
||||
up2 = initEntitySprites("monster/greenslime_down_2");
|
||||
down1 = initEntitySprites("monster/greenslime_down_1");
|
||||
down2 = initEntitySprites("monster/greenslime_down_2");
|
||||
left1 = initEntitySprites("monster/greenslime_down_1");
|
||||
left2 = initEntitySprites("monster/greenslime_down_2");
|
||||
right1 = initEntitySprites("monster/greenslime_down_1");
|
||||
right2 = initEntitySprites("monster/greenslime_down_2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user