We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PImage [] Lambos = new PImage [5];
PImage checkered;
PImage background;
int [] horsePos = new int [5];
int [] results = new int [5];
int [] carY = new int [5];
int [] odds = new int [5];
int currPlace = 0;
float y;
boolean wagerIsAdded = false;
int state = 0;
float playerWager = 0;
float player2Wager = 0;
int xSlider = 235;
int xSlider2 = 800;
int min;
float max;
float max2;
int p1Choice;
int p2Choice;
int Winner = -1;
float playerBank = 1000;
float player2Bank = 1000;
void setup() {
size(1200, 800);
min = 10;
Lambos[0] = loadImage("red.png");
Lambos[1] = loadImage("orange.png");
Lambos[2] = loadImage("blue.png");
Lambos[3] = loadImage("green.png");
Lambos[4] = loadImage("yellow.png");
//Image location on Y coordinate
carY[0] = 302;
carY[1] = 390;
carY[2] = 490;
carY[3] = 585;
carY[4] = 680;
checkered = loadImage("tile.jpg");
background = loadImage("back.png");
}
void draw() {
background(0);
max = playerBank;
max2 = player2Bank;
if (state == 0) {
for (int i=0; i < 5; i++) {
Lambos[i].resize(90, 30);
}
stroke(255);
strokeWeight(10);
fill(255);
line (235, 290, 435, 290);
rect(xSlider, 275, 10, 30);
line (800, 290, 1000, 290);
rect(xSlider2, 275, 10, 30);
stroke(255);
strokeWeight(10);
line(600, 100, 600, 716);
playerWager = map(xSlider, 235, 435, min, max);
player2Wager = map(xSlider2, 800, 1000, min, max2);
if (dist(mouseX, mouseY, xSlider, 275) < 70 && mousePressed) {
xSlider = mouseX;
}
if (dist(mouseX, mouseY, xSlider2, 275) < 70 && mousePressed) {
xSlider2 = mouseX;
}
if (xSlider < 235) {
xSlider = 235;
} else if (xSlider > 435) {
xSlider = 435;
}
if (xSlider2 < 800) {
xSlider2 = 800;
} else if (xSlider2 > 1000) {
xSlider2 = 1000;
}
text("Bank:" + " " + (int)playerBank, 270, 250);
text("Bank:" + " " + (int)player2Bank, 830, 250);
textSize(17);
text("Wager:" + " " + (int)playerWager, 280, 200);
textSize(17);
text("Wager:" + " " + (int)player2Wager, 840, 200);
textSize(30);
text("Race Game Assignment", 460, 50);
textSize(15);
text("By: Nathaniel K.", 560, 75);
textSize(30);
text("PLAYER 1", 260, 130);
text("PLAYER 2", 830, 130);
text("Car Bet On:" + " " + p1Choice, 230, 550);
text("Car Bet On:" + " " + p2Choice, 800, 550);
noFill();
rect(50, 100, 1100, 675);
strokeWeight(5);
textSize(20);
text("START", 568, 752);
noFill();
rect(550, 720, 100, 50);
for (int i= 0; i <5; i ++) {
image(Lambos[i], 70 + (105 * i), 400);
if (mouseX > 70 + (105 * i) && mouseX < 70 + (105 * i) + 100 && mouseY < 430 && mouseY > 400 && mousePressed) {
p1Choice = i + 1;
rect(70 + (105 * i), 400, 92, 31);
}
}
for (int i= 0; i <5; i ++) {
image(Lambos[i], 620 + (105 * i), 400);
if (mouseX > 620 + (105 * i) && mouseX < 620 + (105 * i) + 100 && mouseY < 430 && mouseY > 400 && mousePressed) {
p2Choice = i + 1;
rect(620 + (105 * i), 400, 92, 31);
}
}
if (dist(mouseX, mouseY, 70, 400) < 50) {
rect(65, 395, 95, 35);
}
if (dist(mouseX, mouseY, 600, 740) < 30 && mousePressed) {
state = 1;
}
} else if (state == 1) {
background.resize(width, height);
background(background);
for (int i = 0; i < 5; i ++) {
odds[i] = (int)random(0, 4);
}
for (int i=0; i< 5; i++) {
Lambos[i].resize(110, 40);
}
textSize(30);
text("1", 950, 330);
text("2", 950, 423);
text("3", 950, 520);
text("4", 950, 621);
text("5", 950, 712);
finishline();
for (int i=0; i < 5; i++) {
image(Lambos[i], horsePos[i], carY[i]);
}
for (int i = 0; i < 5; i ++) {
horsePos[i] += noise(y) * 8;
y += 1.8;
}
for (int i = 0; i < 5; i ++) {
if (horsePos[i] > 987 && results[i] == 0) {
results[i] = currPlace;
currPlace ++;
if (Winner == -1) {
Winner = i + 1; // the winner
}
if (currPlace > 5) {
if (p1Choice == Winner) {
playerBank = playerBank + playerWager * odds[p1Choice];
} else {
playerBank = playerBank - playerWager * odds[p1Choice];
}
if (p2Choice == Winner) {
player2Bank = player2Bank + player2Wager * odds[p2Choice];
} else {
player2Bank = player2Bank - player2Wager * odds[p2Choice];
}
state = 2;
}
}
}
} else if (state == 2) {
background(background);
finishline();
for (int i=0; i< 5; i++) {
image(Lambos[i], horsePos[i], carY[i]);
}
fill(0);
rect(50, 100, 870, 675);
textSize(20);
strokeWeight(5);
fill(255);
text("START", 220, 747);
line(500, 100, 500, 770);
noFill();
rect(200, 720, 100, 40);
textSize(30);
text("RESULTS", 240, 130);
text("POINTS", 680, 130);
textSize(20);
for (int i=0; i < 5; i++)
text("Car "+str(i+1)+": "+results[i], 100, 180+i*60);
text("Player 1:" + " " + (int)playerWager + " " + "on" + " " + "Horse #" + p1Choice, 600, 200);
text("Current Points:" + " " + (int)playerBank, 600, 250);
text("Odds:" + " " + odds[p1Choice], 600, 300);
text("Player 2:" + " " + (int)player2Wager + " " + "on" + " " + "Horse #" + p2Choice, 600, 400);
text("Current Points:" + " " + (int)player2Bank, 600, 450);
text("Odds:" + " " + odds[p2Choice], 600, 500);
if (dist(mouseX, mouseY, 230, 730) < 50 && mousePressed) {
state = 0;
for (int i = 0; i < 5; i ++) {
horsePos[i] = 0;
results[i] = 0;
}
currPlace = 0;
Winner = -1;
wagerIsAdded = false;
}
textSize(30);
text("1", 950, 330);
text("2", 950, 423);
text("3", 950, 520);
text("4", 950, 621);
text("5", 950, 712);
if (playerBank <= 0 || player2Bank <= 0) {
state = 3;
}
} else if (state == 3) {
background(0, 255, 0);
if (playerBank <= 0) {
textSize(40);
text("PLAYER 2 WINS!", 470, 300);
text("Bank:" + " " + (int)player2Bank, 520, 400);
}
if (player2Bank <= 0) {
textSize(40);
text("PLAYER 1 WINS!", 470, 300);
text("Bank:" + " " + (int)playerBank, 520, 400);
}
}
}
void finishline() {
checkered.resize(540, 505);
image(checkered, 1100, 260);
}
Answers
http://Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes
That's not your code.
Who is the author?
Is this homework?
Can you explain what a PVector is and to which lines you would apply it?
Show your attempt
https://forum.processing.org/two/discussion/22575/how-can-i-choose-which-car-i-want-to-bet-on-and-then-get-9x-the-amount-wagered-if-i-win
note the vandalism here: https://forum.processing.org/two/discussion/comment/98154/#Comment_98154
Calm down, I deleted that account, or at least I thought I did, and made this one @koogs @Chrisir
This is not homework! Why do people here always think this is homework! I am trying to teach myself coding! A PVector is a shorter than having x, and y variable separately, it is a combination of x, y, and sometimes z
You know what @koogs just close this discussion if no one is going to help me, plz and thx
it's the deleting of previous posts that means i won't be helping you.
the 'new account' deception isn't helping though.
So are you saying you don't believe me?
Please read this discussion DO NOT DELETE YOUR POSTS
If you are not going to follow the forum guidelines then find another forum!
Moderator
@quark, did you not read the rest of the discussion, this code is in another discussion, therefore making this unnecessary. Please do not take the deletion of this discussion as the deletion of code, the code is just on another discussion already.
Nobody wanted to help me with this, so I'm going to try to do it by myself somehow 8-|
Yes I read the rest of the discussion and the code you posted above yesterday does not appear in any of the 3 discussions you have posted so far. There was no link to any previous code posting so I am not sure how you expected anyone to help in this discussion.
No one can read your mind so when you start a discussion think about what readers might need to help you solve your problem. Try and make the question clear and concise and never delete comment text after you get a reply otherwise the discussion becomes disjointed and difficult for latecomers to follow.