子弹不会在太空侵略者中发射

时间:2019-12-27 13:19:37

标签: java processing

我在处理过程中遇到了旧的太空入侵者问题:我的子弹不会发射,我也找不到原因。 我在论坛上进行了搜索,但是由于我是编码新手,所以我无法真正检测到代码问题。也许与我舍入为整数的ship函数中的浮点数有关?

在此先感谢您的帮助!

以下是我的代码的相关摘要:

游戏

import processing.sound.*;

int stage;
int lives;
int endscore;

PImage bg, title,landscp, gameover;
PFont font;
SoundFile jingle;


Bonboniere b;
Shooter s;
Veggie v;

Veggie[] falls = new Veggie[int (random(5))];


void setup()  {
  stage = 1;
  size(700, 900);
  font = loadFont("ArialNova-48.vlw");
  bg = loadImage("CandyLandMenu.jpg");
  landscp = loadImage("Candyland.jpg");
  gameover = loadImage("game-over.jpg");
  imageMode(CENTER);
  title = loadImage ("TITLE.png");

  b = new Bonboniere();
  s = new Shooter();
  v = new Veggie();
  lives = 3;
  jingle = new SoundFile(this, "Jingle.mp3");
  jingle.loop();

  for (int i = 0; i < falls.length; i++) {
    falls[i] = new Veggie();
  }
}


void draw() {
 if (stage==1){
  background(bg);
  image(title, 350, 400);
  textFont(font, 24);
  fill(0);
  textAlign(CENTER);
  text("Press any key to start game", 350, 800);
  if(keyPressed){
    stage = 2;
  }
 }

  if (stage==2) {
  image(landscp,350, 450);

  b.display();

  b.move();

  int x = Math.round(b.posx);
  int y = Math.round(b.posy);

   s.show(x, y);

   v.show();

   v.fall();
   for (int i = 0; i < falls.length; i++) {
    falls[i].show();
    falls[i].fall();

   s.move();

 }
 if (lives < 0) { 
  background(gameover);
  text("SCORE:", 512, 600);
  text(endscore, 512, 700);
  noLoop();
  delay(1000);
   }
  }
 }

运费

class Bonboniere {

int radius = 10, directionX = 1, directionY = 0;
float posx=650, posy=825, speed=1.5;
PImage CandyShooter;
SoundFile file;



 Bonboniere() {
  imageMode(CENTER);
  CandyShooter = loadImage("CandyShooter.png");
  CandyShooter.resize(0, 150); 
  smooth();
}
void display()
{
  posx=posx+speed*directionX;
  posy=posy+speed*directionY; 
  if ((posx>width-radius) || (posx<radius))
  {   
    directionX=-directionX;
  }
  if ((posy>height-radius) || (posy<radius))
  {   
    directionY=-directionY;
  } 
  image(CandyShooter,posx,posy);
}

void move()
{
  if (key == CODED)
  {
    if (keyCode == LEFT)
    {

      directionX=-1;
      directionY=0;

    }
    else if (keyCode == RIGHT)
    {

      directionX=1;
      directionY=0;

      }
    }
  }
}

子弹

    class Shooter {
  int positionX, positionY, vx = 0, vy = 1;
  int velocity;
  int x = Math.round(b.posx);
  int y = Math.round(b.posy);


  Shooter() {
  velocity = 3;

}

void show(int positionX, int positionY) {

  fill(random(255), random(255), random(255));
  ellipse(positionX, positionY, 10, 10);

}

void move() {

  if (mousePressed==true) {
    show(x, y);
    positionY = y + velocity;
     }
    }
  }

0 个答案:

没有答案