I would preferably need help in the next 12 hours if possible.
I am trying to make a maze game with "lasers" that you need to deactivate by running over the "buttons".
I have created two images for active and not "lasers". I have managed to make to deactivated "laser" image appear
when the button is hit by the player, but I don't know how to remove the other "laser" that is underneath it that is
preventing the player from walking through. I do not mind re-locating its position to another position on the map as I am
able to create an area where I can put them. could you please try and help me, I will show you all the code that I have that
could come of use. Thanks a lot if you can help me.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
PLAYERS CODE
/**
* The character that the player of the game plays at to complete the maze
* Xmin_Terminator
* @version (a version number or a date)
*/
public class Player extends Actor
{
public void act()
{
movement();
hitButton1();
}
public Player() //divides the players dimensions by 3 to scale down to fit inside the maze
{
GreenfootImage myImage = getImage();
int myNewHeight = (int)myImage.getHeight()/3;
int myNewWidth = (int)myImage.getWidth()/3;
myImage.scale(myNewWidth, myNewHeight);
}
public void movement()
{
if(Greenfoot.isKeyDown("right"))
{
setRotation(0);
if(getOneObjectInFront(Wall.class)==null) //if all 3 of these are not in front of the player, then the player is allowed to move
if(getOneObjectInFront(Maze.class)==null) //the speed is set to 5 so I can test it quicker, I will turn it down to 3 later
if(getOneObjectInFront(LaserWall.class)==null)
move(5);
}
if(Greenfoot.isKeyDown("left"))
{
setRotation(180);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
move(5);
}
if(Greenfoot.isKeyDown("up"))
{
setRotation(270);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
move(5);
}
if(Greenfoot.isKeyDown("down"))
{
setRotation(90);
if(getOneObjectInFront(Wall.class)==null)
if(getOneObjectInFront(Maze.class)==null)
if(getOneObjectInFront(LaserWall.class)==null)
move(5);
}
}
private Actor getOneObjectInFront(Class c) //checking if there is a certain actor in front of itself
{
GreenfootImage myImage = getImage();
int distanceToFront = myImage.getWidth();
int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation())));
int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation())));
return (getOneObjectAtOffset(xOffset, yOffset, c));
}
public boolean buttonSwitcher = false; //I believe this is the issue, it is not working inside the other actors editors or I don't know how to fix it.
public void hitButton1()
{
World myWorld = getWorld();
if(getOneIntersectingObject(Button1.class)!= null)
{
DeactivatedLasers deactivatedLaser1 = new DeactivatedLasers();
myWorld.addObject(deactivatedLaser1, 12+(1*25),12+(6*25));
buttonSwitcher = true;
}
}
}
LaserWall 1-20 are a sub-class of LaserWall
LASERWALL CODE
public class LaserWall extends Actor
{
public boolean buttonSwitcher = false; // I thought this may link them up but I don't know how this works and I don't think It linked up
/**
* Act - do whatever the LaserWall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//
}
}
laserwall1 is the first one that I am trying to make this code work one, then I will apply that it the other codes so that I can complete it.
So because of this I may not say, assign something to the upper class Laser Actor, as this needs to works for all of my actors,
LaserWall 1 throughout to 20
LASERWALL1 CODE
public class LaserWall1 extends LaserWall
{
public boolean buttonSwitcher = true; // I thought this may connect the Boolean from the player code, but I don't think it did
/**
* Act - do whatever the LaserWall1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(buttonSwitcher != true)
{
setLocation(12+(25*25), 12+(25*25)); //This is the "disposal" location, where I would like to dump the activated lasers away.
}
}
}
I know this is a big favour I am asking for but would be really grateful if somebody could see to my need quickly,
thanks a lot, hoping to get some advice and major help quickly.