Hey guys, I'm doing a game as a schoolproject where u are supposed to catch some things falling, and I want to have hearts that indicates that you have missed an item. I have manage to make one heart dissapear. But the other two hearts i dont know how to remove, i have tried different things...but it hasnt worked.
so please help me out!
Heart heartOne;
Heart heartTwo;
Heart heartThree;
Catcher catcher; // One catcher object
Timer timer; // One timer object
Drop _drops;
Drop[] drops; // An array of drop objects
int totalDrops = 0; // totalDrops
int xValue = 200;
void setup() {
size(400, 400);
smooth();
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(1500); // Create a timer that goes off every 2 seconds
timer.start(); // Starting the timer
heartOne = new Heart(382, 20, 20, 20);
heartTwo = new Heart(360, 20, 20, 20);
heartThree = new Heart(338, 20, 20, 20);
}
void draw() {
background(255);
// Set catcher location
catcher.setLocation(xValue, 360);
// Display the catcher
catcher.display();
//display heart
heartOne.heartDisplay();
heartTwo.heartDisplay();
heartThree.heartDisplay();
// 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();
}
}
//BOUNCE ON WALL
if (xValue<=0)
{
xValue = 0;
}
if (xValue>=width)
{
xValue = width;
}
for (int i = 0; i < totalDrops; i++) {
if (drops[i].reachedBottom())
{
heartOne.remove();
}
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
xValue = xValue-20;
}
}
if (key == CODED) {
if (keyCode == RIGHT) {
xValue = xValue+20;
}
}
}
////////
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,2); // 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) {
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
Hey guys, i have made some balls from an array which are just bouncing around at the moment...I have tried to make them bounce when they intersect with each other, but i have no clue of how to do it. I can manage it when there are only two instances of the ballclass... so please can someone tell me how to make the balls from the same array bounce away from each other?!
Hey guys, I'm doing a game where you shoot some bullets when you press space, that is already done. But instead of only firing one shot once, it shoots alot of bullets..how can i make it so that when you press space it only fire one bullet once?
Hey, I'm making a small shooting-game. I have right now an ellipse which you can move with the arrowkeys from left to right and i have made a bullet which fires when you press a key. But my problem now is that i want the bullet to fire from the same position that my ellipse has. Right now the bullet only fires from the centre of the screen. How can I make the bullet (shot class) follow the ellipse's movement?