Loading...
Logo
Processing Forum
using :
 Conditions
 Loops
 Methods

i need to make a simple shooting game of concentic rings
 when the program starts a target appears with a random number of rings between 5 and 10 with a gap of 20 pixels in between.
 There always should be a white color in the target the other color is random. The target should be displayed as ( random color , white , same random color , white , etc......).
 also when the target is displayed the number of rings start to decrease one by one so when the circle of the random color at first disappears the color of the white circle becomes the same as the that of the random color thus changing the color design of the target then when another circle disappears the design will become the same as it was at first.
 
there are 10 rings i need a score displayed at (20,height-20) when the mouse is pressed it of the target the score shows 10 at the second ring the score shows 9 ect... till the last ring . and the scores should be added together at each press.

finally there is a time limit of 20 second when the game is over should be displayed also

here are some videos to help 



please helpppp please

ive done this till now


float y = random(600);
float x = random(600);
float c1 = random(255);
float c2 = random(255);
float c3 = random(255);


void setup() {
  size(600,600);
  background(255);
  smooth();
}

void draw() {
  displayCircles();
  shrinkTarget();
}

void displayCircles() {
  for (int dia = 200;dia >= 20; dia=dia-20) {
    if ((dia/20)%2 == 0) {
      noStroke();
      fill(c1,c2,c3);
      ellipse(x,y,dia,dia);
    }
    else
    {
      noStroke();
      fill(255,255,255);
      ellipse(x,y,dia,dia);
    }
  }
}


void shrinkTarget() {
  for (int dia = 200;dia < 20; dia=dia-20) {
    if ((dia/20)%2 == 0) {
      noStroke();
      fill(255,255,255);
      ellipse(x,y,dia,dia);
    }
    else
    {
      noStroke();
      fill(c1,c2,c3);
      ellipse(x,y,dia,dia);
    }
  }
}


helpp :S

Replies(9)

Copy code
  1. float px, py;
  2. int n;
  3. color c;
  4. int s, t;

  5. void setup() {
  6.   size(600, 600);
  7.   smooth();
  8.   ellipseMode(CENTER);
  9.   s = 0;
  10.   newTarget();
  11. }

  12. void draw() {
  13.   background(255);
  14.   if ( millis() < 20000 ) {
  15.     for ( int i=n-1; i >=0; i-- ) {
  16.       fill(i%2==0?(n%2==0?255:c):
  17.       ((n%2==0)?c:255));
  18.       stroke(0);
  19.       int r = 20 + (20 * i);
  20.       ellipse(px, py, r, r );
  21.     }
  22.     if ( millis() > t ) {
  23.       n--;
  24.       if ( n == 0 ) {
  25.         newTarget();
  26.       }
  27.       t = millis() + 500;
  28.     }
  29.   } 
  30.   else {
  31.     noStroke();
  32.     fill(0);
  33.     text("GAME OVER", 20,30 );
  34.   }
  35.   fill( 255, 0, 0);
  36.   text( "Score: " + s, 20, height-20);
  37. }

  38. void mousePressed() {
  39.   float d = dist(mouseX, mouseY, px, py );
  40.   if ( d <= 10 * n ) {
  41.     s+=10-int(d/10);
  42.     newTarget();
  43.   }
  44. }

  45. void newTarget() {
  46.   n = int(random(5, 11));
  47.   println( n );
  48.   px = random(width);
  49.   py = random(height);
  50.   c = color( random(255), random(255), random(255) );
  51.   t = millis() + 500;
  52. }
but can you make it simpler ??
with out
 these codes 
Copy code
  1.       fill(i%2==0?(n%2==0?255:c):
  2.       ((n%2==0)?c:255));

That depends on what you mean by "simpler".

http://processing.org/reference/conditional.html

I suppose fill((i+n)%2==0?255:c); might work too. Example code is not optimized!
i mean without this

?: (conditional)

is there another way ? 

it will be perfect 
if you can write it as ( if else ) ?
The reference page I linked to describes how you can convert between the two.
im trying but its too complicated is it like this 
if(i%2==0) {
  if(n%2==0) {
    fill(255);
  } else {
    fill(c);
  } else if(n%2==0) {
    fill(c);
  } else {
    fill(255);
  }
}

?