Loading...
Logo
Processing Forum
Hello everyone, i'm new to processing and have been learning for about 4 days now. I am trying to make my first game (pretty low quality) , the basic idea is that the cursor moves around a picture while a red dot bounces around the screen. the red dot is meant to be the laser sight of a sniper, and your goal is to try not to get hit. I was wondering how i can make it so whenever the dot goes over the picture, a sound is triggered, the screen flashes red, and a blood splatter appears and fades away where the picture was "shot". it would be very helpful is someone send a couple links explaining, or explain it yourself if you would like. Just having the code i am looking for by itself wouldn't be very helpful. Also here is the code i am working on below.

PImage img,vip;
float y, xvelocity, r, x, yvelocity,restitution;
void setup () 
{
  size(567, 381);
   img = loadImage("stage.jpg");
   vip = loadImage("vip.jpg");

  r=10;
  y=250;
  x=250;
  yvelocity=3;
  xvelocity=6;
  restitution=1;

}

void draw () 
{
  y=y+yvelocity;

  // if the ball the past the bottom of the screen
  if (y+r > height)
  {
    yvelocity=yvelocity* - restitution;
    y= height-r;
  }
  if (y-r < 0)
  {
    yvelocity=yvelocity* - restitution;
    y = 0 + r;
  }
  {
    x=x+xvelocity;
  }
  if (x-r < 0 )
  {
    xvelocity=xvelocity* - restitution;
    x= 0 + r;
  }
  if (x+r > width)
  {
  xvelocity=xvelocity* -  restitution;
   x = width - r;
  }
  
  
  
  
  background(255);
  imageMode(CORNER);
  image(img, 0, 0);
  imageMode(CENTER);
  image(vip,mouseX,mouseY);
  stroke(255, 64, 0);
  fill(100,30,0);
  ellipse(x, y, r*2, r*2);
  stroke(0);
  fill(30,100,0);
 
}

Replies(2)

Just in case, I send you to the Technical FAQ, perhaps some of your questions will be answered there.
I would suggest to do this progressively, first by solving the hit condition.


well, since you are a beginner I think drops of blood are hard to paint...

I suggest you draw a nice blood red rectangle fullscreen and make its transparency increase by each loop that draw does.

When transparency is 100%, don't paint it anymore.

Copy code
  1. color col = color(255,1,1);  // blood red

lifespan is the lifespan of your blood rectangle - it is actually opacity of the fill (not transparency, sorry)



if somebody got hit:
Copy code
  1. lifespan = 100; // high opacity - much blood - lifespan is the lifespan of your blood rectangle

in draw()

Copy code
  1.     noStroke();
  2.    if (lifespan>3) {
  3.     fill(col, lifespan);  // red
  4.     rect(0,0,width, height);
  5.     lifespan-=2;  // decrease opacity
  6.    }

not tested...  

additionally you could also make the rect get smaller - as if you have blood before your eyes which slowly flows downwards. But it wouldn't look like rinsing.