add Tent object and implement sleep functionality with lighting adjustments
This commit is contained in:
@@ -4,6 +4,7 @@ import de.miaurizius.jgame2d.core.enums.GameState;
|
|||||||
import de.miaurizius.jgame2d.entity.Entity;
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
import de.miaurizius.jgame2d.entity.item.CoinObj;
|
import de.miaurizius.jgame2d.entity.item.CoinObj;
|
||||||
import de.miaurizius.jgame2d.entity.item.HeartObj;
|
import de.miaurizius.jgame2d.entity.item.HeartObj;
|
||||||
|
import de.miaurizius.jgame2d.environment.Lighting;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -25,7 +26,8 @@ public class UI {
|
|||||||
public int commandNum;
|
public int commandNum;
|
||||||
public int playerSlotCol, playerSlotRow;
|
public int playerSlotCol, playerSlotRow;
|
||||||
public int npcSlotCol, npcSlotRow;
|
public int npcSlotCol, npcSlotRow;
|
||||||
private int transCounter;
|
private int transCount;
|
||||||
|
private int sleepCount;
|
||||||
|
|
||||||
// SUB-STATES
|
// SUB-STATES
|
||||||
public TradeState tradeState = TradeState.SELECT;
|
public TradeState tradeState = TradeState.SELECT;
|
||||||
@@ -64,6 +66,7 @@ public class UI {
|
|||||||
case GAMEOVER -> drawGameOverScreen();
|
case GAMEOVER -> drawGameOverScreen();
|
||||||
case TRANSITION -> drawTransitionScreen();
|
case TRANSITION -> drawTransitionScreen();
|
||||||
case TRADE -> drawTradeScreen();
|
case TRADE -> drawTradeScreen();
|
||||||
|
case SLEEP -> drawSleepScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,11 +378,11 @@ public class UI {
|
|||||||
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
|
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
|
||||||
}
|
}
|
||||||
private void drawTransitionScreen() {
|
private void drawTransitionScreen() {
|
||||||
transCounter++;
|
transCount++;
|
||||||
graphics2d.setColor(new Color(0,0,0, transCounter*5));
|
graphics2d.setColor(new Color(0,0,0, transCount *5));
|
||||||
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
|
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
|
||||||
if(transCounter != 50) return;
|
if(transCount != 50) return;
|
||||||
transCounter = 0;
|
transCount = 0;
|
||||||
panel.gameState = GameState.PLAY;
|
panel.gameState = GameState.PLAY;
|
||||||
panel.currentMap = panel.eventH.tempMap;
|
panel.currentMap = panel.eventH.tempMap;
|
||||||
panel.player.worldX = panel.tileSize * panel.eventH.tempCol;
|
panel.player.worldX = panel.tileSize * panel.eventH.tempCol;
|
||||||
@@ -395,6 +398,22 @@ public class UI {
|
|||||||
}
|
}
|
||||||
panel.keyH.spacePressed = false;
|
panel.keyH.spacePressed = false;
|
||||||
}
|
}
|
||||||
|
private void drawSleepScreen() {
|
||||||
|
sleepCount++;
|
||||||
|
if(sleepCount < 120) {
|
||||||
|
panel.eManager.lighting.filterAlpha += 0.01F;
|
||||||
|
if(panel.eManager.lighting.filterAlpha >= 1F) panel.eManager.lighting.filterAlpha = 1F;
|
||||||
|
}
|
||||||
|
if(sleepCount >= 120) {
|
||||||
|
panel.eManager.lighting.filterAlpha -= 0.01F;
|
||||||
|
if(panel.eManager.lighting.filterAlpha <= 0F) {
|
||||||
|
panel.eManager.lighting.filterAlpha = 0F;
|
||||||
|
sleepCount = 0;
|
||||||
|
panel.eManager.lighting.dayState = Lighting.DayState.DAY;
|
||||||
|
panel.gameState = GameState.PLAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TRADING
|
// TRADING
|
||||||
private void tradeSelect() {
|
private void tradeSelect() {
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ public enum GameState {
|
|||||||
GAMEOVER,
|
GAMEOVER,
|
||||||
TRANSITION,
|
TRANSITION,
|
||||||
TRADE,
|
TRADE,
|
||||||
|
SLEEP,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,25 +40,15 @@ public class AssetSetter {
|
|||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*28;
|
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*28;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
// panel.obj[Map.OVERWORLD.getIndex()][i] = new LanternObj(panel);
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*21;
|
// panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*18;
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
// panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
||||||
i++;
|
// i++;
|
||||||
|
//
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
// panel.obj[Map.OVERWORLD.getIndex()][i] = new TentObj(panel);
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*20;
|
// panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*19;
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
// panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
||||||
i++;
|
// i++;
|
||||||
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*17;
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*21;
|
|
||||||
i++;
|
|
||||||
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new LanternObj(panel);
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*18;
|
|
||||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNPC() {
|
public void setNPC() {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class Sound {
|
|||||||
load(11, "assets/sounds/cuttree.wav");
|
load(11, "assets/sounds/cuttree.wav");
|
||||||
load(12, "assets/sounds/gameover.wav");
|
load(12, "assets/sounds/gameover.wav");
|
||||||
load(13, "assets/sounds/stairs.wav");
|
load(13, "assets/sounds/stairs.wav");
|
||||||
|
load(14, "assets/sounds/sleep.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
30
src/de/miaurizius/jgame2d/entity/item/TentObj.java
Normal file
30
src/de/miaurizius/jgame2d/entity/item/TentObj.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package de.miaurizius.jgame2d.entity.item;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.EntityType;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
|
|
||||||
|
public class TentObj extends Entity {
|
||||||
|
|
||||||
|
public TentObj(GamePanel panel) {
|
||||||
|
super(panel);
|
||||||
|
|
||||||
|
type = EntityType.ITEM;
|
||||||
|
consumable = true;
|
||||||
|
name = "Tent";
|
||||||
|
down1 = initEntitySprites("objects/tent");
|
||||||
|
description = "[" + name + "]\nA small tent to rest\nuntil next morning.";
|
||||||
|
price = 200;
|
||||||
|
stackable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean use(Entity entity) {
|
||||||
|
panel.gameState = GameState.SLEEP;
|
||||||
|
panel.playSE(14);
|
||||||
|
panel.player.life = panel.player.maxLife;
|
||||||
|
panel.player.mana = panel.player.maxMana;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,8 @@ public class MerchantNPC extends Entity {
|
|||||||
inventory.add(new AxeObj(panel));
|
inventory.add(new AxeObj(panel));
|
||||||
inventory.add(new ShieldWoodObj(panel));
|
inventory.add(new ShieldWoodObj(panel));
|
||||||
inventory.add(new IronShieldObj(panel));
|
inventory.add(new IronShieldObj(panel));
|
||||||
|
inventory.add(new LanternObj(panel));
|
||||||
|
inventory.add(new TentObj(panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ public class OldManNPC extends Entity {
|
|||||||
|
|
||||||
public void setAction() {
|
public void setAction() {
|
||||||
|
|
||||||
if(onPath) {
|
// if(onPath) {
|
||||||
searchPath(12, 9);
|
// searchPath(12, 9);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
actionLock++;
|
actionLock++;
|
||||||
if(actionLock != 120) return; //lock action for x frames
|
if(actionLock != 120) return; //lock action for x frames
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.awt.*;
|
|||||||
public class EnvironmentManager {
|
public class EnvironmentManager {
|
||||||
|
|
||||||
GamePanel panel;
|
GamePanel panel;
|
||||||
Lighting lighting;
|
public Lighting lighting;
|
||||||
|
|
||||||
public EnvironmentManager(GamePanel panel) {
|
public EnvironmentManager(GamePanel panel) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ public class Lighting {
|
|||||||
GamePanel panel;
|
GamePanel panel;
|
||||||
BufferedImage darknessFilter;
|
BufferedImage darknessFilter;
|
||||||
int dayCount;
|
int dayCount;
|
||||||
float filterAlpha;
|
public DayState dayState = DayState.DAY;
|
||||||
DayState dayState = DayState.DAY;
|
public float filterAlpha;
|
||||||
|
|
||||||
public Lighting(GamePanel panel) {
|
public Lighting(GamePanel panel) {
|
||||||
this.panel = panel;
|
this.panel = panel;
|
||||||
@@ -47,7 +47,7 @@ public class Lighting {
|
|||||||
switch (dayState) {
|
switch (dayState) {
|
||||||
case DAY -> {
|
case DAY -> {
|
||||||
dayCount++;
|
dayCount++;
|
||||||
if (dayCount > 600) { //10 seconds
|
if (dayCount > 36000) { //10 minutes
|
||||||
dayState = DayState.DUSK;
|
dayState = DayState.DUSK;
|
||||||
dayCount = 0;
|
dayCount = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user