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>();
I managed to create some code that catches randrops every time it hits the rectangle the raindrops disappears. My problem is I want to replace these raindrops with words and have the same effect. Can someone help me here is the code:
String word ="X";
Catcher catcher; // One catcher object
Timer timer; // One timer object
Drop[] drops; // An array of drop objects
PFont font;
float xpos;
float ypos;
float speed = 4;
int totalDrops = 0; // totalDrops
void setup() {
size(400,400);
smooth();
noCursor();
font=createFont("arial",32);
catcher = new Catcher(32); // Create the catcher with a radius of 32
drops = new Drop[1000]; // Create 1000 spots in the array
timer = new Timer(300); // Create a timer that goes off every 2 seconds
timer.start(); // Starting the timer
xpos=random(width);
}
void draw() {
background(255);
// Set catcher location
catcher.setLocation(mouseX,350);
// Display the catcher
catcher.display();
// Check the timer
if (timer.isFinished()) {
// Deal with raindrops
// Initialize one drop
drops[totalDrops] = new Drop();
// Increment totalDrops
totalDrops ++ ;
// If we hit the end of the array
if (totalDrops >= drops.length) {
totalDrops = 0; // Start over
}
timer.start();
}
// Move and display all drops
for (int i = 0; i < totalDrops; i++ ) {
drops[i].move();
drops[i].display();
if (catcher.intersect(drops[i])) {
drops[i].caught();
}
}
ypos+=speed;
}
class Catcher {
float r; // radius
color col; // color
float x,y; // location
Catcher(float tempR) {
r = tempR;
col = color(50,10,10,150);
x = 0;
y = 0;
}
void setLocation(float tempX, float tempY) {
x = tempX;
y = tempY;
}
void display() {
stroke(0);
fill(col);
rect(x,y,30,5);
}
// A function that returns true or false based on
// if the catcher intersects a raindrop
boolean intersect(Drop d) {
// Calculate distance
float distance = dist(x,y,d.x,d.y);
// Compare distance to sum of radii
if (distance < r + d.r) {
return true;
} else {
return false;
}
}
}
class Drop {
float x,y; // Variables for location of raindrop
float speed; // Speed of raindrop
color c;
float r; // Radius of raindrop
Drop() {
r = 8; // All raindrops are the same size
x = random(width); // Start with a random x location
y = -r*4; // Start a little above the window
speed = random(1,5); // Pick a random speed
c = color(50,100,150); // Color
}
// Move the raindrop down
void move() {
// Increment by speed
y += speed;
}
// Check if it hits the bottom
boolean reachedBottom() {
// If we go a little beyond the bottom
if (y > height + r*4) {
return true;
} else {
return false;
}
}
// Display the raindrop
void display() {
// Display the drop
fill(c);
noStroke();
for (int i = 2; i < r; i++ ) {
ellipse(x,y + i*4,i*2,i*2);
}
}
// If the drop is caught
void caught() {
// Stop it from moving by setting speed equal to zero
speed = 0;
// Set the location to somewhere way off-screen
y = - 1000;
}
}
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if 5,000 ms have passed.
// The work of the timer is farmed out to this method.
Someone helped me make some code and I need a little help making the rectangle at the bottom know that it is touching the words in the case being collision detection. So basically when the word hits the rectangle it counts it and produces a score at the top right hand corner of the screen. So basically making a little game and every time the word is hits the rectangle the sped slowly but surely goes up making the game harder:
Hey guys I need help with some short code. I need to know how to make text fall from top to bottom in a slow manner. It needs to loops so everytime it reaches the bottom it gets repeated. This also has to be produced randomly on the screen so it is not repetitive. Also if possible I need some help making an array for this so it loops and the word or text is falling down again in random spots with more than one word on the screen. If possible I do not want them falling too fast.