Problem with random
in
Programming Questions
•
1 year ago
hey guys! i wanted to make X and O "rain from the top to buttom. i want them to rain frrom random x positions and in random times...
do i have to define every single O and X and give them a certain position and than tell the program to let them rain in random times?
i dont get it for 100%
here you can run the program, maybe you understand my question better if you see it.
do i have to define every single O and X and give them a certain position and than tell the program to let them rain in random times?
i dont get it for 100%
here you can run the program, maybe you understand my question better if you see it.
- int score = 0;
int life = 3;
float circleX=300, circleY=0;
float circleR=30;
float circleVY=200;
float linex1=150, liney1=-15, linex2=170, liney2=0;
float linex3=150, liney3=0, linex4=170, liney4=-15;
float lineVY=200;
float bodyX=300, bodyY=430;
float bodyR=50;
float bodyVX=0, bodySpeed=300;
float legX=315, legY=460;
float legR=30;
float legVX=0, legSpeed=300;
float toeX=285, toeY=460, toeX2=315, toeY2=460;
float toeVX=0, toeSpeed=300;
float eyeX=305, eyeY=423;
float eyeVX=0, eyeSpeed=300;
void setup() {
size (640, 480);
}
void keyPressed() {
if (keyCode==LEFT) {
bodyVX = -bodySpeed;
legVX= -legSpeed;
toeVX= -toeSpeed;
eyeVX= -eyeSpeed;
}
else if (keyCode==RIGHT) {
bodyVX = +bodySpeed;
legVX= +legSpeed;
toeVX= +toeSpeed;
eyeVX= +eyeSpeed;
}
}
void keyReleased() {
bodyVX=0;
legVX=0;
toeVX=0;
eyeVX=0;
}
void draw() {
circleY=circleY+circleVY/frameRate;
liney1=liney1+lineVY/frameRate;
liney2=liney2+lineVY/frameRate;
liney3=liney3+lineVY/frameRate;
liney4=liney4+lineVY/frameRate;
bodyX=bodyX+bodyVX/frameRate;
legX=legX+legVX/frameRate;
toeX=toeX+toeVX/frameRate;
toeX2=toeX2+toeVX/frameRate;
eyeX=eyeX+eyeVX/frameRate;
println("mouseX="+mouseX+" mouseY="+mouseY);
if(bodyX<=25) {
bodyX=25;
bodyVX=0;
}
else if(bodyX>515) {
bodyX=515;
bodyVX=0;
}
if(eyeX<30) {
eyeX=30;
eyeVX=0;
}
else if(eyeX>520) {
eyeX=520;
eyeVX=0;
}
if(legX<40) {
legX=40;
legVX=0;
}
else if (legX>530) {
legX=530;
legVX=0;
}
if(toeX<10 && toeX<240) {
toeX=10;
toeX2=40;
toeVX=0;
}
else if(toeX>500 && toeX2>530) {
toeX=500;
toeX2=530;
toeVX=0;
}
if(circleY-circleR<bodyY+bodyR &&
circleY>=bodyY &&
circleX-circleR>bodyX-bodyR &&
circleX+circleR<bodyX+bodyR &&
circleVY>0) {
circleY = 0;
score = score+1;
}
else if(liney2<=bodyY+bodyR &&
liney2>=bodyY &&
liney3<=bodyY+bodyR &&
liney3>=bodyY &&
linex1>=bodyX-bodyR &&
linex2<=bodyX+bodyR &&
lineVY>0) {
liney1 = -15;
liney2 = 0;
liney3 = 0;
liney4 = -15;
life = life-1;
}
if(life<=0) {
score = score = 0;
life = life = 3;
}
if(circleY>=height) {
circleY = 0;
}
else if(liney2>=height &&
liney3>=height) {
liney1 = -15;
liney2 = 0;
liney3 = 0;
liney4 = -15;
}
//Background
strokeWeight(3);
stroke(0);
rectMode(CENTER);
fill(127,237,131);
rect(320,455,640,50);
fill(255,233,118);
rect(320,215,640,430);
fill(98,251,255);
smooth();
line (540,0,540,480);
//clock
int m = millis();
int seconds = m / 1000;
int minutes = seconds / 60;
int hours = minutes / 60;
int days = hours / 24;
seconds -= minutes * 60;
minutes -= hours * 60;
hours -= days * 24;
fill (0);
textSize(20);
textAlign (CENTER, TOP);
text (seconds, 585, 20);
text (":",570, 20);
text (minutes, 555, 20);
//Kirby
stroke(0);
fill(98, 251, 255);
strokeWeight(5);
ellipseMode(CENTER);
ellipse(bodyX, bodyY, bodyR, bodyR);
if (keyPressed && keyCode == RIGHT) {
//Right
point (eyeX, eyeY);
point (eyeX+15, eyeY);
arc(legX, legY, legR, legR, TWO_PI-PI, TWO_PI);
arc(legX-15, legY, legR, legR, TWO_PI-PI, TWO_PI);
line (toeX, toeY, toeX2, toeY2);
line (toeX+15, toeY, toeX2+15, toeY2);
}
else if (keyPressed && keyCode == LEFT) {
//Left
point (eyeX-6, eyeY);
point (eyeX-23, eyeY);
arc(legX-30, legY, legR, legR, TWO_PI-PI, TWO_PI);
arc(legX-15, legY, legR, legR, TWO_PI-PI, TWO_PI);
line (toeX, toeY, toeX2, toeY2);
line (toeX-15, toeY, toeX2-15, toeY2);
}
else {
//Still
point (eyeX+2, eyeY);
point (eyeX-11, eyeY);
arc(legX-25, legY, legR-7, legR, TWO_PI-PI, TWO_PI);
arc(legX-5, legY, legR-7, legR, TWO_PI-PI, TWO_PI);
line (toeX+6, toeY, toeX2+6, toeY2);
line (toeX-6, toeY, toeX2-6, toeY2);
}
//Circle
stroke(0);
fill(31,252,43);
strokeWeight(2);
ellipseMode(CENTER);
ellipse(circleX,circleY,circleR,circleR);
//X
strokeWeight(5);
stroke(255,0,0);
line(linex1,liney1,linex2,liney2);
line(linex3,liney3,linex4,liney4);
// score
textSize (13);
textAlign (CENTER, TOP);
fill(0);
text("SCORE: ",570,50);
textSize (20);
fill (19,250,34);
text (score, 610, 45);
// life
textSize (13);
textAlign (CENTER, TOP);
fill(0);
text("LIFE: ", 560, 80);
textSize (30);
fill (255,0,0);
text (life,590, 70);
}
1