I need help asap BEFORE 19:00 PM

please format code with </> button * homework policy * asking questions

I'm making a bubble shoot game and I want to know when my bullet hit the bubble then it will vanish and i get a point.

PLEASE explain

Can you use it in my code and //explain.?

int x, y, z, r;
boolean moveUp = false; //kulan starts utan att röra sig
float bulletY = 650; // kulans position
float bulletX = 350; // kulans position
float gunX = 350; // bollens position
int i;

void setup() {
size(800, 800);
background(255);
x=400;
y=700;
z=100;
}

void draw() {
fill(0);
frameRate(20);
ellipse(x, y, 30, 30);

fill(0, 0, 255);
for (i = 50; i <= 700; i += 49) {

// (i += 50) = (i=i+50)

rect(i, 100, 30, 30);

}
fill(255, 0, 0);
for (i = 50; i <= 700; i += 49) {
rect(i, 200, 30, 30);
}

fill(0, 255, 0);
for (i = 50; i <= 700; i += 49) {
rect(i, 300, 30, 30);
}
}

void keyPressed() {
if (key == CODED){
if (keyCode == LEFT) {
x = x - 10;

} else if (keyCode == RIGHT) 
x =  x + 10;


}

}

the link provided by @GoToLoop is a great resource. However it seems that you may not be willing to take the time to do the work. Your assignment is important not just so you can pass your semester and get some credits but because it teaches you skills necessary to become a good programmer. Knowing how to read documentation, trying techniques from different sources and evaluating the best one, and problem solving, or learning how to approach a problem and find a solution. I can guarantee you that you will benefit more from working at it, than by having someone simply give you the answer, especially if you also get given points for explaining why you arrived at the solution you did.

Ultimately in the real world a lot of code is found online, stackoverflow etc, however being given small snippets of code is useless if you do not know how to incorporate it.

3 Likes

I couldn’t find anything and i understand but please i need help!!!

thank you:

Please do not duplicate posts.

https://discourse.processing.org/t/how-to-shoot-bullets/24470

this is all I’m going to provide, as I cannot complete your assignment, if you have been paying attention in your class then this should make sense to you, and should be fairly straight forward. However this alone will not be able to pass you assignment

void setup(){
  size(600,600);
};
float x,y = 150;;
void draw(){
  background(50);
  line(100,100,100,200);
  ellipse(x+=10,y,10,10);
  if(x>width)x=0;
};

  boolean check_lineP(PVector a, PVector b, PVector c) {

    boolean k = false;
    float d1 = dist(a.x, a.y, b.x, b.y);
    float d2 = dist(a.x, a.y, c.x, c.y);
    float d3 = dist(b.x, b.y, c.x, c.y);
    float d4 = d2 + d3;
    //point(c.x,c.y);
    if (d4 <= d1 + res && d4 >= d1 - res) {
      k = true;
    }
    return k;
  };

[quote=“paulgoux, post:7, topic:24469”]
`if (d4 <= d1 + res && d4 >= d1 - res) {
It says “res cannot be resolved to a variable”

res is a placeholder for the distance between the point and the line. Set it to whatever you want it. the lower it is the more accurate it will be.

Again though this code is just the intersection code. You have to apply it to your code to make it work.

OK!
Thanks for helping me out

1 Like

here’s a tiny extra step with the collision working

float x,y = 150,res = 0.5;
boolean k = false;
PVector a,b,c;

void setup(){
  size(600,600);
  a = new PVector(0,150);
  b = new PVector(100,100);
  c = new PVector(100,200);
  
};

void draw(){
  background(50);
  line(b.x,b.y,c.x,c.y);
  fill(0);
  if(checkLineP(b,c,a))k = true;
  else k = false;
  if(k)fill(255,0,0);
  ellipse(a.x+=10,a.y,10,10);
  if(a.x>width)a.x=0;
  
};

boolean checkLineP(PVector a, PVector b, PVector c) {

  boolean k = false;
  float d1 = dist(a.x, a.y, b.x, b.y);
  float d2 = dist(a.x, a.y, c.x, c.y);
  float d3 = dist(b.x, b.y, c.x, c.y);
  float d4 = d2 + d3;
  //point(c.x,c.y);
  if (d4 <= d1 + res && d4 >= d1 - res) {
    k = true;
  }
  return k;
};
1 Like

BEFORE 19:00 PM

which time zone?

:wink:

Im from sweden :sweden: