added some sample events
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
12 12 12 12 12 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 14 15 25 12 12 12 12 12 12 12
|
12 12 12 12 12 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 14 15 25 12 12 12 12 12 12 12
|
||||||
12 12 12 12 13 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 13 12 12 12 12
|
12 12 12 12 13 12 18 41 41 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 13 12 12 12 12
|
||||||
12 12 12 12 12 12 24 15 16 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 12 12 12 12
|
12 12 12 12 12 12 24 15 16 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 12 12 12 12
|
||||||
12 12 12 12 12 12 12 12 18 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 13 12 12 12
|
12 12 12 12 12 12 12 12 18 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 10 10 10 41 41 41 41 41 41 41 41 41 31 26 30 17 12 12 12 12 12 13 12 12 12
|
||||||
12 12 13 12 12 12 12 22 21 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 35 33 34 26 30 17 12 12 13 12 12 12 12 12 12
|
12 12 13 12 12 12 12 22 21 41 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 35 33 34 26 30 17 12 12 13 12 12 12 12 12 12
|
||||||
12 12 12 12 12 12 12 18 10 10 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 26 26 30 17 12 12 12 12 12 12 12 12 12
|
12 12 12 12 12 12 12 18 10 10 10 41 41 41 41 41 41 41 41 41 41 41 31 26 30 41 41 41 41 41 41 41 41 41 41 31 26 26 26 30 17 12 12 12 12 12 12 12 12 12
|
||||||
12 12 12 13 12 12 12 18 10 41 41 41 41 41 41 41 41 41 41 41 41 10 31 26 30 10 41 41 41 41 41 41 41 41 41 31 26 27 28 38 17 12 13 12 12 12 12 12 12 12
|
12 12 12 13 12 12 12 18 10 41 41 41 41 41 41 41 41 41 41 41 41 10 31 26 30 10 41 41 41 41 41 41 41 41 41 31 26 27 28 38 17 12 13 12 12 12 12 12 12 12
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package de.miaurizius.jgame2d.core;
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
import de.miaurizius.jgame2d.core.enums.GameState;
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
import de.miaurizius.jgame2d.core.handlers.AssetSetter;
|
import de.miaurizius.jgame2d.core.handlers.*;
|
||||||
import de.miaurizius.jgame2d.core.handlers.CollisionHandler;
|
|
||||||
import de.miaurizius.jgame2d.core.handlers.KeyHandler;
|
|
||||||
import de.miaurizius.jgame2d.core.handlers.Sound;
|
|
||||||
import de.miaurizius.jgame2d.entity.Entity;
|
import de.miaurizius.jgame2d.entity.Entity;
|
||||||
import de.miaurizius.jgame2d.entity.Player;
|
import de.miaurizius.jgame2d.entity.Player;
|
||||||
import de.miaurizius.jgame2d.object.SuperObject;
|
import de.miaurizius.jgame2d.object.SuperObject;
|
||||||
@@ -43,6 +40,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
public CollisionHandler collisionH = new CollisionHandler(this);
|
public CollisionHandler collisionH = new CollisionHandler(this);
|
||||||
public AssetSetter assetSetter = new AssetSetter(this);
|
public AssetSetter assetSetter = new AssetSetter(this);
|
||||||
public UI ui = new UI(this);
|
public UI ui = new UI(this);
|
||||||
|
public EventHandler eventH = new EventHandler(this);
|
||||||
Thread gameThread;
|
Thread gameThread;
|
||||||
|
|
||||||
// ENTITY AND OBJECT
|
// ENTITY AND OBJECT
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ public enum Direction {
|
|||||||
UP,
|
UP,
|
||||||
DOWN,
|
DOWN,
|
||||||
LEFT,
|
LEFT,
|
||||||
RIGHT;
|
RIGHT
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/de/miaurizius/jgame2d/core/handlers/EventHandler.java
Normal file
59
src/de/miaurizius/jgame2d/core/handlers/EventHandler.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package de.miaurizius.jgame2d.core.handlers;
|
||||||
|
|
||||||
|
import de.miaurizius.jgame2d.core.GamePanel;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.Direction;
|
||||||
|
import de.miaurizius.jgame2d.core.enums.GameState;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EventHandler {
|
||||||
|
|
||||||
|
GamePanel panel;
|
||||||
|
Rectangle eventRect;
|
||||||
|
int eventRectDefaultX, eventRectDefaultY;
|
||||||
|
|
||||||
|
public EventHandler(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
|
||||||
|
eventRect = new Rectangle();
|
||||||
|
eventRect.x = 23;
|
||||||
|
eventRect.y = 23;
|
||||||
|
eventRect.width = 2;
|
||||||
|
eventRect.height = 2;
|
||||||
|
eventRectDefaultX = eventRect.x;
|
||||||
|
eventRectDefaultY = eventRect.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkEvent() {
|
||||||
|
if(hit(27,16, Direction.RIGHT)) damagePit(GameState.DIALOGUE);
|
||||||
|
if(hit(23,12, Direction.UP)) healingPool(GameState.DIALOGUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hit(int eventCol, int eventRow, Direction reqDirection) {
|
||||||
|
boolean hit = false;
|
||||||
|
panel.player.solidArea.x = panel.player.worldX + panel.player.solidArea.x;
|
||||||
|
panel.player.solidArea.y = panel.player.worldY + panel.player.solidArea.y;
|
||||||
|
eventRect.x = eventCol*panel.tileSize + eventRect.x;
|
||||||
|
eventRect.y = eventRow*panel.tileSize + eventRect.y;
|
||||||
|
if(panel.player.solidArea.intersects(eventRect)) if(reqDirection == null || panel.player.direction == reqDirection) hit = true;
|
||||||
|
panel.player.solidArea.x = panel.player.solidAreaDefaultX;
|
||||||
|
panel.player.solidArea.y = panel.player.solidAreaDefaultY;
|
||||||
|
eventRect.x = eventRectDefaultX;
|
||||||
|
eventRect.y = eventRectDefaultY;
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void damagePit(GameState gameState) {
|
||||||
|
panel.gameState = gameState;
|
||||||
|
panel.ui.currentDialogue = "You have fallen into a pit!";
|
||||||
|
panel.player.life -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void healingPool(GameState gameState) {
|
||||||
|
if(!panel.keyH.spacePressed) return;
|
||||||
|
panel.gameState = gameState;
|
||||||
|
panel.ui.currentDialogue = "You drank the holy water.\nYour life has been recovered!";
|
||||||
|
panel.player.life = panel.player.maxLife;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -75,6 +75,11 @@ public class Player extends Entity {
|
|||||||
int npcIndex = panel.collisionH.checkEntity(this, panel.npc);
|
int npcIndex = panel.collisionH.checkEntity(this, panel.npc);
|
||||||
interactNPC(npcIndex);
|
interactNPC(npcIndex);
|
||||||
|
|
||||||
|
// CHECK EVENT
|
||||||
|
panel.eventH.checkEvent();
|
||||||
|
|
||||||
|
panel.keyH.spacePressed = false;
|
||||||
|
|
||||||
if(!collisionOn) {
|
if(!collisionOn) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case UP -> worldY -= speed;
|
case UP -> worldY -= speed;
|
||||||
@@ -103,7 +108,6 @@ public class Player extends Entity {
|
|||||||
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
//if(!panel.keyH.spacePressed) return; //Only uncomment if text should only appear if player hits space
|
||||||
panel.gameState = GameState.DIALOGUE;
|
panel.gameState = GameState.DIALOGUE;
|
||||||
panel.npc[index].speak();
|
panel.npc[index].speak();
|
||||||
panel.keyH.spacePressed = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D graphics2d) {
|
public void draw(Graphics2D graphics2d) {
|
||||||
|
|||||||
Reference in New Issue
Block a user