Loading...
Logo
Processing Forum
Hi everyone so I was following an online tutorial to create a vertical shooter game this was the code given:

  PFont fontA;
  int sphereDiameter = 10;
  boolean shoot = false;
  
  int randx()
  {
    return int(random(600));
  }
  
  int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
  int[] sphereYCoords = { 0, 0, 0, 0, 0 };
  
  void setup()
  {
    size(600,620);
  }
  
  void draw()
  {
    background(0);
    fill(color(0,255,0));
    stroke(color(0,255,0));
    triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
    fill(color(255,0,0));
    stroke(color(255,0,0));
  
    if(shoot==true)
    {
      sphereKiller(mouseX);
      shoot = false;
    }
  
    sphereDropper();
    gameEnder();  
  }
  
  void mousePressed()
  {
    shoot = true;
  }
  
  void sphereDropper()
  {  
    stroke(255);
    fill(255);
    for (int i=0; i<5; i++)
    {
      ellipse(sphereXCoords[i], sphereYCoords[i]++,
              sphereDiameter, sphereDiameter);
    }
  }
  
  void sphereKiller(int shotX)
  {
    boolean hit = false;
    for (int i = 0; i < 5; i++)
    {
      if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) && 
         (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
      {
        hit = true;
        line(mouseX, 565, mouseX, sphereYCoords[i]);
        ellipse(sphereXCoords[i], sphereYCoords[i],
                sphereDiameter+25, sphereDiameter+25);
        sphereXCoords[i] = randx();
        sphereYCoords[i] = 0;
      }    
    }
  
    if(hit == false)
    {
      line(mouseX, 565, mouseX, 0);
    }  
  
  }
  
  void gameEnder()
  {
    for (int i=0; i< 5; i++)
    {
      if(sphereYCoords[i]==600)
      {
        fill(color(255,0,0));
        noLoop();
      }
    }
  }


So this easily creates a pretty basic vertical shooter, I already modified several things to make the game more attractive but I wanted to ask if it was possible that what you see displayed isnt the complete size and that if you moved to the left or you would start like scrolling through through other part of the canvas. Something like have a canvas with a size 1000x1000 but only 400x400 is displayed, so if you move a bit to the left the display is still 400x400 but you see another part of the canvas.
I would also like to know how to make the game scroll upwards, as if you were moving upwards or something like 1942 for example.

Dunno if this is too confusing but tried to explain it the best that I could.

Thanks to everyone that is able to help me and sorry to bother you

Replies(1)

I have attempted to do something like this before.
Of course, you would need more complex controls for the player first, but I tried giving everything a location on the total canvas and drawing it there (maybe not things that are offscreen) and performing a translate based on the player location.
So when the player moves, the entire screen moves with him/her. The movement for the player is still performed. And if you want to get more complex with the controls, follow the translate with a rotate of the player's rotation.
So it would look like this:

All objects have normal stuff but there location can be anywhere
At the beginning of draw (or wherever the drawing takes place) you perform translate(playerX, playerY);
If this sounds confusing I can try to explain it in a more understandable way.