Game
in
Programming Questions
•
5 months ago
Hey guys I am having a huge problem with a game I am trying to make. I am trying to create collision detection in the follow code with the text and the rectangle at the bottom can someone help me?A text file is needed to run it otherwise you will not be able to see the words.
String [] s;
ArrayList <FallingWord> words = new ArrayList<FallingWord>();
PFont font = createFont("arial", 20);
void setup() {
size(1300, 750,P3D);
// load text
s = loadStrings("leminsk.txt");
// split in words
for (int i = 0; i < s.length; i++) {
String [] lineWords = splitTokens(s[i]);
for (int j = 0; j < lineWords.length; j++) {
words.add(new FallingWord(lineWords[j]));
}
}
noStroke();
smooth();
}
void draw() {
background(170,255,255);
for (FallingWord fw: words) {
fw.update();
fw.draw();
}
rect(mouseX,700,30,10);
}
class FallingWord {
String word;
float xpos, ypos, speed, acc;
color filler;
float fSize;
FallingWord (String _word) {
word = _word;
initWord();
}
void initWord() {
xpos = random (width);
ypos = random(-height/2, -20);
speed = random(0.4, 1);
acc = random(0.01, 0.08);
filler = color(0, random(180, 250));
fSize = random(14, 22);
}
void update() {
speed+=acc;
ypos +=speed;
if (ypos > height ) {
initWord();
}
if (mousePressed)
initWord();
}
void draw() {
textFont(font);
fill(filler);
textSize(fSize);
text(word, xpos, ypos);
}
}//eof FallingWord
1