sorry for deleting the post earlier but i dont really understand how to use the forum. Also im quite new to processing too.
Problem: the full word wont print and i have tried using if(keyPressed) text(“s”,x,y) to screen but they wont stay on, is there any way i can get a hint for this? Also is there a way to reset my timer variable so that i dont have to name new timer variables to use in my levle functions, thanks.
code down below:
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer song; //https://freemusicarchive.org/genre/Christmas(Dab Yan-key alpine bells(jingle bells);
int timer= 6000; // referenced from Hangman Final by Anthony Yu- openproccessing.org/sketch/61942/*
int timer1=5000;
int timer2=4000;
String type= "";
PImage xmas1,xmas2,xmas5,xmas12;
PFont font; // referenced from Meri Engel Youtube video "Adding and using fonts in processing"
// idea for font sourced from Susan Alden
// either have delay(500) at the start of game or have Mousepressed to start game
int gameLevel; // game level is implemented
void setup()
{
size(626,417,P2D);
minim = new Minim(this);
song= minim.loadFile("song.mp3");
song.loop();
font = loadFont("thinkQuick.vlw");
textFont(font);
xmas1 = loadImage("xmas1.jpg");
xmas2 = loadImage("xmas2.png");// load image and data into scene data structure( from lab 3 with Professor Stephen Brown)
xmas5 = loadImage("xmas5.jpg");//font = createFont("ArialMT-48", 225);
xmas12 = loadImage("xmas12.jpg");
}
void draw()
{
background(xmas1);
switch(gameLevel)
{
case 0:
startMenu();
break;
case 1:
level1();
break;
case 2:
level2();
break;
case 3:
level3();
break;
}
if(key == '1')
{
gameLevel=1;
level1();
}
else if( key == '2')
{
gameLevel=2;
level2();
}
else if( key == '3')
{
gameLevel=3;
level3();
}
else
{
gameLevel=0;
startMenu();
}
}
void startMenu()
{
background(xmas1);
textFont(font,40);
fill(255,0,128);
text("Welcome to Think Quik!", 100,100);
textFont(font,40);
fill(255,0,128);
text("Choose >1< for level 1", 100,200);
textFont(font,40);
fill(255,0,128);
text("Choose >2< for level 2", 100,300);
textFont(font,40);
fill(255,0,128);
text("Choose >3< for level 3", 100,400);
}
void level1()
{
background(xmas12);
fill(0);
rect(80,50,400,100);
fill(255);
textSize(25);
text("Hint:Usually falls in the Winter", 100,100); // hint for the player to guess the word
String word = "snow";
String guess = "";
for(int i = 0; i < word.length();i++)
{
if(keyPressed)
{
if(key == word.charAt(i)) // if the character's key equals any letter in the word prints word to screen
{
type += key;
}
else if(key=='\n')
{
type="";
}
}
for(int j=0; j <word.length(); j++)//for loop creates underlines for the word depending on how many
{
int underScore= 60*j;//referenced from Hangman Final by Anthony Yu- openproccessing.org/sketch/61942/*
int underScore1=200;//referenced from Hangman Final by Anthony Yu- openproccessing.org/sketch/61942/*
line(underScore+50,underScore1,underScore+25,underScore1);//referenced from Hangman Final by Anthony Yu- openproccessing.org/sketch/61942/*
}
}
guess += key+ type;
guess = guess.toUpperCase(); // letters stay on screen but only print one and if line 129-132 is removed multiple letters get printed
if(guess.length() > 1)
{
type="";
}
fill(0);
text(guess,0,200);
for(int a =0; a < guess.length();a++)
{
if(guess.length() == word.length())
{
gameLevel=2; // if the word is guessed then player moves to next level
}
}
timer--;
fill(0);
textSize(25);
text(timer,500,50);
if(timer == 0)
{
exit();
}
}
void level2()
{
background(xmas5);
if(keyPressed)
{
if(key == 'x')
{
text("x",160,200);
}
}
timer1--;
fill(0);
textSize(25);
text(timer1,490,50);
if(timer1 == 0)
{
exit();
}
}
void level3()
{
background(xmas2);
timer2--;
fill(0);
textSize(25);
text(timer2,490,50);
String s1= "winter";
if(keyPressed) // keypressed object to print letters to screen except theyre not staying on the screen
{
if(key == s1.charAt(0))
{
text( "w",170,200);
}
}
if(timer2 == 0)
{
exit();
}
}