Need Help very fast pls!
in
Programming Questions
•
1 year ago
Hey guys i have to programm a game till the next 4 hours and i need help with the final step:
i want the score to get 1 up if the Kirby hits the circle but i dont get it to that point -.-
here is the game if you urn it, you wil understand how it shall work, pls tell how i have to write the if sentence!
i want the score to get 1 up if the Kirby hits the circle but i dont get it to that point -.-
here is the game if you urn it, you wil understand how it shall work, pls tell how i have to write the if sentence!
- //Tunnellänge & -breite
float tubeLength=100000, tubeWidth= 230;
//Position des Tunnel
float screenLeftY = 0;
float health;
float initialHealth = 500;
//Form, Geschwindigkeit und Position der Figur
float bodyX, bodyY;
float bodyR=50;
float bodyVX, speed;
float bodyVY;
float legX, legY;
float legR;
float legVX;
float legVY;
float toeX, toeY, toeX2, toeY2;
float toeVX;
float toeVY;
float eyeX, eyeY;
float eyeVX;
float eyeVY;
//Variablen für den Kreis
float circleX, circleY;
float circleR=30;
float circleVY=100;
int score = 0;
// Variablen die den verschiedenen Spielestatus beschreiben.
int GAMEWAIT=0, GAMERUNNING=1, GAMEOVER=2, GAMEWON=3;
int gameState=GAMEWAIT;
void setup() {
size (640,480);
screenLeftY = 0;
}
//Linksbewegung der Figur
void keyPressed() {
if (keyCode==LEFT) {
bodyVX = -speed;
legVX= -speed;
toeVX= -speed;
eyeVX= -speed;
}
//Rechtsbewegung der Figur
else if (keyCode==RIGHT) {
bodyVX = +speed;
legVX= +speed;
toeVX= +speed;
eyeVX= +speed;
}
// Spielstart
else if (keyCode==' ' && gameState!=GAMERUNNING) {
bodyX= 0.9*height*noise (0)+tubeWidth/2;
bodyY= 0;
bodyVX=0;
speed=300;
bodyVY=100;
legX=bodyX+15;
legY=bodyY+30;
legR=30;
legVX=0;
legVY=100;
toeX=bodyX-15;
toeY=bodyY+30;
toeX2=bodyX+15;
toeY2=bodyY+30;
toeVX=0;
toeVY=100;
eyeX=bodyX+5;
eyeY=bodyY+3;
eyeVX=0;
eyeVY=100;
circleX = 0.9*height*noise (0)+tubeWidth*random(0,3);
circleY = 200;
gameState = GAMERUNNING;
health = initialHealth;
}
}
//Stillstand der Figur
void keyReleased() {
bodyVX=0;
legVX=0;
toeVX=0;
eyeVX=0;
}
void draw() {
//Wenn das Spiel läuft, starten die Bewegungen
if (gameState==GAMERUNNING) {
bodyX = bodyX + bodyVX/frameRate;
bodyY = bodyY + bodyVY/frameRate;
legX=legX+legVX/frameRate;
toeX=toeX+toeVX/frameRate;
toeX2=toeX2+toeVX/frameRate;
eyeX=eyeX+eyeVX/frameRate;
legY=legY+legVY/frameRate;
toeY=toeY+toeVY/frameRate;
toeY2=toeY2+toeVY/frameRate;
eyeY=eyeY+eyeVY/frameRate;
circleY=circleY-circleVY/frameRate;
screenLeftY = bodyY-50;
// Kirby darf den Tunnel nicht verlassen
{
float x=0.9*width*noise (bodyY/width);
if (bodyX-25<=x || bodyX+25>=x+tubeWidth) {health-=20;
bodyX=x+tubeWidth/2;
legX=bodyX+15;
toeX=bodyX-15;
toeX2=bodyX+15;
eyeX=bodyX+5;
}
//Wenn ein Kreis außerhalb des Tunnels generiert wird, soll ihm eine neue Position zugewiesen werden.
if (circleX-15<=x || circleX+15>=x+tubeWidth){
circleX = 0.9*height*noise (0)+tubeWidth*random(0,3);
} - //HERE I NEED HELP:
// Wenn Kirby einen Kreis erwischt, soll sich Score um 1 erhöhen und die Geschwindigkeit von Kirby erhöhen
if(bodyY+bodyR>=circleY-circleR &&
bodyX+bodyR>=circleX-circleR &&
bodyX-bodyR<=circleX+circleR) {
score = score+1;
}
//Wenn der Kreis oben verschwindet soll er eine neue Position bekommen
if(circleY<=0) {
circleY = circleY+height;
}
//Wenn Score sich erhöht, soll sich auch die Geschwindigkeit des Spiels erhöhen
if(score>=20 && score<=39) {
bodyVY=150;
legVY=150;
toeVY=150;
eyeVY=150;
}
else if(score>=40 && score<=59){
bodyVY=200;
legVY=200;
toeVY=200;
eyeVY=200;
}
else if(score>=60 && score<=79){
bodyVY=250;
legVY=250;
toeVY=250;
eyeVY=250;
}
else if(score>=80 && score<=99){
bodyVY=300;
legVY=300;
toeVY=300;
eyeVY=300;
}
else if(score>=100){
bodyVY=350;
legVY=350;
toeVY=350;
eyeVY=350;
}
//Wenn Kirby das Ziel erreicht, ist das Spiel Gewonnen
if (bodyY>tubeLength) gameState = GAMEWON;
}
//Wenn das Leben des Kirby auf 0 fällt ist das Spiel Gameover
if (health<=0) gameState = GAMEOVER;
//Hintergrund, Leben und Verlauf des Tunnels
background (146,136,136);
stroke(0);
strokeWeight(1);
for (float y=screenLeftY; y<screenLeftY+height; y+=1) {
float x=0.9*width*noise (y/width);
line (x, y-screenLeftY, x+tubeWidth, y-screenLeftY);
fill (map(health, 0, initialHealth, 255, 0),
map(health, 0, initialHealth, 0, 255),
0);
rect (0,0,map(health, 0, initialHealth, 0, 500), 18);
}
//Kreis
stroke(0);
fill(31,252,43);
strokeWeight(2);
ellipseMode(CENTER);
ellipse(circleX,circleY,circleR,circleR);
stroke (250,255,0);
strokeWeight (5);
line (0, tubeLength-screenLeftY, width, tubeLength-screenLeftY);
//Kirby
stroke(0);
fill(98, 251, 255);
strokeWeight(5);
ellipseMode(CENTER);
ellipse(bodyX, bodyY-screenLeftY, bodyR, bodyR);
if (keyPressed && keyCode == RIGHT) {
//Kirby schaut nach rechts
point (eyeX, eyeY-screenLeftY);
point (eyeX+15, eyeY-screenLeftY);
arc(legX, legY-screenLeftY, legR, legR, TWO_PI-PI, TWO_PI);
arc(legX-15, legY-screenLeftY, legR, legR, TWO_PI-PI, TWO_PI);
line (toeX, toeY-screenLeftY, toeX2, toeY2-screenLeftY);
line (toeX+15, toeY-screenLeftY, toeX2+15, toeY2-screenLeftY);
}
else if (keyPressed && keyCode == LEFT) {
//Kirby schaut nach links
point (eyeX-6, eyeY-screenLeftY);
point (eyeX-23, eyeY-screenLeftY);
arc(legX-30, legY-screenLeftY, legR, legR, TWO_PI-PI, TWO_PI);
arc(legX-15, legY-screenLeftY, legR, legR, TWO_PI-PI, TWO_PI);
line (toeX, toeY-screenLeftY, toeX2, toeY2-screenLeftY);
line (toeX-15, toeY-screenLeftY, toeX2-15, toeY2-screenLeftY);
}
else {
//Kirby steht still
point (eyeX+2, eyeY-screenLeftY);
point (eyeX-11, eyeY-screenLeftY);
arc(legX-25, legY-screenLeftY, legR-7, legR, TWO_PI-PI, TWO_PI);
arc(legX-5, legY-screenLeftY, legR-7, legR, TWO_PI-PI, TWO_PI);
line (toeX+6, toeY-screenLeftY, toeX2+6, toeY2-screenLeftY);
line (toeX-6, toeY-screenLeftY, toeX2-6, toeY2-screenLeftY);
}
}
//Wenn das Spiel nicht läuft d.h. sich entweder im Startmodus, Game Over oder Game Won befindet, dann soll ein blinkender Text erscheinen, der den jeweiligen Spielestatus anzeigt.
if (gameState!=GAMERUNNING) {
textSize (50);
textAlign (CENTER, CENTER);
fill (random(0,255), random(0,255), random(0,255));
if (gameState==GAMEOVER) text ("GAME OVER", width/2, height/2);
else if (gameState==GAMEWON) text ("VICTORY", width/2, height/2);
else if (gameState==GAMEWAIT) text ("PRESS SPACE TO START", width/2, height/2);
}
//clock
int m = millis();
int seconds = m / 1000;
int minutes = seconds / 60;
seconds -= minutes * 60;
fill (255);
textSize(20);
textAlign (CENTER, TOP);
text (seconds, 585, 20);
text (":",570, 20);
text (minutes, 555, 20);
// score
textSize (13);
textAlign (CENTER, TOP);
fill(255);
text("SCORE: ",570,50);
textSize (20);
fill (19,250,34);
text (score, 610, 45);
}
1