how to check if marco is entered in the textbox and increase balance[0] by 75 when this happens for the first time
static final int NUM = 2;
final TextBox[] tboxes = new TextBox[NUM];
int idx;
PImage shop;
PImage settings;
PImage teams;
PImage kill;
PImage phone;
PImage coin;
PImage bounty;
boolean invert = false;
boolean main = true;
boolean shopb = false;
boolean settingsb = false;
boolean teamsb = false;
boolean killb = false;
boolean balanceb = false;
boolean bountyb = false;
String weapon = "none";
String typed = "";
int[] balance = new int[10];
void setup() {
size(278, 599);
balance[0] = 10;
balance[1] = 75;
balance[2] = 0;
balance[3] = 0;
balance[4] = 0;
balance[5] = 0;
balance[6] = 0;
balance[7] = 0;
balance[8] = 0;
balance[9] = 0;
shop = loadImage("cart.png");
settings = loadImage("settings.png");
teams = loadImage("teams.png");
kill = loadImage("kill.png");
coin = loadImage("coin.png");
bounty = loadImage("bounty.png");
phone = loadImage("android.png");
instantiateBoxes();
tboxes[idx = 1].isFocused = true;
}
void draw() {
background(255);
fill(125);
if(!main){
text("press 1 to go to home",width/2-60,height-30);
}
for (int i = 0; i != NUM; tboxes[i++].display());
if (shopb) {
text("€" + balance[0], width/2-13, height-23);
text("active weapon: " + weapon, width / 2 - 60, height-13);
line(0, height / 4, width, height / 4);
line(0, (height / 4) * 2, width, (height / 4)*2);
line(0, (height / 4) * 3, width, (height / 4)*3);
line(width/2, 0, width/2, height);
color(255);
textSize(25);
text("blowgun €10", 0, 0, width / 2, height / 4);
text("smg €110", 0, height / 4, width / 2, height / 4);
text("shotgun €110", 0, (height / 4) * 2, width / 2, height / 4);
text("carbine €120", 0, (height / 4) * 3, width / 2, height / 4);
text("pistol €25", width / 2, 0, width / 2, height / 4);
text("sniper rifle €150", width / 2, height / 4, width / 2, height / 4);
text("bow and arrow €80", width / 2, (height / 4) * 2, width / 2, height / 4);
text("handgun €120", width / 2, (height / 4) * 3, width / 2, height / 4);
color(125);
}
if (bountyb) {
text("john €" + balance[0], width / 2 - 50, 20);
text("marco €" + balance[1], width / 2 - 50, 30);
text("kaj €" + balance[2], width / 2 - 50, 40);
text("zack €" + balance[3], width / 2 - 50, 50);
text("daan €" + balance[4], width / 2 - 50, 60);
}
if (balanceb) {
textSize(20);
text("€" + balance[0], width / 2, height / 2);
}
if (teamsb) {
fill(0, 0, 255);
text("john", width / 2 + 50, 20);
text("marco", width / 2 + 50, 30);
text("kaj", width / 2 + 50, 40);
text("zack", width / 2 + 50, 50);
text("daan", width / 2 + 50, 60);
fill(255, 0, 0);
text("lily", width / 2 - 50, 20);
text("esmeralda", width / 2 - 50, 30);
text("damian", width / 2 - 50, 40);
text("mary", width / 2 - 50, 50);
text("thom", width / 2 - 50, 60);
fill(125);
}
if (invert) {
filter(INVERT);
}
if (settingsb) {
text("dark mode", width / 2 - 20, 10);
text("waring: icons will stay dark and may not be visible", 10, 40);
rect(width / 2, 10, 20, 20);
}
if (main) {
textSize(13);
text("active weapon: " + weapon, width / 2 - 60, 13);
line(width / 2, 0, width / 2, height);
line(0, (599.05511811 / 4) * 2, width, (599.05511811 / 4) * 2);
line(0, (599.05511811 / 4) * 3, width, (599.05511811 / 4) * 3);
if (invert) {
}
if (!invert) {
image(teams, -40, -70, 278.17322835 / 2 + 80, (599.05511811 / 4) * 2 + 130);
image(shop, width / 2, 30, 278.17322835 / 2, (599.05511811 / 4) * 2 - 90);
image(settings, 5, (599.05511811 / 4) * 2, 278.17322835 / 2 - 15, (599.05511811 / 4) * 2 - 180);
image(kill, width / 2 + 10, (599.05511811 / 4) * 2, 278.17322835 / 2 - 15, (599.05511811 / 4) * 2 - 180);
image(coin, 10, (599.05511811 / 4) * 3 + 10, 278.17322835 / 2 - 20, (599.05511811 / 4) * 2 - 190);
image(bounty, width / 2, (599.05511811 / 4) * 3 + 10, 278.17322835 / 2, (599.05511811 / 4) * 2 - 190);
}
textSize(40);
text("shop", width / 2 + 40, (599.05511811 / 4) * 2 - 20, 50);
text("teams", 20, (599.05511811 / 4) * 2 - 20, 50);
text("settings", 0, (599.05511811 / 4) * 2 + 100, 278.17322835 / 2, (599.05511811 / 4) * 2 - 150);
text("kill", width / 2 + 45, (599.05511811 / 4) * 2 + 100, 278.17322835 / 2 - 15, (599.05511811 / 4) * 2 - 180);
text("balance", 0, (599.05511811 / 4) * 2 + 255, 278.17322835 / 2, (599.05511811 / 4) * 2 + 300);
text("bounty", width / 2 + 10, (599.05511811 / 4) * 3 + 105, 278.17322835 / 2, (599.05511811 / 4) * 2 - 190);
}
if (key == '1') {
key = '';
settingsb = false;
main = true;
shopb = false;
settingsb = false;
teamsb = false;
killb = false;
balanceb = false;
bountyb = false;
}
}
void mouseClicked() {
int i = idx = -1;
while (++i != NUM) if (tboxes[i].checkFocus()) idx = i;
if(shopb){
if(balance[0]>=10 && weapon != "blowgun"){
if(mouseX>=0 && mouseX<=width/2 && mouseY >=0 && mouseY<= height/ 4){
weapon= "blowgun";
balance[0]=balance[0]-10;
}
}
}
if (settingsb) {
if (mouseX >= width / 2 && mouseX <= width / 2 + 20 && mouseY >= 10 && mouseY <= 30) {
invert = true;
}
}
if (main) {
if (mouseX >= 0 && mouseX <= width / 2 && mouseY >= 0 && mouseY <= (599.05511811 / 4) * 2) {
teamsb = true;
main = false;
}
if (mouseX >= width / 2 && mouseX <= width && mouseY >= 0 && mouseY <= (599.05511811 / 4) * 2) {
shopb = true;
main = false;
}
if (mouseX >= 0 && mouseX <= width / 2 && mouseY >= (599.05511811 / 4) * 2 && mouseY <= (599.05511811 / 4) * 3) {
settingsb = true;
main = false;
}
if (mouseX >= width / 2 && mouseX <= width && mouseY >= (599.05511811 / 4) * 2 && mouseY <= (599.05511811 / 4) * 3) {
killb = true;
main = false;
}
if (mouseX >= 0 && mouseX <= width / 2 && mouseY >= (599.05511811 / 4) * 3 && mouseY <= height) {
balanceb = true;
main = false;
}
if (mouseX >= width / 2 && mouseX <= width && mouseY >= (599.05511811 / 4) * 3 && mouseY <= height) {
bountyb = true;
main = false;
}
}
}
void keyTyped() {
final char k = key;
if (k == CODED | idx < 0) return;
final TextBox tbox = tboxes[idx];
final int len = tbox.txt.length();
if(killb){
if (k == BACKSPACE) tbox.txt = tbox.txt.substring(0, max(0, len-1));
else if (len >= tbox.lim) return;
else if (k == ENTER | k == RETURN){ tbox.txt = "";}
else if (k == TAB & len < tbox.lim-3) tbox.txt += " ";
else if (k == DELETE) tbox.txt = "";
else if (k >= ' ') tbox.txt += str(k);
}
}
void keyPressed() {
if (key != CODED | idx < 0) return;
final int k = keyCode;
if( tbox.txt == "marco"){
balance[0]=balance[0]+75;
}
final TextBox tbox = tboxes[idx];
final int len = tbox.txt.length();
if (k == LEFT) tbox.txt = tbox.txt.substring(0, max(0, len-1));
else if (k == RIGHT & len < tbox.lim-3) tbox.txt += " ";
}
void instantiateBoxes() {
tboxes[0] = new TextBox(
width>>2, height/4 + height/16, // x, y
width - width/2, height/2 - height/4 - height/8, // w, h
215, // lim
0300 << 030, color(-1, 040), // textC, baseC
color(-1, 0100), color(#FF00FF, 0200)); // bordC, slctC
tboxes[1] = new TextBox(
width>>3, height/2 + height/8, // x, y
width - width/4, height - height/2 - height/4, // w, h
640, // lim
0300 << 030, color(-1, 040), // textC, baseC
color(-1, 0100), color(#FFFF00, 0200)); // bordC, slctC
}
class TextBox { // demands rectMode(CORNER)
final color textC, baseC, bordC, slctC;
final short x, y, w, h, xw, yh, lim;
boolean isFocused;
String txt = "";
TextBox(int xx, int yy, int ww, int hh, int li,
color te, color ba, color bo, color se) {
x = (short) xx;
y = (short) yy;
w = (short) ww;
h = (short) hh;
lim = (short) li;
xw = (short) (xx + ww);
yh = (short) (yy + hh);
textC = te;
baseC = ba;
bordC = bo;
slctC = se;
}
void display() {
if(killb){
stroke(isFocused? slctC : bordC);
fill(baseC);
if(killb){
rect(x, y, w, h);
fill(textC);
text(txt + blinkChar(), x, y, w, h);
}
}
}
String blinkChar() {
return isFocused && (frameCount>>2 & 1) == 0 ? "_" : "";
}
boolean checkFocus() {
return isFocused = mouseX > x & mouseX < xw & mouseY > y & mouseY < yh;
}
}