Erio wrote...
well, here is my code for wall collision:
< Code Omitted >
public void checkCollision()
{
if (getOneIntersectingObject(Wall.class) != null)
{
turn(180);
move(3);
}
else
{
followHuman();
}
}
I tried making my Zombie to move and turn when they collide with a wall, but they seem to be confused because I have a follow method where they turn towards the Human and move towards it. Can you make me a code that if there is collision they move and turn else they go back to following human? I'm not really sure on how to make a code for that.
public void checkCollision()
{
if (getOneIntersectingObject(Wall.class) != null)
{
turn(180);
move(3);
wallCounter = 15;
}
else
{
if (wallCounter == 0) {
followHuman();
}
else {
move(3);
}
}
}
public void detectWall()
{
Game game = (Game)getWorld();
WallCounter wallCounter = game.getWallCounter();
if (getOneIntersectingObject(Wall.class) != null)
{
wallCounter.setWall(15);
}
else
{
wallCounter.setWall(0);
}
}
public void Collision()
{
Game game = (Game)getWorld();
WallCounter wallCounter = game.getWallCounter();
if (wallCounter.getWall() == 15)
{
turn(180);
move(3);
}
else
{
if (wallCounter.getWall() == 0)
{
followHuman();
}
else {
move(3);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class WallCounter extends Actor
{
int wall = 0;
public WallCounter()
{
}
/**
* Create a new counter, initialised to 0.
*/
public void act()
{
}
public void add(int value)
{
wall+=value;
}
public void subtract()
{
wall--;
}
public int getWall()
{
return wall;
}
public void setWall(int newWall)
{
wall = newWall;
}
}
WallCounter wallCounter = game.getWallCounter();
private int wallCounter = 0;
public void checkCollision()
{
if (getOneIntersectingObject(Wall.class) != null)
{
turn(180);
move(3);
wallCounter = 15;
}
else
{
if (wallCounter == 0) {
followHuman();
}
else {
move(3);
wallCounter--; // I missed this last time
}
}
}
Greenfoot.getRandomNumber(180) + 90