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

2012/7/6

game paused

Andriyanto Andriyanto

2012/7/6

#
i have class player and i have class book, i want if player take a book then game paused, if i press any key game run again.. can you help me, how i make game pause like above?
Zamoht Zamoht

2012/7/6

#
I don't know what exactly your looking for, but depending on how many moving classes you got, you can add some kind of loop. I don't know your methods, but here is an example: add this out of any method.
1
private int pause = 0;
This is what your act will look like.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public void act()
{
     if (pause == 1)
     {
            if (Greenfoot.isKeyDown("p");
            {
                    pause = 0;
            }
     }
     else if (pause == 0)
     {
           if (/* find book boolean */)
           {
                   pause = 1;
           }
           //add your other act stuff
     }
}
This is one way of doing it, but as I said since I don't know exactly what you're looking for this is the best example I can give you for now.
danpost danpost

2012/7/6

#
Changing worlds will effectively 'pause' the one you are leaving. Just give the new world a reference to the old one, so it can 'Greenfoot.setWorld(oldWorld);' back to it (to un-pause it). See my Crayon Babies: a World-changing Demo scenario. In your case, you could show the open book with a instruction at the bottom of the window to 'press any key to continue', and wait for 'Greenfoot.getKey() != null' to return.
Andriyanto Andriyanto

2012/7/6

#
zamoht : ok i try.. I like when players pick up the book and the book gives a lesson then the game stops, when the user has read the game starts again.
Andriyanto Andriyanto

2012/7/6

#
danpost.. thanks.. I have tried but have to press a specific keyboard button to pause the game when what I want when the player gets the book and then pause the game.
danpost danpost

2012/7/6

#
I do not know what code you have for 'player.getBook()' or whatever; but, if you set up a boolean in the player class, call it 'hasPaused', and also a String to hold the name of the book taken, call it 'takenBook', initially set to an empty string; and set 'hasPaused' to 'false' and 'takenBook' to the name of the book taken in the 'getBook()' method (or whatever) and then use:
1
2
3
4
5
if (!hasPaused && !"".equals(takenBook))
{
    hasPaused = true;
    setWorld(new BookWorld(takenBook, nameOfWorld))
}
Where 'nameOfWorld' is the world you are leaving (the sub-class of World that was currently running).
Andriyanto Andriyanto

2012/7/8

#
i want when sholeh find book then show text and game pause, if was read text i press any key game running again.. this is my code for class book : import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class book here. * * @author (your name) * @version (a version number or a date) */ public class book extends item { boolean bpickedup = false; boolean bremoved = false; private myWorld mworld; public void addedToWorld(World world) { mworld = (myWorld) world; } public void act() { if (bremoved) {return;} findsholeh(); picked(); } //act private void findsholeh() { if (bpickedup) { return; }//if its already picked up then dont bother sholeh neb = (sholeh) getOneIntersectingObject(sholeh.class); if (neb != null) { Greenfoot.playSound("keycollect.wav"); bpickedup = true; if (mworld.currentLevel == 4){ mworld.addObject(new Text("aqidah-rukuniman",250, 13f),372,212);} if (mworld.currentLevel == 5){ mworld.addObject(new Text("aqidah-asmaulhusna",250, 13f),217,325); } if (mworld.currentLevel == 6){ mworld.addObject(new Text("aqidah-hariakhir",250, 13f),141,304); } if (mworld.currentLevel == 21){ mworld.addObject(new Text("fikih-rukunislam",250, 13f),141,304); } if (mworld.currentLevel == 22){ mworld.addObject(new Text("fikih-berwudhu",250, 13f),141,304); } if (mworld.currentLevel == 23){ mworld.addObject(new Text("fikih-zakat",250, 13f),141,304); } } }//findsholeh private void destroy() { if (bremoved) {return;} bremoved = true; getWorld().removeObject(this); }//destroy private void picked() { if (!bpickedup) {return;} int px =(int) ( getX()+ ((mworld.sholehx - getX()) *0.05f)); int py = (int)( getY()+ ((mworld.sholehy - getY()) *0.05f)); setLocation(px, py); destroy(); } }
You need to login to post a reply.