Hi everyone.
I have 3 little problems with my game I can't find a solution for. I bet someone can help me out. :)
#1
I found another discussion on how to create obstacles: http://www.greenfoot.org/topics/2746
danpost's code works well but I can't find out how to make two different classes become obstacles. If I copy the code and change the class name in it I can move through both objects.
This is how the code looks like:
#2 and 3
The player can can create a hallucination that stuns all enemies on impact which makes them unable to move for 10 seconds. This works well so far but the counter doesn't work. Enemies will not move ever again as soon as they get stunned.
In the same class there is an option to shield the player which makes him/her invulnerable. This should prevent that enemies can't kill the player for 10 seconds but this option doesn't work at all.
I hope anyone of you can help me. Thanks in advance.
Greetings
Alex
public void setLocGuardianShield(int x, int y)
{
int oldX = getX();
int oldY = getY();
super.setLocation(x, y);
if(!getIntersectingObjects(GuardianShield.class).isEmpty())
{
super.setLocation(oldX, oldY);
}
}
public void setLocWall(int x, int y)
{
int oldX = getX();
int oldY = getY();
super.setLocation(x, y);
if(!getIntersectingObjects(Wall.class).isEmpty())
{
super.setLocation(oldX, oldY);
}
}//Enemy class
public class Enemy extends Creatures
{
int enemymovement=1; //To toggle the movement for enemies. 1=activated; 0=deactivated.
int shield=0; //To toggle the shield for the Sentry. 1=activated; 0=deactivated.
public void act()
{
Stuncount();
Shield();
}
//Code you don't need to care about.
public void Shield() //If the f-key is pressed the Guardian Shield gets activated and the Sentry becomes invicible.
{
String key = Greenfoot.getKey();
if("s".equals(key))
{
shield = 1;
Shieldcount();
}
}
public void Shieldcount()
{
//Enemies can't kill the Sentry for 10 seconds when the Guardian Shield is activated.
int shieldcounter=250;
if(shieldcounter == 0)
{
shield=0;
}
else if (shieldcounter>0)
{
shieldcounter--;
}
}
public void Stuncount()
{
//Enemies can move again after 10 seconds when touched by a Hallucination.
int stuncounter=250;
if(stuncounter == 0)
{
enemymovement=1;
}
else if (stuncounter>0)
{
stuncounter--;
}
}
}
//Zergling (an enemy) class
public class Zergling extends Enemy
{
public void act()
{
movement();
eatFood();
}
public void eatFood() //The Sentry dies at a touch with the enemy excepet when the Guardian Shield is activated..
{
if (canSee(Sentry.class) && shield==0)
{
eat (Sentry.class);
Greenfoot.stop();
}
else if (canSee(Hallucination.class)) //Stuns all enemies at a touch with a Hallucination.
{
eat(Hallucination.class);
enemymovement=0;
}
}
//Code you don't need to care about.
}

