Doing a processing project for my university course [closed]











up vote
-1
down vote

favorite












could anyone tell me where i am going wrong?



The problem is that i want to shoot a bullet thats initial direction will follow the where the mouse INITIALLY was compared to location of character on mouseclick. but my code now on mouseclick will draw another bullet(not shown here), but all bullets drawn will travel in a direction following an angle respective to current character location.



this is an example of what it looks like



int bulletTotal = 5;
float bulletX = new float [bulletTotal];
float bulletY = new float [bulletTotal];
int shots;
float bulletSpeed;
float angle;
int charaStartX, charaStartY;
int charaWid, charaHght;
int sx, sy;
boolean isUp, isDown, isLeft, isRight;

void setup()
{
size(1500,900);
charaStartX = width/2;
charaStartY = height/2;
charaWid = charaHght = 75;
sx = sy = 4;
for(int j =0; j < bulletTotal; j++)
{
bulletX[j] = charaStartX;
bulletY[j] = charaStartY;
}
bulletSpeed = 5;
isUp = false;
isDown = false;
isLeft = false;
isRight = false;
}

void draw()
{
ellipse(charaStartX, charaStartY, charaWid, charaHght);
for(int j = 0; j < bulletTotal; j++)
{
rect(bulletX[j], bulletY[j], 25, 25);
movement();
angle = atan2(mouseY - charaStartY, mouseX - charaStartX);
bulletX[j] += bulletSpeed * cos(angle);
bulletY[j] += bulletSpeed * sin(angle);
}
}

void movement()
{
if(isUp == true)
{
charaStartY = charaStartY - sy;
}else if(isDown == true)
{
charaStartY = charaStartY + sy;
}
if(isLeft == true)
{
charaStartX = charaStartX - sx;
}else if (isRight == true)
{
charaStartX = charaStartX + sx;
}
}
void keyPressed()
{
if(key == 'w'||key == 'W')
{
isUp = true;
}
if(key == 's'||key == 'S')
{
isDown = true;
}
if(key == 'a'||key == 'A')
{
isLeft = true;
}
if(key =='d'||key == 'D')
{
isRight = true;
}

}

void keyReleased()
{
if(key == 'w'||key == 'W')
{
isUp = false;
}
if(key == 's'||key == 'S')
{
isDown = false;
}
if(key == 'a'||key == 'A')
{
isLeft = false;
}
if(key =='d'||key == 'D')
{
isRight = false;
}
}









share|improve this question















closed as off-topic by JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs Nov 19 at 17:45


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
    – Kevin Workman
    Nov 18 at 17:02










  • ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
    – Tan Yu Hau Sean
    Nov 19 at 13:50










  • void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
    – Tan Yu Hau Sean
    Nov 19 at 13:50












  • also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
    – Tan Yu Hau Sean
    Nov 19 at 14:08






  • 1




    Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
    – Kevin Workman
    Nov 19 at 17:37















up vote
-1
down vote

favorite












could anyone tell me where i am going wrong?



The problem is that i want to shoot a bullet thats initial direction will follow the where the mouse INITIALLY was compared to location of character on mouseclick. but my code now on mouseclick will draw another bullet(not shown here), but all bullets drawn will travel in a direction following an angle respective to current character location.



this is an example of what it looks like



int bulletTotal = 5;
float bulletX = new float [bulletTotal];
float bulletY = new float [bulletTotal];
int shots;
float bulletSpeed;
float angle;
int charaStartX, charaStartY;
int charaWid, charaHght;
int sx, sy;
boolean isUp, isDown, isLeft, isRight;

void setup()
{
size(1500,900);
charaStartX = width/2;
charaStartY = height/2;
charaWid = charaHght = 75;
sx = sy = 4;
for(int j =0; j < bulletTotal; j++)
{
bulletX[j] = charaStartX;
bulletY[j] = charaStartY;
}
bulletSpeed = 5;
isUp = false;
isDown = false;
isLeft = false;
isRight = false;
}

void draw()
{
ellipse(charaStartX, charaStartY, charaWid, charaHght);
for(int j = 0; j < bulletTotal; j++)
{
rect(bulletX[j], bulletY[j], 25, 25);
movement();
angle = atan2(mouseY - charaStartY, mouseX - charaStartX);
bulletX[j] += bulletSpeed * cos(angle);
bulletY[j] += bulletSpeed * sin(angle);
}
}

