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

2019/5/8

Getting an action in one class to interact with another class

Thomasthedood Thomasthedood

2019/5/8

#
Hey! sorry i'm new to greenfoot but i am working on a game in which i have two actors who should have the ability to attack each other. the player's attack is manual and uses an animated gif and the AI should use an attack gif within a certain radius of the player. But i dont know how to get them to interact
ErasedBlade ErasedBlade

2019/5/8

#
this is how i did it i have the bullet's as seperate actors from the origional and they spawn in with a key beying pressed(player) and the other being spawned at a random chance, lets call the enemy Enimy andthe bullet Bullet then since i want them to hit the bullet to hit the other actor I use in the method you want in my case damage
{
Enemy enemy = (Enemy) getOneIntersectingObject(Enemy.class)
 if (enemy != null)
{
enemy. //Method you want to call
}
}
this says if there is an enemy, then whatever method you add happens otherwise it will nt you could also use other peramiters for the if statement.
Thomasthedood Thomasthedood

2019/5/8

#
Thank you for responding quickly. I am aware of the collision methods with objects but my problem is that my characters use melee attacks, when the space bar is pushed, the animation plays, i want it so that whenever this animation plays, the player will eliminate his foe.
Super_Hippo Super_Hippo

2019/5/9

#
You could check which image is shown right now. If it is one specific image (or even if it is playing the animation at all), check if the actor is intersecting the opponent.
You need to login to post a reply.