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

2014/1/10

limit my actors movement

4
5
6
7
Aaron91 Aaron91

2014/1/20

#
Yeaaaaa.. it was a attempt to........ the replacing the actor part of my game is still confusing for me.. i placed the getShield method in my 'boot' actor now, but how can i replace the 'boot' actor with the 'UpgradeBoot' actor? i tried with the if statement in the world, but the only thing that it USED to did was place the 'upgradeBoot' actor on the given coordinates with the 'boot' actor still in play.
danpost danpost

2014/1/20

#
If you are going to use two separate actors, you cannot place all the code in one place. Also, if using two actors, there is no need for the boolean or the method. When the upgrade is purchased (in the MenuWorld world actor object clicked on, where the purchase actually takes place, do the following: (1) subtract purchase price from score (2) add the UpgradeBoot object at the location the boot object is at (3) remove the boot object from the world In the UpgradeBoot class, use an int field as a timer and increment it in its act method, checking for a specified value (approximately sixty times the number of seconds in the life of the upgrade). When that value is reached (still in the act method of the UpgradeBoot class): (1) add a new boot object at its location (2) remove itself
Aaron91 Aaron91

2014/1/20

#
I got the score substracting part done. Iam not sure what you mean with
(2) add the UpgradeBoot object at the location the boot object is at
he add/remove part of the actor is killing me at the moment. I just seem to get that part done. Or the game stops when i open the 'MenuWorld' or there isnt a actor appearing or being removed at all. And i assume you're talking about doing this in the UpgradeBoot actor right?
danpost danpost

2014/1/20

#
The 3-step process is all done at the same place. If you already got (1) done, then (2) and (3) should be placed immediately after where (1) was done. With (2) use the World class method 'addObject' to add a new UpradeBoot object at the location where the boot object is currently at. With (3) use the World class method 'removeObject' to remove the boot object. Steps (2) and (3) together are what replace the boot object with an UpgradeBoot object.
Aaron91 Aaron91

2014/1/20

#
Thanks for that explanation. I got this now. The problem this time is that even though the UpgradeBoot appears, my current playable actor 'boot' wont go away and the UpgradeBoot isnt playable. If its needed to know, i called the boot actor in my world with the addObject(boot,350,600);.
    public void updateScore()
    {
        if(RestoreHeart.aftrek)
        {
            score -= 200;
            RestoreHeart.aftrek = false;
        }
        if(Shield.aftrek)
        {
            
            score -= 100;
            Shield.aftrek = false;
            Actor boot = getOneObjectAtOffset(0,0,boot.class);
            UpgradeBoot upgradeShip = new UpgradeBoot();  
            getWorld().addObject(upgradeShip,350,600);
            getWorld().removeObject(boot);
        }
        if (initialTime == 0) initialTime = System.currentTimeMillis();
        if(System.currentTimeMillis() >= initialTime + 10000)  
        {

            score += 100;
            if(score != 1)
            {
                initialTime = 0;
            }
        }

    }
Super_Hippo Super_Hippo

2014/1/20

#
Replace line 16 with 'getWorld().removeObject(this);'. With getOneObjectAtOffset(...) you will never get your current class. By the way, in line 23: 'if(score != 1)'. Is this as you wish? Because you have a += 100 right in front of it and -= 100/200 earlier. '1' seems to be an unreachable number.
Aaron91 Aaron91

2014/1/20

#
Hey supperhippo .. Yea the if statement on line 23 is what i wanted. Its just something temporarly. But i should inform you that this is happening in my Score Actor. I need to let my main actor 'boot' be removed and let actor 'UpgradeBoot' replace it from within this actor. So i changed the removeObject line to getWorld().removeObject(boot); But this actor wont go away + the UpgradeBoot actor isnt playable. The UpgradeBoot actor appears though, but thats about it.
Super_Hippo Super_Hippo

2014/1/20

#
Why do you want to do this in the Score actor? Do you really need to create a new actor when it gets a shield? Do you have any code in your UpgradeBoot class?
Aaron91 Aaron91

2014/1/20

#
I did this in my score cause danpost suggested it cause i used 2 actors for this and i needed to place the 'replace' code at the moment i charged my score to call the 'UpgradeBoot' actor to replace my current 'boot' actor.. to be honest.. i have no clue why i did this, i thought every new image needed to be a new actor. But the deadline is tonight so not going to change to much right now. The actor is empty for now, so i could easily remove it if that would speed up things.
Super_Hippo Super_Hippo

2014/1/20

#
If the class is empty, it is not a wonder that you can not move it. In fact, it would have almost exactly the same cade as the normal Boot class. I think it would be easier to just have one instead of having two actor which are almost doing the same.
Aaron91 Aaron91

2014/1/20

#
-_-' makes sense yeah.. my bad there........ But how would i .. if i lets say call this UpgradeBoot, let my 'boot' actor be removed from the game? cause when i call this 'UpgradeBoot' actor, the 'boot' actor is still around aswell..
Super_Hippo Super_Hippo

2014/1/20

#
There are many possibilities.
getWorld().removeObjects(getObjects(Boot.class));
Well, not tested, could be wrong. If you only have one object of the boot class, you can also have a static boolean in the boot class (for example 'public static boolean kill = false;') and have this at the end of the act() method:
if(kill) getWorld().removeObject(this);
To remove the object from the world from a method in any other actor, you just use 'Boot.kill = true' then. But... seriously you don't need to have two actors to represent one. It is much easier with one. Just change the image of the actor when it activates the upgrade:
setImage( new GreenfootImage(/* the name of the image located in the images folder with .png or something similar. Everything in "" */));
You can use a boolean, too. But as danpost pointed out, it is enough to set a timer. By the way, what exactly does 'System.currentTimeMillis()' return? The time how long the scenario was run or the real time? Because if it would be the real time, it would also increase if you pause the scenario. That's why I do not really see the use of it. Well, good luck with your project, hopefully you can finish it soon enough! Good night.
danpost danpost

2014/1/20

#
@Super_Hippo, and all others, 'System.currentTimeMillis()' does return the real time (system time) and increases regardless of the state of your scenario.
You need to login to post a reply.
4
5
6
7