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

2018/3/8

spawning arrows

doglover555 doglover555

2018/3/8

#
If I'm doing a dane dance revolution type game, how to I make the 4 types of arrows (one up, one down, one right, one left) randomly spawn in (same time interval) into 1 of 4 "alleys" (1 alley for up arrows, 1 alley for down arrows, etc.)? I have an Arrow class and then 4 subclasses of Arrow (Up, Down, Right, Left).
Super_Hippo Super_Hippo

2018/3/8

#
Just have one arrow class without subclasses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private int type;
 
public Arrow(int t)
{
    type = t;
    //set image based on type
}
 
public void act()
{
    //do something
}
 
public int getType()
{
    return type;
}
1
2
3
4
5
6
7
8
9
10
11
12
//in world subclass
private int spawnTimer = 100, spawnTimeMax = spawnTimer;
 
public void act()
{
    if (--spawnTimer == 0)
    {
        spawnTimer = spawnTimerMax;
        int rand = Greenfoot.getRandomNumber(4);
        addObject(new Arrow(rand), 100+rand*50, 0);
    }
}
As a start.
danpost danpost

2018/3/8

#
I agree that only one subclass for the arrows is the way to go. I also believe you should have actors for the pads (again, using only one subclass of Actor). The rotation of a pad can be given to any arrow that approaches it and the arrows can be placed into the world at the location of its pad and immediately moved to the other end of the alley so it can begin its approach.
You need to login to post a reply.