Collision and Timer-- PLEASE HELP SOON
in
Core Library Questions
•
1 years ago
The sketch is a basic game-ish thing; a fly is loosely attached to the cursor, which then is supposed to follow the cursor to collect about 50 small sugar cubes on the screen. A large spider moves in a Brownian-motion pattern across the screen while this is happening. What I want to happen is:
--The white blocks to vanish when the fly passes over them
--The "scream" in the minim library to play when the spider hits the fly
--A thirty-second timer in the upper-right-hand corner. When the timer
hits 30 seconds (30000 millis) the game resets.
--The white blocks to vanish when the fly passes over them
--The "scream" in the minim library to play when the spider hits the fly
--A thirty-second timer in the upper-right-hand corner. When the timer
hits 30 seconds (30000 millis) the game resets.
The code for the main sketch is below--it is not complete (the timer and collision coding, especially), although the sketch does load without error messages at this point. Any help would be greatly appreciated, as my professor is unavailable through the weekend except by email. Thank you!
//Game
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
//Minim Library import
Minim minim;
AudioSample scream;
AudioSample click;
//declares variables for audio samples (scream and click)
PFont timetxt;
ArrayList scubes;
//array for sugar cubes
Fly player;
Spider enemy;
Countdown timer;
//declares classes in sketch
void setup() {
background(0);
size(800, 600);
//hazard= new Blocks [numShapes];
player=new Fly(random(0, width), random(0, height), mouseX, mouseY);
//places Fly at random position relative to cursor
enemy= new Spider(random(0, width-10), random(0, height-190), 190, 190);
//arranges spider randomly on screen
scubes = new ArrayList();
for (int i=0; i<50;i++) {
scubes.add(new Blocks(random(0, width), random(0, height)));
}//end loop
//places 50 blocks in random position on screen
minim= new Minim(this);
scream =minim.loadSample("cri-d-effroi-scream.wav");
click =minim.loadSample("click_x.wav");
//loads sounds from minim
timetxt= loadFont("Haettenschweiler-48.vlw");
timer = new Countdown(5000);
timer.start();
//first attempt at timer from the countdown class. I need it to display on screen for thirty seconds
}//end setup
void draw() {
background(0);
player.move();
player.display();
//displays fly and allows it to move
for (int j=0; j<scubes.size();j++) {
Blocks temp=(Blocks)scubes.get(j);
temp.display();
}//end loop
//displays random blocks
enemy.move();
enemy.display();
//displays spider on screen
if (timer.isFinished()) {
background(0);
timer.start();
}//timer
}//end draw
void checkCollision(Fly c, Blocks cl, int index) {
if (dist(c.xpos+25, c.ypos+25, cl.xpos+10, cl.ypos+10)<35) {
scubes.remove(index);
}
}//end checkCol
1