level 1
冷幕※極端
楼主
Ball[] balls = new Ball[16];/////
////////////////////////////////
int score;
int n = 8;
int dia = 70;
///////////////////////////////////
color[] colors = {
color(252, 36, 36, 178), //RED
color(248, 114, 23, 178), //ORANGE
color(255, 255, 0, 178), //YELLOW
color(76, 196, 23, 178), //GREEN
color(56, 172, 236, 178), //BLUE
color(127, 56, 235, 178), // PURPLE
color(128, 178), //GREY
color(255, 193, 230, 178), //PINK
color(127, 56, 235, 178), // PURPLE
color(248, 114, 23, 178), //ORANGE
color(255, 193, 230, 178), //PINK
color(255, 255, 0, 178), //YELLOW
color(56, 172, 236, 178), //BLUE
color(76, 196, 23, 178), //GREEN
color(248, 114, 23, 178), //ORANGE
color(252, 36, 36, 178), //RED
color(128, 178), //GREY
};
int index;
/////////////////////////////////////////////////
String[] headlines = {
"ORANGE",
"GREY",
"PINK",
"YELLOW",
"GREEN",
"RED",
"BLUE",
"PURPLE",
};
int index1;
////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
int INTRO = 0;
int RUN_GAME = 1;
int GAME_OVER = 2;
int gameState = 1;
void setup() {
size(1000, 700);
imageMode(CENTER);
smooth();
noStroke();
pick();
//////////////////////////////////
for (int i=0; i<balls.length; i++) {
balls[i] = new Ball(random(20, width-20), random(20, height/2-100), dia, 10.0);//size, speed
}
///////////////////////////////////////////////
}
void draw() {
if (gameState == INTRO) intro();
else if (gameState == RUN_GAME) runGame();
else if (gameState == GAME_OVER) gameOver();
}
void intro() {
background(0);
textSize(60);
fill(255);
textAlign(CENTER, BOTTOM);
text("COLOUR\nCHALLENGE", width/2, height/2);
fill(255);
textSize(20);
text("Click anywhere to start", width/2, height/2+height/4);
}
///////////////////////////////////////////////////////////////////////
///////////////RUN GAME STATE
void runGame() {
background(255);
textSize(60);
fill(colors[index]);
textAlign(CENTER, BOTTOM);
text(headlines[index1], width/2, height/2);
if (mousePressed) {
index1 = (index1 + 1) % headlines.length;
printStringToInts(headlines[index1]);
}
//////////////////////////////////////////////////////////
for (int i=0; i<balls.length; i++) {
fill(colors[i]);
balls[i].constrained();
balls[i].update();
balls[i].display();
}
if (mousePressed) {
for (int i=0; i<balls.length; i++) {
if (pow(mouseX-balls[i].x, 2)+pow(mouseY-balls[i].y, 2) < pow(balls[i].D/2, 2)) {
balls[i].unfreeze();
break;
}
}
}
////////////////////////////////////////////////////////////
score++;
fill(0, 255, 0);
textSize(16);
textAlign(LEFT);
text(score, 10, 20);
}
///////////////////////////////////////////////////////////
void printStringToInts(String s) {
// for the length of the String
for (int i=0; i<s.length(); i++) {
// convert each character in the string to an int
// and print it to the console (with a comma added)
print(int(s.charAt(i)) + ",");
}
/////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////
void pick() {
index = int(random(colors.length));
}
void mousePressed() {
pick();
}
void keyPressed() {
pick();
}
///////////////////////////////////////////////////////////////////////////
////////////////GAME OVER STATE
void gameOver() {
fill(255);
textAlign(CENTER);
textSize(48);
text("GAME OVER", width/2, height/2);
textSize(16);
textAlign(CENTER);
text("Click to try again", width/2, height/2+height/4);
}
class Ball {
float x, y;
float D;
float dy;
boolean frozen;
Ball(float x_, float y_, float D_, float dy_) {
x = x_;
y = y_;
D = D_;
dy = dy_;
frozen=true;
}
void unfreeze() {
frozen = false;
}
void freeze() {
frozen = true;
}
void update() {
if (!frozen) y=y+dy;
}
void constrained() {
if (y+D/2>height) freeze();
}
void display() {
noStroke();
ellipse(x, y, D, D);
}
}
请问有没有大神知道 怎么点错颜色就会GameOver?
2017年04月15日 19点04分
1
////////////////////////////////
int score;
int n = 8;
int dia = 70;
///////////////////////////////////
color[] colors = {
color(252, 36, 36, 178), //RED
color(248, 114, 23, 178), //ORANGE
color(255, 255, 0, 178), //YELLOW
color(76, 196, 23, 178), //GREEN
color(56, 172, 236, 178), //BLUE
color(127, 56, 235, 178), // PURPLE
color(128, 178), //GREY
color(255, 193, 230, 178), //PINK
color(127, 56, 235, 178), // PURPLE
color(248, 114, 23, 178), //ORANGE
color(255, 193, 230, 178), //PINK
color(255, 255, 0, 178), //YELLOW
color(56, 172, 236, 178), //BLUE
color(76, 196, 23, 178), //GREEN
color(248, 114, 23, 178), //ORANGE
color(252, 36, 36, 178), //RED
color(128, 178), //GREY
};
int index;
/////////////////////////////////////////////////
String[] headlines = {
"ORANGE",
"GREY",
"PINK",
"YELLOW",
"GREEN",
"RED",
"BLUE",
"PURPLE",
};
int index1;
////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
int INTRO = 0;
int RUN_GAME = 1;
int GAME_OVER = 2;
int gameState = 1;
void setup() {
size(1000, 700);
imageMode(CENTER);
smooth();
noStroke();
pick();
//////////////////////////////////
for (int i=0; i<balls.length; i++) {
balls[i] = new Ball(random(20, width-20), random(20, height/2-100), dia, 10.0);//size, speed
}
///////////////////////////////////////////////
}
void draw() {
if (gameState == INTRO) intro();
else if (gameState == RUN_GAME) runGame();
else if (gameState == GAME_OVER) gameOver();
}
void intro() {
background(0);
textSize(60);
fill(255);
textAlign(CENTER, BOTTOM);
text("COLOUR\nCHALLENGE", width/2, height/2);
fill(255);
textSize(20);
text("Click anywhere to start", width/2, height/2+height/4);
}
///////////////////////////////////////////////////////////////////////
///////////////RUN GAME STATE
void runGame() {
background(255);
textSize(60);
fill(colors[index]);
textAlign(CENTER, BOTTOM);
text(headlines[index1], width/2, height/2);
if (mousePressed) {
index1 = (index1 + 1) % headlines.length;
printStringToInts(headlines[index1]);
}
//////////////////////////////////////////////////////////
for (int i=0; i<balls.length; i++) {
fill(colors[i]);
balls[i].constrained();
balls[i].update();
balls[i].display();
}
if (mousePressed) {
for (int i=0; i<balls.length; i++) {
if (pow(mouseX-balls[i].x, 2)+pow(mouseY-balls[i].y, 2) < pow(balls[i].D/2, 2)) {
balls[i].unfreeze();
break;
}
}
}
////////////////////////////////////////////////////////////
score++;
fill(0, 255, 0);
textSize(16);
textAlign(LEFT);
text(score, 10, 20);
}
///////////////////////////////////////////////////////////
void printStringToInts(String s) {
// for the length of the String
for (int i=0; i<s.length(); i++) {
// convert each character in the string to an int
// and print it to the console (with a comma added)
print(int(s.charAt(i)) + ",");
}
/////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////
void pick() {
index = int(random(colors.length));
}
void mousePressed() {
pick();
}
void keyPressed() {
pick();
}
///////////////////////////////////////////////////////////////////////////
////////////////GAME OVER STATE
void gameOver() {
fill(255);
textAlign(CENTER);
textSize(48);
text("GAME OVER", width/2, height/2);
textSize(16);
textAlign(CENTER);
text("Click to try again", width/2, height/2+height/4);
}
class Ball {
float x, y;
float D;
float dy;
boolean frozen;
Ball(float x_, float y_, float D_, float dy_) {
x = x_;
y = y_;
D = D_;
dy = dy_;
frozen=true;
}
void unfreeze() {
frozen = false;
}
void freeze() {
frozen = true;
}
void update() {
if (!frozen) y=y+dy;
}
void constrained() {
if (y+D/2>height) freeze();
}
void display() {
noStroke();
ellipse(x, y, D, D);
}
}
请问有没有大神知道 怎么点错颜色就会GameOver?