# Hey guys, was wondering how i can make a scoring system and get my character to reset? I also need to be able to change the max score

**URL:** <https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940>\
**Category:** Beginners\
**Created:** [May 18, 2022, 9:42am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940 "2022-05-18T09:42:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mosey](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mosey](https://discourse.processing.org/u/mosey)\
**Post date:** [May 18, 2022, 9:42am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/1 "2022-05-18T09:42:35Z")

</div>

int pedestrianX;  
int pedestrianY;  
int vehicleX;  
int vehicleY;  
PFont f;  
int lineX = 0;  
int lineY = 80; // Vertical location of each line  
int spacing = 50; // How far apart is each line  
int len = 50; // Length of each line  
float speed = random(0, 10);

void setup() {  
size(1200, 400);  
f = createFont(“Arial”, 100, true);  
}

void draw() {  
background(255);  
boolean dash = true;  
for (int y = 0; y \< height; y+=20) {  
for (int i = 0; i \< width; i+=20) {  
if (dash) stroke(0);  
else stroke(255);  
line(i, 100, i + 20, 100);  
dash = !dash;  
}  
}

//line(0, height / 4, 1200, height / 4);

vehicleX = (frameCount \* 5) % width;  
vehicleY = 0;

drawPedestrian(pedestrianX, pedestrianY); // This is used to create the pedestrian  
drawVehicle(vehicleX, vehicleY); // This is used to create the vehicle.  
// The speed can be altered by changing the number multipied by the frameCount.  
// The % is used to reset the vehicle

collisionDetection();  
fill(0);  
if ( collisionDetection()) {  
stop();  
background(#F70000);  
textFont(f);  
text(“Game over!”, 300, 200);  
}  
if (pedestrianY \> height) {  
pedestrianY = 314;  
}  
}

void drawVehicle(int vehicleX, int ypos) {  
int x[] = { 0 + vehicleX, 150 + vehicleX, 100 + vehicleX, 105 + vehicleX, 70 + vehicleX, 30 + vehicleX, 40 };  
int y[] = { 0, 80, 70, 40, 30, 10, 60, 78, 50 }; // These are all common points in the shapes. The vehicleX variable enables the vehicle to move.

stroke(0);  
fill(#DE482B);  
quad(x[4], y[3], x[2], y[4], x[2], y[1], x[4], y[2]); //This is the hood of the vehicle

fill(#1AB718);  
quad(x[0], y[4], x[5], y[3], x[5], y[2], x[0], y[1]); //This is the boot of the vehicle

rectMode(CORNER);

fill(#144EA7);  
rect(x[5], y[3], x[6], y[3]); //This is the roof of the vehicle

fill(#E2E359);  
quad(x[0], y[1], x[5], y[2], x[4], y[2], x[2], y[1]);  
quad(x[0], y[4], x[5], y[3], x[4], y[3], x[2], y[4]); //These are the doors of the vehicle

stroke(#E2E359);  
triangle(x[2], y[3], x[1], y[4], x[1], y[6]);  
triangle(x[2], y[2], x[1], y[8], x[1], y[7]); //These are the headlights of the vehicle

stroke(0);  
}

void drawPedestrian(int pedestrianX, int pedestrianY) {

int x[] = { 11, 31, 600 + pedestrianX};  
int y[] = { 10, 20, 30, 30, 314 + pedestrianY, 347 + pedestrianY, 375 + pedestrianY, 392 + pedestrianY };

stroke(0);  
fill(#FF1803);  
ellipse(x[2], y[4], x[1], y[2]); // This is the head of the pedestrian

fill(#1FC14E);  
rectMode(CENTER);  
rect(x[2], y[5], x[1], y[3]); // This is the body of the pedestrian

fill(#341FC1);  
rect(x[2], y[6], x[0], y[1]); // This is the pillar of the pedestrian

fill(#F5FA17);  
ellipse(x[2], y[7], x[0], y[0]); // This is the sphere on which the pedestrian glides on  
}

void keyPressed() {  
if ((keyPressed == true) && (key == CODED)) {  
if (keyCode == UP) {  
pedestrianY = pedestrianY - height/4;  
} else if (keyCode == DOWN ) {  
pedestrianY = pedestrianY + height/4;  
} else if (keyCode == LEFT) {  
pedestrianX = pedestrianX - 50;  
} else if (keyCode == RIGHT) {  
pedestrianX = pedestrianX + 50;  
}  
}  
}

boolean collisionDetection() {  
float vx = vehicleX + 5;  
float vy = vehicleY + 30;  
float vw = 150;  
float vh = 50;  
float px = pedestrianX + 585;  
float py = pedestrianY + 300;  
float pw = 30;  
float ph = 95;  
// Turn the lines below on to see borders on the collsion zones.  
noFill();  
noStroke();  
rect(vx, vy, vw, vh);  
rect(px, py, pw, ph);  
stroke(0);

if (vx + vw \>= px && vx \<= px + pw && vy + vh \>= py && vy \<= py + ph) {  
return true;  
} else {  
return false;  
}  
}

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 18, 2022, 9:48am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/2 "2022-05-18T09:48:08Z")

</div>

How would the scoring system work? Do you mean if the pedestran successfully manages to dodge the car?

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 18, 2022, 10:05am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/3 "2022-05-18T10:05:13Z")

</div>

Assuming you have a boolean that determens if you can increase the score you can use something like

```auto
if(higherScore){
if(score<=hardCap) score++;
reset();
}

```

You just have to definie score and hardCap as a global field and reset as method.

You can change the max score by changing the hardCap field.  
If you want some input from the user though you look at this code:

```auto
import javax.swing.*;
int inp=int(JOptionPane.showInputDialog(null, "Window Text", "Window name", JOptionPane.INFORMATION_MESSAGE));
println(inp);

```

Basicly when you enter a number it will be put in inp. Keep in mind that this will interrupt the sketch so you can’t give it inputs anymore and the car won’t move.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 18, 2022, 10:27am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/4 "2022-05-18T10:27:43Z")

</div>

Also, do you want to store the score on the hard drive? This changes the thing a bit too.

---

<div class="post-metadata">

**Author:** ![mosey](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mosey](https://discourse.processing.org/u/mosey)\
**Post date:** [May 18, 2022, 1:27pm UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/5 "2022-05-18T13:27:22Z")

</div>

Yea it cant hit the car

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 18, 2022, 1:35pm UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/6 "2022-05-18T13:35:32Z")

</div>

So the condition to increment the score is that the y-coordinate of the character reaches or exceeds a certain value. I think

```auto
if (pedestranY<=0){
   if(score<=hardCap) score++;
   reset();
}

```

The next thing is thinking about what you want to actually reset.  
I would absolutly reset pedestranY. But maybe reseting the pedesstranX might also be a good idea.

---

<div class="post-metadata">

**Author:** ![mosey](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mosey](https://discourse.processing.org/u/mosey)\
**Post date:** [May 19, 2022, 7:33am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/7 "2022-05-19T07:33:44Z")

</div>

I’ve tried this but for some reason it doesn’t work at all. Like the character doesnt get reset

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 19, 2022, 9:14am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/8 "2022-05-19T09:14:10Z")

</div>

> [@mosey](#):
>
> Like the character doesnt get reset

Post your entire code please

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 19, 2022, 1:34pm UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/9 "2022-05-19T13:34:59Z")

</div>

I just tested it myself. I thought that pedestrianY was the Y-position of the sprite but I was wrong. Checking if `pedestrianY<=-400` should do the trick.

You can put this code in draw:

```auto
  if(pedestrianY<=-400){
    pedestrianY=0;
    if(score<hardCap) score++;
    println(score);
  }

```

And dont forget to create the score and hard-cap fields!

I hope that helps!

---

<div class="post-metadata">

**Author:** ![mosey](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mosey](https://discourse.processing.org/u/mosey)\
**Post date:** [May 20, 2022, 4:13am UTC](https://discourse.processing.org/t/hey-guys-was-wondering-how-i-can-make-a-scoring-system-and-get-my-character-to-reset-i-also-need-to-be-able-to-change-the-max-score/36940/10 "2022-05-20T04:13:22Z")

</div>

Oh my god thank you so much. I’ve been stuck on this for days and you finally helped me work it out. Thank you so much
