import greenfoot.*;
import java.awt.Color;
import java.util.List;
import java.util.ArrayList;
public class levelBackground extends World
{
platformMap map = new platformMap();
GreenfootImage mapImg = map.getImage();
final int MAPIMGWIDTH = mapImg.getWidth();
final int MAPIMGHEIGHT = mapImg.getHeight();
Block platformTemplate = new Block(0,0);
GreenfootImage pfImg = platformTemplate.getImage();
final int PLATFORMHEIGHT = pfImg.getHeight();
final int PLATFORMWIDTH = pfImg.getWidth();
final int MAPWIDTH = MAPIMGWIDTH * PLATFORMWIDTH;
final int MAPHEIGHT = MAPIMGHEIGHT * PLATFORMHEIGHT;
private List<Block> thePlatforms = new ArrayList<Block>();
int leftBound = 0;
int bottomBound = MAPHEIGHT;
int topBound = MAPHEIGHT - getHeight();
int rightBound = getWidth();
public levelBackground()
{
super(1000, 600, 1);
makeMap();
update();
}
public void makeMap()
{
for(int y=0; y<MAPIMGHEIGHT; y++)
{
for(int x=0; x<MAPIMGWIDTH; x++)
{
int colorRGB = mapImg.getColorAt(x, y).getRGB();
if(colorRGB==Color.BLACK.getRGB())
{
int mapX = x * PLATFORMWIDTH + PLATFORMWIDTH/2;
int mapY = y * PLATFORMHEIGHT + PLATFORMHEIGHT/2;
thePlatforms.add(new Block(mapX,mapY));
}
}
}
}
public void update()
{
Block thisPlatform;
int thisPlatformX;
int thisPlatformY;
int screenX;
int screenY;
for(int i=0; i<thePlatforms.size(); i++)
{
thisPlatform = thePlatforms.get(i);
thisPlatformX = thisPlatform.mapX;
thisPlatformY = thisPlatform.mapY;
if(thisPlatformX>=leftBound && thisPlatformX<=rightBound && thisPlatformY>=topBound && thisPlatformY<=bottomBound)
{
screenX = thisPlatformX - leftBound;
screenY = thisPlatformY - topBound;
if(thisPlatform.getWorld()==null)
{
addObject(thisPlatform, screenX, screenY);
}
}
}
}
}

