Skip to content
Snippets Groups Projects
Commit 28819087 authored by aarnereime's avatar aarnereime
Browse files

La til en interactable option når du er nær npc'en som sier at du kan holde x...

La til en interactable option når du er nær npc'en som sier at du kan holde x for å snakke med han. Gjør det litt lettere for spillere å vite at man kan kommunisere med npc'ene
parent cebdf2ca
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ public class NPC implements IGameObject{ ...@@ -13,6 +13,7 @@ public class NPC implements IGameObject{
private int gravity = 5; private int gravity = 5;
public int runCounter = 0; public int runCounter = 0;
public boolean canMoveDown = true; public boolean canMoveDown = true;
public boolean interactableOption = false;
public boolean interactable; public boolean interactable;
public int direction = -1; public int direction = -1;
...@@ -115,4 +116,19 @@ public class NPC implements IGameObject{ ...@@ -115,4 +116,19 @@ public class NPC implements IGameObject{
gc.restore(); gc.restore();
} }
public void drawInteractableOption(GraphicsContext gc, double w, double h) {
int width = 300;
int height = 80;
double x = w/2 - width/2;
double y = h/3.5 - height/2;
gc.setFill(Color.rgb(0, 0, 0, 0.8));
gc.fillRoundRect(x, y, width, height, 35, 35);
gc.setFill(Color.WHITE);
gc.setFont(new Font("Comic sans MS", 20));
gc.fillText("Hold x to interact with npc", x + 20, y + 50);
gc.restore();
}
} }
...@@ -147,8 +147,6 @@ public class Game extends Application { ...@@ -147,8 +147,6 @@ public class Game extends Application {
ListTrees.add(new Tree(296, 315, "tree")); ListTrees.add(new Tree(296, 315, "tree"));
ListTrees.add(new Tree(900, 385, "tree")); ListTrees.add(new Tree(900, 385, "tree"));
ListNPC.add(new NPC(500, 315));
ListPlatforms.add(new Platform(200, 480, 100, 100, "grass")); ListPlatforms.add(new Platform(200, 480, 100, 100, "grass"));
ListPlatforms.add(new Platform(296, 480, 100, 100, "grass")); ListPlatforms.add(new Platform(296, 480, 100, 100, "grass"));
...@@ -176,6 +174,8 @@ public class Game extends Application { ...@@ -176,6 +174,8 @@ public class Game extends Application {
idx2 += 96; idx2 += 96;
} }
ListNPC.add(new NPC(2000, 100));
int idx3 = 1696; int idx3 = 1696;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
ListPlatforms.add(new Platform(idx3, 480, 100, 100, "grass")); ListPlatforms.add(new Platform(idx3, 480, 100, 100, "grass"));
...@@ -348,9 +348,11 @@ public class Game extends Application { ...@@ -348,9 +348,11 @@ public class Game extends Application {
npc.idle(); npc.idle();
if (cd.checkCollision(player, npc, "left") || cd.checkCollision(player, npc, "right") || if (cd.checkCollision(player, npc, "left") || cd.checkCollision(player, npc, "right") ||
cd.checkCollision(player, npc, "up") || cd.checkCollision(player, npc, "down")) { cd.checkCollision(player, npc, "up") || cd.checkCollision(player, npc, "down")) {
npc.interactableOption = true;
npc.interactable = true; npc.interactable = true;
} }
else { else {
npc.interactableOption = false;
npc.interactable = false; npc.interactable = false;
} }
...@@ -476,6 +478,9 @@ public class Game extends Application { ...@@ -476,6 +478,9 @@ public class Game extends Application {
//NPC //NPC
for (NPC npc : ListNPC) { for (NPC npc : ListNPC) {
npc.drawNPC(context, player); npc.drawNPC(context, player);
if (npc.interactableOption == true && player.interact == false) {
npc.drawInteractableOption(context, this.width, this.height);
}
if (player.interact && npc.interactable) { if (player.interact && npc.interactable) {
if (player.direction == 1) { if (player.direction == 1) {
npc.direction = -1; npc.direction = -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment