I want to make the int variable to get a random number between 20 and 200 but its only doing 200 and i need it to make the heightshift change in the act section, here's the code if you can help me:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class FlappyWorld here. * * @author (your name) * @version (a version number or a date) */ public class FlappyWorld extends World { int counter = 0 ; int heightShift = Greenfoot.getRandomNumber( 200 ); /** * Constructor for objects of class FlappyWorld. * */ public FlappyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 600 , 400 , 1 , false ); FlappyBird flappy = new FlappyBird(); addObject(flappy, 100 , getHeight()/ 2 ); } public void act() { counter++; if (counter == 100 ) { BottomPipe pippy = new BottomPipe(); GreenfootImage image = pippy.getImage(); addObject(pippy, getWidth(), getHeight()/ 2 + image.getHeight() - heightShift); counter = 0 ; } } } |