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

2016/3/12

Methods

Freekywill Freekywill

2016/3/12

#
I am currently making a tower defense game and would like a minimap to keep track of all the enemies. This is because enemies and other things can be off the side of the screen. I keep track of where they are by the following
if((getObjectsAtOffset(50, 0, null).size() == 0)) 
                {
                    xOffset += 1;
                }
                else
                {
                    for(int i = 0; i < ((getObjectsAtOffset(50, 0, null).size())); i++)
                    {
                        if ((getObjectsAtOffset(50, 0, null).get(i) instanceof Wall)) count++;                            
                    }
                    if(count == 0) xOffset += 2;
                    count = 0;                     
                    timer = 0;
                }
setLocation(xOffset + Var.xPos, yOffset + Var.yPos);
This checks what is in front of the enemy, then determines if it can move or not. The easiest way to explain is that xOffset is where the object thinks the master point if the game is, then it adds that to xPos. xPos and yPos are what changes when you move around, since the player always stays in the middle. How would I create a minimap with moving red dots that symbolize enemies?
Super_Hippo Super_Hippo

2016/3/12

#
The code given does not really "keep track of where the enemies are". You can implement a minimap like that: Whenever you create an enemy, you create a dot. When the enemy moves, the dot moves as well. (Just less of course because the minimap is smaller.) If the minimap is on the bottom left corner with a size of 50x50, it could look like this:
private Dot myDot = new Dot();

public addedToWorld(World w)
{
    w.addObject(myDot, getX()/50, w.getHeight()-50+getY()/50);
}

public void moving(int x)
{
    move(x);
    myDot.setLocation(getX()/50, w.getHeight()-50+getY()/50);
}
Another way could be to find every enemy every act-cycle and draw a dot for every enemy on an image and draw this image on the background or use it as the image of a minimap class. But I don't know if that would be more effective.
Freekywill Freekywill

2016/3/12

#
I will try this, but I dont think it will work because my game is a scroller. That means you can move off to the side and more things will show up. That is what I mean by "keep track of where they are". But I will try this regardless
Super_Hippo Super_Hippo

2016/3/13

#
Well, that means that objects which are outside the bottom or left edge would not show up. But I think you can still make this work if you adjust the numbers.
danpost danpost

2016/3/13

#
A mini-map should be an Actor object created by a subclass of Actor. It can update itself depending on the current state of the World object it is located in. Its behavior (code in its act method; or, its updating) can be defined for the specific type world you will be placing it in.
You need to login to post a reply.