void movement()
{
if(isUp == true)
{
charaStartY = charaStartY - sy;
}else if(isDown == true)
{
charaStartY = charaStartY + sy;
}
if(isLeft == true)
{
charaStartX = charaStartX - sx;
}else if (isRight == true)
{
charaStartX = charaStartX + sx;
}
}
void keyPressed()
{
if(key == 'w'||key == 'W')
{
isUp = true;
}
if(key == 's'||key == 'S')
{
isDown = true;
}
if(key == 'a'||key == 'A')
{
isLeft = true;
}
if(key =='d'||key == 'D')
{
isRight = true;
}

}

void keyReleased()
{
if(key == 'w'||key == 'W')
{
isUp = false;
}
if(key == 's'||key == 'S')
{
isDown = false;
}
if(key == 'a'||key == 'A')
{
isLeft = false;
}
if(key =='d'||key == 'D')
{
isRight = false;
}
}









share|improve this question















closed as off-topic by JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs Nov 19 at 17:45


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
    – Kevin Workman
    Nov 18 at 17:02










  • ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
    – Tan Yu Hau Sean
    Nov 19 at 13:50










  • void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
    – Tan Yu Hau Sean
    Nov 19 at 13:50












  • also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
    – Tan Yu Hau Sean
    Nov 19 at 14:08






  • 1




    Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
    – Kevin Workman
    Nov 19 at 17:37













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











could anyone tell me where i am going wrong?



The problem is that i want to shoot a bullet thats initial direction will follow the where the mouse INITIALLY was compared to location of character on mouseclick. but my code now on mouseclick will draw another bullet(not shown here), but all bullets drawn will travel in a direction following an angle respective to current character location.



this is an example of what it looks like



int bulletTotal = 5;
float bulletX = new float [bulletTotal];
float bulletY = new float [bulletTotal];
int shots;
float bulletSpeed;
float angle;
int charaStartX, charaStartY;
int charaWid, charaHght;
int sx, sy;
boolean isUp, isDown, isLeft, isRight;

void setup()
{
size(1500,900);
charaStartX = width/2;
charaStartY = height/2;
charaWid = charaHght = 75;
sx = sy = 4;
for(int j =0; j < bulletTotal; j++)
{
bulletX[j] = charaStartX;
bulletY[j] = charaStartY;
}
bulletSpeed = 5;
isUp = false;
isDown = false;
isLeft = false;
isRight = false;
}

void draw()
{
ellipse(charaStartX, charaStartY, charaWid, charaHght);
for(int j = 0; j < bulletTotal; j++)
{
rect(bulletX[j], bulletY[j], 25, 25);
movement();
angle = atan2(mouseY - charaStartY, mouseX - charaStartX);
bulletX[j] += bulletSpeed * cos(angle);
bulletY[j] += bulletSpeed * sin(angle);
}
}

void movement()
{
if(isUp == true)
{
charaStartY = charaStartY - sy;
}else if(isDown == true)
{
charaStartY = charaStartY + sy;
}
if(isLeft == true)
{
charaStartX = charaStartX - sx;
}else if (isRight == true)
{
charaStartX = charaStartX + sx;
}
}
void keyPressed()
{
if(key == 'w'||key == 'W')
{
isUp = true;
}
if(key == 's'||key == 'S')
{
isDown = true;
}
if(key == 'a'||key == 'A')
{
isLeft = true;
}
if(key =='d'||key == 'D')
{
isRight = true;
}

}

void keyReleased()
{
if(key == 'w'||key == 'W')
{
isUp = false;
}
if(key == 's'||key == 'S')
{
isDown = false;
}
if(key == 'a'||key == 'A')
{
isLeft = false;
}
if(key =='d'||key == 'D')
{
isRight = false;
}
}









share|improve this question















could anyone tell me where i am going wrong?



The problem is that i want to shoot a bullet thats initial direction will follow the where the mouse INITIALLY was compared to location of character on mouseclick. but my code now on mouseclick will draw another bullet(not shown here), but all bullets drawn will travel in a direction following an angle respective to current character location.



this is an example of what it looks like



int bulletTotal = 5;
float bulletX = new float [bulletTotal];
float bulletY = new float [bulletTotal];
int shots;
float bulletSpeed;
float angle;
int charaStartX, charaStartY;
int charaWid, charaHght;
int sx, sy;
boolean isUp, isDown, isLeft, isRight;

void setup()
{
size(1500,900);
charaStartX = width/2;
charaStartY = height/2;
charaWid = charaHght = 75;
sx = sy = 4;
for(int j =0; j < bulletTotal; j++)
{
bulletX[j] = charaStartX;
bulletY[j] = charaStartY;
}
bulletSpeed = 5;
isUp = false;
isDown = false;
isLeft = false;
isRight = false;
}

