Ich mache ein Spiel für mein College-Projekt mit Processing3. Das Spiel besteht aus einem Auto, das du mit deiner Maus steuerst, die sich nur auf der X-Achse bewegt. Ich habe Menschen und Münzen hinzugefügt und sie bewegen sich auch auf der X-Achse auf und ab. Wie kann ich die Punktzahl erhöhen, wenn ein Rechteck auf ein bewegtes Bild trifft? Ich möchte, dass der Punktestand steigt, wenn das Rechteck Teil des Autos, das ich erschuf, ein Bild einer Münze schlägt, die auf und ab auf der Straße bewegt. Ich werde so viel Hilfe wie möglich zu schätzen wissen, da ich ehrlich gesagt nicht dazu in der Lage bin. Ich habe hervorgehoben, wo ich versucht habe, mein Problem mit der Punktzahl zu beheben. Hier ist mein Code:Wie kann ich die Punktzahl erhöhen, wenn ein Rechteck auf ein bewegtes Bild trifft?
PImage sun,person1,person2,person3,person4,**coin**;
int x,y;
float ypos=0;
float ypos2=4;
**int coin_x,coin_y,coin_count;
int score=0,lives=3;**
void setup()
{
size(1000,585);
person1 = loadImage("person1.png");
sun = loadImage("sun.png");
**coin = loadImage("coin.png");**
person2 = loadImage("person2.png");
person3 = loadImage("person3.png");
person4 = loadImage("person4.png");
x=width/2;
y=height/2;
}
void draw()
{
background(170,200,255);
image(sun,720,-30,160,160);
fill(255,240,50);
ellipse(800,50,85,85);
fill(200,255,150);
rect(0,200,1000,400);
fill(0,0,0);
rect((-frameCount%200)*10+1000,130,90,70);
rect((-frameCount%200)*10+1090,100,50,100);
rect((-frameCount%200)*10+1500,130,90,70);
rect((-frameCount%200)*10+1900,100,50,100);
fill(200,200,200);
rect(0,250,1000,90);
fill(200,200,200);
rect(0,350,1000,90);
fill(200,200,200);
rect(0,450,1000,90);
fill(255,100,100);
//vvvvvvvvv The car vvvvvvvvvvv
**rect(0,mouseY+0,200,80);
fill(0);
ellipse(50,mouseY+60,60,60);
fill(0);
ellipse(150,mouseY+60,60,60);
fill(100);
ellipse(50,mouseY+60,40,40);
fill(100);
ellipse(150,mouseY+60,40,40);
fill(255,100,100);
arc(100,mouseY+0,160,150,PI,TWO_PI);
fill(160,210,300);
arc(100,mouseY+0,130,130,PI,TWO_PI);
fill(255,100,100);
rect(95,mouseY+0,10,-75);
fill(0);
rect(99,mouseY+0,2,80);**
//^^^^^^^^^The car^^^^^^^^^
image(person4,(-frameCount%300)*10+2500,250+sin(ypos)*100,120,120);
ypos +=0.01;
image(person3,(-frameCount%450)*5+2000,400+sin(ypos)*140,120,120);
ypos +=0.01;
image(person1,(-frameCount%300)*5+1000,300+sin(ypos)*50,120,120);
ypos +=0.01;
**image(coin,coin_x+(-frameCount%100)*20+1000,coin_y+300-sin(ypos2)*130,50,50);**
ypos2 +=0.05;
image(person2,(-frameCount%400)*5+1600,250-sin(ypos)*100,120,120);
ypos +=0.08;
**image(coin,coin_x+(-frameCount%300)*20+1900,coin_y+300+sin(ypos2)*130,50,50);
ypos2 +=0.05;**
**if((coin_x>10)&&(coin_x<10))
{
if(abs((coin_y+10)-(mouseY+0))<25)
{
coin_count++;
}
}**
**textSize(30);
fill(0);
text("Score:"+coin_count,0,25);**
}
Bitte verknüpfen Sie Crosspoints. Diese Frage wurde auch hier veröffentlicht: https://forum.processing.org/two/discussion/25682/how-can-i-make-the-score-go-up-when-a-rectangle-hits-a- bewegendes Bild –