0

我需要帮助弄清楚为什么当敌人的子弹具有相同的代码时它们不会移动...请帮助...我没有将任何一个单独的类作为简单的动画

现在我想你可以看到当我说他们有相同的代码时,我的意思是像相同的代码哈哈。玩家的子弹可以正常工作,但敌人的子弹不会做任何事情,这真的让我失望

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
map.draw(0,0);
// First enemy
enemy1.draw(enemy1PosX, enemy1PosY);
enemyShot.draw(enemy1PosX+30, enemy1PosY + 65);


//Player
ship.draw(shipPosX, shipPosY);
playerShot.draw(shootPosX+23, shootPosY);
Animation copy = playerShot.copy();
copy.draw(shootPosX+23, shootPosY);

g.drawString("Ship X: " + shipPosX + "\nShips Y: " + shipPosY,400,20);

if(quit == true) {
    g.drawString("Resume (R)",250,100);
    g.drawString("Main Menu (M)",250,150);
    g.drawString("Quit Game(Q)",250,200);
    if(quit==false){
        g.clear();
    }

}

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
//Move Enemy

enemy1=enemyA;
//enemy1PosX += delta * .7f;
//enemy1PosY += delta * .1f;
    if(enemy1PosX > 668){
        enemy1PosX = -1;
        if(isEnemyHit(enemy1)){
            deadEnemies.add(enemy1);
    }
}


// up
if(input.isKeyDown(Input.KEY_UP)){
    ship = move;
    movefx.play();
    shipPosY -= delta * .6f;
    //collision detection
    if(shipPosY < 9){
        shipPosY = 9;

    }
}
//down
if(input.isKeyDown(Input.KEY_DOWN)){
    ship = move;
    shipPosY += delta * .6f;
    //collision detection
    if(shipPosY > 468){
        shipPosY = 468;
    }
}
//left
if(input.isKeyDown(Input.KEY_LEFT)){
    ship = move;
    shipPosX -= delta * .6f;
    //collision detection
    if(shipPosX < -1){
        shipPosX =-1;
    }
}
//right
if(input.isKeyDown(Input.KEY_RIGHT)){
    ship = move;
    shipPosX += delta * .6f;

    //collision detection
    if(shipPosX > 668){
        shipPosX = 668;
    }
}
    //FIRE PLAYER BULLETS
    playerShot = shootUp;
    playerShot.start();
    shootPosX = shipPosX-10;
    shootPosY -= delta * 1.3f;
    Animation copy = playerShot.copy();

    //Auto-Shoot bullet
    if(shootPosY <= shipPosY - 480){
        copy = playerShot;
        shootPosX = shipPosX;
        shootPosY = shipPosY; 
        shootPosY -= delta * 1.7f;
        copy.restart();
    }

    //FIRE ENEMY BULLETS
    enemyShot = shootDown;
    enemyShot.start();
    enemyShotPosX = enemy1PosX + 10;
    enemyShotPosY += delta * .3f;
    Animation dbl = playerShot.copy();

EnemyShot 是一个动画 playerShot 是一个动画 没有单独的敌人或玩家类。请帮忙

4

1 回答 1

0

您可能希望给每个单独的敌人子弹它自己的位置,而不是相对于敌人本身的位置。这是在您的渲染方法中:

enemyShot.draw(enemy1PosX+30, enemy1PosY + 65);

据我了解,在最好的情况下,这将使子弹以少量位移跟随敌人的 x 和 y 位置。此外,您还注释了启用敌人移动的代码,即: //enemy1PosX += delta * .7f; //enemy1PosY += delta * .1f; 希望这会有所帮助!

于 2013-04-29T15:31:00.473 回答