void draw()
{
ellipse(charaStartX, charaStartY, charaWid, charaHght);
for(int j = 0; j < bulletTotal; j++)
{
rect(bulletX[j], bulletY[j], 25, 25);
movement();
angle = atan2(mouseY - charaStartY, mouseX - charaStartX);
bulletX[j] += bulletSpeed * cos(angle);
bulletY[j] += bulletSpeed * sin(angle);
}
}

void movement()
{
if(isUp == true)
{
charaStartY = charaStartY - sy;
}else if(isDown == true)
{
charaStartY = charaStartY + sy;
}
if(isLeft == true)
{
charaStartX = charaStartX - sx;
}else if (isRight == true)
{
charaStartX = charaStartX + sx;
}
}
void keyPressed()
{
if(key == 'w'||key == 'W')
{
isUp = true;
}
if(key == 's'||key == 'S')
{
isDown = true;
}
if(key == 'a'||key == 'A')
{
isLeft = true;
}
if(key =='d'||key == 'D')
{
isRight = true;
}

}

void keyReleased()
{
if(key == 'w'||key == 'W')
{
isUp = false;
}
if(key == 's'||key == 'S')
{
isDown = false;
}
if(key == 'a'||key == 'A')
{
isLeft = false;
}
if(key =='d'||key == 'D')
{
isRight = false;
}
}






processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 13:31

























asked Nov 18 at 16:23









Tan Yu Hau Sean

12




12




closed as off-topic by JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs Nov 19 at 17:45


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs Nov 19 at 17:45


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – JJJ, John Coleman, Kevin Workman, Michael Dodd, K.Dᴀᴠɪs

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
    – Kevin Workman
    Nov 18 at 17:02










  • ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
    – Tan Yu Hau Sean
    Nov 19 at 13:50










  • void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
    – Tan Yu Hau Sean
    Nov 19 at 13:50












  • also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
    – Tan Yu Hau Sean
    Nov 19 at 14:08






  • 1




    Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
    – Kevin Workman
    Nov 19 at 17:37














  • 1




    Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
    – Kevin Workman
    Nov 18 at 17:02










  • ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
    – Tan Yu Hau Sean
    Nov 19 at 13:50










  • void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
    – Tan Yu Hau Sean
    Nov 19 at 13:50












  • also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
    – Tan Yu Hau Sean
    Nov 19 at 14:08






  • 1




    Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
    – Kevin Workman
    Nov 19 at 17:37








1




1




Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
– Kevin Workman
Nov 18 at 17:02




Please post your code in the form of a Minimal, Complete, and Verifiable example directly in your post. That means do not post your full project, and do not post links to other sites. Narrow your problem down to an example program that focuses on the problem in as few lines as possible, and include that code directly in your post. Good luck.
– Kevin Workman
Nov 18 at 17:02












ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
– Tan Yu Hau Sean
Nov 19 at 13:50




ok i m not using classes anymore. way above my league. now i want to draw enemies using an array. i loaded 5 enemies into my array. but i want to draw more enemies and each enemy is a random of these 5. how do i do so?
– Tan Yu Hau Sean
Nov 19 at 13:50












void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
– Tan Yu Hau Sean
Nov 19 at 13:50






void setup() { for(int i = 0; i<number; i++) { enemy[i] = loadImage("enemy"+i+".png"); } } void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); while (dist( enemyX[i], enemyY[i], width/2, height/2) < 500) { enemyX[i] = int(random(0, width)); enemyY[i] = int(random(0, height)); } } }
– Tan Yu Hau Sean
Nov 19 at 13:50














also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
– Tan Yu Hau Sean
Nov 19 at 14:08




also i want enemies to come in from top, bottom, left and right sides of the screen but my code says || operator is undefined for what i m doing. void drawEnemy() { for(int i = 0; i<5; i++) { image(enemy[type], enemyX[i], enemyY[i], charaWid, charaHght); enemyX[i] = int(random(-charaWid, 0))||int(random(width, width+charaWid)); enemyY[i] = int(random(-charaHght, 0))||int(random(height, height+charaHght)); } }
– Tan Yu Hau Sean
Nov 19 at 14:08




1




1




Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
– Kevin Workman
Nov 19 at 17:37




Please edit your post to include the code. Also please make sure we can copy-paste your code to run it.
– Kevin Workman
Nov 19 at 17:37

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]