i try to built a game with enemy have randomly movements, but even i try some code from this forum i just saw my enemy turn from top-left to right side.
this my world code, what i should to do, please help master
<sorry for bad english>
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A class that has a scrolling background image
*/
public class ScrollWorld extends World
{
private static final GreenfootImage bgImage = new GreenfootImage("Background 2.jpg");
private static final int scrollSpeed = 2;
private GreenfootImage scrollingImage;
private int scrollPosition = 0;
private int spawnCounter = 0;
public ScrollWorld()
{
super(400, 600, 1);
GreenfootImage background = new GreenfootImage(400, 600);
scrollingImage = getScrollingImage(400, 600);
background.drawImage(scrollingImage, 0, 0);
setBackground(background);
addObject(new SpaceShip(), 200, 540);
addObject(new Counter(),20,570);
}
public void act()
{
//if(scrollSpeed > 0 && scrollPosition <= 0) {
// scrollPosition = 0;
//}
if(scrollSpeed > 0 && scrollPosition >= getHeight()) {
scrollPosition = 0;
}
//if (Greenfoot.getRandomNumber(100) <3) {
// addObject(new Asteroid(), 3 - 1, Greenfoot.getRandomNumber(getHeight()));
//}
if (spawnCounter > 100) {
spawnCounter = 0;
addObject(new Asteroid(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()));
}
spawnCounter++;
scrollPosition += scrollSpeed;
paint(scrollPosition);
}
/**
* Paint scrolling image at given position and make sure the rest of
* the background is also painted with the same image.
*/
private void paint(int position)
{
GreenfootImage bg = getBackground();
bg.drawImage(scrollingImage,0, position);
bg.drawImage(scrollingImage,0, position - scrollingImage.getHeight());
}
private GreenfootImage getScrollingImage(int width, int height)
{
GreenfootImage image = new GreenfootImage(width, height);
//for(int x = 0; x < width; x += bgImage.getWidth()) {
for(int y = 0; y < height; y += bgImage.getHeight()) {
image.drawImage(bgImage, x, y);
}
//}
return image;
}
}

