This site requires JavaScript, please enable it in your browser!
Greenfoot back
AttackTheMOON
AttackTheMOON wrote ...

2019/1/11

Bullet travel in a spiral path

AttackTheMOON AttackTheMOON

2019/1/11

#
I am working on a space shooter game and I have an enemy that shoots bullets. I want the bullets to travel in a spiral path so each time a bullet is created it turns +18 and move but the code I have is not working. The bullet should only turn once when its is created. I am new to Greenfoot and Java so I need help!!! This is the code I have for the bullet-
private int angle = 0;  
        public void act() 
        {           
            move(5);
            angle+= 18;
        }
        public enemyBullet()
        {
            turn(angle);
        }
danpost danpost

2019/1/11

#
AttackTheMOON wrote...
I am working on a space shooter game and I have an enemy that shoots bullets. I want the bullets to travel in a spiral path so each time a bullet is created it turns +18 and move but the code I have is not working. The bullet should only turn once when its is created. I am new to Greenfoot and Java so I need help!!! << Code Omitted >>
I think what you want is this:
private static int angle;

public enemyBullet()
{
    turn(angle);
    angle += 18;
}

public void act()
{
    move(5);
}
AttackTheMOON AttackTheMOON

2019/1/11

#
Thank you @danpost It works how I wanted it to!
You need to login to post a reply.