0

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. 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. Please help

iibinxx
  • 13
  • 3
  • *"Need some assistance.."* Need an [SSCCE](http://sscce.org/) & a question. – Andrew Thompson Apr 29 '13 at 14:32
  • "I need help figuring out why the enemy bullets won't move when they have identical code." I did explain what I don't understand... The player bullets have the same code... the player bullets work the enemy bullets don't... I don't get how that's not explaining what I don't understand – iibinxx Apr 29 '13 at 14:46
  • Man I just came here hoping somebody better than me with java seeing as how I am a beginner at this can help me out – iibinxx Apr 29 '13 at 14:53
  • You're a grown man... why do you need a '?' to know the subject of the post... All I need is a little bit of help that's all... – iibinxx Apr 29 '13 at 14:55
  • So you're not going to help? All you just did instead of sharing knowledge was spark a little "argument" how's that helping... – iibinxx Apr 29 '13 at 14:57
  • childish, you vote it down for what reason? – iibinxx Apr 29 '13 at 15:10
  • Have you tried switching the ordering of the player and enemy animations? If the enemy bullet fires and the player's does not, there might be a transform that needs to be reset. – Captain Skyhawk Apr 29 '13 at 15:20
  • thank you for your help... I just tried it and no luck the image of the animation just sits at the X and Y position I set for it – iibinxx Apr 29 '13 at 15:27

1 Answers1

0

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:

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. Also, you have the code that enables enemy movement commented, which is: //enemy1PosX += delta * .7f; //enemy1PosY += delta * .1f; Hope this helps!

Liam
  • 28
  • 2