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

2020/4/25

making enemies move downwards every couple of seconds (for space invaders game)

EthanWasHere_ EthanWasHere_

2020/4/25

#
Hi All! Been having trouble making my enemy move downwards every couple of seconds. I've got the part where it moves every couple of seconds it just doesn't move the right way, how would I fix this?
 private int taxManMove = 275, taxManMoveTimer=taxManMove; 
   public void act()
   { 
       move();
   }
   
   public void move()
   { 
        if (--taxManMoveTimer==0)
        {
            move(10);
            taxManMoveTimer = 275;
        }   
   }
danpost danpost

2020/4/25

#
Change line 10 to:
setLocation(getX(), getY()+10);
or replace it with:
turn(90);
move(10);
turn(-90);
EthanWasHere_ EthanWasHere_

2020/4/26

#
Thanks! Works like a charm!
You need to login to post a reply.