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

2016/8/7

need help for my school project

1
2
Dayuyu Dayuyu

2016/8/7

#
need help for some coding.... i want to make the game for children 10 - 12 about math.. my game is want the main actor go to the monkey and monkey will give math question.. if the answer right they get point and monkey will disappear.. if the answer wrong they life less.. i still do not know how to make that coding. Hope anyone can help. sorry for my poor english..
christ christ

2016/8/12

#
have you made any code yet?
christ christ

2016/8/12

#
I know how to make the actor and how to make the monkey disappear and you will need to create a score counter for the lives
christ christ

2016/8/12

#
if you any code please post it
christ christ

2016/8/12

#
*how to make the actor move
Super_Hippo Super_Hippo

2016/8/12

#
christ, you can edit your last post instead of posting each sentence in a different post. No one will write you the whole program. Try it on your own and if you need help with a specific thing, ask for help, show your attempt and we can try to help you.
christ christ

2016/8/12

#
ok thanks for letting me know, however it isn't me needing help with the program it is dayuyu
Dayuyu Dayuyu

2016/8/19

#
i have make the codding... for main actor import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Rahmat here. * * @author (your name) * @version (a version number or a date) */ public class Rahmat extends Actor { private int vSpeed = 0; private int acceleration = 2; private int speed = 2; public int totalPisangEat = 0; Life life_field = new Life("Life:" + totalPisangEat); private GreenfootImage kanan = new GreenfootImage ("kanan.png"); private GreenfootImage kanan1 = new GreenfootImage ("kanan1.png"); private GreenfootImage kanan2 = new GreenfootImage ("kanan2.png"); private GreenfootImage kiri = new GreenfootImage ("kiri.png"); private GreenfootImage kiri1 = new GreenfootImage ("kiri1.png"); private GreenfootImage kiri2 = new GreenfootImage ("kiri2.png"); private GreenfootImage dpn = new GreenfootImage ("dpn.png"); private GreenfootImage dpn1 = new GreenfootImage ("dpn1.png"); private GreenfootImage dpn2 = new GreenfootImage ("dpn2.png"); private GreenfootImage blakang = new GreenfootImage ("blakang.png"); private GreenfootImage belakang1 = new GreenfootImage ("belakang1.png"); private GreenfootImage belakang2 = new GreenfootImage ("belakang2.png"); private int frame = 1; /** * Act - do whatever the Rahmat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. checkKey(); makan(); soalan1(); } public void checkKey() { if(Greenfoot.isKeyDown("right")) { moveRight(); } if(Greenfoot.isKeyDown("left")) { moveLeft(); } if(Greenfoot.isKeyDown("up")) { moveUp(); } if(Greenfoot.isKeyDown("down")) { moveDown(); } } public void makan() { Actor Score; Actor Pisang; Pisang = getOneObjectAtOffset(4, 4, Pisang.class); getWorld().addObject(life_field, 90, 30); if (Pisang != null) { World world; world = getWorld() ; world.removeObject(Pisang); totalPisangEat++; life_field.setText("Life: " +totalPisangEat); } /*if(isTouching(Pisang.class)) { removeTouching(Pisang.class); }*/ } public void soalan1() { if(isTouching(Monyet.class)) { Greenfoot.setWorld(new Q()); removeTouching(Monyet.class); } } public void moveRight() { setLocation(getX()+ speed, getY()); animateRight(); } public void moveLeft() { setLocation(getX()- speed, getY()); animateLeft(); } public void moveUp() { setLocation(getX(), getY()- speed); animateUp(); } public void moveDown() { setLocation(getX(), getY()+ speed); animateDown(); } public void animateRight() { if(frame == 1) { setImage(kanan); } else if(frame == 2) { setImage(kanan1); } else if(frame == 3) { setImage(kanan2); frame = 1; } } public void animateLeft() { if(frame == 4) { setImage(kiri); } else if(frame == 5) { setImage(kiri1); } else if(frame == 6) { setImage(kiri2); frame = 1; } } public void animateUp() { if(frame == 7) { setImage(dpn); } else if(frame == 8) { setImage(dpn1); } else if(frame == 9) { setImage(dpn2); frame = 1; } } public void animateDown() { if(frame == 10) { setImage(blakang); } else if(frame == 11) { setImage(belakang1); } else if(frame == 12) { setImage(belakang2); frame = 1; } frame ++; return; } }
Dayuyu Dayuyu

2016/8/19

#
my problem now is after the main actor touching monkey the new world for question will show and after choose the answer main actor will go back to the main platform...but the monkey is still there..how to make the game continue
danpost danpost

2016/8/19

