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

2015/1/6

HELP

pactz pactz

2015/1/6

#
can someone help me basically i want to make add an enemy so it moves back and forward on tiles, could you please give me your email so i can send you the file or if you could write the code for any actor and ill simply copy it to the greenfoot editor (including what i need to add to the world)... i feel me sending me your email is easier thanks
xFabi xFabi

2015/1/6

#
Can You be a little more Precise? Just move forward and back? Randomly? If yes, in which delay? You can post code here by inserting it between Code and /Code
pactz pactz

2015/1/6

#
*Here's the actor i that i want to move back and forward* import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Alligator here. * * @author (your name) * @version (a version number or a date) */ public class Alligator extends Actor { /** * Act - do whatever the Alligator 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. } } could you add the code for it to do that, also once it make connection with one of the actors called goldenball the goldenball will disappear
xFabi xFabi

2015/1/6

#
Well I'll just pretend u want it to walk forward and back in a certain duration? Use a random number, which you have to figure out for yourself since I don't know how long you want it to move Whenever your number is 0 Turn 180 degrees
Private void walk()
{
   Int pause = x  //<- Pick a number
   Move(y);        // y= move speed
   If(pause>o)
{
   pause--;
}
   else
{
    setRotation(getRotation-180)
    pause = x
}
}

private void touch
{
    Actor a = getOneIntersectingObject(goldenball.class)
    If( a != null)
{
    removeObject(a)
}
}
pactz pactz

2015/1/6

#
I want it to move 3 steps back and forward
xFabi xFabi

2015/1/6

#
afaik there is nothing as "steps", they move pixel by pixel Just try around some numbers for x, to get the desired distance
pactz pactz

2015/1/6

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Alligator here. * * @author (your name) * @version (a version number or a date) */ public class Alligator extends Actor { /** * Act - do whatever the Alligator wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAround(); eat(); } public void moveAround() { move(60); if (Greenfoot.getRandomNumber (100) < 10) { turn(Greenfoot.getRandomNumber(180)-90); } } public void eat() { Actor GoldenBall= getOneObjectAtOffset(0,0,GoldenBall.class); if(GoldenBall !=null) { World world = getWorld(); world.removeObject(GoldenBall); } } } Could you add the part to make the lobster move 60px forward and backwards like you know them super mario games when the shells move back and forward like a gate
You need to login to post a reply.