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.item.CoinObj;
|
||||
import de.miaurizius.jgame2d.entity.item.HeartObj;
|
||||
import de.miaurizius.jgame2d.environment.Lighting;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -25,7 +26,8 @@ public class UI {
|
||||
public int commandNum;
|
||||
public int playerSlotCol, playerSlotRow;
|
||||
public int npcSlotCol, npcSlotRow;
|
||||
private int transCounter;
|
||||
private int transCount;
|
||||
private int sleepCount;
|
||||
|
||||
// SUB-STATES
|
||||
public TradeState tradeState = TradeState.SELECT;
|
||||
@@ -64,6 +66,7 @@ public class UI {
|
||||
case GAMEOVER -> drawGameOverScreen();
|
||||
case TRANSITION -> drawTransitionScreen();
|
||||
case TRADE -> drawTradeScreen();
|
||||
case SLEEP -> drawSleepScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,11 +378,11 @@ public class UI {
|
||||
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
|
||||
}
|
||||
private void drawTransitionScreen() {
|
||||
transCounter++;
|
||||
graphics2d.setColor(new Color(0,0,0, transCounter*5));
|
||||
transCount++;
|
||||
graphics2d.setColor(new Color(0,0,0, transCount *5));
|
||||
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
|
||||
if(transCounter != 50) return;
|
||||
transCounter = 0;
|
||||
if(transCount != 50) return;
|
||||
transCount = 0;
|
||||
panel.gameState = GameState.PLAY;
|
||||
panel.currentMap = panel.eventH.tempMap;
|
||||
panel.player.worldX = panel.tileSize * panel.eventH.tempCol;
|
||||
@@ -395,6 +398,22 @@ public class UI {
|
||||
}
|
||||
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
|
||||
private void tradeSelect() {
|
||||
|
||||
@@ -13,5 +13,6 @@ public enum GameState {
|
||||
GAMEOVER,
|
||||
TRANSITION,
|
||||
TRADE,
|
||||
SLEEP,
|
||||
|
||||
}
|
||||
|
||||
@@ -40,25 +40,15 @@ public class AssetSetter {
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*28;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*21;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
||||
i++;
|
||||
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i] = new PotionObj(panel);
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*20;
|
||||
panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
||||
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++;
|
||||
// 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++;
|
||||
//
|
||||
// panel.obj[Map.OVERWORLD.getIndex()][i] = new TentObj(panel);
|
||||
// panel.obj[Map.OVERWORLD.getIndex()][i].worldX = panel.tileSize*19;
|
||||
// panel.obj[Map.OVERWORLD.getIndex()][i].worldY = panel.tileSize*20;
|
||||
// i++;
|
||||
}
|
||||
|
||||
public void setNPC() {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Sound {
|
||||
load(11, "assets/sounds/cuttree.wav");
|
||||
load(12, "assets/sounds/gameover.wav");
|
||||
load(13, "assets/sounds/stairs.wav");
|
||||
load(14, "assets/sounds/sleep.wav");
|
||||
}
|
||||
|
||||
@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 ShieldWoodObj(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() {
|
||||
|
||||
if(onPath) {
|
||||
searchPath(12, 9);
|
||||
return;
|
||||
}
|
||||
// if(onPath) {
|
||||
// searchPath(12, 9);
|
||||
// return;
|
||||
// }
|
||||
|
||||
actionLock++;
|
||||
if(actionLock != 120) return; //lock action for x frames
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.awt.*;
|
||||
public class EnvironmentManager {
|
||||
|
||||
GamePanel panel;
|
||||
Lighting lighting;
|
||||
public Lighting lighting;
|
||||
|
||||
public EnvironmentManager(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
|
||||
@@ -10,8 +10,8 @@ public class Lighting {
|
||||
GamePanel panel;
|
||||
BufferedImage darknessFilter;
|
||||
int dayCount;
|
||||
float filterAlpha;
|
||||
DayState dayState = DayState.DAY;
|
||||
public DayState dayState = DayState.DAY;
|
||||
public float filterAlpha;
|
||||
|
||||
public Lighting(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
@@ -47,7 +47,7 @@ public class Lighting {
|
||||
switch (dayState) {
|
||||
case DAY -> {
|
||||
dayCount++;
|
||||
if (dayCount > 600) { //10 seconds
|
||||
if (dayCount > 36000) { //10 minutes
|
||||
dayState = DayState.DUSK;
|
||||
dayCount = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user