Hey I'm making a game in which the maze is comprised of 4 different coloured walls. If i touch( i am facing) a blue wall then all the blue walls light up etc... But i'm having trouble making it glow.
these are all my classes
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.List;
/**
* Write a description of class MWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MWorld extends World
{
private GreenfootImage image = getBackground();
public Wall wink;
private Color colour;
/**
* Constructor for objects of class MWorld.
*
*/
public MWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(30,30, 20);
image.setColor(Color.BLACK);
image.fill();
setBackground(image);
addWalls();
addObject(new Player(),0,0);
prepare();
}
public void show(Color c){
List<Wall> walls = getObjects(Wall.class);
for(Wall w:walls){
if(w.getColour().equals(c)){
w.glow();
}
}
}
public void glow(){
wink.glow();
}
this is my player class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
private static final int EAST =0;
private static final int SOUTH =90;
private static final int WEST =180;
private static final int NORTH =270;
private int MOVE = 1;
private int counter = 0;
public Player(){
GreenfootImage img= new GreenfootImage(20,20);
img.setColor(Color.WHITE);
img.fill();
setImage(img);
}
public void act()
{
move();
Actor a = (Actor)getOneIntersectingObject(Wall.class);
if(a!=null){
getWorld().removeObject(this);
}
}
public void move(){
move(MOVE);
if(Greenfoot.isKeyDown("left")){
setRotation(WEST);
}
if(Greenfoot.isKeyDown("right")){
setRotation(EAST);
}
if(Greenfoot.isKeyDown("down")){
setRotation(SOUTH);
}
if(Greenfoot.isKeyDown("up")){
setRotation(NORTH);
}
if(facingWall()){
MWorld mw = (MWorld)getWorld();
//mw.show();
MOVE=0;
}else{
timer();
}
}
public void timer(){
counter++;
if(counter<10){
MOVE=0;
}else if(counter>10){
MOVE=1;
counter = 0;
}
}
public boolean facingWall(){
int dx = 0;
int dy = 0;
switch(getRotation())
{
case EAST:dx=1; break;
case WEST: dx= -1; break;
case SOUTH: dy =1; break;
case NORTH: dy = -1; break;
}
return getOneObjectAtOffset(dx,dy,Wall.class) !=null;
}
}
this is my wall class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
/**
* Write a description of class Wall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Wall extends Actor
{
private int trans = 255;
private boolean glowing =true;
private Color colour;
public Wall(Color col){
GreenfootImage img= new GreenfootImage(20,20);
img.setColor(col);
img.fill();
setImage(img);
colour = col;
GreenfootImage image = new GreenfootImage(30,30);
img.setColor(colour);
}
public Color getColour()
{
return colour;
}
public void act()
{
if(glowing){
getImage().setTransparency( trans );
trans = trans - 5;
if( trans < 0 ) {
trans = 0;
}
}else{
glowing = false;
}
}
public void glow()
{
trans =255;
glowing = true;
}
}

