Help in my first game (shooting with the ship).

Help in my first game (shooting with the ship).

Hello, Goodnight everyone! My name is Gabriel Almeida, I am Brazilian and I started my studies in game design a short time, when my initial focus will be on schedule, I started to try a little game of spacecraft today in processing language and am having difficulties with the shot ship. Remembering that I am using google translate to communicate and do not know if I published the question in the correct section of the forum, if in the wrong section please move my question to the appropriate place =) The code I've written so far is as follows:

int vidaNave= 3; int pxnave; int pynave; int posx= 400; int posy= 300; PImage nave; PImage tiro_1; PImage efeito_tiro; PImage vidaNave1; PImage vidaNave2; PImage vidaNave3; int tiroy; boolean delay=true; int b; int c;

void setup() { size(800, 600); background(200, 200, 200); nave = loadImage("nave1.png"); tiro_1 = loadImage("tiro1.png"); efeito_tiro = loadImage("efeitotiro.png"); }

void draw() { background(200, 200, 200); image(nave, posx, posy); frameRate(60); movimento(); tiro();

}

void tiro(){

tiroy-=0; if(key == 'l' || key == 'L'){ int y=posy; image(tiro_1,posx+40,y+tiroy-5+(b-=5)); image(efeito_tiro,posx+30,posy); c = (y+tiroy+(b-=5)); }

}

void movimento() { int d=posx+40; if (keyPressed) { if (key == 'a' || key == 'A') { image(tiro_1,d,c); c-=5; posx -=10; if (posx<0) { posx +=10; } } if (key == 'd' || key == 'D') { image(tiro_1,d,c); c-=5; posx =posx+10; if (posx>700) { posx -=10; } } if (key == 'w' || key == 'W') { image(tiro_1,d,c); c-=5; posy-=5; if (posy<0) { posy+=5; } } if (key == 's' || key == 'S') { image(tiro_1,d,c);

  posy+=5;
  if (posy>500) {
    posy-=5;
  }
}

} }

void vida_nave() {

}

"Sorry, not yet picked up the habit of using comments"

I would like to processing programming book recommendations aimed at games (in the case in the English language because I did not think in Portuguese), aid in relation to the method "shot" of my schedule and if possible a code that would make a shooting missiles using arrays (I'm still learning how to use arrays in processing) that is equal to this video:

The author does not teach how to make this shot using arrays but advises that easy.

I thank the attention =)

Tagged:

Answers

  • edited June 2015

    for the organization of your code:

    you want to show the ship tiro all the time, so call tiro in draw() but use image() outside any if-clause

    instead of

    void tiro() {
      tiroy-=0; 
      if (key == 'l' || key == 'L') { 
        int y=posy; 
        image(tiro_1, posx+40, y+tiroy-5+(b-=5)); 
        image(efeito_tiro, posx+30, posy); 
        c = (y+tiroy+(b-=5));
      }
    }
    

    you want

    void tiro() {
      tiroy-=0; 
    
        image(tiro_1, posx+40, y+tiroy-5+(b-=5)); 
        image(efeito_tiro, posx+30, posy); 
    
      if (key == 'l' || key == 'L') { 
        int y=posy; 
    
        c = (y+tiroy+(b-=5));
      }
    }
    

    (these lines for the key can also be in movimento())

    in movimento()

    also in movimento(): no need to have

    image("tiro_1", d, c);
    

    (it's in draw() already)

    for shooting

    for shooting see

    http://www.openprocessing.org/sketch/77863

    Best, Chrisir ;-)

Sign In or Register to comment.