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

2023/2/28

how do you have an actor shoot if and only if another actor is on screen

envxity envxity

2023/2/28

#
in this scenerio actor 1 is the player that can be controlled but then their are "enemies" which is actor 2 how do i make it fire "bullets" which i already have programmed in, only when another actor is on the scenerio. another question i have is about how to make a game that has different worlds that the character can travel to since in making a game that kinda like a rouge like. something else im curious about is how to make soemthing drop gold and exp and depending on the enemy affects how much gold they drop.
danpost danpost

2023/3/1

#
envxity wrote...
in this scenerio actor 1 is the player that can be controlled but then their are "enemies" which is actor 2 how do i make it fire "bullets" which i already have programmed in, only when another actor is on the scenerio.
To check if a type of actor is in the world, use the following (change the class type as needed to specify the type of actor):
if ( ! getWorld().getObjects(Actor.class).isEmpty() )
how to make a game that has different worlds that the character can travel to since in making a game that kinda like a rouge like.
You can pass the player from world to world or you can retain the player in a static field so it can be accessed from any world.
how to make soemthing drop gold and exp and depending on the enemy affects how much gold they drop.
You can use:
getWorld().addObject(new Gold(), getX(), getY());
to "drop" gold (or whatever, creating other type objects). As far as how much, you will need to be more specific as to what you want.
envxity envxity

2023/3/1

#
thanks danpost by more for example basic enemy drops 1 gold, mid teir enemy drops 2 gold, and advanced tier enemy drops 3 gold ect. something like that
danpost danpost

2023/3/2

#
envxity wrote...
by more for example basic enemy drops 1 gold, mid teir enemy drops 2 gold, and advanced tier enemy drops 3 gold ect. something like that
A simple int field can be used to hold how many each drops. A value can be passed to the constructor of the class, where the field can be set to that value. For example:
import greenfoot.*;

public class Enemy extends Actor
{
    private int tier;
    
    public Enemy(int level)
    {
       tier = level;
    // etc.
Then you can create the specific enemies with new Enemy(1), new Enemy(2) or new Enemy(3). The value is then used to determine how much gold is dropped.
envxity envxity

2023/3/2

#
thx man
envxity envxity

2023/3/2

#
1 last question is it possible to make the bullet fire to the enemy as well?
danpost danpost

2023/3/2

#
envxity wrote...
1 last question is it possible to make the bullet fire to the enemy as well?
What mechanism do you want for aiming and triggering?
You need to login to post a reply.