Ok but .. why did the method 'runActCounterBomb' you simplified worked and the 1 had did not? cause arent they the same?
And another question i got is about the game speed. So far i can speed up my background by controlling the instance scrollSpeed. But is there a way to adjust my actor automaticlly to the scrollSpeed i give? This is my world class at the moment.
public class BotenUpgrade extends World
{
private static final GreenfootImage bgImage = new GreenfootImage("Backgroundje.png");
private static final int scrollSpeed = 4;
private GreenfootImage scrollingImage;
private int scrollPosition = 8;
// instance fields
private int maxBarrels = 4;
private int maxBomb = 0;
private int actCounter;
/**
* Constructor for objects of class BotenUpgrade.
*
*/
public BotenUpgrade()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(760, 760, 1);
GreenfootImage background = new GreenfootImage(760, 760);
scrollingImage = getScrollingImage(760, 760);
background.drawImage(scrollingImage, 500, 500);
setBackground(background);
addObject(new boot(), 350, 600);
setBackground("Backgroundje.png");
addHeart();
addTime();
addObject(new Clock(true, true, 180, "Meter over:"), 700, 50);
}
public void act()
{
if(scrollSpeed > 0 && scrollPosition <= 0) {
scrollPosition = getWidth();
}
if(scrollSpeed < 0 && scrollPosition >= getWidth()) {
scrollPosition = 0;
}
scrollPosition -= scrollSpeed;
paint(scrollPosition);
spawnBarrel();
spawnBomb();
runCounters();
}
public void spawnBarrel()
{
if (Greenfoot.getRandomNumber(200) == 1)
{
if (getObjects(barrel.class).size() < maxBarrels) {
addObject(new barrel(), 750, Greenfoot.getRandomNumber(250)+500);
}
}
}
public void spawnBomb()
{
if (Greenfoot.getRandomNumber(200) == 1)
{
if (getObjects(Bomb.class).size() < maxBomb) {
addObject(new Bomb(), 750, Greenfoot.getRandomNumber(250)+500);
}
}
}
private void runCounters()
{
actCounter++;
runActCounterBarrel();
runActCounterBomb();
}
private void runActCounterBarrel()
{
if (actCounter%3000 == 0)
{
maxBarrels++;
//if (maxBarrels == 9) Greenfoot.stop();
}
}
private void runActCounterBomb()
{
if (actCounter%3000 == 0) maxBomb++;
}
/**
* 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, position, 0);
bg.drawImage(scrollingImage, position - scrollingImage.getWidth(), 0);
}
/**
* Returns an image with the given dimensions.
*/
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;
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void addHeart()
{
heart heart = new heart();
addObject(heart, 142, 58);
}
GreenfootSound music = new GreenfootSound("Wind Waker The Great Sea (Ocean) Music Extended.mp3");
public void started()
{
music.playLoop();
}
private void addTime()
{
TimeChecker time = new TimeChecker();
addObject(time, 700, 50);
}
}
