We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I'm having trouble with the program I'm working on. I want it to show a top and bottom line, which it does, and a triangle along the bottom line that would be considered the gun. Then with a left click, a bullet is shot out of the top of the triangle, and it goes up but stops at the top line, which I want, but, I don't want it to continuously keep shooting when I only click it once. It's like it's on repeat. Also, I don't want the bullet to disappear when my mouse moves. How would I do this? And then when you click the right mouse button, a pac man sort of image appears from the top line and ends at the bottom. It's also doing the same as the bullet where it repeats and disappears when I move my mouse and I need help fixing that. And then with the pac man image, I have inserted two images, one where it's a closed yellow circle and one where it's slightly open, how can I alternate between the two while it's moving along the y-axis so it looks like it's "chomping"? Sorry this is a lot of questions but I could really use some help! Thank you so much! Here is what I currently have:
*/
// import images
PImage close, open1;
// define global variables
int bulletX;
int bulletY = 430;
float pacX = random(30,470);
float pacY = random(30,30);
boolean bulletShown = false;
boolean pacShown = false;
boolean pacOpen;
void setup() {
size(500,500); // Set the size of the window
PFont font = loadFont ("agency-20.vlw"); // Load font
textFont (font); // Configure font
color(255); // Set font color to white
close = loadImage("close.png");
open1 = loadImage("open1.jpg");
} // end setup
void draw() {
background(0); // Erase background with black
stroke(255); // Set line color to white
line(30,450,470,450); // Draw bottom line
line(30,30,470,30); // Draw top line
fill(255); // Set text to white
text("Left mouseClick = Bullet & Right mouseClick = PacMan Invader",70,480); // Insert text "Left mouseClick = Bullet & Right mouseClick = PacMan Invader"
gun();
bullet();
pac();
} // end draw
void gun() {
// gun follows wherever mouse is using mouseX
if (mouseX < 30) {
mouseX = 30;
}
if (mouseX > 450) {
mouseX = 450;
}
triangle(mouseX,450, mouseX + 10,430, mouseX + 20,450); // Draw gun at mouseX
} // end gun
void bullet() {
if (mouseButton == LEFT) {
bulletShown = true;
ellipse(mouseX + 10,bulletY,5,5);
bulletY -= 5;
if (bulletY <= 30) {
bulletShown = false;
bulletY = 430;
}
}
if (bulletY == pacY) {
bulletShown = false;
pacShown = false;
}
} // end bullet
void pac() {
if (mouseButton == RIGHT) {
pacShown = true;
image(open1,pacX,pacY);
image(close,pacX,pacY);
pacY +=5;
if (pacY >= 400) {
pacShown = false;
pacY = 30;
}
}
} // end pac
Answers
edited
Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
An additional note, posting screenshots don't help when it is related to code. Images get resize by forum, code is hard to read and we cannot copy and paste it to be able to run it. Just format the code by editing your post.
Kf
Then add a condition that checks whether a bullet already exists somewhere around line 57. Perhaps using bulletShown.
That block looks wrong, generally. The bullet moving, being drawn and the check for it to disappear when it reaches the top of the screen shouldn't be conditional on the mouse button. Same with the pac code.