This site requires JavaScript, please enable it in your browser!
Greenfoot back
Hawx_
Hawx_ wrote ...

2013/5/6

AI

Hawx_ Hawx_

2013/5/6

#
Ok , I've never done this before, but I'd like to make it so an enemy can shoot "plasma"(the 'bullet') at the player when it's facing the player , every so often. Thanks, Hawx
Hawx_ Hawx_

2013/5/7

#
anyone can help?
Kartoffelbrot Kartoffelbrot

2013/5/7

#
The player can save his coordinates into a public static variable, which can be used by the enemy. Maybe you can work with the turnTowards()-method then.
public class Player
{
public static int playerX;
public static int playerY;

public void act()
{
setCoordinates();
//and the whole other things
}

public void setCoordinates()
{
playerX=getX();
playerY=getY();
}
}
and the enemy class:
public class Enemy
{
public void act()
{
turnTowards(Player.playerX,Player.playerY);
shoot();
}
}
Hawx_ Hawx_

2013/5/7

#
I don't have a shoot method for the "DarkPlasma" , I need it to go where the AI fired it too, how do I code that?
Hawx_ Hawx_

2013/5/7

#
thanks
Kartoffelbrot Kartoffelbrot

2013/5/8

#
public void shoot()
{
darkPlasma d = new darkPlasma();
getWorld().addObject(d, getX(), getY());
d.setRotation(getRotation());
d.move(halfLengthOfTheShootingObject);
}
and then write into darkPlasma
public void act()
{
move(speed); //type in how fast the plasma should be
}
You need to login to post a reply.