added trigger event cells

This commit is contained in:
musilto9 2020-03-13 22:56:42 +01:00
parent 48c17f5c92
commit 3af9f48386
6 changed files with 93 additions and 14 deletions

View File

@ -1,9 +1,9 @@
package ruscz.game.gameOfProd.Cells;
import ruscz.game.gameOfProd.Cells.Cell;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Image.ImageCell;
import ruscz.game.gameOfProd.Image.ImageDialog;
import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*;
@ -77,4 +77,8 @@ public class InteractionCell extends Cell {
g.drawImage(imageCell.getImagesOfTiles().get(334), getX() * WindowOfFreeMove.CELL_SIZE,
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
}
public ImageCell getImageCell() {
return imageCell;
}
}

View File

@ -88,15 +88,18 @@ public class Person extends Cell {
else if (isEventInFront(x,y,directionSight) && isInEvent) {
map.findInteractionByXY(x, y, directionSight).readNextLine();
}
else if (map.isActiveTriggerCell(x,y) && isInEvent) {
map.findTriggerByXY(x,y).readNextLine();
}
break;
}
if (directionMove != 69) {
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
if (directionMove != 0 && !map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) {
directionMoveLast = directionMove;
isMoving = true;
} else if (directionMove != 0 && map.isBusyCell(x, y)) {
directionMoveLast = 0;
} else if (directionMove != 0 && map.isCellEvent(x, y)) {
} else if (directionMove != 0 && map.isInteractionCell(x, y)) {
directionMoveLast = 0;
}
if (map.isCellMoveTo(x, y)) {
@ -106,13 +109,19 @@ public class Person extends Cell {
map.findEventByXY(x, y).moveToMap();
}
} else {
if (!map.isBusyCell(x, y) && !map.isCellEvent(x, y)) {
if (!map.isBusyCell(x, y) && !map.isInteractionCell(x, y)) {
set(x, y);
}
}
}
directionMove = 0;
if (map.isActiveTriggerCell(x,y) && !isInEvent) {
isInEvent = true;
WindowOfFreeMove.setNextMove(WindowOfFreeMove.KEY_EVENT);
map.findTriggerByXY(x,y).startEvent();
}
}
}
@ -131,7 +140,7 @@ public class Person extends Cell {
y++;
break;
}
return map.isCellEvent(x, y);
return map.isInteractionCell(x, y);
}
public void stopPerson(){

View File

@ -0,0 +1,33 @@
package ruscz.game.gameOfProd.Cells;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Image.ImageCell;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*;
public class TriggerCell extends InteractionCell {
private boolean isActive;
public TriggerCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) {
super(x, y, message, dialog, imageCell);
this.isActive = true;
}
@Override
public void endEvent() {
super.endEvent();
this.isActive = false;
}
@Override
public void paint(Graphics2D g) {
super.paint(g);
g.drawImage(super.getImageCell().getImagesOfTiles().get(147), getX() * WindowOfFreeMove.CELL_SIZE,
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
}
public boolean getActive() { return isActive; }
public void setActive(boolean isActive) { this.isActive = isActive; }
}

View File

@ -12,7 +12,8 @@ public class Map {
private Person person;
private LinkedList<EventMoveToCell> moveToCells;
private LinkedList<Block> block;
private LinkedList<InteractionCell> eventCells;
private LinkedList<InteractionCell> interactionCells;
private LinkedList<TriggerCell> triggerCells;
private boolean isBlocked;
private int idExit;
private ImageCell imageCell;
@ -22,7 +23,8 @@ public class Map {
idExit = 0;
mapArray = new TypeOfCell[height][width];
moveToCells = new LinkedList<EventMoveToCell>();
eventCells = new LinkedList<InteractionCell>();
interactionCells = new LinkedList<InteractionCell>();
triggerCells = new LinkedList<TriggerCell>();
block = new LinkedList<Block>();
isBlocked = false;
imageCell = new ImageCell();
@ -50,7 +52,8 @@ public class Map {
idExit = 0;
moveToCells = new LinkedList<EventMoveToCell>();
block = new LinkedList<Block>();
eventCells = new LinkedList<InteractionCell>();
interactionCells = new LinkedList<InteractionCell>();
triggerCells = new LinkedList<TriggerCell>();
mapArray = new TypeOfCell[height][width];
this.isBlocked = isBlocked;
imageCell = new ImageCell();
@ -84,7 +87,12 @@ public class Map {
public void addInteractionEvent(InteractionCell interactionCell) {
mapArray[interactionCell.getX()][interactionCell.getY()] = TypeOfCell.EVENT;
eventCells.add(interactionCell);
interactionCells.add(interactionCell);
}
public void addInteractionEvent(TriggerCell triggerCell) {
mapArray[triggerCell.getX()][triggerCell.getY()] = TypeOfCell.EVENT;
triggerCells.add(triggerCell);
}
public void setName(String name) {
@ -112,7 +120,7 @@ public class Map {
}
public LinkedList<InteractionCell> getInteractionEventCells() {
return eventCells;
return interactionCells;
}
public void setIdExit(int id) {
@ -197,13 +205,20 @@ public class Map {
return false;
}
public boolean isCellEvent(int x, int y) {
for (InteractionCell cell : eventCells)
public boolean isInteractionCell(int x, int y) {
for (InteractionCell cell : interactionCells)
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.InteractionCell"))
return true;
return false;
}
public boolean isActiveTriggerCell(int x, int y) {
for (TriggerCell cell : triggerCells)
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.TriggerCell") && cell.getActive())
return true;
return false;
}
public EventMoveToCell findEventByXY(int x, int y) {
for (EventMoveToCell cell : moveToCells)
if (x == cell.getX() && y == cell.getY())
@ -226,9 +241,16 @@ public class Map {
y++;
break;
}
for (InteractionCell cell : eventCells)
for (InteractionCell cell : interactionCells)
if (x == cell.getX() && y == cell.getY())
return cell;
return eventCells.getFirst();
return interactionCells.getFirst();
}
public TriggerCell findTriggerByXY(int x, int y) {
for (TriggerCell cell : triggerCells)
if (x == cell.getX() && y == cell.getY())
return cell;
return triggerCells.getFirst();
}
}

View File

@ -2,6 +2,7 @@ package ruscz.game.gameOfProd.Windows;
import ruscz.game.gameOfProd.Cells.Cell;
import ruscz.game.gameOfProd.Cells.EventMoveToCell;
import ruscz.game.gameOfProd.Cells.InteractionCell;
import ruscz.game.gameOfProd.Cells.TriggerCell;
import ruscz.game.gameOfProd.Dialog.Dialog;
import ruscz.game.gameOfProd.Dialog.DialogBar;
import ruscz.game.gameOfProd.Map.Map;
@ -55,6 +56,8 @@ public class WindowOfFreeMove extends JFrame {
this.map.createMap();
}
public static void setNextMove(int nextMove) { WindowOfFreeMove.nextMove = nextMove; }
public WindowOfFreeMove() {
isReadyToPaint = false;
canPersonMove = true;
@ -153,6 +156,7 @@ public class WindowOfFreeMove extends JFrame {
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
m1.addInteractionEvent(new InteractionCell(3,5,"first-dialog", new Dialog(dialogBar), m1.getImageCell()));
m1.addInteractionEvent(new InteractionCell(5, 5, "dialog-test", new Dialog(dialogBar), m1.getImageCell()));
m1.addInteractionEvent(new TriggerCell(7,5,"second-dialog", new Dialog(dialogBar), m1.getImageCell()));
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));

View File

@ -0,0 +1,7 @@
Cop: Turn around!
Me: every now and then I get a little bit lonely,
and you're never comming 'round
Cop: Turn around!
Me: every now and then...
*gets tazed*
<end>