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

2012/1/10

Painting Starts onto a Background Image

4
5
6
7
Wavesludge Wavesludge

2012/10/28

#
It works! Thank you so very much @danpost :D
leeX leeX

2012/10/28

#
some help with adding stars to array plz.
        while (i < stars) {
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(new Star(), x, y);
            i++;
        }
how could i make all the stars that are added also add to array?
SPower SPower

2012/10/28

#
private Stars[] stars;

// before the while loop:
stars = new Stars[stars];

// in the while loop:
int x = ....
int y = ....
Star s = new Star();
addObject(s, x, y);
stars[i] = s;
i++;
leeX leeX

2012/10/28

#
public class Space extends World
{
    int stars = 100;
    int i;
    private  Stars[] stars;  

    private void createStars()
    {
        stars = new Stars[stars];  
        while (i < stars) {
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            Star s = new Star();  
            addObject(s, x, y);  
            stars[i] = s;
            i++;
        }
    }
i get error cant find symbol class Stars. if i change to star as my class named
    private  Star[] star;  
i get error in this line saying incompatible type
        star = new Star[star];  
danpost danpost

2012/10/28

#
Change the name of the variable that holds the total number of stars from 'stars' to 'starCount' (you have too many things names 'star' or 'stars' and it is confusing the compiler).
leeX leeX

2012/10/28

#
private Star stars; // i left it like this stars = new Star; // here it says incompatible type
danpost danpost

2012/10/28

#
Of course, the compiler is looking at 'stars' and saying "alright, let us see if we can put the array named 'stars' and use it as an integer for the length of the array." So, because it cannot, it informs you that, hey, we got incompatible types here!
leeX leeX

2012/10/28

#
ty XD
Wavesludge Wavesludge

2012/10/29

#
OK the last one works great, but I want to make one completely controlled by arrays. Arrays to set the colors, size and speed for the stars, and the size and speed to be randomized. And I need a move method in the actor which I call for in the world class when the stars are supposed to move. The stars should move from right to left and be moving all the time. And I'm very new with arrays so I don't understand them very well.
hkrhässleholm hkrhässleholm

2012/10/29

#
Hi I will post the requirements for my school work (Parallax Scrolling) : Does anyone has done it before, if no then please write the codes for grade 3&4 please. It means that I will study on those to make sure that I understand and try to solve the grade 5 then! Lab 4 instructions The goal of this lab is to practice the use of arrays. We will do this by implementing a parallax scrolling space scene. The scene will contain layers of moving stars to simulate depth. See Figure 1 for an example of how the finished scene might look. An example of a moving scene can be found on screenr . The application shall use several layers of stars that move from right to left. When the stars reach the left edge of the screen they shall be removed and another star shall enter from the right. To get a feeling of depth have the stars in the background move slower and be darker. The following requirements have to be met for this lab. For Grade 3: 1. You must have one layer of stars. 2. The stars shall move from right to left in a smooth manner. 3. When a star exits to the left a new (or the same) star shall appear from the right. 4. A star class shall exist. Each star shall be an object of this class. The class shall at least store the x, y and size of one star. 5. The star class shall have appropriate methods but one method named move must exist. The move method shall be called from the world class when the star is supposed to move. 6. The world class shall use array(s) to keep track of all stars. 7. There must be at least 100 stars in the scene at any time. For Grade 4: 8. All requirements for grade 3. 9. Introduce a variable speed in the stars class that is used for regulating how fast the star in moving. 10. All values used for position, speed and size shall be randomized. For Grade 5: 11. All requirements for grade 4. 12. Add two more layers to the scene. Make sure they add to the depth by having different speed ranges and colors.
dragon_06 dragon_06

2012/10/29

#
does anyone know what the opposite of % is? this is suppose to make objects move left to right if i am correct, but how do mirror the action?
danpost danpost

2012/10/29

#
@dragon_06, the '%' is an numeric operator. It returns the remaining part after division. The opposite, I guess, would be to return the main part after division, which is '/' for integers. The answer to what you are actually trying to ask, has to do with the additive offset.
// the 'opposite' of
x = (x + 1) % getWorld().getWidth();
// would be
x = (x - 1 + getWorld().getWidth()) % getWorld().getWidth();
Anytime you do a subtraction in the first part (before the '%'), you need to make sure the value does not go below zero. By adding the one of what is on the right side to the part on the left side, you do not change to returned value when the left side remains above zero. When to left side goes below zero, there is an abrupt change in what '%' returns, and this step corrects that.
richardzombie richardzombie

2015/1/19

#
how can you make a color for just 1 separate square (im trying to make the earth with WombatWorld)
danpost danpost

2015/1/19

#
@richardzombie, please start a new discussion thread for your issue and do not revive old threads. Also, please show your code for what you have tried.
You need to login to post a reply.
4
5
6
7