#
You must realize that when the Q world creates a 'new' platform world, it also creates one or more new Monyet and Pisang objects. It also creates a new Rahmat object and places all these actors at their initial locations in the new world. Obviously, a 'new' world is not what you are wanting, here. What you want is to be able to return back to the world that was replaced by the Q world after the Q world has done its thing. In order to do that, the Q world must retain a reference to the previously set world so it can set it active again. Therefore, you need a field to hold that reference in the Q class:
private World lastWorld;
Then, you need a way to accept the reference when creating a Q world object. This means using a parameter in the Q class constructor:
public Q(World world)
Now the value of the parameter can be set to the field within the constructor:
lastWorld = world;
Finally, when creating a Q world object from the Rahmat class, you can use:
new Q(getWorld())
Now that the reference is passed and retained by the Q world object, you can use that reference to return to the same game world:
Greenfoot.setWorld(lastWorld);
Dayuyu Dayuyu

2016/8/19

#
i cannot enter Q world.. main actor codding.. public class Rahmat extends Actor { private int vSpeed = 0; private int acceleration = 2; private int speed = 2; private World lastWorld; public int totalPisangEat = 0; Life life_field = new Life("Life:" + totalPisangEat); private GreenfootImage kanan = new GreenfootImage ("kanan.png"); private GreenfootImage kanan1 = new GreenfootImage ("kanan1.png"); private GreenfootImage kanan2 = new GreenfootImage ("kanan2.png"); private GreenfootImage kiri = new GreenfootImage ("kiri.png"); private GreenfootImage kiri1 = new GreenfootImage ("kiri1.png"); private GreenfootImage kiri2 = new GreenfootImage ("kiri2.png"); private GreenfootImage dpn = new GreenfootImage ("dpn.png"); private GreenfootImage dpn1 = new GreenfootImage ("dpn1.png"); private GreenfootImage dpn2 = new GreenfootImage ("dpn2.png"); private GreenfootImage blakang = new GreenfootImage ("blakang.png"); private GreenfootImage belakang1 = new GreenfootImage ("belakang1.png"); private GreenfootImage belakang2 = new GreenfootImage ("belakang2.png"); private int frame = 1; /** * Act - do whatever the Rahmat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. checkKey(); makan(); soalan1(); } public void checkKey() { if(Greenfoot.isKeyDown("right")) { moveRight(); } if(Greenfoot.isKeyDown("left")) { moveLeft(); } if(Greenfoot.isKeyDown("up")) { moveUp(); } if(Greenfoot.isKeyDown("down")) { moveDown(); } } public void makan() { Actor Score; Actor Pisang; Pisang = getOneObjectAtOffset(4, 4, Pisang.class); getWorld().addObject(life_field, 90, 30); if (Pisang != null) { World world; world = getWorld() ; world.removeObject(Pisang); totalPisangEat++; life_field.setText("Life: " +totalPisangEat); } /*if(isTouching(Pisang.class)) { removeTouching(Pisang.class); }*/ } public void soalan1() { if(isTouching(Monyet.class)) { Greenfoot.setWorld(new Q(getWorld())); removeTouching(Monyet.class); Greenfoot.setWorld(lastWorld); } }
Dayuyu Dayuyu

2016/8/19

#
Q world codding.. public class Q extends World { /** * Constructor for objects of class Q. * */ private World lastWorld; public Q(World world) { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(500, 550, 1); lastWorld = world; prepare(); } private void prepare() { q1 q1 = new q1(); addObject(q1,300,200); q1.setLocation(230,300); a a = new a(); addObject(a,300,200); a.setLocation(80,250); b b = new b(); addObject(b,300,200); b.setLocation(80,350); c c = new c(); addObject(c,300,200); c.setLocation(300,250); d d = new d(); addObject(d,300,200); d.setLocation(300,350); } }
danpost danpost

2016/8/19

#
Dayuyu wrote...
i cannot enter Q world.
That is because you placed the code in gave you in more than one place. The Rahmat class is not supposed to have a 'lastWorld' field and should not be setting a 'lastWorld' world active (only the Q class is supposed to do that).
Dayuyu Dayuyu

2016/8/20

#
now i a bit confuse.. main actor
    public void soalan1()
    {
        if(isTouching(Monyet.class))
        {
            Greenfoot.setWorld(new Q(getWorld()));
            removeTouching(Monyet.class);
        }
    }
Q world
    private World lastWorld;
    public Q(World world)
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(500, 550, 1);
        lastWorld = world();
        prepare();
    }
object Qworld
    private World lastWorld;
    public void act() 
    {
        // Add your action code here.
         if (Greenfoot.mouseClicked(this)) {
         win alert_win = new win();
         getWorld().addObject(alert_win, 370, 300); 
         Greenfoot.delay(100);
         Greenfoot.setWorld(lastWorld);
        }
    }    
}
Dayuyu Dayuyu

2016/8/20

#
at Q world the error is lastworld = world...the word world cannot find symbol..
There are more replies on the next page.
1
2