Sorry for later response. You don't to reinvent the wheel, you can mix the two values of light of day/night cycle light, and torches together, along with light being modified by how deep the dirt is.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Block here. * * @author (your name) * @version (a version number or a date) */ public class Block extends Actor { int blockSize = ((PlayerWorld) getWorld()).blockSize; public GreenfootImage lightMap = new GreenfootImage(blockSize, blockSize); public Color trans = new Color(0,0,0,0); GreenfootImage originalImg = new GreenfootImage(blockSize, blockSize); GreenfootImage grass = new GreenfootImage("grass.png"); GreenfootImage dirt = new GreenfootImage("dirt.png"); public Block() { lightMap.setColor(new java.awt.Color(0,0,0,darkness)); lightMap.fillRect(0, 0, blockSize, blockSize); // in Block constructor baseImg = getImage(); } /** * Act - do whatever the Block wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } public void trimEdge(Block obj) { if (obj.getClass() == grass.class) { originalImg.drawImage(grass,0,0); } else if (obj.getClass() == Dirt.class) { originalImg.drawImage(dirt,0,0); } else { originalImg.fill(); } obj.setImage(originalImg); if(obj.getOneObjectAtOffset(blockSize, 0, Block.class) == null) { obj.setImage(trimRight(obj.getImage())); } if(obj.getOneObjectAtOffset(-blockSize, 0, Block.class) == null) { obj.setImage(trimLeft(obj.getImage())); } if(obj.getOneObjectAtOffset(0, -blockSize, Block.class) == null) { obj.setImage(trimTop(obj.getImage())); } if(obj.getOneObjectAtOffset(0, blockSize, Block.class) == null) { obj.setImage(trimBottom(obj.getImage())); } } public GreenfootImage trimTop(GreenfootImage img) { img.setColorAt(0, 0, trans); img.setColorAt(7, 0, trans); img.setColorAt(8, 0, trans); img.setColorAt(9, 0, trans); return img; } public GreenfootImage trimBottom(GreenfootImage img) { img.setColorAt(0, 9, trans); img.setColorAt(7, 9, trans); img.setColorAt(8, 9, trans); img.setColorAt(9, 9, trans); return img; } public GreenfootImage trimLeft(GreenfootImage img) { img.setColorAt(0, 0, trans); img.setColorAt(0, 7, trans); img.setColorAt(0, 8, trans); img.setColorAt(0, 9, trans); return img; } public GreenfootImage trimRight(GreenfootImage img) { img.setColorAt(9, 0, trans); img.setColorAt(9, 7, trans); img.setColorAt(9, 8, trans); img.setColorAt(9, 9, trans); return img; } public void inheirt(Block obj) { GreenfootImage image = obj.getImage(); image.scale(10,10); //setLight(obj, 200); } // in Block class // with instance fields int darkness, lightness, tint; GreenfootImage baseImg; // the setLight method (renamed) private void updateImage() { if (Math.abs(tint-(255-lightness)*darkness/255) < 8) return; tint = (255-lightness)*darkness/255; GreenfootImage image = new GreenfootImage(baseImg); GreenfootImage tintImg = new GreenfootImage(image.getWidth(), image.getHeight()); tintImg.setColor(Color.BLACK); tintImg.fill(); // default color for new image is black tintImg.setTransparency(tint); image.drawImage(tintImg, 0 ,0); setImage(image); } // with these methods public void setDarkness(int dark) { if (dark < 0) dark = 0; if (dark > 255) dark = 255; darkness = dark; updateImage(); } public void setLightness(int light) { if (light < 0) light = 0; if (light > 255) light = 255; lightness = light; updateImage(); } }