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

2015/1/7

Can anyone help me, I'm trying to make the lobster move forward and back like the shells in super mario games

pactz pactz

2015/1/7

#
***could someone edit the movement so that the lobster moves foward and back at 60 px *** import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class GoldenBall here. * * @author (your name) * @version (a version number or a date) */ public class Lobster extends Actor { /** * Act - do whatever the GoldenBall wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkGoldenBall(); walk(); } public boolean canMove(int x, int y) { Actor sand; sand=getOneObjectAtOffset(x,y,sandroad.class); //the section below checks if there is a block you can move to // if there is it sets sand to a vlaue otherwise it says null // The errors are in this section boolean flag=false; if (sand !=null) { flag=true; } return flag; } /** * Check if Lobster eats the ball */ private void checkGoldenBall() { Actor GoldenBall= getOneIntersectingObject(GoldenBall.class); if (GoldenBall !=null ) { getWorld().removeObject(GoldenBall); } } /** * Make the lobster move */ private void walk() { Int pause= 60; move(60); If(pause>0); { pause--; } { setRotation(getRotation-180); pause= 60 } } }
xFabi xFabi

2015/1/7

#
One thread is enough bro. You Only have To play around with the pause value, And see How far it goes
danpost danpost

2015/1/8

#
The 'pause' variable needs to be declared outside the method for its value to be retained between act cycles. Changing your 'walk' method to the following might help (I renamed the 'pause' field to 'steps' since it is more appropriate):
private int steps;

private void walk()
{
    move(1);
    steps++;
    if (steps == 60)
    {
        turn(180);
        steps = 0;
    }
}
pactz pactz

2015/1/9

#
Thanks
You need to login to post a reply.