Array Questions
in
Programming Questions
•
1 year ago
Hey all i got a simple array here of climbers. I have to put in text on the screen who reached the top of the mountain first.
can you guys write me a block of code that searches through the array and puts what climber reached the top of the mountain first?
i also need to make a function where if the mouse presses on one of the climbers the color of that climber changes....this one is not that important though.
well here is my code and i hope you guys can help me as i will really appreciate it.
*** Press the space bar to move the characters up the mountain at various speeds and press R to reset the program
- int climberCount = 5;
- int ropeCount = 5;
- Climber[] climbers = new Climber[climberCount];
- Rope[] ropes = new Rope[ropeCount];
- void setup() {
- size(800, 600);
- reset();
- for (int i = 0; i < ropeCount; i++) {
- ropes[i] = new Rope(100+150*i,100);
- }
- }
- void draw() {
- background(0);
- scene();
- ropes();
- climbers();
- }
- void reset() {
- for (int i = 0; i < climberCount; i++) {
- climbers[i] = new Climber(75+150*i, 450, color(random(255), random(255), random(255)));
- }
- }
- void scene() {
- fill(160, 82, 45);
- rect(0, 0, width, 600);
- fill(0, 0, 255);
- rect(0, 0, width, 100);
- }
- void ropes() {
- for (int i = 0; i < ropeCount; i++ ) {
- ropes[i].display();
- }
- }
- void climbers() {
- for (int i = 0; i < climberCount; i++ ) {
- climbers[i].display();
- }
- }
- void keyPressed() {
- if (key == ' ' ) {
- for (int i = 0; i < climberCount; i++) {
- climbers[i].update();
- }
- }
- if (key =='r') {
- reset();
- }
- }
- class Climber {
- float xpos;
- float ypos;
- color c;
- Climber(float tempXpos, float tempYpos, color tempC) {
- xpos = tempXpos;
- ypos = tempYpos;
- c = tempC;
- }
- void display() {
- fill(c);
- rect(xpos, ypos, 50, 100);
- }
- void update() {
- ypos-=random(100);
- }
- }
- class Rope {
- float xpos;
- float ypos;
- Rope(float tempXpos, float tempYpos) {
- xpos = tempXpos;
- ypos = tempYpos;
- }
- void display() {
- fill(200,175,0);
- rect(xpos,ypos,5,450);
- }
- void update() {
- }
- }
1