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

2018/12/26

Game Creation: Directional Idle, Shooting and Jumping.

6
7
8
9
10
Unlimited Unlimited

2019/1/1

#
No thats what im asking i do not know how to check where the player character is. I want him to only start acting once the player character is within a certain range (but preferablly only once at the beginning so you cannot just walk out of his range) nor how to check where the character is in comparison if the enemy keeps on moving back on forth. Thats what i dont know.
danpost danpost

2019/1/1

#
Unlimited wrote...
No thats what im asking i do not know how to check where the player character is. I want him to only start acting once the player character is within a certain range (but preferablly only once at the beginning so you cannot just walk out of his range) nor how to check where the character is in comparison if the enemy keeps on moving back on forth. Thats what i dont know.
You can use a condition like:
if (!getObjectsInRange(200, Azure.class).isEmpty())
to determine when it the player comes into proximity of the enemy. Since you want it that once the enemy detects a player, the player is then "tagged" for that enemy, use a Actor reference field to have an enemy "lock" in on the player:
private Actor azure; // = null, by default
Then only call the above condition if player is not yet locked in:
if (azure == null)
{
    if (!getObjectsInRange(200, Azure.class).isEmpty()) azure = getObjectsInRange(200, Azure.class).get(0);
}
else if (shooting()) // a boolean method you need to include that runs the shot timer and returns true when time to shoot
{
    int playerX = azure.getX();
    int playerY = azure.getY();
    // add shot to world and turn it toward the actor
}
Unlimited Unlimited

2019/1/2

#
This code
int playerX = azure.getX();
    int playerY = azure.getY();
This is what determines where the character is in comparison? Do i have to add any other perameter for this to work or is that everything?
Unlimited Unlimited

2019/1/2

#
What do i need to write so he uses the animation that is in the direction of the player character?
danpost danpost

2019/1/2

#
Unlimited wrote...
This code << Code Omitted >> This is what determines where the character is in comparison? Do i have to add any other perameter for this to work or is that everything?
No. That just gets the player's current location coordinates. Either they will need to be compared to the coordinates of the enemy's location or an angle can be calculated between the two location. Then, you can determine which animation to use.
Unlimited Unlimited

2019/1/2

#
And how do i do that?
danpost danpost

2019/1/2

#
Unlimited wrote...
And how do i do that?
The difference between the two x-coordinate values will give you the left/right relationship and that between the y-coordinates will give you the up/down relationship.
Unlimited Unlimited

2019/1/2

#
Well yeah but i dont know how to check for the character. I dont know how to write it.
danpost danpost

2019/1/2

#
Unlimited wrote...
Well yeah but i dont know how to check for the character. I dont know how to write it.
Then write it in pseudo-code. Create a step-by-step list of what you would need to do and then post it here (I do not have time to write code for you right now and probably shouldn't be writing code for you at all). You write, I help guide and fix code. That is the way it should be.
Unlimited Unlimited

2019/1/2

#
Something like this?
public void checkPlayer()
    {
        if(Azure == null)
        {
            if (!getObjectsInRange(200, Azure.class).isEmpty()) Azure = getObjectsInRange(200, Azure.class).get(0);
        }
        else if (shooting() == true) 
        {
            int playerX = Azure.getX();
            int playerY = Azure.getY();
                if(Azure.getX()<0 && animSet != shootAnim) setAnim(shootAnim, 2);
                else if (Azure.getX()>0 && animSet != shootAnim) setAnim(shootAnim, 2);
        }
    }
Unlimited Unlimited

2019/1/2

#
no?
danpost danpost

2019/1/2

#
Unlimited wrote...
Something like this? << Code Omitted >>
First off, you should start your variables with lower case letters. You have an Azure class and you do not want to confuse that with the Azure object created from the class. Secondly, "Azure.getX()" does not by itself give any type of relationship as far as the positions of the two actors (two actors require two sets of coordinates). Finally, your "if / if-else" statement seems to be equivalent to the following:
if (Azure.getX() != 0 && animSet != shootAnim) setAnim(shootAnim, 2);
which says as long as the actor is not at the right edge of the world and currently not shooting, then shoot. The is nothing special about the actor being at the left edge of the world (is there?).
Unlimited Unlimited

2019/1/2

#
Oh yes you right i forgot to change the second one to left its the same animation. So how do i define the difference between the two?
int playerX = Azure.getX();
            int playerY = Azure.getY();
                if((Azure actor.getX())<(Vile actor getX()) && animSet != shootAnim) setAnim(shootAnim, 2);
                else if ((Azure actor.getX())>(Vile actor getX()) && animSet != shootLeftAnim) setAnim(shootLeftAnim, 2);
        }
    }
Do you mean something like this? Because i really dont know anymore.
danpost danpost

2019/1/2

#
Unlimited wrote...
Oh yes you right i forgot to change the second one to left its the same animation. So how do i define the difference between the two? << Code Omitted >> Do you mean something like this? Because i really dont know anymore.
If that is in pseudo-code, it is more like what you want. Although, once you define playerX, you do not need to use getX on the Azure object anymore. The playerY variable is not needed. I just showed that to show another example of getting a coordinate value from the player.
Unlimited Unlimited

2019/1/3

#
So to get that to work i need to remove PlayerY and the getX() after Azure actor and Vile actor. Is that correct?
There are more replies on the next page.
6
7
8
9
10