made map switching possible
This commit is contained in:
@@ -38,7 +38,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
// WORLD SETTINGS
|
// WORLD SETTINGS
|
||||||
public final int maxWorldCol = 50;
|
public final int maxWorldCol = 50;
|
||||||
public final int maxWorldRow = 50;
|
public final int maxWorldRow = 50;
|
||||||
public final Map currentMap = Map.OVERWORLD;
|
public Map currentMap = Map.OVERWORLD;
|
||||||
|
|
||||||
//FPS
|
//FPS
|
||||||
final int FPS = 60;
|
final int FPS = 60;
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ public class AssetSetter {
|
|||||||
panel.npc[Map.OVERWORLD.getIndex()][0] = new OldManNPC(panel);
|
panel.npc[Map.OVERWORLD.getIndex()][0] = new OldManNPC(panel);
|
||||||
panel.npc[Map.OVERWORLD.getIndex()][0].worldX = panel.tileSize*21;
|
panel.npc[Map.OVERWORLD.getIndex()][0].worldX = panel.tileSize*21;
|
||||||
panel.npc[Map.OVERWORLD.getIndex()][0].worldY = panel.tileSize*21;
|
panel.npc[Map.OVERWORLD.getIndex()][0].worldY = panel.tileSize*21;
|
||||||
|
|
||||||
|
panel.npc[Map.HUT.getIndex()][0] = new OldManNPC(panel);
|
||||||
|
panel.npc[Map.HUT.getIndex()][0].worldX = panel.tileSize*12;
|
||||||
|
panel.npc[Map.HUT.getIndex()][0].worldY = panel.tileSize*7;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonster() {
|
public void setMonster() {
|
||||||
|
|||||||
@@ -49,23 +49,27 @@ public class EventHandler {
|
|||||||
if(distance > panel.tileSize) canTouchEvent = true;
|
if(distance > panel.tileSize) canTouchEvent = true;
|
||||||
if(!canTouchEvent) return;
|
if(!canTouchEvent) return;
|
||||||
|
|
||||||
if(hit(27,16, Direction.RIGHT)) damagePit(GameState.DIALOGUE);
|
if(hit(Map.OVERWORLD, 27,16, Direction.RIGHT)) damagePit(GameState.DIALOGUE);
|
||||||
if(hit(23,12, null)) healingPool(GameState.DIALOGUE);
|
else if(hit(Map.OVERWORLD, 23,12, null)) healingPool(GameState.DIALOGUE);
|
||||||
|
|
||||||
|
// HUT
|
||||||
|
else if(hit(Map.OVERWORLD, 10, 39, null)) changeMap(Map.HUT, 12, 13);
|
||||||
|
else if(hit(Map.HUT, 12, 13, null)) changeMap(Map.OVERWORLD, 10, 39);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param reqDirection Set to null if no direction is required
|
* @param reqDirection Set to null if no direction is required
|
||||||
*/
|
*/
|
||||||
public boolean hit(int eventCol, int eventRow, Direction reqDirection) {
|
public boolean hit(Map map, int eventCol, int eventRow, Direction reqDirection) {
|
||||||
boolean hit = false;
|
boolean hit = false;
|
||||||
panel.player.solidArea.x = panel.player.worldX + panel.player.solidArea.x;
|
panel.player.solidArea.x = panel.player.worldX + panel.player.solidArea.x;
|
||||||
panel.player.solidArea.y = panel.player.worldY + panel.player.solidArea.y;
|
panel.player.solidArea.y = panel.player.worldY + panel.player.solidArea.y;
|
||||||
eventRect[panel.currentMap.getIndex()][eventCol][eventRow].x = eventCol*panel.tileSize + eventRect[panel.currentMap.getIndex()][eventCol][eventRow].x;
|
eventRect[map.getIndex()][eventCol][eventRow].x = eventCol*panel.tileSize + eventRect[map.getIndex()][eventCol][eventRow].x;
|
||||||
eventRect[panel.currentMap.getIndex()][eventCol][eventRow].y = eventRow*panel.tileSize + eventRect[panel.currentMap.getIndex()][eventCol][eventRow].y;
|
eventRect[map.getIndex()][eventCol][eventRow].y = eventRow*panel.tileSize + eventRect[map.getIndex()][eventCol][eventRow].y;
|
||||||
if(
|
if(
|
||||||
panel.player.solidArea.intersects(eventRect[panel.currentMap.getIndex()][eventCol][eventRow]) &&
|
panel.player.solidArea.intersects(eventRect[map.getIndex()][eventCol][eventRow]) &&
|
||||||
(reqDirection == null || panel.player.direction == reqDirection) &&
|
(reqDirection == null || panel.player.direction == reqDirection) &&
|
||||||
!eventRect[panel.currentMap.getIndex()][eventCol][eventRow].eventDone
|
!eventRect[map.getIndex()][eventCol][eventRow].eventDone
|
||||||
) {
|
) {
|
||||||
hit = true;
|
hit = true;
|
||||||
prevEventX = panel.player.worldX;
|
prevEventX = panel.player.worldX;
|
||||||
@@ -73,8 +77,8 @@ public class EventHandler {
|
|||||||
}
|
}
|
||||||
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
|
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
|
||||||
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
|
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
|
||||||
eventRect[panel.currentMap.getIndex()][eventCol][eventRow].x = eventRect[panel.currentMap.getIndex()][eventCol][eventRow].eventRectDefaultX;
|
eventRect[map.getIndex()][eventCol][eventRow].x = eventRect[map.getIndex()][eventCol][eventRow].eventRectDefaultX;
|
||||||
eventRect[panel.currentMap.getIndex()][eventCol][eventRow].y = eventRect[panel.currentMap.getIndex()][eventCol][eventRow].eventRectDefaultY;
|
eventRect[map.getIndex()][eventCol][eventRow].y = eventRect[map.getIndex()][eventCol][eventRow].eventRectDefaultY;
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +89,6 @@ public class EventHandler {
|
|||||||
panel.player.life -= 1;
|
panel.player.life -= 1;
|
||||||
canTouchEvent = false;
|
canTouchEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void healingPool(GameState gameState) {
|
public void healingPool(GameState gameState) {
|
||||||
if(!panel.keyH.spacePressed) return;
|
if(!panel.keyH.spacePressed) return;
|
||||||
panel.gameState = gameState;
|
panel.gameState = gameState;
|
||||||
@@ -96,6 +99,15 @@ public class EventHandler {
|
|||||||
canTouchEvent = false;
|
canTouchEvent = false;
|
||||||
panel.assetSetter.setMonster();
|
panel.assetSetter.setMonster();
|
||||||
}
|
}
|
||||||
|
public void changeMap(Map map, int col, int row) {
|
||||||
|
panel.currentMap = map;
|
||||||
|
panel.player.worldX = panel.tileSize*col;
|
||||||
|
panel.player.worldY = panel.tileSize*row;
|
||||||
|
prevEventX = panel.player.worldX;
|
||||||
|
prevEventY = panel.player.worldY;
|
||||||
|
canTouchEvent = false;
|
||||||
|
panel.playSE(13);
|
||||||
|
}
|
||||||
|
|
||||||
static private class EventRect extends Rectangle {
|
static private class EventRect extends Rectangle {
|
||||||
int eventRectDefaultX, eventRectDefaultY;
|
int eventRectDefaultX, eventRectDefaultY;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class Sound {
|
|||||||
load(10, "assets/sounds/burning.wav");
|
load(10, "assets/sounds/burning.wav");
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -46,6 +47,7 @@ public class Sound {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MANAGER
|
||||||
private void load(int index, String path) {
|
private void load(int index, String path) {
|
||||||
try {
|
try {
|
||||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(path));
|
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(path));
|
||||||
@@ -55,11 +57,9 @@ public class Sound {
|
|||||||
Boot.logger.log(Level.SEVERE, "Could not load Sound File: " + soundURL[index], e);
|
Boot.logger.log(Level.SEVERE, "Could not load Sound File: " + soundURL[index], e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
clip.stop();
|
clip.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkVolume() {
|
public void checkVolume() {
|
||||||
switch(volumeScale) {
|
switch(volumeScale) {
|
||||||
case 0 -> volume = -80f;
|
case 0 -> volume = -80f;
|
||||||
|
|||||||
@@ -293,10 +293,8 @@ public class Player extends Entity {
|
|||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
public void setDefaultValues() {
|
public void setDefaultValues() {
|
||||||
// worldX = panel.tileSize * 23;
|
worldX = panel.tileSize * 23;
|
||||||
// worldY = panel.tileSize * 21;
|
worldY = panel.tileSize * 21;
|
||||||
worldX = panel.tileSize * 12;
|
|
||||||
worldY = panel.tileSize * 13;
|
|
||||||
speed = 4;
|
speed = 4;
|
||||||
direction = Direction.DOWN;
|
direction = Direction.DOWN;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user