简体   繁体   English

需要一些帮助,将敌人的子弹动画向下移动到屏幕上

[英]Need some assistance with moving an enemy bullet animation down the screen

I need help figuring out why the enemy bullets won't move when they have identical code... Please help... I didn't make either one as a separate class just simple animations 我需要帮助弄清楚为什么敌人的子弹具有相同的代码时为什么它们不会移动...请帮助...我没有将其中一个作为简单的动画制作为一个单独的类

Now I think that you can see when I say they have identical code, I mean like IDENTICAL code haha. 现在,我想您可以看到当我说它们具有相同的代码时,我的意思是像IDENTICAL代码一样。 It's really throwing me off that the player bullets work fine but the enemy bullets won't do anything 玩家的子弹可以正常工作,但是敌人的子弹什么也做不了,这真让我失望

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 is an Animation playerShot is an animation No seperate enemy or player class either. EnemyShot是动画玩家Shot是动画也没有单独的敌人或玩家类别。 Please help 请帮忙

You may want to give each individual enemy bullet it's own position, instead of one relative to the position of the enemy itself. 您可能需要给每个单独的敌人子弹自己的位置,而不是相对于敌人本身位置的位置。 This was inside of your render method: 这是在您的render方法内部:

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

From what I understand, in the very best case scenario, this will make the bullet follow the enemies x and y position with a small amount of displacement. 据我了解,在最佳情况下,这会使子弹以很小的位移跟随敌人的x和y位置。 Also, you have the code that enables enemy movement commented, which is: //enemy1PosX += delta * .7f; //enemy1PosY += delta * .1f; 另外,您还可以注释使敌人运动的代码,即: //enemy1PosX += delta * .7f; //enemy1PosY += delta * .1f; //enemy1PosX += delta * .7f; //enemy1PosY += delta * .1f; Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM